// File: /workspace/github_c_makefile_star2_O3/aquaxis[P]synverll/src/parser_ir_proc.c
// Function: output_proc_tree
int output_proc_tree(FILE *fp)
{
	PROC_TREE *now_proc_tree;
	PROC_TREE *next_proc_tree;

	printf(" -> Output Verilog HDL: module = %s\n", sep_p(module_name));

	// モジュールヘッダの生成
	fprintf(fp,"/*\n");
	fprintf(fp," * Copyright (C)2005-2015 AQUAXIS TECHNOLOGY.\n");
	fprintf(fp," *  Don't remove this header.\n");
	fprintf(fp," * When you use this source, there is a need to inherit this header.\n");
	fprintf(fp," *\n");
	fprintf(fp," * This software is released under the MIT License.\n");
	fprintf(fp," * http://opensource.org/licenses/mit-license.php\n");
	fprintf(fp," *\n");
	fprintf(fp," * For further information please contact.\n");
	fprintf(fp," *  URI:    http://www.aquaxis.com/\n");
	fprintf(fp," *  E-Mail: info(at)aquaxis.com\n");
	fprintf(fp," */\n");

	fprintf(fp,"module %s(\n", sep_p(module_name));
	fprintf(fp,"\tinput __func_clock,\n");
	fprintf(fp,"\tinput __func_reset,\n");
	fprintf(fp,"\tinput __func_start,\n");
	fprintf(fp,"\toutput reg __func_done,\n");
	fprintf(fp,"\toutput reg __func_ready,\n\n");

	if(is_module_gm_if){
		fprintf(fp,"\t// Global Memory\n");
		fprintf(fp,"\tinput [31:0] __gm_base,\n");
		fprintf(fp,"\toutput reg __gm_req,\n");
		fprintf(fp,"\toutput reg __gm_rnw,\n");
		fprintf(fp,"\tinput __gm_done,\n");
		fprintf(fp,"\toutput reg [31:0] __gm_adrs,\n");
		fprintf(fp,"\toutput reg [1:0] __gm_leng,\n");
		fprintf(fp,"\tinput [31:0] __gm_di,\n");
		fprintf(fp,"\toutput reg [31:0] __gm_do,\n\n");
	}

	fprintf(fp,"\t// Memory Singal\n");
	output_memory_tree(fp, 0);	// 引数の出力

	fprintf(fp,"\t// Call Singal\n");
	output_call_signal_tree(fp);

	fprintf(fp,"\t// Result Singal\n");
	output_memory_tree(fp ,1);	// returnの出力

	fprintf(fp,");\n\n");

	// reg,wire宣言
	output_signal_tree(fp);	// 信号定義の出力

	// WIRE接続(assign文)の出力
	if(verilog_wire != NULL){
		fprintf(fp,"%s", verilog_wire);
	}
	output_memory_tree(fp, 2);	// 宣言の出力

	// ステートマシンの宣言出力
	if(verilog_state != NULL){
		fprintf(fp,"%s", verilog_state);
	}

	output_verilog_sdiv(fp);

    now_proc_tree = proc_tree_top;

	// ステートマシンの生成
	fprintf(fp,"always @(posedge __func_clock or negedge __func_reset) begin\n");
	fprintf(fp,"\tif(!__func_reset) begin\n");
	fprintf(fp,"\t\t__state <= __state_start_req;\n");
	fprintf(fp,"\t\t__func_ready <= 1;\n");
	fprintf(fp,"\t\t__func_done <= 0;\n");
	// 初期化を入れる
	fprintf(fp,"\tend else begin\n");
	fprintf(fp,"\tcase(__state)\n");

	fprintf(fp,"\t\t__state_start_req: begin\n");
	fprintf(fp,"\t\t\t__state <= __state_start_wait;\n");
	fprintf(fp,"\t\tend\n");

	fprintf(fp,"\t\t__state_start_wait: begin\n");
	fprintf(fp,"\t\t\tif(__func_start) begin\n");
	fprintf(fp,"\t\t\t\t__state <= __state_start_exec;\n");
	fprintf(fp,"\t\t\t\t__func_ready <= 0;\n");
	fprintf(fp,"\t\t\t\t__func_done <= 0;\n");
	output_memory_tree(fp, 3);	// procの出力
	fprintf(fp,"\t\t\tend\n");
	fprintf(fp,"\t\tend\n");

	fprintf(fp,"\t\t__state_start_exec: begin\n");
	if(now_proc_tree->seq_req.ena){
		fprintf(fp,"\t\t\t__state <= __state_1_req;\n");
	}else if(now_proc_tree->seq_wait.ena){
		fprintf(fp,"\t\t\t__state <= __state_1_wait;\n");
	}else{
		fprintf(fp,"\t\t\t__state <= __state_1_exec;\n");
	}
	fprintf(fp,"\t__label_pre <= __label_0;\n");
	fprintf(fp,"\t\tend\n");

    while(now_proc_tree != NULL){
		if(now_proc_tree->seq_req.ena){
			fprintf(fp, "\t\t__state_%d_req: begin\n", now_proc_tree->stage);
			fprintf(fp, "%s", now_proc_tree->seq_req.state);
			if(now_proc_tree->seq_req.body != NULL )		fprintf(fp, "%s", now_proc_tree->seq_req.body);
			fprintf(fp, "\t\tend\n");
		}

		if(now_proc_tree->seq_wait.ena){
			fprintf(fp, "\t\t__state_%d_wait: begin\n", now_proc_tree->stage);
			fprintf(fp, "%s", now_proc_tree->seq_wait.state);
			if(now_proc_tree->seq_wait.body != NULL )		fprintf(fp, "%s", now_proc_tree->seq_wait.body);
			fprintf(fp, "\t\tend\n");
		}

		{
			fprintf(fp, "\t\t__state_%d_exec: begin\n", now_proc_tree->stage);
			if(now_proc_tree->seq_exec.state != NULL){
				if(strlen(now_proc_tree->seq_exec.state) > 0){
					fprintf(fp, "%s\n", now_proc_tree->seq_exec.state);
				}
			}else{
		        next_proc_tree = now_proc_tree->next_ptr;
		        if(next_proc_tree != NULL){
					if(next_proc_tree->seq_req.ena){
						fprintf(fp, "\t\t\t__state <= __state_%d_req;\n", now_proc_tree->stage + 1);
					}else if(next_proc_tree->seq_wait.ena){
						fprintf(fp, "\t\t\t__state <= __state_%d_wait;\n", now_proc_tree->stage + 1);
					}else{
						fprintf(fp, "\t\t\t__state <= __state_%d_exec;\n", now_proc_tree->stage + 1);
					}
				}
			}
			if(now_proc_tree->seq_exec.body != NULL )	fprintf(fp, "%s", now_proc_tree->seq_exec.body);
			fprintf(fp, "\t\tend\n");
		}
        now_proc_tree = now_proc_tree->next_ptr;
    }

	fprintf(fp,"\t\t__state_fin_exec: begin\n");
	fprintf(fp,"\t\t\t__state <= __state_start_req;\n");
	fprintf(fp,"\t\t\t__func_ready <= 1;\n");
	fprintf(fp,"\t\t\t__func_done <= 1;\n");
	fprintf(fp,"\t\tend\n");

	fprintf(fp,"\tendcase\n");
	fprintf(fp,"\tend\n");
	fprintf(fp,"end\n");

	fprintf(fp,"endmodule\n");

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xd00e(%rip), %r15      # 0x14148
movq (%r15), %rsi
movzbl (%rsi), %eax
cmpl $0x40, %eax
je 0x714a
cmpl $0x25, %eax
jne 0x714d
incq %rsi
leaq 0x797f(%rip), %rdi      # 0xead3
xorl %eax, %eax
callq 0x10b0
leaq 0x7996(%rip), %rdi      # 0xeaf8
movl $0x3, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7981(%rip), %rdi      # 0xeafc
movl $0x2e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7997(%rip), %rdi      # 0xeb2b
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x799d(%rip), %rdi      # 0xeb4a
movl $0x45, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79ca(%rip), %r14      # 0xeb90
movl $0x3, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b2(%rip), %rdi      # 0xeb94
movl $0x34, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79ce(%rip), %rdi      # 0xebc9
movl $0x32, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movl $0x3, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
leaq 0x79d3(%rip), %rdi      # 0xebfc
movl $0x2b, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79e6(%rip), %rdi      # 0xec28
movl $0x24, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79f2(%rip), %rdi      # 0xec4d
movl $0x20, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79fa(%rip), %rdi      # 0xec6e
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq (%r15), %rdx
movzbl (%rdx), %eax
cmpl $0x40, %eax
je 0x7296
cmpl $0x25, %eax
jne 0x7299
incq %rdx
leaq 0x79d3(%rip), %rsi      # 0xec73
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1110
leaq 0x79ce(%rip), %rdi      # 0xec7f
movl $0x15, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79cb(%rip), %rdi      # 0xec95
movl $0x15, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79c8(%rip), %rdi      # 0xecab
movl $0x15, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79c5(%rip), %rdi      # 0xecc1
movl $0x19, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79c6(%rip), %rdi      # 0xecdb
movl $0x1b, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0xd272(%rip)      # 0x145a0
je 0x7415
leaq 0x79bc(%rip), %rdi      # 0xecf7
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b6(%rip), %rdi      # 0xed0a
movl $0x19, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b7(%rip), %rdi      # 0xed24
movl $0x16, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b5(%rip), %rdi      # 0xed3b
movl $0x16, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b3(%rip), %rdi      # 0xed52
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79ad(%rip), %rdi      # 0xed65
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b3(%rip), %rdi      # 0xed84
movl $0x1d, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b8(%rip), %rdi      # 0xeda2
movl $0x17, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79b7(%rip), %rdi      # 0xedba
movl $0x1d, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79bc(%rip), %rdi      # 0xedd8
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x589b
leaq 0x79ac(%rip), %rdi      # 0xedeb
movl $0x10, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
callq 0x5310
leaq 0x799c(%rip), %rdi      # 0xedfc
movl $0x12, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x589b
leaq 0x7989(%rip), %rdi      # 0xee0f
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
callq 0x9cdf
movq 0xd0e1(%rip), %rdi      # 0x14588
testq %rdi, %rdi
je 0x74b4
movq %rbx, %rsi
callq 0x10c0
movq %rbx, %rdi
movl $0x2, %esi
callq 0x589b
movq 0xd0d0(%rip), %rdi      # 0x14598
testq %rdi, %rdi
je 0x74d5
movq %rbx, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x7980
movq 0xd09c(%rip), %r12      # 0x14580
leaq 0x7929(%rip), %rdi      # 0xee14
movl $0x3d, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x794e(%rip), %rdi      # 0xee52
movl $0x19, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7b97(%rip), %rdi      # 0xf0b4
movl $0x20, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7ba0(%rip), %rdi      # 0xf0d6
movl $0x15, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x79f3(%rip), %rdi      # 0xef42
movl $0x14, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7904(%rip), %rdi      # 0xee6c
movl $0x10, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78fc(%rip), %rdi      # 0xee7d
movl $0xf, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78f3(%rip), %rdi      # 0xee8d
movl $0x1b, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78f6(%rip), %rdi      # 0xeea9
movl $0x22, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7ccc(%rip), %r14      # 0xf298
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
leaq 0x78e4(%rip), %rdi      # 0xeecc
movl $0x1c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78e8(%rip), %rdi      # 0xeee9
movl $0x1a, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78ea(%rip), %rdi      # 0xef04
movl $0x23, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78f5(%rip), %rdi      # 0xef28
movl $0x17, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78f4(%rip), %rdi      # 0xef40
movl $0x16, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
movl $0x3, %esi
callq 0x589b
leaq 0x7c25(%rip), %rdi      # 0xf297
movl $0x7, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
leaq 0x78b7(%rip), %rdi      # 0xef57
movl $0x1c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0x18(%r12)
je 0x76c8
leaq 0x78b3(%rip), %rdi      # 0xef74
movl $0x1d, %esi
jmp 0x76e5
cmpl $0x0, 0x38(%r12)
je 0x76d9
leaq 0x78bb(%rip), %rdi      # 0xef92
jmp 0x76e0
leaq 0x78d1(%rip), %rdi      # 0xefb1
movl $0x1e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x78d7(%rip), %rdi      # 0xefd0
movl $0x1b, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7b86(%rip), %r14      # 0xf298
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
leaq 0x78f1(%rip), %r15      # 0xf01f
leaq 0x78d0(%rip), %r13      # 0xf005
leaq 0x78b0(%rip), %rbp      # 0xefec
cmpl $0x0, 0x18(%r12)
je 0x778a
movl 0x10(%r12), %edx
movq %rbx, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1110
movq 0x20(%r12), %rdi
movq %rbx, %rsi
callq 0x10c0
movq 0x30(%r12), %rdi
testq %rdi, %rdi
je 0x7775
movq %rbx, %rsi
callq 0x10c0
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0x38(%r12)
je 0x77d8
movl 0x10(%r12), %edx
movq %rbx, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1110
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x10c0
movq 0x50(%r12), %rdi
testq %rdi, %rdi
je 0x77c3
movq %rbx, %rsi
callq 0x10c0
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
movl 0x10(%r12), %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1110
movq 0x60(%r12), %rdx
testq %rdx, %rdx
je 0x780c
cmpb $0x0, (%rdx)
je 0x7859
movq %rbx, %rdi
leaq 0x72c3(%rip), %rsi      # 0xeac6
xorl %eax, %eax
callq 0x1110
jmp 0x7859
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x7859
cmpl $0x0, 0x18(%rax)
je 0x782f
movl 0x10(%r12), %edx
incl %edx
movq %rbx, %rdi
leaq 0x780c(%rip), %rsi      # 0xf039
jmp 0x7852
movl 0x10(%r12), %edx
incl %edx
cmpl $0x0, 0x38(%rax)
je 0x7848
movq %rbx, %rdi
leaq 0x7812(%rip), %rsi      # 0xf058
jmp 0x7852
movq %rbx, %rdi
leaq 0x7826(%rip), %rsi      # 0xf078
xorl %eax, %eax
callq 0x1110
movq 0x70(%r12), %rdi
testq %rdi, %rdi
je 0x786b
movq %rbx, %rsi
callq 0x10c0
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x773c
leaq 0x7803(%rip), %rdi      # 0xf098
movl $0x1a, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7805(%rip), %rdi      # 0xf0b3
movl $0x21, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x780e(%rip), %rdi      # 0xf0d5
movl $0x16, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x780c(%rip), %rdi      # 0xf0ec
movl $0x15, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x799f(%rip), %rdi      # 0xf298
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7a49(%rip), %rdi      # 0xf35b
movl $0x9, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x796e(%rip), %rdi      # 0xf299
movl $0x5, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7956(%rip), %rdi      # 0xf29a
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
leaq 0x77a5(%rip), %rdi      # 0xf102
movl $0xa, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11c0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq