// File: /workspace/github_c_makefile_star2_O2/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 0xc358(%rip), %r13      # 0x13148
movq (%r13), %rsi
movzbl (%rsi), %eax
cmpl $0x40, %eax
je 0x6e01
cmpl $0x25, %eax
jne 0x6e04
incq %rsi
leaq 0x6ca8(%rip), %rdi      # 0xdab3
xorl %eax, %eax
callq 0x10b0
leaq 0x6cbf(%rip), %rdi      # 0xdad8
pushq $0x3
popq %r15
pushq $0x1
popq %r14
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6ca6(%rip), %rdi      # 0xdadc
pushq $0x2e
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6cc0(%rip), %rdi      # 0xdb0b
pushq $0x1e
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6cca(%rip), %rdi      # 0xdb2a
pushq $0x45
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6cfb(%rip), %r12      # 0xdb70
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6ce7(%rip), %rdi      # 0xdb74
pushq $0x34
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d07(%rip), %rdi      # 0xdba9
pushq $0x32
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d14(%rip), %rdi      # 0xdbdc
pushq $0x2b
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d2b(%rip), %rdi      # 0xdc08
pushq $0x24
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d3b(%rip), %rdi      # 0xdc2d
pushq $0x20
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d47(%rip), %rdi      # 0xdc4e
pushq $0x4
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq (%r13), %rdx
movzbl (%rdx), %eax
cmpl $0x40, %eax
je 0x6f26
cmpl $0x25, %eax
jne 0x6f29
incq %rdx
leaq 0x6d23(%rip), %rsi      # 0xdc53
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1110
leaq 0x6d1e(%rip), %rdi      # 0xdc5f
pushq $0x15
popq %r15
pushq $0x1
popq %r14
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d17(%rip), %rdi      # 0xdc75
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d18(%rip), %rdi      # 0xdc8b
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d19(%rip), %rdi      # 0xdca1
pushq $0x19
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d1e(%rip), %rdi      # 0xdcbb
pushq $0x1b
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0xc5ee(%rip)      # 0x135a0
je 0x7085
leaq 0x6d18(%rip), %rdi      # 0xdcd7
pushq $0x12
popq %r15
pushq $0x1
popq %r14
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d0e(%rip), %rdi      # 0xdcea
pushq $0x19
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d13(%rip), %rdi      # 0xdd04
pushq $0x16
popq %r12
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d11(%rip), %rdi      # 0xdd1b
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d13(%rip), %rdi      # 0xdd32
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d11(%rip), %rdi      # 0xdd45
pushq $0x1e
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d1b(%rip), %rdi      # 0xdd64
pushq $0x1d
popq %r15
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d20(%rip), %rdi      # 0xdd82
pushq $0x17
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d23(%rip), %rdi      # 0xdd9a
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d2c(%rip), %rdi      # 0xddb8
pushq $0x12
popq %r15
pushq $0x1
popq %r14
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5624
leaq 0x6d18(%rip), %rdi      # 0xddcb
pushq $0x10
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
callq 0x50db
leaq 0x6d0c(%rip), %rdi      # 0xdddc
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x5624
leaq 0x6cff(%rip), %rdi      # 0xddef
pushq $0x4
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %rbx, %rdi
callq 0x9879
movq 0xc47b(%rip), %rdi      # 0x13588
testq %rdi, %rdi
je 0x711a
movq %rbx, %rsi
callq 0x10c0
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x5624
movq 0xc46c(%rip), %rdi      # 0x13598
testq %rdi, %rdi
je 0x7139
movq %rbx, %rsi
callq 0x10c0
movq %rbx, %rdi
callq 0x7558
movq 0xc438(%rip), %rbp      # 0x13580
leaq 0x6ca5(%rip), %rdi      # 0xddf4
pushq $0x3d
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6cca(%rip), %rdi      # 0xde32
pushq $0x19
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6f17(%rip), %rdi      # 0xe094
pushq $0x20
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6f24(%rip), %rdi      # 0xe0b6
pushq $0x15
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d7b(%rip), %rdi      # 0xdf22
pushq $0x14
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c90(%rip), %rdi      # 0xde4c
pushq $0x10
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c8c(%rip), %rdi      # 0xde5d
pushq $0xf
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c87(%rip), %rdi      # 0xde6d
pushq $0x1b
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c8e(%rip), %rdi      # 0xde89
pushq $0x22
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x7068(%rip), %r15      # 0xe278
pushq $0x6
popq %r12
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c80(%rip), %rdi      # 0xdeac
pushq $0x1c
popq %r13
movq %r13, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c84(%rip), %rdi      # 0xdec9
pushq $0x1a
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c8a(%rip), %rdi      # 0xdee4
pushq $0x23
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c99(%rip), %rdi      # 0xdf08
pushq $0x17
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c9c(%rip), %rdi      # 0xdf20
pushq $0x16
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x5624
leaq 0x6fd3(%rip), %rdi      # 0xe277
pushq $0x7
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c6d(%rip), %rdi      # 0xdf37
movq %r13, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0x18(%rbp)
je 0x72e9
leaq 0x6c6f(%rip), %rdi      # 0xdf54
pushq $0x1d
jmp 0x7301
cmpl $0x0, 0x38(%rbp)
je 0x72f8
leaq 0x6c7c(%rip), %rdi      # 0xdf72
jmp 0x72ff
leaq 0x6c92(%rip), %rdi      # 0xdf91
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6c9c(%rip), %rdi      # 0xdfb0
pushq $0x1b
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6f4b(%rip), %r15      # 0xe278
pushq $0x6
popq %r12
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6cb6(%rip), %r13      # 0xdfff
testq %rbp, %rbp
je 0x7486
cmpl $0x0, 0x18(%rbp)
je 0x739a
movl 0x10(%rbp), %edx
movq %rbx, %rdi
leaq 0x6c67(%rip), %rsi      # 0xdfcc
xorl %eax, %eax
callq 0x1110
movq 0x20(%rbp), %rdi
movq %rbx, %rsi
callq 0x10c0
movq 0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x7389
movq %rbx, %rsi
callq 0x10c0
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
cmpl $0x0, 0x38(%rbp)
je 0x73e2
movl 0x10(%rbp), %edx
movq %rbx, %rdi
leaq 0x6c38(%rip), %rsi      # 0xdfe5
xorl %eax, %eax
callq 0x1110
movq 0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x10c0
movq 0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x73d1
movq %rbx, %rsi
callq 0x10c0
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movl 0x10(%rbp), %edx
movq %rbx, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x1110
movq 0x60(%rbp), %rdx
testq %rdx, %rdx
je 0x7413
cmpb $0x0, (%rdx)
je 0x745b
movq %rbx, %rdi
leaq 0x669c(%rip), %rsi      # 0xdaa6
xorl %eax, %eax
callq 0x1110
jmp 0x745b
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0x745b
cmpl $0x0, 0x18(%rax)
je 0x7433
movl 0x10(%rbp), %edx
incl %edx
movq %rbx, %rdi
leaq 0x6be8(%rip), %rsi      # 0xe019
jmp 0x7454
movl 0x10(%rbp), %edx
incl %edx
cmpl $0x0, 0x38(%rax)
je 0x744a
movq %rbx, %rdi
leaq 0x6bf0(%rip), %rsi      # 0xe038
jmp 0x7454
movq %rbx, %rdi
leaq 0x6c04(%rip), %rsi      # 0xe058
xorl %eax, %eax
callq 0x1110
movq 0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x746c
movq %rbx, %rsi
callq 0x10c0
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
movq 0x8(%rbp), %rbp
jmp 0x7349
leaq 0x6beb(%rip), %rdi      # 0xe078
pushq $0x1a
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6bed(%rip), %rdi      # 0xe093
pushq $0x21
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6bfa(%rip), %rdi      # 0xe0b5
pushq $0x16
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6bfc(%rip), %rdi      # 0xe0cc
pushq $0x15
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d93(%rip), %rdi      # 0xe278
pushq $0x6
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6e41(%rip), %rdi      # 0xe33b
pushq $0x9
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d6a(%rip), %rdi      # 0xe279
pushq $0x5
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6d56(%rip), %rdi      # 0xe27a
pushq $0x4
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
leaq 0x6ba9(%rip), %rdi      # 0xe0e2
pushq $0xa
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x11c0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq