Skip to content

Commit

Permalink
fix: Fixed function parameters not being usable
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed Mar 10, 2022
1 parent b01ebba commit 086a231
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
- [x] Allow return void
- [ ] Fix symbols with same name but different function signatures (mangled and non-manged) overlapping, it should issue a warning and the newest one replace the old one
- [ ] Fix being able to call function without respective arguments, but throw error
- [x] Fix arguments not being usable (not stored in LLVM IR)

## Refactoring
- [ ] Replace SourceLocation by Span
- [ ] Highlight errors line
- [x] Add name mangling

## Features
- [ ] Add parenthesis support
- [ ] Add analyzer phase (add tree walker interface?)
- [x] Add type inference
- [ ] Add operator overloading
Expand Down
12 changes: 9 additions & 3 deletions src/Backend/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,20 @@ void Codegen::visit(FuncDecl *node) {
FunctionType *FT = FunctionType::get(visit(node->getReturnType()), paramTypes, false);
Function *F = Function::Create(FT, linkage, name, *TheModule);

for (auto &param: F->args())
param.setName(node->getParameters()[param.getArgNo()].first);

// deferStack.push({});

BasicBlock *BB = BasicBlock::Create(*TheContext, "entry", F);
Builder->SetInsertPoint(BB);


for (auto &param: F->args()) {
param.setName(node->getParameters()[param.getArgNo()].first);

auto ptr = Builder->CreateAlloca(param.getType(), nullptr, param.getName() + "_ptr");
Builder->CreateStore(&param, ptr);

Scope->insertSymbol(param.getName().str(), ptr, param.getType(), false);
}
visit(node->getBody());

// auto instrs = deferStack.top();
Expand Down

0 comments on commit 086a231

Please sign in to comment.