Added scopes

This commit is contained in:
Rafał Grodziński
2025-07-05 18:42:58 +09:00
parent 2e0015c9be
commit da1b5852ff
3 changed files with 85 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
#define MODULE_BUILDER_H
#include <map>
#include <stack>
#include <llvm/IR/Module.h>
#include <llvm/IR/IRBuilder.h>
@@ -33,6 +34,11 @@ class StatementBlock;
using namespace std;
typedef struct {
map<string, llvm::AllocaInst*> allocaMap;
map<string, llvm::Function*> funMap;
} Scope;
class ModuleBuilder {
private:
string moduleName;
@@ -48,8 +54,7 @@ private:
llvm::Type *typeReal32;
vector<shared_ptr<Statement>> statements;
map<string, llvm::AllocaInst*> allocaMap;
map<string, llvm::Function*> funMap;
stack<Scope> scopes;
void buildStatement(shared_ptr<Statement> statement);
void buildFunctionDeclaration(shared_ptr<StatementFunction> statement);
@@ -72,6 +77,12 @@ private:
llvm::Value *valueForVar(shared_ptr<ExpressionVariable> expression);
llvm::Value *valueForCall(shared_ptr<ExpressionCall> expression);
bool setAlloca(string name, llvm::AllocaInst *alloca);
llvm::AllocaInst *getAlloca(string name);
bool setFun(string name, llvm::Function *fun);
llvm::Function *getFun(string name);
llvm::Type *typeForValueType(shared_ptr<ValueType> valueType);
void failWithMessage(string message);