fix function argument + add _ptr suffix
parent
c6507fdcb7
commit
26ffaf45d4
22
compiler.c
22
compiler.c
|
@ -251,12 +251,15 @@ static void AddStructVariables(
|
|||
{
|
||||
for (j = 0; j < structTypeFieldDeclarations[i].fieldCount; j += 1)
|
||||
{
|
||||
char *ptrName = strdup(structTypeFieldDeclarations[i].fields[j].name);
|
||||
strcat(ptrName, "_ptr");
|
||||
LLVMValueRef elementPointer = LLVMBuildStructGEP(
|
||||
builder,
|
||||
structPointer,
|
||||
structTypeFieldDeclarations[i].fields[j].index,
|
||||
structTypeFieldDeclarations[i].fields[j].name
|
||||
ptrName
|
||||
);
|
||||
free(ptrName);
|
||||
|
||||
AddLocalVariable(
|
||||
scope,
|
||||
|
@ -466,18 +469,23 @@ static void CompileAssignment(LLVMValueRef wStructValue, LLVMBuilderRef builder,
|
|||
|
||||
static void CompileFunctionVariableDeclaration(LLVMBuilderRef builder, Node *variableDeclaration)
|
||||
{
|
||||
char *variableName = variableDeclaration->children[1]->value.string;
|
||||
LLVMValueRef variable;
|
||||
char *variableName = variableDeclaration->children[1]->value.string;
|
||||
char *ptrName = strdup(variableName);
|
||||
strcat(ptrName, "_ptr");
|
||||
|
||||
if (variableDeclaration->children[0]->type == CustomType)
|
||||
{
|
||||
char *customTypeName = variableDeclaration->children[0]->children[0]->value.string;
|
||||
variable = LLVMBuildAlloca(builder, LookupCustomType(customTypeName), variableName);
|
||||
variable = LLVMBuildAlloca(builder, LookupCustomType(customTypeName), ptrName);
|
||||
}
|
||||
else
|
||||
{
|
||||
variable = LLVMBuildAlloca(builder, WraithTypeToLLVMType(variableDeclaration->children[0]->type), variableName);
|
||||
variable = LLVMBuildAlloca(builder, WraithTypeToLLVMType(variableDeclaration->children[0]->type), ptrName);
|
||||
}
|
||||
|
||||
free(ptrName);
|
||||
|
||||
AddLocalVariable(scope, variable, variableName);
|
||||
}
|
||||
|
||||
|
@ -543,8 +551,12 @@ static void CompileFunction(
|
|||
|
||||
for (i = 0; i < functionSignature->children[2]->childCount; i += 1)
|
||||
{
|
||||
char *ptrName = strdup(functionSignature->children[2]->children[i]->children[1]->value.string);
|
||||
strcat(ptrName, "_ptr");
|
||||
LLVMValueRef argument = LLVMGetParam(function, i + 1);
|
||||
LLVMValueRef argumentCopy = LLVMBuildAlloca(builder, LLVMTypeOf(argument), functionSignature->children[2]->children[i]->children[1]->value.string);
|
||||
LLVMValueRef argumentCopy = LLVMBuildAlloca(builder, LLVMTypeOf(argument), ptrName);
|
||||
LLVMBuildStore(builder, argument, argumentCopy);
|
||||
free(ptrName);
|
||||
AddLocalVariable(scope, argumentCopy, functionSignature->children[2]->children[i]->children[1]->value.string);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue