// File: /workspace/github_c_makefile_star2_O2/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 0xb7c0
movl %eax, %ebx
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
leaq 0x3569(%rip), %r15      # 0xf078
xorl %ebp, %ebp
movl $0x400, %edi            # imm = 0x400
callq 0x1130
movq %rax, %r14
cmpl %ebp, %ebx
je 0xbb45
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11a0
movq %r14, %rdi
callq 0xb87c
movq %r14, %rdi
callq 0x1030
incl %ebp
jmp 0xbb11
movabsq $0x7478742e70616d, %rax # imm = 0x7478742E70616D
movq %rax, 0x7(%r14)
movabsq $0x6d5f79726f6d656d, %rax # imm = 0x6D5F79726F6D656D
movq %rax, (%r14)
leaq 0x3525(%rip), %rsi      # 0xf08c
movq %r14, %rdi
callq 0x1160
testq %rax, %rax
je 0xbc5b
movq %rax, %r15
movq %rax, %rdi
callq 0x549e
movq %r15, %rdi
callq 0x1080
xorl %eax, %eax
callq 0x525c
xorl %eax, %eax
callq 0xa5f7
xorl %eax, %eax
callq 0x9f6a
movq 0x7a39(%rip), %rdx      # 0x135e0
leaq 0x34be(%rip), %rsi      # 0xf06c
movq %r14, %rdi
xorl %eax, %eax
callq 0x11a0
leaq 0x34cd(%rip), %rsi      # 0xf08c
movq %r14, %rdi
callq 0x1160
testq %rax, %rax
je 0xbc71
movq %rax, %r15
movq 0x7a06(%rip), %rsi      # 0x135e0
movq %rax, %rdi
callq 0xb248
movq %r15, %rdi
callq 0x1080
leaq 0x3467(%rip), %r15      # 0xf058
leaq 0x3497(%rip), %r12      # 0xf08f
xorl %ebp, %ebp
cmpl %ebp, %ebx
je 0xbc30
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
jmp 0xbbfa
leaq 0x3462(%rip), %rdi      # 0xf099
callq 0x1050
leaq 0x3461(%rip), %rdi      # 0xf0a4
callq 0x1050
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x34c9(%rip), %rdi      # 0xf12b
callq 0x1070
movq %r14, %rdi
callq 0x1030
jmp 0xbc7d
leaq 0x34b3(%rip), %rdi      # 0xf12b
callq 0x1070
pushq $0x1
popq %rdi
callq 0x11b0