1 | #include "struct_cc.h" |
---|---|
2 | #include "cc_layout.h" |
3 | #include "cc_utils.h" |
4 | |
5 | namespace taichi::lang { |
6 | namespace cccp { |
7 | |
8 | void CCLayoutGen::generate_children(SNode *snode) { |
9 | ScopedIndent _s(line_appender_); |
10 | for (auto const &ch : snode->ch) { |
11 | generate_types(ch.get()); |
12 | } |
13 | } |
14 | |
15 | void CCLayoutGen::generate_types(SNode *snode) { |
16 | // suffix is for the array size |
17 | auto node_name = snode->node_type_name; |
18 | auto struct_name = "Ti_"+ snode->get_node_type_name_hinted(); |
19 | |
20 | if (snode->type == SNodeType::place) { |
21 | const auto type = cc_data_type_name(snode->dt); |
22 | emit("{} {};", type, node_name); |
23 | |
24 | } else if (snode->type == SNodeType::root) { |
25 | emit("struct {} {{", struct_name); |
26 | generate_children(snode); |
27 | emit("}};"); |
28 | |
29 | } else if (snode->type == SNodeType::dense) { |
30 | emit("struct {} {{", struct_name); |
31 | generate_children(snode); |
32 | emit("}} {}[{}];", node_name, snode->num_cells_per_container); |
33 | |
34 | } else { |
35 | TI_ERROR("SNodeType={} not supported on C backend", |
36 | snode_type_name(snode->type)); |
37 | } |
38 | } |
39 | |
40 | std::unique_ptr<CCLayout> CCLayoutGen::compile() { |
41 | TI_ASSERT(root_->type == SNodeType::root); |
42 | generate_types(root_); |
43 | |
44 | auto lay = std::make_unique<CCLayout>(cc_program_impl_); |
45 | lay->source = line_appender_.lines(); |
46 | return lay; |
47 | } |
48 | |
49 | } // namespace cccp |
50 | } // namespace taichi::lang |
51 |