// File: /workspace/github_c_makefile_star2_O2/aquaxis[P]synverll/src/parser_ir_proc.c
// Function: create_verilog_call_args
int create_verilog_call_args(char *name, char *args, char *buf, int is_call)
{
	char *token;
	char *line;
	char *temp;
	char *type;
	int args_num = 0;
	char *str;
	int width;

	token = calloc(STR_MAX, 1);
	temp = calloc(STR_MAX, 1);
	type = calloc(STR_MAX, 1);
	line = charalloc(args);
	strcpy(buf, "");

	get_token_llvm(line, token);	// "("

	/* ToDo:
	 * Verilog HDLを作成しつつ、外部信号も生成すること
	 */
	while(strlen(line) > 0){
		// タイプ
		/*
		 * タイプが整数の場合は、Writeのみ
		 * タイプがポインタの場合はRead/Write有り
		 * タイプがメモリの場合はRead/Write有り
		 */
		get_irtype_llvm(line, token);
		if(!strcmp(token, "") || !strcmp(token,")")) break;
		strcpy(type, token);

		{
			do{
				get_token_llvm(line, token);
				if(!strcmp(token, "align")){
					get_token_llvm(line, token);
					get_token_llvm(line, token);
				}
			}while(
				!strcmp(token, "zeroext") ||
				!strcmp(token, "signext") ||
				!strcmp(token, "inreg") ||
				!strcmp(token, "byval") ||
				!strcmp(token, "sret") ||
				!strcmp(token, "align") ||
				!strcmp(token, "noalias") ||
				!strcmp(token, "nocapture") ||
				!strcmp(token, "nest") ||
				!strcmp(token, "readonly") ||
				!strcmp(token, "readnone") ||
				!strcmp(token, "returned") ||
				!strcmp(token, "dereferenceable") ||
				!strcmp(token, "dereferenceable_or_null")
			);
		}

		if(!strcmp(token, "getelementptr")){
			// ポインタの場合はアドレス値を算出するように復元
			sprintf(temp, "%s%s", token, line);
			free(line);
			line = calloc(strlen(temp)+1, 1);
			strcpy(line, temp);
			get_irtype_llvm(line, token);
		}

		create_adrs_getelementptr(token, token);
		str = regalloc(token);
		sprintf(temp, "\t\t\t__call_%s_args_%d <= %s;\n", name, args_num, str);
		free(str);
		strcat(buf, temp);

		// インターフェースの作成
		width = get_width(type);
		// call_sianal_treeへ登録
		if(!is_call) register_call_signal_tree(name, "args", args_num, width, 1);
		args_num++;

		// 次の","か")"まで読み飛ばし
		do{
			get_token_llvm(line, token);
		}while(strcmp(token, ",") && strcmp(token, ")"));
	}

	free(token);
	free(type);
	free(temp);
	free(line);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
pushq $0x1
popq %r15
movl $0x400, %edi            # imm = 0x400
movq %r15, %rsi
callq 0x10f0
movq %rax, %rbp
movl $0x400, %edi            # imm = 0x400
movq %r15, %rsi
callq 0x10f0
movq %rax, 0x8(%rsp)
movl $0x400, %edi            # imm = 0x400
movq %r15, %rsi
callq 0x10f0
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x1372
movq %rax, %rbx
movq %r14, 0x28(%rsp)
movb $0x0, (%r14)
movq %rax, %rdi
movq %rbp, %rsi
callq 0xc4ad
leaq 0x5f22(%rip), %r15      # 0xd7ea
leaq 0x5c9c(%rip), %r12      # 0xd56b
leaq 0x683b(%rip), %r13      # 0xe111
leaq 0x5f13(%rip), %r14      # 0xd7f0
movl $0x0, 0x4(%rsp)
cmpb $0x0, (%rbx)
je 0x7b98
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1ec1
cmpb $0x0, (%rbp)
je 0x7b98
movq %rbp, %rdi
leaq 0x6063(%rip), %rsi      # 0xd970
callq 0x1100
testl %eax, %eax
je 0x7b98
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x1060
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc4ad
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
jne 0x7957
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc4ad
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc4ad
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5e68(%rip), %rsi      # 0xd7f6
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5e5b(%rip), %rsi      # 0xd7fc
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x674e(%rip), %rsi      # 0xe119
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5e1f(%rip), %rsi      # 0xd801
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5e12(%rip), %rsi      # 0xd80b
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5e00(%rip), %rsi      # 0xd810
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5df2(%rip), %rsi      # 0xd819
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5de4(%rip), %rsi      # 0xd822
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5dd6(%rip), %rsi      # 0xd82b
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5dcf(%rip), %rsi      # 0xd83b
callq 0x1100
testl %eax, %eax
je 0x7927
movq %rbp, %rdi
leaq 0x5727(%rip), %rsi      # 0xd1aa
callq 0x1100
testl %eax, %eax
jne 0x7ade
movq 0x8(%rsp), %rdi
leaq 0x57a8(%rip), %rsi      # 0xd240
movq %rbp, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x10f0
movq %rax, %rbx
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x1060
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1ec1
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x7bcd
movq %rbp, %rdi
callq 0x7706
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x661f(%rip), %rsi      # 0xe121
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x11a0
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1190
movq 0x10(%rsp), %rdi
callq 0x12dc
cmpl $0x0, 0x1c(%rsp)
jne 0x7b5a
movq 0x20(%rsp), %rdi
leaq 0x65f3(%rip), %rsi      # 0xe13e
movl 0x4(%rsp), %edx
movl %eax, %ecx
pushq $0x1
popq %r8
callq 0x4f40
incl 0x4(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc4ad
movq %rbp, %rdi
leaq 0x6efd(%rip), %rsi      # 0xea70
callq 0x1100
testl %eax, %eax
je 0x78e5
movq %rbp, %rdi
leaq 0x5de6(%rip), %rsi      # 0xd970
callq 0x1100
testl %eax, %eax
jne 0x7b5e
jmp 0x78e5
movq %rbp, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq