summaryrefslogtreecommitdiff
path: root/src/trans/codegen_c.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/trans/codegen_c.hpp')
-rw-r--r--src/trans/codegen_c.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/trans/codegen_c.hpp b/src/trans/codegen_c.hpp
new file mode 100644
index 00000000..72d0c796
--- /dev/null
+++ b/src/trans/codegen_c.hpp
@@ -0,0 +1,47 @@
+/*
+ */
+#pragma once
+#include <vector>
+#include <memory>
+
+class Node;
+
+struct NodeRef
+{
+ ::std::unique_ptr<Node> node;
+ size_t bb_idx;
+
+ NodeRef(size_t idx): bb_idx(idx) {}
+ NodeRef(Node node);
+
+ bool has_target() const;
+ size_t target() const;
+
+ bool operator==(size_t idx) const {
+ return !node && bb_idx == idx;
+ }
+};
+
+TAGGED_UNION(Node, Block,
+(Block, struct {
+ size_t next_bb;
+ ::std::vector<NodeRef> nodes;
+ }),
+(If, struct {
+ size_t next_bb;
+ const ::MIR::LValue* val;
+ NodeRef arm_false;
+ NodeRef arm_true;
+ }),
+(Switch, struct {
+ size_t next_bb;
+ const ::MIR::LValue* val;
+ ::std::vector<NodeRef> arms;
+ }),
+(Loop, struct {
+ size_t next_bb;
+ NodeRef code;
+ })
+);
+
+extern ::std::vector<Node> MIR_To_Structured(const ::MIR::Function& fcn);