// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x105a0
movl %eax, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x10a87
movl $0x400, %edi            # imm = 0x400
callq 0x1100
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x4682(%rip), %rsi      # 0x150e5
movb $0x0, %al
callq 0x1160
movq -0x20(%rbp), %rdi
callq 0x10670
movq -0x20(%rbp), %rdi
callq 0x1030
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x10a3f
movl $0x400, %edi            # imm = 0x400
callq 0x1100
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x464a(%rip), %rsi      # 0x150ea
movb $0x0, %al
callq 0x1160
movq -0x20(%rbp), %rdi
leaq 0x4647(%rip), %rsi      # 0x150f9
callq 0x1120
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x10ae2
leaq 0x45ff(%rip), %rdi      # 0x150c7
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1170
movq -0x10(%rbp), %rdi
callq 0x7a90
movq -0x10(%rbp), %rdi
callq 0x1060
movb $0x0, %al
callq 0x7710
movb $0x0, %al
callq 0xede0
movb $0x0, %al
callq 0xe3d0
movq -0x20(%rbp), %rdi
movq 0x7aac(%rip), %rdx      # 0x185c0
leaq 0x45be(%rip), %rsi      # 0x150d9
movb $0x0, %al
callq 0x1160
movq -0x20(%rbp), %rdi
leaq 0x45cc(%rip), %rsi      # 0x150f9
callq 0x1120
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x10b54
leaq 0x4584(%rip), %rdi      # 0x150c7
movb $0x0, %al
callq 0x1090
movl $0x1, %edi
callq 0x1170
movq -0x10(%rbp), %rdi
movq 0x7a61(%rip), %rsi      # 0x185c0
callq 0xff80
movq -0x10(%rbp), %rdi
callq 0x1060
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x10bc3
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x4508(%rip), %rsi      # 0x15092
movb $0x0, %al
callq 0x1160
movq -0x20(%rbp), %rdi
callq 0x1040
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x4554(%rip), %rsi      # 0x150fc
movb $0x0, %al
callq 0x1160
movq -0x20(%rbp), %rdi
callq 0x1040
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x10b74
leaq 0x453c(%rip), %rdi      # 0x15106
callq 0x1040
leaq 0x453b(%rip), %rdi      # 0x15111
callq 0x1040
movq -0x20(%rbp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)