1 | #include "taichi/program/function.h" |
---|---|
2 | #include "taichi/program/program.h" |
3 | #include "taichi/ir/transforms.h" |
4 | #include "taichi/analysis/offline_cache_util.h" |
5 | |
6 | namespace taichi::lang { |
7 | |
8 | Function::Function(Program *program, const FunctionKey &func_key) |
9 | : func_key(func_key) { |
10 | this->program = program; |
11 | } |
12 | |
13 | void Function::set_function_body(const std::function<void()> &func) { |
14 | context = std::make_unique<FrontendContext>(program->compile_config().arch); |
15 | ir = context->get_root(); |
16 | ir_type_ = IRType::AST; |
17 | |
18 | func(); |
19 | |
20 | if (program->compile_config().offline_cache) { // For generating AST-Key |
21 | std::ostringstream oss; |
22 | gen_offline_cache_key(ir.get(), &oss); |
23 | ast_serialization_data_ = oss.str(); |
24 | } |
25 | } |
26 | |
27 | void Function::set_function_body(std::unique_ptr<IRNode> func_body) { |
28 | ir = std::move(func_body); |
29 | ir_type_ = IRType::InitialIR; |
30 | } |
31 | |
32 | std::string Function::get_name() const { |
33 | return func_key.get_full_name(); |
34 | } |
35 | |
36 | } // namespace taichi::lang |
37 |