// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, %r14
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, 0x8(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x137c
movq %rax, %rbp
movq %r15, 0x28(%rsp)
movb $0x0, (%r15)
movq %rax, %rdi
movq %r14, %rsi
callq 0xcaa7
cmpb $0x0, (%rbp)
je 0x8007
leaq 0x6acf(%rip), %r12      # 0xe80a
leaq 0x6829(%rip), %r13      # 0xe56b
leaq 0x73e8(%rip), %rbx      # 0xf131
leaq 0x6ac0(%rip), %r15      # 0xe810
movl $0x0, 0x4(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1fbb
cmpb $0x0, (%r14)
je 0x8007
movq %r14, %rdi
leaq 0x6c19(%rip), %rsi      # 0xe990
callq 0x1100
testl %eax, %eax
je 0x8007
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x1060
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcaa7
movq %r14, %rdi
movq %r12, %rsi
callq 0x1100
testl %eax, %eax
jne 0x7dc1
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcaa7
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcaa7
movq %r14, %rdi
movq %r13, %rsi
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x6a1e(%rip), %rsi      # 0xe816
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x6a11(%rip), %rsi      # 0xe81c
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
movq %r12, %rsi
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x7304(%rip), %rsi      # 0xf139
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x69d5(%rip), %rsi      # 0xe821
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x69c8(%rip), %rsi      # 0xe82b
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x69b6(%rip), %rsi      # 0xe830
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x69a8(%rip), %rsi      # 0xe839
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x699a(%rip), %rsi      # 0xe842
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x698c(%rip), %rsi      # 0xe84b
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x6985(%rip), %rsi      # 0xe85b
callq 0x1100
testl %eax, %eax
je 0x7d91
movq %r14, %rdi
leaq 0x62bd(%rip), %rsi      # 0xe1aa
callq 0x1100
testl %eax, %eax
jne 0x7f4a
movq 0x8(%rsp), %rdi
leaq 0x633e(%rip), %rsi      # 0xe240
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x11a0
movq %rbp, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x10f0
movq %rax, %rbp
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x1060
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1fbb
movq %r14, %rdi
movq %r14, %rsi
callq 0x803c
movq %r14, %rdi
callq 0x7b63
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x71d3(%rip), %rsi      # 0xf141
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 0x7fc8
movq 0x20(%rsp), %rdi
leaq 0x71a7(%rip), %rsi      # 0xf15e
movl 0x4(%rsp), %edx
movl %eax, %ecx
movl $0x1, %r8d
callq 0x5170
incl 0x4(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcaa7
movq %r14, %rdi
leaq 0x7aaf(%rip), %rsi      # 0xfa90
callq 0x1100
testl %eax, %eax
je 0x7ffd
movq %r14, %rdi
leaq 0x699c(%rip), %rsi      # 0xe990
callq 0x1100
testl %eax, %eax
jne 0x7fcc
cmpb $0x0, (%rbp)
jne 0x7d58
movq %r14, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq