// File: /workspace/github_c_makefile_star2_O3/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 0xbd54
movl %eax, %ebx
testl %eax, %eax
jle 0xc0cf
leaq 0x3ffd(%rip), %r14      # 0x10098
xorl %ebp, %ebp
movl $0x400, %edi            # imm = 0x400
callq 0x1130
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11a0
movq %r15, %rdi
callq 0xbe07
movq %r15, %rdi
callq 0x1030
incl %ebp
cmpl %ebp, %ebx
jne 0xc09d
movl $0x400, %edi            # imm = 0x400
callq 0x1130
movq %rax, %r14
movabsq $0x6d5f79726f6d656d, %rax # imm = 0x6D5F79726F6D656D
movq %rax, (%r14)
movabsq $0x7478742e70616d, %rax # imm = 0x7478742E70616D
movq %rax, 0x7(%r14)
leaq 0x3fae(%rip), %rsi      # 0x100ac
movq %r14, %rdi
callq 0x1160
testq %rax, %rax
je 0xc1f4
movq %rax, %r15
movq %rax, %rdi
callq 0x56f6
movq %r15, %rdi
callq 0x1080
xorl %eax, %eax
callq 0x5494
xorl %eax, %eax
callq 0xaa7a
xorl %eax, %eax
callq 0xa3e0
movq 0x84a2(%rip), %rdx      # 0x145e0
leaq 0x3f47(%rip), %rsi      # 0x1008c
movq %r14, %rdi
xorl %eax, %eax
callq 0x11a0
leaq 0x3f56(%rip), %rsi      # 0x100ac
movq %r14, %rdi
callq 0x1160
testq %rax, %rax
je 0xc20a
movq %rax, %r15
movq 0x846f(%rip), %rsi      # 0x145e0
movq %rax, %rdi
callq 0xb733
movq %r15, %rdi
callq 0x1080
testl %ebx, %ebx
jle 0xc1c9
leaq 0x3eec(%rip), %r15      # 0x10078
leaq 0x3f1c(%rip), %r12      # 0x100af
xorl %ebp, %ebp
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11a0
movq %r14, %rdi
callq 0x1050
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11a0
movq %r14, %rdi
callq 0x1050
incl %ebp
cmpl %ebp, %ebx
jne 0xc195
leaq 0x3ee9(%rip), %rdi      # 0x100b9
callq 0x1050
leaq 0x3ee8(%rip), %rdi      # 0x100c4
callq 0x1050
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f50(%rip), %rdi      # 0x1014b
callq 0x1070
movq %r14, %rdi
callq 0x1030
jmp 0xc216
leaq 0x3f3a(%rip), %rdi      # 0x1014b
callq 0x1070
movl $0x1, %edi
callq 0x11b0