// File: /workspace/github_c_makefile_star2_O1/aquaxis[P]synverll/src/synverll.c
// Function: process
int process(char *csource)
{
    FILE *fp;
    int function_count;
	char *filename;
	int i;

	/*
	 * Cソースコードを分離する
	 */
	function_count = split_c_source(csource);

	/*
	 * 解析
	 * ToDo:
	 *   最初にグローバルメモリを解析し、アドレスを確定しておく
	 */
	for(i = 0; i < function_count; i++){
		filename = malloc(STR_MAX);
		sprintf(filename, "%03d", i);
		process_function(filename);	// 関数の解析
		free(filename);
	}

#if 0
	// モジュールツリーの表示
	filename = malloc(STR_MAX);
	sprintf(filename, "module_list.txt");

//	printf(" -> Open file: %s\n", filename);
	if((fp = fopen(filename,"w+")) == NULL){
		printf("can't open file.\n");
		free(filename);
		exit(1);
	}
	print_module_tree(fp);
	fclose(fp);
#endif

	// メモリマップ出力
	filename = malloc(STR_MAX);
	sprintf(filename, "memory_map.txt");

//	printf(" -> Open file: %s\n", filename);
	if((fp = fopen(filename,"w+")) == NULL){
		printf("can't open file.\n");
		free(filename);
		exit(1);
	}
	print_memmap_tree(fp);			// メモリマップの出力
	fclose(fp);
	clean_memmap_tree();			// メモリマップの削除

	// 最上位モジュールの生成
	create_top_module();
	create_top_assign();

	sprintf(filename, "%s.v", topname);
	if((fp = fopen(filename,"w+")) == NULL){
		printf("can't open file.\n");
		exit(1);
	}
	output_top_module(fp, topname);
	fclose(fp);

	for(i = 0; i < function_count; i++){
		sprintf(filename, "__%03d.c", i);
		remove(filename);
		sprintf(filename, "__%03d.ll", i);
		remove(filename);
	}

	remove("__extern.c");
	remove("__extern.h");

	free(filename);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
callq 0xbe58
movl %eax, %ebx
testl %eax, %eax
jle 0xc1d3
leaq 0x3f05(%rip), %r14      # 0x100a4
xorl %ebp, %ebp
movl $0x400, %edi            # imm = 0x400
callq 0x1140
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11b0
movq %r15, %rdi
callq 0xbf0b
movq %r15, %rdi
callq 0x1030
incl %ebp
cmpl %ebp, %ebx
jne 0xc1a1
movl $0x400, %edi            # imm = 0x400
callq 0x1140
movq %rax, %r14
movabsq $0x6d5f79726f6d656d, %rax # imm = 0x6D5F79726F6D656D
movq %rax, (%r14)
movabsq $0x7478742e70616d, %rax # imm = 0x7478742E70616D
movq %rax, 0x7(%r14)
leaq 0x3eb6(%rip), %rsi      # 0x100b8
movq %r14, %rdi
callq 0x1170
testq %rax, %rax
je 0xc2f8
movq %rax, %r15
movq %rax, %rdi
callq 0x57ed
movq %r15, %rdi
callq 0x1080
xorl %eax, %eax
callq 0x5580
xorl %eax, %eax
callq 0xab76
xorl %eax, %eax
callq 0xa4dc
movq 0x83ae(%rip), %rdx      # 0x145f0
leaq 0x3e4f(%rip), %rsi      # 0x10098
movq %r14, %rdi
xorl %eax, %eax
callq 0x11b0
leaq 0x3e5e(%rip), %rsi      # 0x100b8
movq %r14, %rdi
callq 0x1170
testq %rax, %rax
je 0xc30e
movq %rax, %r15
movq 0x837b(%rip), %rsi      # 0x145f0
movq %rax, %rdi
callq 0xb82f
movq %r15, %rdi
callq 0x1080
testl %ebx, %ebx
jle 0xc2cd
leaq 0x3df4(%rip), %r15      # 0x10084
leaq 0x3e24(%rip), %r12      # 0x100bb
xorl %ebp, %ebp
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11b0
movq %r14, %rdi
callq 0x1050
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11b0
movq %r14, %rdi
callq 0x1050
incl %ebp
cmpl %ebp, %ebx
jne 0xc299
leaq 0x3df1(%rip), %rdi      # 0x100c5
callq 0x1050
leaq 0x3df0(%rip), %rdi      # 0x100d0
callq 0x1050
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e5b(%rip), %rdi      # 0x1015a
callq 0x1070
movq %r14, %rdi
callq 0x1030
jmp 0xc31a
leaq 0x3e45(%rip), %rdi      # 0x1015a
callq 0x1070
movl $0x1, %edi
callq 0x11c0