7 #ifndef TREELITE_SEMANTIC_H_ 8 #define TREELITE_SEMANTIC_H_ 30 case Operator::kEQ:
return "==";
31 case Operator::kLT:
return "<";
32 case Operator::kLE:
return "<=";
33 case Operator::kGT:
return ">";
34 case Operator::kGE:
return ">=";
49 case Operator::kEQ:
return lhs == rhs;
50 case Operator::kLT:
return lhs < rhs;
51 case Operator::kLE:
return lhs <= rhs;
52 case Operator::kGT:
return lhs > rhs;
53 case Operator::kGE:
return lhs >= rhs;
54 default: LOG(FATAL) <<
"operator undefined";
68 virtual std::vector<std::string> Compile()
const = 0;
75 : preamble(preamble), body(body) {}
77 : preamble(std::move(preamble)), body(std::move(body)) {}
80 std::vector<std::string> Compile(
const std::string& header_filename)
const;
82 DeepCopyUniquePtr<CodeBlock> preamble;
83 DeepCopyUniquePtr<CodeBlock> body;
92 std::string prototype;
95 : prototype(prototype), dll_export(dll_export) {}
97 std::unique_ptr<CodeBlock> common_header;
98 std::vector<FunctionEntry> function_registry;
99 std::vector<TranslationUnit> units;
102 inline std::ostream &operator<<(std::ostream &os,
105 const std::string declspec(
"__declspec(dllexport) ");
107 const std::string declspec(
"");
109 if (entry.dll_export) {
110 os << declspec << entry.prototype <<
";\n";
112 os << entry.prototype <<
";\n";
122 explicit PlainBlock(
const std::string& inner_text)
123 : inner_text({inner_text}) {}
124 explicit PlainBlock(
const std::vector<std::string>& inner_text)
125 : inner_text(inner_text) {}
126 explicit PlainBlock(std::vector<std::string>&& inner_text)
127 : inner_text(std::move(inner_text)) {}
129 std::vector<std::string> Compile()
const override;
131 std::vector<std::string> inner_text;
145 std::vector<FunctionEntry>* p_function_registry,
146 bool dll_export =
false)
147 : prototype(prototype), body(body), dll_export(dll_export) {
148 if (p_function_registry !=
nullptr) {
149 p_function_registry->emplace_back(this->prototype, this->dll_export);
154 std::vector<FunctionEntry>* p_function_registry,
155 bool dll_export =
false)
156 : prototype(std::move(prototype)), body(std::move(body)),
157 dll_export(dll_export) {
158 if (p_function_registry !=
nullptr) {
159 p_function_registry->emplace_back(this->prototype, this->dll_export);
163 std::vector<std::string> Compile()
const override;
165 std::string prototype;
167 DeepCopyUniquePtr<CodeBlock> body;
175 std::vector<std::string> Compile()
const override;
176 void Reserve(
size_t size);
180 std::vector<DeepCopyUniquePtr<CodeBlock>> sequence;
187 virtual std::string Compile()
const = 0;
200 : condition(condition), if_block(if_block), else_block(else_block),
206 : condition(std::move(condition)),
207 if_block(std::move(if_block)), else_block(std::move(else_block)),
210 std::vector<std::string> Compile()
const override;
212 DeepCopyUniquePtr<Condition> condition;
213 DeepCopyUniquePtr<CodeBlock> if_block;
214 DeepCopyUniquePtr<CodeBlock> else_block;
220 #endif // TREELITE_SEMANTIC_H_ plain code block containing one or more lines of code
float tl_float
float type to be used internally
fundamental block in semantic model. All code blocks should inherit from this class.
std::string OpName(Operator op)
get string representation of comparsion operator
bool CompareWithOp(tl_float lhs, Operator op, tl_float rhs)
perform comparison between two float's using a comparsion operator The comparison will be in the form...
BranchHint
enum class to store branch annotation
abstract interface for classes that can be cloned
a wrapper around std::unique_ptr that supports deep copying and moving.
function block with a prototype and code body. Its prototype can optionally be registered with a func...
if-else statement with condition may store a branch hint (>50% or <50% likely)
#define CLONEABLE_BOILERPLATE(className)
macro to define boilerplate code for Cloneable classes
sequence of one or more code blocks
translation unit is abstraction of a source file
semantic model consists of a header, function registry, and a list of translation units ...
Operator
comparison operators