4 #ifndef ILANG_TARGET_SC_ILATOR_H__
5 #define ILANG_TARGET_SC_ILATOR_H__
10 #include <fmt/format.h>
18 #define ILATOR_PRECISE_MEM
33 void Generate(
const std::string& dst,
bool opt);
37 typedef fmt::memory_buffer StrBuff;
39 typedef std::unordered_map<ExprPtr, std::string, ExprHash> ExprVarMap;
43 CxxFunc(
const std::string& in_name,
const ExprPtr& in_ret,
44 const ExprPtr& in_target =
nullptr)
45 : name(in_name), ret(in_ret), target(in_target) {}
46 CxxFunc(
const std::string& in_name,
const SortPtr& in_ret_type)
47 : name(in_name), ret_type(in_ret_type) {}
48 const std::string name =
"";
51 const SortPtr ret_type =
nullptr;
52 std::vector<SortPtr> args;
60 std::map<std::string, CxxFunc*> functions_;
62 std::map<std::string, CxxFunc*> externs_;
64 std::map<std::string, CxxFunc*> memory_updates_;
66 std::set<std::string> source_files_;
68 std::set<ExprPtr> const_mems_;
70 std::set<ExprPtr> global_vars_;
76 bool SanityCheck()
const;
78 bool Bootstrap(
const std::string& root,
bool opt);
81 bool GenerateIlaBasics(
const std::string& dir);
83 bool GenerateInstrContent(
const InstrPtr& instr,
const std::string& dir);
85 bool GenerateMemoryUpdate(
const std::string& dir);
87 bool GenerateConstantMemory(
const std::string& dir);
89 bool GenerateInitialSetup(
const std::string& dir);
91 bool GenerateExecuteKernel(
const std::string& dir);
93 bool GenerateGlobalHeader(
const std::string& dir);
95 bool GenerateBuildSupport(
const std::string& dir);
98 bool RenderExpr(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
100 void DfsExpr(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
102 void DfsVar(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut)
const;
104 void DfsConst(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
106 void DfsOp(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
108 void DfsOpMemory(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
110 void DfsOpAppFunc(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
112 void DfsOpSpecial(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut);
114 void DfsOpRegular(
const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut)
const;
117 CxxFunc* RegisterFunction(
const std::string& func_name,
118 ExprPtr return_expr =
nullptr);
120 CxxFunc* RegisterExternalFunc(
const FuncPtr& func);
122 CxxFunc* RegisterMemoryUpdate(
const ExprPtr& expr);
125 void BeginFuncDef(CxxFunc* func, StrBuff& buff)
const;
127 void EndFuncDef(CxxFunc* func, StrBuff& buff)
const;
129 void WriteFuncDecl(CxxFunc* func, StrBuff& buff)
const;
131 void CommitSource(
const std::string& file_name,
const std::string& dir,
132 const StrBuff& buff);
135 inline std::string GetProjectName()
const {
return m_->name().str(); }
137 static inline std::string GetLocalVar(
const ExprVarMap& lut) {
138 return fmt::format(
"local_var_{}", lut.size());
141 static inline std::string GetCxxType(
const ExprPtr& expr) {
142 return GetCxxType(expr->sort());
145 static std::string GetCxxType(
const SortPtr& sort);
147 static std::string GetCxxName(
const ExprPtr& expr);
151 static std::string GetDecodeFuncName(
const InstrPtr& instr);
153 static std::string GetUpdateFuncName(
const InstrPtr& instr);
155 static std::string GetMemoryFuncName(
const ExprPtr& expr);
157 inline std::string LookUp(
const ExprPtr& e,
const ExprVarMap& lut)
const {
158 auto pos = lut.find(e);
167 #endif // ILANG_TARGET_SC_ILATOR_H__
#define ILA_ASSERT(b)
Assertion with message logged to FATAL (lvl 3). (Debug)
Definition: log.h:33
The ILAtor class - for CMake-based SystemC simulator generation.
Definition: ilator.h:21
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
InstrLvlAbs::InstrLvlAbsCnstPtr InstrLvlAbsCnstPtr
Pointer type for read-only usage of InstrLvlAbs.
Definition: instr_lvl_abs.h:328
Ilator(const InstrLvlAbsPtr &m)
Constructor with a fixed ILA model.
Sort::SortPtr SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:82
void Generate(const std::string &dst, bool opt)
Generate the SystemC simulator.
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
Func::FuncPtr FuncPtr
Pointer type for normal use of Func.
Definition: func.h:83
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326