From 26ffaf45d40908c37bf73e5da1c38c1d7749c5ae Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 21 Apr 2021 21:38:58 -0700 Subject: [PATCH] fix function argument + add _ptr suffix --- compiler.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler.c b/compiler.c index b5e42b3..05b2c2b 100644 --- a/compiler.c +++ b/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); }