-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
217 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "code_gen.h" | ||
#include <iostream> | ||
|
||
CodeGen::CodeGen(llvm::LLVMContext& context, llvm::Module* module) : context(context), builder(context), ast_types_resolver(context) { | ||
this->module = module; | ||
} | ||
|
||
CodeGen::~CodeGen() { | ||
return; | ||
} | ||
|
||
void CodeGen::push_block(llvm::BasicBlock* block) { | ||
std::cout << "Pushing block" << std::endl; | ||
this->blocks.push(block); | ||
this->builder.SetInsertPoint(this->current_block()); | ||
} | ||
|
||
void CodeGen::pop_block() { | ||
std::cout << "Popping block" << std::endl; | ||
this->blocks.pop(); | ||
this->builder.SetInsertPoint(this->current_block()); | ||
} | ||
|
||
void CodeGen::push_scope() { | ||
std::cout << "Pushing scope" << std::endl; | ||
this->scope.push(); | ||
} | ||
|
||
void CodeGen::pop_scope() { | ||
std::cout << "Popping scope" << std::endl; | ||
this->scope.pop(); | ||
} | ||
|
||
llvm::BasicBlock* CodeGen::current_block() { | ||
if (this->blocks.size() == 0) { | ||
return NULL; | ||
} | ||
return this->blocks.top(); | ||
} | ||
|
||
void CodeGen::visit(ASTNodeIdentifier* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodePrimitive* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeDeclaration* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeBlock* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeCast* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeAssignment* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeBinaryOperator* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeFunctionPrototype* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeFunction* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeFunctionCall* node) { | ||
return; | ||
} | ||
|
||
void CodeGen::visit(ASTNodeIfElse* node) { | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef __CODE_GEN_H_ | ||
#define __CODE_GEN_H_ | ||
|
||
#include <stack> | ||
#include <list> | ||
#include <llvm/Analysis/Passes.h> | ||
#include <llvm/Analysis/Verifier.h> | ||
#include <llvm/ExecutionEngine/ExecutionEngine.h> | ||
#include <llvm/ExecutionEngine/JIT.h> | ||
#include <llvm/IR/DataLayout.h> | ||
#include <llvm/IR/DerivedTypes.h> | ||
#include <llvm/IR/IRBuilder.h> | ||
#include <llvm/IR/LLVMContext.h> | ||
#include <llvm/IR/Module.h> | ||
#include <llvm/PassManager.h> | ||
#include <llvm/Support/TargetSelect.h> | ||
#include <llvm/Transforms/Scalar.h> | ||
#include "identifier_scope.h" | ||
#include "ast_types_resolver.h" | ||
#include "ast_node.h" | ||
|
||
class CodeGen : public IASTNodeVisitor { | ||
public: | ||
llvm::LLVMContext& context; | ||
llvm::Module* module; | ||
llvm::IRBuilder<> builder; | ||
std::stack<llvm::BasicBlock*> blocks; | ||
IdentifierScope scope; | ||
ASTTypesResolver ast_types_resolver; | ||
|
||
CodeGen(llvm::LLVMContext&, llvm::Module*); | ||
~CodeGen(); | ||
|
||
void push_block(llvm::BasicBlock*); | ||
void pop_block(); | ||
void push_scope(); | ||
void pop_scope(); | ||
llvm::BasicBlock* current_block(); | ||
|
||
virtual void visit(ASTNodeIdentifier*) override; | ||
virtual void visit(ASTNodePrimitive*) override; | ||
virtual void visit(ASTNodeDeclaration*) override; | ||
virtual void visit(ASTNodeBlock*) override; | ||
virtual void visit(ASTNodeCast*) override; | ||
virtual void visit(ASTNodeAssignment*) override; | ||
virtual void visit(ASTNodeBinaryOperator*) override; | ||
virtual void visit(ASTNodeFunctionPrototype*) override; | ||
virtual void visit(ASTNodeFunction*) override; | ||
virtual void visit(ASTNodeFunctionCall*) override; | ||
virtual void visit(ASTNodeIfElse*) override; | ||
}; | ||
|
||
#endif /* __CODE_GEN_H_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters