77// ------------------------------------------------------------------------------
88#pragma once
99
10+ #include < flat_hash_map.hpp>
1011#include < memory>
1112#include < string>
13+ #include < vector>
1214
1315#include " slang/util/Util.h"
1416
1517namespace llvm {
1618
19+ class BasicBlock ;
20+ class Constant ;
21+ class Function ;
1722class LLVMContext ;
1823class Module ;
24+ class Type ;
25+ class Value ;
1926
2027} // namespace llvm
2128
2229namespace slang {
2330
2431class Compilation ;
32+ class ConstantValue ;
33+ class Expression ;
34+ class InstanceSymbol ;
35+ class ProceduralBlockSymbol ;
36+ class Statement ;
37+ class SubroutineSymbol ;
38+ class SVInt ;
2539class Symbol ;
40+ class SystemSubroutine ;
41+ class Type ;
42+ class VariableSymbol ;
43+
44+ struct CodegenOptions {
45+ uint32_t maxIntBits = 128 ;
46+ bool flattenFourState = false ;
47+ };
2648
2749class CodeGenerator {
2850public:
2951 CodeGenerator (Compilation& compilation);
3052 ~CodeGenerator ();
3153
32- std::string run (const Symbol& symbol);
54+ std::string finish ();
55+
56+ void genInstance (const InstanceSymbol& instance);
57+ void genStmt (llvm::BasicBlock* bb, const Statement& stmt);
58+
59+ llvm::Constant* genConstant (const Type& type, const ConstantValue& cv);
60+ llvm::Constant* genConstant (const Type& type, const SVInt& integer);
61+ llvm::Type* genType (const Type& type);
62+ llvm::Value* genExpr (llvm::BasicBlock* bb, const Expression& expr);
63+ llvm::Function* genSubroutine (const SubroutineSymbol& subroutine);
64+ llvm::Function* genSubroutine (const SystemSubroutine& subroutine);
3365
3466private:
67+ void genGlobal (const VariableSymbol& variable);
68+ void genBlock (const ProceduralBlockSymbol& variable);
69+
3570 std::unique_ptr<llvm::LLVMContext> ctx;
3671 std::unique_ptr<llvm::Module> module ;
72+ flat_hash_map<const Type*, llvm::Type*> typeMap;
73+ flat_hash_map<const Symbol*, llvm::Value*> globalMap;
74+ flat_hash_map<const SubroutineSymbol*, llvm::Function*> userSubroutineMap;
75+ flat_hash_map<const SystemSubroutine*, llvm::Function*> sysSubroutineMap;
76+ llvm::BasicBlock* globalInitBlock;
77+ std::vector<llvm::BasicBlock*> initialBlocks;
78+ llvm::Function* mainFunc;
3779 Compilation& compilation;
80+ CodegenOptions options;
3881};
3982
4083} // namespace slang
0 commit comments