-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bunch of codegen infrastructure
- Loading branch information
1 parent
62fb1a9
commit ced646f
Showing
11 changed files
with
393 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//------------------------------------------------------------------------------ | ||
//! @file ExpressionEmitter.h | ||
//! @brief Code emitter for expression trees | ||
//! @note Only included if slang is configured to use LLVM | ||
// | ||
// File is under the MIT license; see LICENSE for details | ||
//------------------------------------------------------------------------------ | ||
#pragma once | ||
|
||
#include <llvm/IR/BasicBlock.h> | ||
#include <llvm/IR/IRBuilder.h> | ||
|
||
#include "slang/symbols/ASTVisitor.h" | ||
|
||
namespace slang { | ||
|
||
class CodeGenerator; | ||
|
||
class ExpressionEmitter { | ||
public: | ||
ExpressionEmitter(CodeGenerator& generator, llvm::BasicBlock* bb); | ||
|
||
llvm::Value* emit(const Expression& expr); | ||
|
||
// TODO: remove once all expressions are handled | ||
template<typename T> | ||
llvm::Value* visit(const T& expr) { return getUndef(*expr.type); } | ||
|
||
llvm::Value* visit(const IntegerLiteral& expr); | ||
llvm::Value* visit(const CallExpression& expr); | ||
|
||
llvm::Value* visitInvalid(const Expression&) { return ir.CreateUnreachable(); } | ||
|
||
private: | ||
llvm::Value* getUndef(const Type& type); | ||
|
||
CodeGenerator& generator; | ||
llvm::IRBuilder<> ir; | ||
}; | ||
|
||
} // namespace slang |
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,38 @@ | ||
//------------------------------------------------------------------------------ | ||
//! @file StatementEmitter.h | ||
//! @brief Code emitter for statements | ||
//! @note Only included if slang is configured to use LLVM | ||
// | ||
// File is under the MIT license; see LICENSE for details | ||
//------------------------------------------------------------------------------ | ||
#pragma once | ||
|
||
#include <llvm/IR/BasicBlock.h> | ||
#include <llvm/IR/IRBuilder.h> | ||
|
||
#include "slang/binding/Statements.h" | ||
|
||
namespace slang { | ||
|
||
class CodeGenerator; | ||
|
||
class StatementEmitter { | ||
public: | ||
StatementEmitter(CodeGenerator& generator, llvm::BasicBlock* bb); | ||
|
||
void emit(const Statement& stmt); | ||
|
||
// TODO: remove once all statements are handled | ||
template<typename T> | ||
void visit(const T&) {} | ||
|
||
void visit(const ExpressionStatement& stmt); | ||
|
||
void visitInvalid(const Statement&) {} | ||
|
||
private: | ||
CodeGenerator& generator; | ||
llvm::IRBuilder<> ir; | ||
}; | ||
|
||
} // namespace slang |
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,28 @@ | ||
//------------------------------------------------------------------------------ | ||
//! @file SystemCallEmitter.h | ||
//! @brief Code emitter for system calls (tasks and functions) | ||
//! @note Only included if slang is configured to use LLVM | ||
// | ||
// File is under the MIT license; see LICENSE for details | ||
//------------------------------------------------------------------------------ | ||
#pragma once | ||
|
||
#include <flat_hash_map.hpp> | ||
#include <llvm/IR/BasicBlock.h> | ||
#include <llvm/IR/IRBuilder.h> | ||
|
||
#include "slang/util/Util.h" | ||
|
||
namespace slang { | ||
|
||
class CodeGenerator; | ||
class Expression; | ||
class Scope; | ||
class SystemSubroutine; | ||
|
||
class SystemCallEmitter { | ||
public: | ||
private: | ||
}; | ||
|
||
} // namespace slang |
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
Oops, something went wrong.