diff --git a/src/compiler/backend.fut b/src/compiler/backend.fut new file mode 100644 index 0000000..08d0710 --- /dev/null +++ b/src/compiler/backend.fut @@ -0,0 +1,154 @@ +import "codegen/tree" +import "datatypes" +import "codegen/instr" +import "codegen/instr_count" +import "codegen/symtab" +import "codegen/register" +import "codegen/preprocess" +import "codegen/optimizer" +import "codegen/postprocess" +-- import "bridge" + +--Frontend bridge entry +-- entry make_from_frontend [n] +-- (node_types: [n]front_node_type) +-- (node_res_types: [n]front_data_type) +-- (node_parents: [n]front_node_idx_type) +-- (node_depth: [n]front_depth_type) +-- (node_child_idx : [n]front_child_idx_type) +-- (node_data: [n]front_node_data_type) +-- (max_depth: front_depth_type) : Tree[n] = +-- backend_convert node_types node_res_types node_parents node_depth node_child_idx node_data max_depth + +let make_variable (data_type: u8) (offset: u32) : Variable = + { + decl_type = i32.u8 data_type, + offset = offset + } + +let make_node (node_type: u8) (data_type: u8, parent: i32, depth: i32, child_idx: i32, node_data: u32) : Node = + { + node_type = i32.u8 node_type, + resulting_type = i32.u8 data_type, + parent = parent, + depth = depth, + child_idx = child_idx, + node_data = node_data + } + +let make_functab (id: u32) (start: u32) (size: u32) = + { + id = id, + start = start, + size = size + } + +-- Data structure rewrite functions +entry make_symtab [m] (data_types: [m]u8) (offsets: [m]u32) : Symtab[m] = + { + variables = map2 make_variable data_types offsets + } + +entry make_tree [n] (max_depth: i32) (node_types: [n]u8) (data_types: [n]u8) (parents: [n]i32) + (depth: [n]i32) (child_idx: [n]i32) (node_data: [n]u32): Tree[n] = + { + nodes = zip5 data_types parents depth child_idx node_data |> map2 make_node node_types, + max_depth = max_depth + } + +--Stage 1, preprocessor +entry stage_preprocess [n] (tree: Tree[n]) : (Tree[n]) = + tree |> preprocess_tree + +--Stage 2: instruction counting +entry stage_instr_count [n] (tree: Tree[n]) : [n]u32 = + instr_count tree + +--Stage 2.2: function table creation +entry stage_instr_count_make_function_table [n] (tree: Tree[n]) (instr_offset: [n]u32) = + get_function_table tree instr_offset + +entry stage_compact_functab [n] (func_id: [n]u32) (func_start: [n]u32) (func_size: [n]u32) : [n]FuncInfo = + map3 make_functab func_id func_start func_size + +let split_instr (instr: Instr) = + (instr.instr, instr.rd, instr.rs1, instr.rs2, instr.jt) + +--Stage 3: instruction gen +entry stage_instr_gen [n] [m] [k] (tree: Tree[n]) (symtab: Symtab[m]) (instr_offset: [n]u32) (func_tab: [k]FuncInfo) : []Instr = + let func_start = map (.start) func_tab + let func_size = map (.size) func_tab + let max_instrs = if n == 0 then 0 else i64.u32 instr_offset[n-1] + let instr_offset_i64 = map i64.u32 instr_offset + let func_ends = iota k |> map (\i -> func_start[i] + func_size[i]) + in + compile_tree tree symtab instr_offset_i64 max_instrs func_start func_ends + +let make_instr (instr: u32) (rd: i64) (rs1: i64) (rs2: i64) (jt: u32) = + { + instr = instr, + rd = rd, + rs1 = rs1, + rs2 = rs2, + jt = jt + } + +let split_functab (func_info: FuncInfo) = + (func_info.id, func_info.start, func_info.size) + +let fix_func_tab [n] (instr_offsets: [n]i32) (func_info: FuncInfo) = + let func_start = u32.i32 instr_offsets[i64.u32 func_info.start] + let func_end_loc = i64.u32 (func_info.start + func_info.size) + let func_end = if func_end_loc >= n then u32.i32 instr_offsets[n-1]+1 else u32.i32 instr_offsets[func_end_loc] + let func_size = func_end - func_start + in + { + id = func_info.id, + start = func_start, + size = func_size + } + +--Stage 4, optimizer +entry stage_optimize [n] [m] (instr_data: [n]Instr) (func_tab: [m]FuncInfo) : ([n]Instr, [m]FuncInfo, [n]bool) = + -- let instr_data = map5 make_instr instrs rd rs1 rs2 jt + -- let func_tab = map3 make_functab func_id func_start func_size + let (instrs, functab, optimize_away) = optimize instr_data func_tab + + -- let (res_instr, res_rd, res_rs1, res_rs2, res_jt) = instrs |> map split_instr |> unzip5 + -- let (res_id, res_start, res_size) = functab |> map split_functab |> unzip3 + in + (instrs, functab, optimize_away) + + +--Stage 5,6 regalloc + instr-split +entry stage_regalloc [n] [m] (instrs: [n]Instr) (func_tab: [m]FuncInfo) (func_symbols: [m]u32) (optimize_away: [n]bool) : ([]Instr, [m]FuncInfo) = + -- let instrs = map5 make_instr instrs rd rs1 rs2 jt + -- let func_tab = map3 make_functab func_id func_start func_size + + let (instr_offset, lifetime_mask, registers, overflows, swapped, instrs) = (instrs, func_tab, optimize_away, func_symbols) |> register_alloc + let func_tab = map (fix_func_tab instr_offset) func_tab + let new_instrs = fill_stack_frames func_tab func_symbols overflows instrs lifetime_mask + + -- let (res_instr, res_rd, res_rs1, res_rs2, res_jt) = new_instrs |> map split_instr |> unzip5 + in + (new_instrs, func_tab) + +--Stage 7: jump fix +entry stage_fix_jumps [n] [m] (instrs: [n]Instr) (func_tab: [m]FuncInfo) : ([]Instr, [m]u32, [m]u32, [m]u32) = + let (instrs, instr_offset) = instrs |> finalize_jumps + let func_tab = map (fix_func_tab instr_offset) func_tab + + let (res_id, res_start, res_size) = func_tab |> map split_functab |> unzip3 + in + (instrs, res_id, res_start, res_size) + +-- Stage 8: postprocess +entry stage_postprocess [n] (instrs: [n]Instr) = + -- let instrs = map5 make_instr instrs rd rs1 rs2 jt + + let result = instrs |> finalize_instr + let (res_instrs, _, _, _, _) = result |> map split_instr |> unzip5 + + in + + res_instrs diff --git a/src/compiler/bridge.fut b/src/compiler/bridge.fut new file mode 100644 index 0000000..44a9e5a --- /dev/null +++ b/src/compiler/bridge.fut @@ -0,0 +1,88 @@ +import "tree" +import "datatypes" + +type front_node_type = i32 +type front_data_type = i32 +type front_node_idx_type = i32 +type front_depth_type = i32 +type front_child_idx_type = i32 +type front_node_data_type = u32 + +let NODE_TYPE_LOOKUP : []NodeType = [ + --TODO: fill in table to map node types + 0 +] + +let DATA_TYPE_LOOKUP : []DataType = [ + 0, --Invalid + 1, --Void + 2, --Int + 3, --Float + 4, --Int_ref + 5 --Float_ref +] + +let convert_node_type (node_type: front_node_type) = + NODE_TYPE_LOOKUP[node_type] + +let convert_data_type (data_type: front_data_type) = + DATA_TYPE_LOOKUP[data_type] + +let convert_node_idx (idx: front_node_idx_type) = + idx + +let convert_depth (depth: front_depth_type) = + depth + +let convert_child_idx (child_idx: front_child_idx_type) = + child_idx + +let convert_node_data (node_data: front_node_data_type) = + node_data + +let backend_convert_node ( + node_type: front_node_type, + data_type: front_data_type, + parent: front_node_idx_type, + depth: front_depth_type, + child_idx: front_child_idx_type, + data: front_node_data_type) : Node = + { + node_type = convert_node_type node_type, + resulting_type = convert_data_type data_type, + parent = convert_node_idx parent, + depth = convert_depth depth, + child_idx = convert_child_idx child_idx, + node_data = convert_node_data data + } + +let zip6 [n] 'a 'b 'c 'd 'e 'f + (x0: [n]a) + (x1: [n]b) + (x2: [n]c) + (x3: [n]d) + (x4: [n]e) + (x5: [n]f) = + + let c1 = zip5 x0 x1 x2 x3 x4 + in + map2 (\(t0, t1, t2, t3, t4) t5 -> (t0, t1, t2, t3, t4, t5)) c1 x5 + +let backend_convert [n] + (node_types: [n]front_node_type) + (node_res_types: [n]front_data_type) + (node_parents: [n]front_node_idx_type) + (node_depth: [n]front_depth_type) + (node_child_idx : [n]front_child_idx_type) + (node_data: [n]front_node_data_type) + (max_depth: front_depth_type) : Tree[n] = + + let input = zip6 node_types node_res_types node_parents node_depth node_child_idx node_data + + let nodes: [n]Node = input |> + map backend_convert_node + + in { + nodes = nodes, + max_depth = convert_depth max_depth + } \ No newline at end of file diff --git a/src/compiler/codegen/bridge.fut b/src/compiler/codegen/bridge.fut new file mode 100644 index 0000000..b90c05b --- /dev/null +++ b/src/compiler/codegen/bridge.fut @@ -0,0 +1,88 @@ +import "tree" +import "datatypes" + +type front_node_type = i32 +type front_data_type = i32 +type front_node_idx_type = i32 +type front_depth_type = i32 +type front_child_idx_type = i32 +type front_node_data_type = u32 + +let NODE_TYPE_LOOKUP : []NodeType = [ + --TODO: fill in table to map node types + 0 +] + +let DATA_TYPE_LOOKUP : []DataType = [ + 0, --Invalid + 1, --Void + 2, --Int + 3, --Float + 4, --Int_ref + 5 --Float_ref +] + +let convert_node_type (node_type: front_node_type) = + NODE_TYPE_LOOKUP[node_type] + +let convert_data_type (data_type: front_data_type) = + DATA_TYPE_LOOKUP[data_type] + +let convert_node_idx (idx: front_node_idx_type) = + idx + +let convert_depth (depth: front_depth_type) = + depth + +let convert_child_idx (child_idx: front_child_idx_type) = + child_idx + +let convert_node_data (node_data: front_node_data_type) = + node_data + +let backend_convert_node ( + node_type: front_node_type, + data_type: front_data_type, + parent: front_node_idx_type, + depth: front_depth_type, + child_idx: front_child_idx_type, + data: front_node_data_type) : Node = + { + node_type = convert_node_type node_type, + resulting_type = convert_data_type data_type, + parent = convert_node_idx parent, + depth = convert_depth depth, + child_idx = convert_child_idx child_idx, + node_data = convert_node_data data + } + +let zip6 [n] 'a 'b 'c 'd 'e 'f + (x0: [n]a) + (x1: [n]b) + (x2: [n]c) + (x3: [n]d) + (x4: [n]e) + (x5: [n]f) = + + let c1 = zip5 x0 x1 x2 x3 x4 + in + map2 (\(t0, t1, t2, t3, t4) t5 -> (t0, t1, t2, t3, t4, t5)) c1 x5 + +let backend_convert [n] + (node_types: [n]front_node_type) + (node_res_types: [n]front_data_type) + (node_parents: [n]front_node_idx_type) + (node_depth: [n]front_depth_type) + (node_child_idx : [n]front_child_idx_type) + (node_data: [n]front_node_data_type) + (max_depth: front_depth_type) : Tree[n] = + + let input = zip6 node_types node_res_types node_parents node_depth node_child_idx node_data + + let nodes: [n]Node = input |> + map backend_convert_node + + in { + nodes = nodes, + max_depth = convert_depth max_depth + } diff --git a/src/compiler/codegen/instr.fut b/src/compiler/codegen/instr.fut new file mode 100644 index 0000000..ec6fde0 --- /dev/null +++ b/src/compiler/codegen/instr.fut @@ -0,0 +1,2116 @@ +import "tree" +import "datatypes" +import "symtab" +import "instr_count" +import "../lib/github.com/diku-dk/sorts/radix_sort" + +type Instr = { + instr: u32, + rd: i64, + rs1: i64, + rs2: i64, + jt: u32 +} + +let EMPTY_INSTR : Instr = { + instr = 0, + rd = 0, + rs1 = 0, + rs2 = 0, + jt = 0 +} + +let PARENT_IDX_PER_NODE : i64 = 3 + +let INSTR_TABLE : [][][]u32 = [ + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Invalid + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Statement list + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Empty statement + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_01000_00010_000_00010_0110011, 0b0000000_01000_00010_000_00010_0110011, 0b0000000_01000_00010_000_00010_0110011, 0b0000000_01000_00010_000_00010_0110011, 0b0000000_01000_00010_000_00010_0110011, 0b0000000_01000_00010_000_00010_0110011], + [0b1111111_11100_00010_010_00001_0100011, 0b1111111_11100_00010_010_00001_0100011, 0b1111111_11100_00010_010_00001_0100011, 0b1111111_11100_00010_010_00001_0100011, 0b1111111_11100_00010_010_00001_0100011, 0b1111111_11100_00010_010_00001_0100011], + [0b1111111_11000_00010_010_01000_0100011, 0b1111111_11000_00010_010_01000_0100011, 0b1111111_11000_00010_010_01000_0100011, 0b1111111_11000_00010_010_01000_0100011, 0b1111111_11000_00010_010_01000_0100011, 0b1111111_11000_00010_010_01000_0100011], + [0b0000000_00000_00001_000_00000_1100111, 0b0000000_00000_00001_000_00000_1100111, 0b0000000_00000_00001_000_00000_1100111, 0b0000000_00000_00001_000_00000_1100111, 0b0000000_00000_00001_000_00000_1100111, 0b0000000_00000_00001_000_00000_1100111] + ], --Func decl + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100111], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Func arg + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Func arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Expr stat + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --If stat + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011], + [0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --If else stat + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011, 0b0000000_00000_00000_000_00000_1100011], + [0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --While stat + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00001_1100111, 0b0000000_00000_00000_000_00001_1100111, 0b0000000_00000_00000_000_00001_1100111, 0b0000000_00000_00000_000_00001_1100111, 0b0000000_00000_00000_000_00001_1100111, 0b0000000_00000_00000_000_00001_1100111], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_01010_000_00000_0110011, 0b0010000_01010_01010_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Func call expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0110011, 0b0010000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Func call arg + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00010_111_00010_0010011, 0b0000000_00000_00010_111_00010_0010011, 0b0000000_00000_00010_111_00010_0010011, 0b0000000_00000_00010_111_00010_0010011, 0b0000000_00000_00010_111_00010_0010011, 0b0000000_00000_00010_111_00010_0010011], + [0b0000000_00000_00010_110_00010_0010011, 0b0000000_00000_00010_110_00010_0010011, 0b0000000_00000_00010_110_00010_0010011, 0b0000000_00000_00010_110_00010_0010011, 0b0000000_00000_00010_110_00010_0010011, 0b0000000_00000_00010_110_00010_0010011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Func call arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0110011, 0b0000000_00000_00000_111_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Add expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0100000_00000_00000_000_00000_0110011, 0b0000100_00000_00000_111_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Sub expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000001_00000_00000_000_00000_0110011, 0b0001000_00000_00000_111_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Mul expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000001_00000_00000_100_00000_0110011, 0b0001100_00000_00000_111_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Div expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000001_00000_00000_110_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Mod expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_111_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Bitand expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_110_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Bitor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_100_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Bitxor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_001_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Lshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0100000_00000_00000_101_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Rshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_101_00000_0110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Urshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Land expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Lor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0100000_00000_00000_000_00000_0110011, 0b1010000_00000_00000_010_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00001_00000_011_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Eq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0100000_00000_00000_000_00000_0110011, 0b1010000_00000_00000_010_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_011_00000_0110011, 0b0000000_00001_00000_011_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Neq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0110011, 0b1010000_00000_00000_001_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Less expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0110011, 0b1010000_00000_00000_001_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Great expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0110011, 0b1010000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00001_00000_011_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Lesseq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0110011, 0b1010000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00001_00000_011_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Greateq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b1111111_11111_00000_100_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Bitnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00001_00000_011_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Lnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0100000_00000_00000_000_00000_0110011, 0b0010000_00000_00000_001_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Neg expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0110111, 0b0000000_00000_00000_000_00000_0110111, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0010011, 0b0000000_00000_00000_000_00000_0010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b1111000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Lit expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b1100000_00000_00000_111_00000_1010011, 0b1101000_00000_00000_111_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Cast expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0000011, 0b0000000_00000_00000_010_00000_0000111, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Deref expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100111, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0110011, 0b0010000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Assign expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Decl expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011, 0b0000000_00000_01000_000_00000_0010011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Id expr + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --While dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [0b1111111_00001_00010_010_11100_1110011, 0b1111111_00001_00010_010_11100_1110011, 0b1111111_00001_00010_010_11100_1110011, 0b1111111_00001_00010_010_11100_1110011, 0b1111111_00001_00010_010_11100_1110011, 0b1111111_00001_00010_010_11100_1110011], + [0b1111111_01000_00010_010_11000_1110011, 0b1111111_01000_00010_010_11000_1110011, 0b1111111_01000_00010_010_11000_1110011, 0b1111111_01000_00010_010_11000_1110011, 0b1111111_01000_00010_010_11000_1110011, 0b1111111_01000_00010_010_11000_1110011], + [0b0100000_01000_00010_011_00010_0110011, 0b0100000_01000_00010_011_00010_0110011, 0b0100000_01000_00010_011_00010_0110011, 0b0100000_01000_00010_011_00010_0110011, 0b0100000_01000_00010_011_00010_0110011, 0b0100000_01000_00010_011_00010_0110011], + [0b0000000_00010_01000_000_01000_0110011, 0b0000000_00010_01000_000_01000_0110011, 0b0000000_00010_01000_000_01000_0110011, 0b0000000_00010_01000_000_01000_0110011, 0b0000000_00010_01000_000_01000_0110011, 0b0000000_00010_01000_000_01000_0110011] + ], --Func decl dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_0110011, 0b0000000_00000_00000_000_00000_0110011, 0b0010000_00000_00000_000_00000_1010011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111, 0b0000000_00000_00000_000_00000_1100111], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Return stat + [ -- Invalid Void Int Float Int_ref Float_ref + [0b1110000_00000_00000_000_00000_1010011, 0b1110000_00000_00000_000_00000_1010011, 0b1110000_00000_00000_000_00000_1010011, 0b1110000_00000_00000_000_00000_1010011, 0b1110000_00000_00000_000_00000_1010011, 0b1110000_00000_00000_000_00000_1010011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Call arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_010_00010_0100011, 0b0000000_00000_00000_010_00010_0100111, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Call arg stack + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ], --Arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [0b0000000_00000_01000_010_00000_0100011, 0b0000000_00000_01000_010_00000_0100011, 0b0000000_00000_01000_010_00000_0100011, 0b0000000_00000_01000_010_00000_0100011, 0b0000000_00000_01000_010_00000_0100011, 0b0000000_00000_01000_010_00000_0100011], + [0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011, 0b0000000_00000_00000_010_00000_0100011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011], + [0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011, 0b0000000_00000_00000_000_00000_1110011] + ] --Arg stack +] + +let HAS_INSTR_TABLE : [][][]bool = [ + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Invalid + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Statement list + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Empty statement + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [true, true, true, true, true, true] + ], --Func decl + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func arg + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Expr stat + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --If stat + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --If else stat + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --While stat + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, true, true, false, false], + [false, false, false, false, false, false] + ], --Func call expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func call arg + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func call arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Add expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Sub expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Mul expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Div expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Mod expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitand expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitxor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Rshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Urshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Land expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Eq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Neq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Less expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Great expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lesseq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Greateq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Neg expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, true, false, false], + [false, false, false, false, false, false] + ], --Lit expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Cast expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Deref expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Assign expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Decl expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Id expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --While dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [true, true, true, true, true, true] + ], --Func decl dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Return stat + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Call arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Call arg stack + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ] --Arg stack +] + +let NODE_GET_PARENT_ARG_IDX_LOOKUP : [][][]i8 = [ + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Invalid + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Statement list + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Empty statement + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func decl + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func arg + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func arg list + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Expr stat + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --If stat + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --If else stat + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --While stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call arg + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call arg list + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Add expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Sub expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Mul expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Div expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Mod expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitand expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitor expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitxor expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Rshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Urshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Land expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lor expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 0, 2, 2, 2], + [0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Eq expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [1, 1, 1, 1, 1, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Neq expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Less expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Great expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 0, 2, 2, 2], + [0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lesseq expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 0, 2, 2, 2], + [0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Greateq expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Neg expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [1, 1, 1, 0, 1, 1], + [0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lit expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Cast expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Deref expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [1, 1, 1, 1, 1, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Assign expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Decl expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Id expr + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --While dummy + [ -- Inval Void Int Float Int_ref Float_ref + [2, 2, 2, 2, 2, 2], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func decl dummy + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Return stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Call arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Call arg stack + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ] --Arg stack +] + +let HAS_OUTPUT_TABLE : [][][]bool = [ + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Invalid + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Statement list + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Empty statement + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func decl + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func arg + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Expr stat + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --If stat + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --If else stat + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --While stat + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func call expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func call arg + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func call arg list + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Add expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Sub expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Mul expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Div expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Mod expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitand expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitxor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Rshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Urshift expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Land expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lor expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Eq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Neq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Less expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Great expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lesseq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, true, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Greateq expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Bitnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lnot expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Neg expr + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, true, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Lit expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Cast expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Deref expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Assign expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Decl expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Id expr + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --While dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Func decl dummy + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Return stat + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Call arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Call arg stack + [ -- Invalid Void Int Float Int_ref Float_ref + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ], --Arg float in int + [ -- Invalid Void Int Float Int_ref Float_ref + [true, true, true, true, true, true], + [false, false, false, false, false, false], + [false, false, false, false, false, false], + [false, false, false, false, false, false] + ] --Arg stack +] + +let INSTR_CONSTANT_TABLE : [][]i8 = [ + [0,0,0,0], --Invalid + [0,0,0,0], --Statement list + [0,0,0,0], --Empty statement + [0,0,0,0], --Func decl + [0,0,0,0], --Func arg + [0,0,0,0], --Func arg list + [0,0,0,0], --Expr stat + [0,0,0,0], --If stat + [0,0,0,0], --If else stat + [0,0,0,0], --While stat + [0,0,0,0], --Func call expr + [0,0,0,0], --Func call arg + [5,4,0,0], --Func call arg list + [0,0,0,0], --Add expr + [0,0,0,0], --Sub expr + [0,0,0,0], --Mul expr + [0,0,0,0], --Div expr + [0,0,0,0], --Mod expr + [0,0,0,0], --Bitand expr + [0,0,0,0], --Bitor expr + [0,0,0,0], --Bitxor expr + [0,0,0,0], --Lshift expr + [0,0,0,0], --Rshift expr + [0,0,0,0], --Urshift expr + [0,0,0,0], --Land expr + [0,0,0,0], --Lor expr + [0,0,0,0], --Eq expr + [0,0,0,0], --Neq expr + [0,0,0,0], --Less expr + [0,0,0,0], --Great expr + [0,0,0,0], --Lesseq expr + [0,0,0,0], --Greateq expr + [0,0,0,0], --Bitnot expr + [0,0,0,0], --Lnot expr + [0,0,0,0], --Neg expr + [1,2,0,0], --Lit expr + [0,0,0,0], --Cast expr + [0,0,0,0], --Deref expr + [0,0,0,0], --Assign expr + [3,0,0,0], --Decl expr + [3,0,0,0], --Id expr + [0,0,0,0], --While dummy + [0,0,0,0], --Func decl dummy + [0,0,0,0], --Return stat + [0,0,0,0], --Call arg float in int + [4,0,0,0], --Call arg stack + [0,0,0,0], --Arg float in int + [4,0,0,0] --Arg stack +] + +let INSTR_JT_TABLE : [][]i8 = [ + [0,0,0,0], --Invalid + [0,0,0,0], --Statement list + [0,0,0,0], --Empty statement + [0,0,0,0], --Func decl + [0,0,0,0], --Func arg + [0,0,0,0], --Func arg list + [0,0,0,0], --Expr stat + [1,0,0,0], --If stat + [2,3,0,0], --If else stat + [4,5,0,0], --While stat + [7,0,0,0], --Func call expr + [0,0,0,0], --Func call arg + [0,0,0,0], --Func call arg list + [0,0,0,0], --Add expr + [0,0,0,0], --Sub expr + [0,0,0,0], --Mul expr + [0,0,0,0], --Div expr + [0,0,0,0], --Mod expr + [0,0,0,0], --Bitand expr + [0,0,0,0], --Bitor expr + [0,0,0,0], --Bitxor expr + [0,0,0,0], --Lshift expr + [0,0,0,0], --Rshift expr + [0,0,0,0], --Urshift expr + [0,0,0,0], --Land expr + [0,0,0,0], --Lor expr + [0,0,0,0], --Eq expr + [0,0,0,0], --Neq expr + [0,0,0,0], --Less expr + [0,0,0,0], --Great expr + [0,0,0,0], --Lesseq expr + [0,0,0,0], --Greateq expr + [0,0,0,0], --Bitnot expr + [0,0,0,0], --Lnot expr + [0,0,0,0], --Neg expr + [0,0,0,0], --Lit expr + [0,0,0,0], --Cast expr + [0,0,0,0], --Deref expr + [0,0,0,0], --Assign expr + [0,0,0,0], --Decl expr + [0,0,0,0], --Id expr + [0,0,0,0], --While dummy + [0,0,0,0], --Func decl dummy + [0,6,0,0], --Return stat + [0,0,0,0], --Call arg float in int + [0,0,0,0], --Call arg stack + [0,0,0,0], --Arg float in int + [0,0,0,0] --Arg stack +] + +let GET_OUTPUT_TABLE : [][][]i8 = [ + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Invalid + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Statement list + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Empty statement + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func decl + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func arg + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func arg list + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Expr stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --If stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --If else stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --While stat + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 1, 2, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call arg + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func call arg list + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Add expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Sub expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Mul expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Div expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Mod expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitand expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitor expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitxor expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Rshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Urshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Land expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lor expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Eq expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Neq expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Less expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Great expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lesseq expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Greateq expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Bitnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Neg expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Lit expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Cast expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Deref expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Assign expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Decl expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Id expr + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --While dummy + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Func decl dummy + [ -- Inval Void Int Float Int_ref Float_ref + [4, 4, 4, 3, 4, 4], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Return stat + [ -- Inval Void Int Float Int_ref Float_ref + [1, 1, 1, 1, 1, 1], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Call arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Call arg stack + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ], --Arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0] + ] --Arg stack +] + +let OPERAND_TABLE : [][][][]i8 = [ + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Invalid + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Statement list + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Empty statement + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func decl + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,2], [1,3]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func arg + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func arg list + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Expr stat + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --If stat + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --If else stat + [ -- Inval Void Int Float Int_ref Float_ref + [[4,0], [4,0], [4,0], [4,0], [4,0], [4,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --While stat + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func call expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,6], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func call arg + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func call arg list + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Add expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Sub expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Mul expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Div expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Mod expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Bitand expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Bitor expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Bitxor expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Lshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Rshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Urshift expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Land expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Lor expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [7,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Eq expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,7], [7,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Neq expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Less expr + [ -- Inval Void Int Float Int_ref Float_ref + [[5,5], [5,5], [5,5], [5,5], [5,5], [5,5]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Great expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [5,5], [1,1], [0,0], [0,0]], + [[0,0], [0,0], [7,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Lesseq expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [1,1], [5,5], [0,0], [0,0]], + [[0,0], [0,0], [7,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Greateq expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Bitnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Lnot expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Neg expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[7,0], [7,0], [7,0], [7,0], [7,0], [7,0]], + [[0,0], [0,0], [0,0], [7,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Lit expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Cast expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Deref expr + [ -- Inval Void Int Float Int_ref Float_ref + [[1,1], [1,1], [1,1], [1,1], [1,1], [1,1]], + [[4,0], [4,0], [4,0], [4,4], [4,0], [4,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Assign expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Decl expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Id expr + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --While dummy + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Func decl dummy + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [1,0], [1,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Return stat + [ -- Inval Void Int Float Int_ref Float_ref + [[1,0], [1,0], [1,0], [1,0], [1,0], [1,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Call arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [[6,0], [6,0], [6,0], [6,0], [6,0], [6,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Call arg stack + [ -- Inval Void Int Float Int_ref Float_ref + [[1,2], [1,2], [1,2], [1,2], [1,2], [1,2]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ], --Arg float in int + [ -- Inval Void Int Float Int_ref Float_ref + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[1,7], [1,7], [1,7], [1,7], [1,7], [1,7]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]], + [[0,0], [0,0], [0,0], [0,0], [0,0], [0,0]] + ] --Arg stack +] + +let node_instr(node_type: NodeType) (data_type: DataType) (instr_offset: i64) : u32 = + INSTR_TABLE[node_type, instr_offset, data_type] + +let has_instr (node_type: NodeType) (data_type: DataType) (instr_offset: i64) : bool = + HAS_INSTR_TABLE[node_type, instr_offset, data_type] + +let node_has_return(_ : NodeType) (data_type : DataType) : bool = + !(data_type == datatype_void || data_type == node_type_invalid) + +let parent_arg_idx (node: Node) : i64 = + i64.i32 node.parent * PARENT_IDX_PER_NODE + i64.i32 node.child_idx + +let node_get_parent_arg_idx_sub (node: Node) (instr_offset: i64) : i64 = + let calc_type = NODE_GET_PARENT_ARG_IDX_LOOKUP[node.node_type, instr_offset, node.resulting_type] in + if calc_type == 1 then + parent_arg_idx node + else if calc_type == 2 then + if node_has_return node.node_type node.resulting_type then + parent_arg_idx node + else + -1 + else + -1 + +let node_get_parent_arg_idx (nodes: []Node) (node: Node) (instr_offset: i64) : i64 = + if node.parent == INVALID_NODE_IDX then + node_get_parent_arg_idx_sub node instr_offset + else + let parent = nodes[node.parent] + in + if node.child_idx > 0 && (parent.node_type == node_type_if_stat || parent.node_type == node_type_if_else_stat) then + parent_arg_idx node + else if (node.child_idx == 0 || node.child_idx == 2) && (parent.node_type == node_type_while_stat) then + parent_arg_idx node + else + node_get_parent_arg_idx_sub node instr_offset + +let register (instr_no: i64) = + instr_no + 64 + +let node_get_instr_arg (node_id: i64) (node: Node) (registers: []i64) (arg_no: i64) (instr_no: i64) (instr_offset: i64) : i64 = + let calc_type = OPERAND_TABLE[node.node_type, instr_offset, node.resulting_type, arg_no] in + if calc_type == 1 then + registers[node_id * PARENT_IDX_PER_NODE + arg_no] + else if calc_type == 2 then + i64.u32 node.node_data + 10 + else if calc_type == 3 then + i64.u32 node.node_data + 42 + else if calc_type == 4 then + registers[node_id * PARENT_IDX_PER_NODE + 1] + else if calc_type == 5 then + registers[node_id * PARENT_IDX_PER_NODE + 1 - arg_no] + else if calc_type == 6 then + registers[node_id * PARENT_IDX_PER_NODE] + else if calc_type == 7 then + register (instr_no - 1) + else + 0 + +let node_has_output (nodes: []Node) (node: Node) (instr_offset: i64) : bool = + (node_get_parent_arg_idx nodes node instr_offset) != -1 || HAS_OUTPUT_TABLE[node.node_type, instr_offset, node.resulting_type] + +-- let make_branch_constant (node_id: i64) (registers: []i64) (delta: i64) (instr_loc: i64) (idx: i64) : u32 = +-- let offset = (registers[node_id * PARENT_IDX_PER_NODE + idx] + delta - instr_loc) * 4 +-- let low_offset = (((offset >> 1) & 0xF) << 1) | ((offset >> 11) & 0x1) +-- let high_offset = ((offset >> 5) & 0x1F) | (((offset >> 12) & 0x1) << 5) +-- in +-- u32.i64 ((low_offset << 7) | (high_offset << 25)) + +-- let make_jump_constant (node_id: i64) (registers: []i64) (instr_loc: i64) (idx: i64): u32 = +-- let offset = (registers[node_id * PARENT_IDX_PER_NODE + idx] - instr_loc) * 4 +-- in +-- u32.i64 ( +-- (((offset >> 12) & 0xFF) << 12) | +-- (((offset >> 11) & 0x1) << 20) | +-- (((offset >> 1) & 0x3FF) << 21) | +-- (((offset >> 20) & 0x1) << 31) +-- ) + +let signextend(x: u32) = + let signed_x = i32.u32 x in + u32.i32 (signed_x << 20 >> 20) + +let instr_constant [max_vars] (node: Node) (instr_offset: i64) (symtab: Symtab[max_vars]) : u32 = + let calc_type = INSTR_CONSTANT_TABLE[node.node_type, instr_offset] in + if calc_type == 1 then + node.node_data - (signextend (node.node_data & 0xFFF)) & 0xFFFFF000 + else if calc_type == 2 then + (node.node_data & 0xFFF) << 20 + else if calc_type == 3 then + (-(4 * ((symtab_local_offset symtab node.node_data) + 2))) << 20 + else if calc_type == 4 then + (4 * node.node_data) << 20 + else if calc_type == 5 then + (-(4 * node.node_data)) << 20 + else + 0 + +let instr_jt (node: Node) + (node_id: i64) (instr_offset: i64) (registers: []i64) (func_starts: []u32) (func_ends: []u32): i64 = + let calc_type = INSTR_JT_TABLE[node.node_type, instr_offset] in + if calc_type == 1 then + registers[node_id * PARENT_IDX_PER_NODE + 1] + else if calc_type == 2 then + registers[node_id * PARENT_IDX_PER_NODE + 1] + 1 + else if calc_type == 3 then + registers[node_id * PARENT_IDX_PER_NODE + 2] + else if calc_type == 4 then + registers[node_id * PARENT_IDX_PER_NODE + 2] + 1 + else if calc_type == 5 then + registers[node_id * PARENT_IDX_PER_NODE] + else if calc_type == 6 then + i64.u32 func_ends[i64.u32 node.node_data] - 6 + else if calc_type == 7 then + i64.u32 func_starts[i64.u32 node.node_data] + else + 0 + +let get_instr_loc (node: Node) (nodes: []Node) (node_id: i64) (instr_no: i64) (instr_offset: i64) (registers: []i64) = + if instr_offset == 1 && (node.node_type == node_type_if_else_stat) then + registers[node_id * PARENT_IDX_PER_NODE + 1] + else if instr_offset == 1 && node.node_type == node_type_while_stat then + registers[node_id * PARENT_IDX_PER_NODE + 2] + else if (instr_offset >= 2 && node.node_type == node_type_func_decl_dummy) || node.node_type == node_type_func_decl then + instr_no + 2 + else if instr_offset == 1 && (node.node_type == node_type_func_call_arg_list) then + if node_id == 0 then + instr_no + 2 + else + let prev_node = nodes[node_id - 1] + in + instr_no + 2 + (if prev_node.node_type == node_type_func_call_arg || prev_node.node_type == node_type_func_call_arg_float_in_int || prev_node.node_type == node_type_func_call_arg_stack then + i64.i32 prev_node.child_idx + else + 0 + ) + else + instr_no + +let get_data_prop_value [tree_size] (tree: Tree[tree_size]) (node: Node) (rd: i64) (instr_no: i64) = + if node.parent == INVALID_NODE_IDX then + rd + else + let parent_type = tree.nodes[node.parent].node_type + let instr_no = instr_no + i64.u32 NODE_COUNT_TABLE[node.node_type, node.resulting_type] + in + if parent_type == node_type_if_stat || parent_type == node_type_if_else_stat then + if node.child_idx == 1 || node.child_idx == 2 then + instr_no + else + rd + else if parent_type == node_type_while_stat then + if node.child_idx == 0 || node.child_idx == 2 then + instr_no + else + rd + else + rd + +let get_output_register [tree_size] (tree: Tree[tree_size]) (node: Node) (instr_no: i64) (instr_offset: i64) = + let calc_type = GET_OUTPUT_TABLE[node.node_type, instr_offset, node.resulting_type] in + if calc_type == 1 then + i64.u32 node.node_data + 10 + else if calc_type == 2 then + i64.u32 node.node_data + 42 + else if calc_type == 3 then + 32 + else if calc_type == 4 then + 10 + else + if node_has_output tree.nodes node instr_offset then register instr_no else 0 + +let get_node_instr [tree_size] [max_vars] (tree: Tree[tree_size]) (node: Node) (instr_no: i64) (node_index: i64) (registers: []i64) (symtab: Symtab[max_vars]) (func_starts: []u32) (func_ends: []u32) (instr_offset: i64): (i64, i64, Instr, i64) = + let node_type = node.node_type + let data_type = node.resulting_type + let rd = get_output_register tree node instr_no instr_offset + let instr_loc = get_instr_loc node tree.nodes node_index instr_no instr_offset registers + in + ( + instr_loc, + node_get_parent_arg_idx tree.nodes node instr_offset, + { + instr = node_instr node_type data_type instr_offset | instr_constant node instr_offset symtab, + rd = rd, + rs1 = node_get_instr_arg node_index node registers 0 instr_no instr_offset, + rs2 = node_get_instr_arg node_index node registers 1 instr_no instr_offset, + jt = u32.i64 (instr_jt node node_index instr_offset registers func_starts func_ends) + }, + get_data_prop_value tree node rd instr_no + ) + +let compile_node [tree_size] [max_vars] (tree: Tree[tree_size]) (symtab: Symtab[max_vars]) (registers: []i64) (instr_offset: [tree_size]i64) (func_starts: []u32) (func_ends: []u32) + (node_index: i64) = + let node = tree.nodes[node_index] + let node_instr = instr_offset[node_index] + in + iota 4i64 |> + map (\i -> + if has_instr node.node_type node.resulting_type i then + get_node_instr tree node (node_instr+i) node_index registers symtab func_starts func_ends i + else if i == 0 then + (-1, node_get_parent_arg_idx tree.nodes node 0, EMPTY_INSTR, get_data_prop_value tree node 0 node_instr) + else + (-1, -1, EMPTY_INSTR, 0) + ) + -- [ + -- if has_instr node.node_type node.resulting_type 0 then + -- get_node_instr tree node node_instr node_index registers symtab func_starts func_ends 0 + -- else + -- (-1, node_get_parent_arg_idx tree.nodes node 0, EMPTY_INSTR, get_data_prop_value tree node 0 node_instr) + -- , + -- if has_instr node.node_type node.resulting_type 1 then get_node_instr tree node (node_instr+1) node_index registers symtab func_starts func_ends 1 else (-1, -1, EMPTY_INSTR, 0), + -- if has_instr node.node_type node.resulting_type 2 then get_node_instr tree node (node_instr+2) node_index registers symtab func_starts func_ends 2 else (-1, -1, EMPTY_INSTR, 0), + -- if has_instr node.node_type node.resulting_type 3 then get_node_instr tree node (node_instr+3) node_index registers symtab func_starts func_ends 3 else (-1, -1, EMPTY_INSTR, 0) + -- ] + +let check_idx_node_depth [tree_size] (tree: Tree[tree_size]) (depth: i32) (i: i64) = + is_level tree.nodes[i] depth + +let bit_width (x: i32): i32 = + i32.num_bits - (i32.clz x) + +let compile_tree [tree_size] [max_vars] [num_funcs] (tree: Tree[tree_size]) (symtab: Symtab[max_vars]) (instr_offset: [tree_size]i64) (max_instrs: i64) (func_starts: [num_funcs]u32) (func_ends: [num_funcs]u32) = + let idx_array = iota tree_size |> radix_sort (bit_width tree.max_depth) (\bit idx -> i32.get_bit bit tree.nodes[idx].depth) + let depth_starts = iota tree_size |> filter (\i -> i == 0 || tree.nodes[idx_array[i]].depth != tree.nodes[idx_array[i-1]].depth) + let initial_registers = replicate (tree_size * PARENT_IDX_PER_NODE) 0i64 + let initial_instr = replicate max_instrs EMPTY_INSTR + let (instr_result, _) = + loop (data, registers) = (initial_instr, initial_registers) for i < tree.max_depth+1 do + let j = tree.max_depth-i + let start = depth_starts[j] + let end = if j == tree.max_depth then tree_size else depth_starts[j + 1] + let (idx, parent_idx, instrs, new_regs) = + idx_array[start:end] |> + map (compile_node tree symtab (copy registers) instr_offset func_starts func_ends) |> + flatten |> + unzip4 + in + ( + scatter data idx instrs, + scatter registers parent_idx new_regs + ) + in + instr_result diff --git a/src/compiler/codegen/instr_count.fut b/src/compiler/codegen/instr_count.fut new file mode 100644 index 0000000..58ca08c --- /dev/null +++ b/src/compiler/codegen/instr_count.fut @@ -0,0 +1,186 @@ +import "tree" +import "datatypes" + +let NODE_COUNT_TABLE : [][]u32 = [ +-- Invalid Void Int Float Int_ref Float_ref + [0, 0, 0, 0, 0, 0], --Invalid + [0, 0, 0, 0, 0, 0], --Statement list + [0, 0, 0, 0, 0, 0], --Empty statement + [6, 6, 6, 6, 6, 6], --Func decl + [1, 1, 1, 1, 1, 1], --Func arg + [0, 0, 0, 0, 0, 0], --Func arg list + [0, 0, 0, 0, 0, 0], --Expr stat + [0, 0, 0, 0, 0, 0], --If stat + [0, 0, 0, 0, 0, 0], --If else stat + [1, 1, 1, 1, 1, 1], --While stat + [3, 2, 3, 3, 3, 3], --Func call expr + [0, 0, 0, 0, 0, 0], --Func call arg + [0, 0, 0, 0, 0, 0], --Func call arg list + [1, 1, 1, 1, 1, 1], --Add expr + [1, 1, 1, 1, 1, 1], --Sub expr + [1, 1, 1, 1, 1, 1], --Mul expr + [1, 1, 1, 1, 1, 1], --Div expr + [1, 1, 1, 1, 1, 1], --Mod expr + [1, 1, 1, 1, 1, 1], --Bitand expr + [1, 1, 1, 1, 1, 1], --Bitor expr + [1, 1, 1, 1, 1, 1], --Bitxor expr + [1, 1, 1, 1, 1, 1], --Lshift expr + [1, 1, 1, 1, 1, 1], --Rshift expr + [1, 1, 1, 1, 1, 1], --Urshift expr + [0, 0, 0, 0, 0, 0], --Land expr + [0, 0, 0, 0, 0, 0], --Lor expr + [0, 0, 2, 1, 0, 0], --Eq expr + [2, 2, 2, 2, 2, 2], --Neq expr + [1, 1, 1, 1, 1, 1], --Less expr + [1, 1, 1, 1, 1, 1], --Great expr + [0, 0, 2, 1, 0, 0], --Lesseq expr + [0, 0, 2, 1, 0, 0], --Greateq expr + [1, 1, 1, 1, 1, 1], --Bitnot expr + [1, 1, 1, 1, 1, 1], --Lnot expr + [1, 1, 1, 1, 1, 1], --Neg expr + [0, 0, 2, 3, 0, 0], --Lit expr + [1, 1, 1, 1, 1, 1], --Cast expr + [1, 1, 1, 1, 1, 1], --Deref expr + [2, 2, 2, 2, 2, 2], --Assign expr + [1, 1, 1, 1, 1, 1], --Decl expr + [1, 1, 1, 1, 1, 1], --Id expr + [0, 0, 0, 0, 0, 0], --While dummy + [6, 6, 6, 6, 6, 6], --Func decl dummy + [2, 2, 2, 2, 2, 2], --Return stat + [0, 0, 0, 0, 0, 0], --Call arg float in int + [0, 0, 0, 0, 0, 0], --Call arg stack + [1, 1, 1, 1, 1, 1], --Arg float in int + [2, 2, 2, 2, 2, 2] --Arg stack +] + +let node_type_counts (t: NodeType) (d: DataType) : u32 = + NODE_COUNT_TABLE[t, d] + +let node_counts (nodes: []Node) (instr_offset: i64) = + let n = nodes[instr_offset] + let base_count = node_type_counts n.node_type n.resulting_type + let delta = ( + if n.node_type == node_type_func_call_arg_list && instr_offset > 0 then + let prev_node = nodes[instr_offset - 1] + in + 1 + (if prev_node.node_type == node_type_func_call_arg || prev_node.node_type == node_type_func_call_arg_float_in_int || prev_node.node_type == node_type_func_call_arg_stack then + let total_args = u32.i32 prev_node.child_idx + 1 + + -- let stack_args = u32.i32 (if prev_node.node_type == node_type_func_call_arg_stack then + -- i32.u32 prev_node.node_data + 1 --If we have a stack node, we know the number of stack args + -- else if prev_node.node_type == node_type_func_call_arg_float_in_int then + -- 0 + -- else + -- if prev_node.resulting_type == datatype_float then + -- let float_args = prev_node.node_data + 1 + -- let int_args = total_args - float_args + -- in + -- i32.max ((i32.u32 int_args)-8) 0 + -- else + -- 0 + -- ) + -- let non_stack_args = total_args - stack_args + -- let prev_node_data = prev_node.node_data + -- let float_args = if prev_node.resulting_type == datatype_float || prev_node.resulting_type == datatype_float_ref then prev_node_data + 1 else total_args - (prev_node_data + 1) + -- let int_args = total_args - float_args + + -- let float_reg_args = u32.min float_args 8 + -- let int_reg_args = u32.min (((u32.max float_args 8)-8)+int_args) 8 + -- let non_stack_args = float_reg_args + int_reg_args + -- let stack_args = total_args - non_stack_args + in + --2 * stack_args + total_args + else + 0 --No arguments + ) + else + 0 + ) + + if n.parent == INVALID_NODE_IDX then + 0 + else + let parent_type = nodes[n.parent].node_type + in + if n.child_idx == 0 && (parent_type == node_type_if_stat || parent_type == node_type_if_else_stat) then + 1 + else if n.child_idx == 1 && (parent_type == node_type_if_else_stat || parent_type == node_type_while_stat) then + 1 + else + 0 + in + base_count + delta + +let instr_count_fix (node: Node) (instr_offset: u32) = + if node.node_type == node_type_invalid then + 0xFFFFFFFF + else + instr_offset + +let instr_call_arg_offset (node: Node) = + let total_args = u32.i32 node.child_idx + -- let stack_args = u32.i32 (if node.node_type == node_type_func_call_arg_stack then + -- i32.u32 node.node_data --If we have a stack node, we know the number of stack args + -- else if node.node_type == node_type_func_call_arg_float_in_int then + -- 0 + -- else + -- if node.resulting_type == datatype_float then + -- let float_args = node.node_data + -- let int_args = total_args - float_args + -- in + -- i32.max ((i32.u32 int_args)-8) 0 + -- else + -- 0 + -- ) + -- let non_stack_args = total_args - stack_args + + in + total_args + 1 + +let instr_count_fix_post (nodes: []Node) (node_locs: []u32) (node_idx: i64) (instr_offset: u32) = + let node = nodes[node_idx] in + if node.parent == INVALID_NODE_IDX then + (-1i64, 0) + else + let parent_type = nodes[node.parent].node_type in + if node.child_idx == 0 && (parent_type == node_type_if_stat || parent_type == node_type_if_else_stat) then + (i64.i32 node.parent, instr_offset + node_type_counts node.node_type node.resulting_type) + else if node.child_idx == 1 && (parent_type == node_type_while_stat) then + (i64.i32 node.parent, instr_offset + node_type_counts node.node_type node.resulting_type) + else if node.node_type == node_type_func_call_arg || node.node_type == node_type_func_call_arg_float_in_int || node.node_type == node_type_func_call_arg_stack then + (node_idx, node_locs[node.parent] + instr_call_arg_offset node) + else + (-1i64, 0u32) + +let instr_count [max_nodes] (tree: Tree[max_nodes]) = + let initial_result = map (node_counts tree.nodes) (iota max_nodes) |> + scan (+) 0 |> + rotate (-1) |> + map2 (\i x -> if i == 0 then 0 else x) (iota max_nodes) |> + map2 instr_count_fix tree.nodes + + let (fix_idx, fix_offsets) = + map2 (instr_count_fix_post tree.nodes initial_result) (iota max_nodes) initial_result |> + unzip2 + in + scatter initial_result fix_idx fix_offsets + +let shift_right [n] 't (x: t) (xs: [n]t) : [n]t = + xs |> + rotate (-1) |> + zip (iota n) |> + map (\(i, y) -> if i == 0 then x else y) + +let get_function_table [max_nodes] (tree: Tree[max_nodes]) (instr_count: [max_nodes]u32) = + let (function_ids, offsets) = iota max_nodes |> + filter (\i -> tree.nodes[i].node_type == node_type_func_decl) |> + map (\i -> (tree.nodes[i].node_data, instr_count[i] + 6)) |> + unzip2 + let rotated_offsets = + offsets |> + shift_right 0 + let function_sizes = + indices function_ids |> + map (\i -> if i == 0 then offsets[0] else offsets[i] - offsets[i-1]) + in + (function_ids, rotated_offsets, function_sizes) diff --git a/src/compiler/codegen/optimizer.fut b/src/compiler/codegen/optimizer.fut new file mode 100644 index 0000000..8e3e4e1 --- /dev/null +++ b/src/compiler/codegen/optimizer.fut @@ -0,0 +1,49 @@ +import "instr" +import "register" + +let can_remove (i: Instr) (register_usage: []bool) = + if i.rd < 64 then + false + else + !register_usage[i.rd - 64] + +let has_side_effect (i: Instr) = + let opcode = i.instr & 0b0000000_00000_00000_111_00000_1111111 in + opcode == 0b0000000_00000_00000_010_00000_0100011 || opcode == 0b0000000_00000_00000_010_00000_0100111 + +let optimize_unused [n] [m] (instr: [n]Instr, functab: [m]FuncInfo) = + let initial_used_registers_length = 2 * n + let initial_used_registers = instr |> + map (\i -> (i.rs1 - 64, i.rs2 - 64)) |> + unzip |> + \(a, b) -> flatten [a, b] + let used_registers = scatter (replicate n false) (initial_used_registers :> [initial_used_registers_length]i64) (replicate initial_used_registers_length true) + --let used_registers_i = copy used_registers + let (used_registers, _) = loop (used_registers, continue) = (used_registers, true) while continue do + let used_registers_cpy = copy used_registers + let newly_used = instr |> + map (\i -> if can_remove i used_registers_cpy then (i.rs1 - 64, i.rs2 - 64) else (-1, -1)) |> + unzip |> + \(a, b) -> flatten [a, b] + + let new_used_registers = scatter used_registers (newly_used :> [initial_used_registers_length]i64) (replicate initial_used_registers_length false) + let side_effect_correct = instr |> + map (\i -> if has_side_effect i then (i.rs1 - 64, i.rs2 - 64) else (-1, -1)) |> + unzip |> + \(a, b) -> flatten [a, b] + + let result = scatter new_used_registers (side_effect_correct :> [initial_used_registers_length]i64) (replicate initial_used_registers_length true) + let continue = !(map2 (==) used_registers_cpy result |> reduce (&&) true) + in + ( + result, + continue + ) + let used_instrs = iota n |> + map (\i -> instr[i].rd < 64 || used_registers[i]) + in + (instr, functab, used_instrs) + + +let optimize [n] [m] (instr: [n]Instr) (functab: [m]FuncInfo) = + (instr, functab) |> optimize_unused diff --git a/src/compiler/codegen/postprocess.fut b/src/compiler/codegen/postprocess.fut new file mode 100644 index 0000000..aa1840c --- /dev/null +++ b/src/compiler/codegen/postprocess.fut @@ -0,0 +1,137 @@ +import "instr" + +let copy_instr_with_jt (instr: Instr) (jt: u32) = + { + instr = instr.instr, + rd = instr.rd, + rs1 = instr.rs1, + rs2 = instr.rs2, + jt = jt + } + +let is_jump (instr: Instr) = + let instr_class = instr.instr & 0x7F + in + instr_class == 0b1100111 + +let is_branch (instr: Instr) = + let instr_class = instr.instr & 0x7F + in + instr_class == 0b1100011 + +let make_auipc (constant: u32) : Instr = + let opcode = 0b00001_0010111 | (constant << 12) + in + { + instr = opcode, + rd = 0, + rs1 = 0, + rs2 = 0, + jt = 0 + } + +let make_jump (instr: Instr) (constant: u32) : Instr = + let opcode = instr.instr | (constant << 20) | (0b00001 << 15) + in + { + instr = opcode, + rd = instr.rd, + rs1 = instr.rs1, + rs2 = instr.rs2, + jt = 0 + } + +let process_jump (instr_loc: i64) (instr: Instr) = + let target = instr.jt * 4 + let upper_offset = (target & 0xFFFFF000) >> 12 + let lower_bits = target & 0xFFF + let sign_bit = (target >> 11) & 0x1 + let upper_bit_constant = upper_offset + sign_bit + in + [ + (instr_loc, make_auipc upper_bit_constant), + (instr_loc+1, make_jump instr lower_bits) + ] + +let make_branch (instr: Instr) (delta: u32) : Instr = + let bit_12 = (delta >> 12) & 0x1 + let bit_11 = (delta >> 11) & 0x1 + let bit_10_5 = (delta >> 5) & 0x3F + let bit_1_4 = (delta >> 1) & 0xF + + let opcode = instr.instr | + (bit_12 << 31) | + (bit_11 << 7) | + (bit_10_5 << 25) | + (bit_1_4 << 8) + + in + { + instr = opcode, + rd = instr.rd, + rs1 = instr.rs1, + rs2 = instr.rs2, + jt = 0 + } + +let process_branch (instr_loc: i64) (instr: Instr) = + let target = i64.u32 instr.jt * 4 + let delta = target - instr_loc * 4 + in + [ + (instr_loc, make_branch instr (u32.i64 delta)), + (-1, EMPTY_INSTR) + ] + + +let finalize_jumps [n] (instr : [n]Instr) = + let instr_offsets = instr |> + map (\i -> if is_jump i then 2i64 else 1i64) |> + scan (+) 0 |> + rotate (-1) + let num_instr = if n == 0 then 0 else instr_offsets[0] + let instr_offsets = iota n |> map (\i -> if i == 0 then 0 else instr_offsets[i]) + let new_instr = scatter (replicate num_instr EMPTY_INSTR) instr_offsets instr |> + map (\i -> copy_instr_with_jt i (u32.i64 instr_offsets[i64.u32 i.jt])) + + let (jump_offsets, jump_instr) = iota n |> map (\i -> + let instr = new_instr[instr_offsets[i]] + in + if is_jump instr then + process_jump instr_offsets[i] instr + -- else if is_branch instr then + -- process_branch instr_offsets[i] instr + else + [(-1, EMPTY_INSTR), (-1, EMPTY_INSTR)] + ) |> + flatten |> + unzip2 + + let new_instr = scatter (copy new_instr) jump_offsets jump_instr + in + --iota n |> map (\i -> copy_instr_with_jt instr[i] (u32.i64 instr_offsets[i])) + (new_instr, instr_offsets |> map i32.i64) + +let finalize_instr_opcode (opcode: u32) (rd: i64) (rs1: i64) (rs2: i64) : u32 = + let rd = rd & 0x1F + let rs1 = rs1 & 0x1F + let rs2 = rs2 & 0x1F + + in + + opcode | + (u32.i64 rd << 7) | + (u32.i64 rs1 << 15) | + (u32.i64 rs2 << 20) + +let finalize_instr [n] (instr: [n]Instr) = + instr |> + map (\i -> + { + instr = finalize_instr_opcode i.instr i.rd i.rs1 i.rs2, + rd = i.rd, + rs1 = i.rs1, + rs2 = i.rs2, + jt = i.jt + } + ) diff --git a/src/compiler/codegen/preprocess.fut b/src/compiler/codegen/preprocess.fut new file mode 100644 index 0000000..a83c75e --- /dev/null +++ b/src/compiler/codegen/preprocess.fut @@ -0,0 +1,135 @@ +import "tree" +import "datatypes" + +let INVALID_NODE : Node = { + node_type = node_type_invalid, + resulting_type = datatype_invalid, + parent = 0, + depth = 0, + child_idx = 0, + node_data = 0 +} + +let is_compare_node (t: NodeType) = + t >= node_type_eq_expr && t <= node_type_greateq_expr + +let copy_node_with_nodetype (n: Node) (t: NodeType) (d: u32) = + { + node_type = t, + resulting_type = n.resulting_type, + parent = n.parent, + depth = n.depth, + child_idx = n.child_idx, + node_data = d + } + +let copy_node_with_nodedata (n: Node) (d: u32) = + { + node_type = n.node_type, + resulting_type = n.resulting_type, + parent = n.parent, + depth = n.depth, + child_idx = n.child_idx, + node_data = d + } + +let copy_node_with_type (n: Node) (d: DataType) = + { + node_type = n.node_type, + resulting_type = d, + parent = n.parent, + depth = n.depth, + child_idx = n.child_idx, + node_data = n.node_data + } + +let replace_float_compare_types [n] (tree: Tree[n]) = + let (ind, values) = tree.nodes |> + map (\i -> + if i.parent == INVALID_NODE_IDX then + (-1i64, INVALID_NODE) + else if is_compare_node tree.nodes[i.parent].node_type && i.resulting_type == datatype_float then + (i64.i32 i.parent, copy_node_with_type tree.nodes[i.parent] datatype_float_ref) + else + (-1i64, INVALID_NODE) + ) |> + unzip2 in + + { + nodes = scatter (copy tree.nodes) ind values, + max_depth = tree.max_depth + } + +--Calling convention +-- If float and number of float args < 8 -> float +-- If int and number of int args + max(float_args - 8, 0) < 8 -> int +-- If float and number of int args + float_args - 8 < 8 -> int +-- Else stack + +let calling_convention_node_replace_sub (n: Node) (def: NodeType) (fltint: NodeType) (stack: NodeType) = + if n.resulting_type == datatype_float_ref || n.resulting_type == datatype_float then + if n.node_data < 8 then + n + else + let num_float_args = i32.u32 n.node_data + let num_int_args = n.child_idx - num_float_args + let reg_offset = num_int_args + num_float_args - 8 + in + if reg_offset < 8 then + copy_node_with_nodetype n fltint (u32.i32 reg_offset) + else + copy_node_with_nodetype n stack (u32.i32 (reg_offset - 8)) + else --Int + let num_int_args = i32.u32 n.node_data + let num_float_args = n.child_idx - num_int_args + let reg_offset = num_int_args + (if num_float_args < 8 then 0 else num_float_args - 8) + in + if reg_offset < 8 then + copy_node_with_nodetype n def (u32.i32 reg_offset) + else + copy_node_with_nodetype n stack (u32.i32 (reg_offset - 8)) + +let calling_convention_node_replace (n: Node) = + if n.node_type == node_type_func_call_arg then + calling_convention_node_replace_sub n node_type_func_call_arg node_type_func_call_arg_float_in_int node_type_func_call_arg_stack + else if n.node_type == node_type_func_arg then + calling_convention_node_replace_sub n node_type_func_arg node_type_func_arg_float_in_int node_type_func_arg_stack + else + n + +let replace_arg_types [n] (tree: Tree[n]) = + { + nodes = tree.nodes |> map calling_convention_node_replace, + max_depth = tree.max_depth + } + +let replace_arg_lists [n] (tree: Tree[n]) = + { + nodes = iota n |> map (\i -> + let node = tree.nodes[i] in + if i > 0 && node.node_type == node_type_func_call_arg_list then + let prev_node = tree.nodes[i-1] + let num_stack_args = (if prev_node.node_type == node_type_func_call_arg then + if prev_node.resulting_type == datatype_float then + let total_args = prev_node.child_idx + let float_args = i32.u32 prev_node.node_data + let int_args = total_args - float_args + in + u32.i32 (i32.max (int_args-8) 0) + else + 0 + else if prev_node.node_type == node_type_func_call_arg_stack then + prev_node.node_data + 1 + else + 0 + ) + in + copy_node_with_nodedata node num_stack_args + else + node + ), + max_depth = tree.max_depth + } + +let preprocess_tree [n] (tree: Tree[n]) = + tree |> replace_arg_types |> replace_arg_lists |> replace_float_compare_types diff --git a/src/compiler/codegen/register.fut b/src/compiler/codegen/register.fut new file mode 100644 index 0000000..e18c975 --- /dev/null +++ b/src/compiler/codegen/register.fut @@ -0,0 +1,427 @@ +import "instr" +import "../lib/github.com/diku-dk/segmented/segmented" + +type FuncInfo = { + id: u32, + start: u32, + size: u32 +} + +type SymbolData = { + register: u8, + swapped: bool +} + +let EMPTY_SYMBOL_DATA : SymbolData = { + register = 0u8, + swapped = false +} + +let NUM_SYSTEM_REGS = 64i64 +let PRESERVED_REGISTER_MASK = 0x0FFC0300_0FFC031Fu64 +let NONSCRATCH_REGISTERS = 0x0FFC0300_0FFC0200u64 + +let is_system_register (register: i64) = + register < NUM_SYSTEM_REGS + +let needs_float_register (instr: u32) (offset: u32) = + if instr == 0b1100000_00000_00000_111_00000_1010011 then -- Float -> int + offset != 0 + else if instr == 0b1101000_00000_00000_111_00000_1010011 then -- Int -> float + offset == 0 + else + instr & 0b1111111 == 0b1010011 + +let find_free_register (float_reg: bool) (lifetime_mask: u64) = + let fixed_registers = lifetime_mask | (0xFFFFFFFFu64 << (if float_reg then 0 else 32)) + in + u64.ctz (!fixed_registers) + +let make_symbol_data (reg: i32) = + { + register = u8.i32 reg, + swapped = false + } + +let deallocate_register (d: SymbolData) = + { + register = d.register, + swapped = d.swapped + } + +let get_symbol_data (symbol_registers: []SymbolData) (reg: i64) : SymbolData = + if is_system_register reg then + { + register = u8.i64 reg, + swapped = false + } + else + symbol_registers[reg - NUM_SYSTEM_REGS] + +let set_swap (data: SymbolData) : SymbolData = + { + register = data.register, + swapped = true + } + +let clear_register (reg: i32) (lifetime_mask: u64) = + if reg == 0 then + lifetime_mask + else + lifetime_mask & !(1 << u64.i32 reg) + +let lifetime_analyze_is_call (instr: Instr) (function: FuncInfo) = + let func_start = function.start + let func_end = function.start + function.size + in + instr.instr == 0b0000000_00000_00000_000_00001_1101111 && instr.jt < func_start || instr.jt >= func_end + +let lifetime_analyze_valid [n] (instrs: [n]Instr) (symbol_registers: []SymbolData) (instr_offset: u32) (lifetime_mask: u64) (register_state: [64]i64) (function: FuncInfo) = + let instr = instrs[i64.u32 instr_offset] + in + if lifetime_analyze_is_call instr function then + let register_info = [(-1i64, EMPTY_SYMBOL_DATA), (-1i64, EMPTY_SYMBOL_DATA), (-1i64, EMPTY_SYMBOL_DATA)] + + let new_lifetime_mask = lifetime_mask & PRESERVED_REGISTER_MASK + let spilled_register_mask = lifetime_mask & !PRESERVED_REGISTER_MASK + let spilled_registers = iota 64i64 |> map (\i -> + if spilled_register_mask & (1 << u64.i64 i) != 0 then + i + else + -1 + ) + let new_register_state = iota 64i64 |> map (\i -> + if new_lifetime_mask & (1 << u64.i64 i) != 0 then + register_state[i] + else + -1 + ) + in + --(new_lifetime_mask, register_info, spilled_registers, new_register_state) + (new_lifetime_mask, register_info, spilled_registers, new_register_state) + else + let old_rs1_data = get_symbol_data symbol_registers instr.rs1 + let old_rs2_data = get_symbol_data symbol_registers instr.rs2 + -- let old_rd_data = get_symbol_data symbol_registers instr.rd + + let rs1_register = if old_rs1_data.swapped then if needs_float_register instr.instr 1 then 37 else 5 else i32.u8 old_rs1_data.register + let rs2_register = if old_rs2_data.swapped then if needs_float_register instr.instr 2 then 38 else 6 else i32.u8 old_rs2_data.register + let cleared_lifetime_mask = lifetime_mask |> clear_register rs1_register |> clear_register rs2_register + + let rd_register = if instr.rd < 64 then + i32.i64 instr.rd + else + let float_reg = needs_float_register instr.instr 0 + let rd_tmp = find_free_register float_reg cleared_lifetime_mask + in + if rd_tmp == 64 then + if float_reg then 37 else 5 -- Use x5 for scratch + else + rd_tmp + let swap_rd = if rd_register != 0 && (cleared_lifetime_mask & (1u64 << u64.i32 rd_register) != 0) then rd_register else -1 + let swap_rs1 = if rs1_register != 0 && (lifetime_mask & (1u64 << u64.i32 rs1_register) != 0) then rs1_register else -1 + let swap_rs2 = if rs1_register != 0 && (lifetime_mask & (1u64 << u64.i32 rs2_register) != 0) then rs2_register else -1 + + let new_lifetime_mask = cleared_lifetime_mask | (1u64 << u64.i32 rd_register) + let register_info = [ + (if !(is_system_register instr.rd) then instr.rd - NUM_SYSTEM_REGS else -1, rd_register |> make_symbol_data), + (if !(is_system_register instr.rs1) then instr.rs1 - NUM_SYSTEM_REGS else -1, old_rs1_data |> deallocate_register), + (if !(is_system_register instr.rs2) then instr.rs2 - NUM_SYSTEM_REGS else -1, old_rs2_data |> deallocate_register) + ] + + let (updated_register_no, updated_register_data) = [ + (i64.i32 rd_register, instr.rd), + (if rs1_register == rd_register then -1 else i64.i32 rs1_register, -1), + (if rs2_register == rd_register then -1 else i64.i32 rs2_register, -1) + ] |> unzip2 + + let new_register_state = scatter (copy register_state) updated_register_no updated_register_data + let swapped_registers = [i64.i32 swap_rd, i64.i32 swap_rs1, i64.i32 swap_rs2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1] + in + (new_lifetime_mask, register_info, swapped_registers, new_register_state) + +let lifetime_analyze [n] (instrs: [n]Instr) (symbol_registers: []SymbolData) (enabled: [n]bool) (instr_offset: u32) (lifetime_mask: u64) (register_state: [64]i64) (function: FuncInfo)= + let register_info = [(-1i64, EMPTY_SYMBOL_DATA), (-1i64, EMPTY_SYMBOL_DATA), (-1i64, EMPTY_SYMBOL_DATA)] in + if instr_offset == 0xFFFFFFFF || !enabled[i64.u32 instr_offset] then + (lifetime_mask, register_info, replicate 64 (-1i64), register_state) + else + lifetime_analyze_valid instrs symbol_registers instr_offset lifetime_mask register_state function + +let current_func_offset(i: i64) (f: FuncInfo) = + if i >= i64.u32 f.size then + 0xFFFFFFFFu32 + else + u32.i64 i + f.start + +let count_instr [n] (instrs: [n]Instr) (symb_data: []SymbolData) (enabled: [n]bool) (instr: i64) : i32 = + if enabled[instr] then + 1 -- Instruction itself + + (if (get_symbol_data symb_data instrs[instr].rd).swapped then 1 else 0) -- Result register swap + + (if (get_symbol_data symb_data instrs[instr].rs1).swapped then 1 else 0) --Instruction rs1 swap + + (if (get_symbol_data symb_data instrs[instr].rs2).swapped then 1 else 0) --Instruction rs2 swap + else + 0 + +let count_instr_add_preserve [n] [m] (functions: [m]FuncInfo) (preserve_masks: [m]u64) (instr_counts: [n]i32) = + let (preserve_offsets, preserve_data) = iota m |> + map (\i -> + let regs_preserved = u64.popc preserve_masks[i] + let func_start_idx = i64.u32 (functions[i].start + 5) + let func_end_idx = i64.u32 (functions[i].start + functions[i].size - 6) + in + [ + (func_start_idx, instr_counts[func_start_idx] + regs_preserved), + (func_end_idx, instr_counts[func_end_idx] + regs_preserved) + ]) |> + flatten |> + unzip2 + in + scatter (copy instr_counts) preserve_offsets preserve_data + +let regalloc_make_load (dest_reg: i64) (stack_offset: u32) : Instr = + let instr_offset = (4*(stack_offset-1)) << 20 + in + { + instr = 0b0000000_00000_00000_010_00000_0000011 | instr_offset, + rd = dest_reg, + rs1 = 0, + rs2 = 0, + jt = 0 + } + +let regalloc_make_store (src_reg: i64) (stack_offset: u32) : Instr = + let stack_data = (-(4*(stack_offset-1))) + let lower_bits = (stack_data & 0x1F) << 7 + let upper_bits = (stack_data & 0xFE) << 19 + in + { + instr = 0b0000000_00000_00000_010_00000_0100011 | lower_bits | upper_bits, + rd = 0, + rs1 = src_reg, + rs2 = 0, + jt = 0 + } + +let regalloc_make_instr (instr: Instr) (rd_register: i64) (rs1_register: i64) (rs2_register: i64) (instr_offset: []i32) : Instr = + { + instr = instr.instr, + rd = rd_register, + rs1 = rs1_register, + rs2 = rs2_register, + jt = u32.i32 instr_offset[i64.u32 instr.jt] + } + +let register_alloc [n] [m] (instrs: [n]Instr, functions: [m]FuncInfo, enabled: [n]bool, stack_sizes: [m]u32)= + let max_func_size = functions |> map (.size) |> u32.maximum |> i64.u32 + let lifetime_masks_init = replicate m 0b00000000_00000000_00000000_00000000_00000000_00000000_00000000_00011111u64 + let preserve_masks_init = replicate m 0u64 + let symbol_registers_init = replicate n EMPTY_SYMBOL_DATA + let register_state = replicate m (replicate 64 (-1i64)) + + let (_, preserve_masks, symbol_registers, _) = loop (lifetime_masks, preserve_masks, symbol_registers, register_state) = (lifetime_masks_init, preserve_masks_init, symbol_registers_init, register_state) for i < max_func_size do + let old_offsets = map (current_func_offset i) functions + let reg_state_copy = copy register_state + let (lifetime_masks, updated_symbols, swapped_registers, register_state) = map4 (lifetime_analyze instrs symbol_registers enabled) old_offsets lifetime_masks register_state functions |> unzip4 + let swap_data = + iota m |> + map ( + \k -> + swapped_registers[k] |> + map ( + \i -> + if i < 0 then + (-1, EMPTY_SYMBOL_DATA) + else + (reg_state_copy[k, i] - 64, get_symbol_data symbol_registers reg_state_copy[k, i] |> set_swap) + ) + ) |> + flatten + let symb_data = updated_symbols |> flatten + let (symbol_offsets, symbol_data) = concat swap_data symb_data |> unzip2 + let preserve_masks = map2 (|) preserve_masks lifetime_masks + in + ( + lifetime_masks, + preserve_masks, + scatter symbol_registers symbol_offsets symbol_data, + register_state + ) + + let preserve_masks = map (\i -> i & NONSCRATCH_REGISTERS) preserve_masks + + let func_start_bools = scatter (replicate n false) (functions |> map (.start) |> map i64.u32) (replicate m true) + let reverse_func_id_map = func_start_bools |> map i64.bool |> scan (+) 0 + let spill_offsets = symbol_registers |> + map (.swapped) |> + map i64.bool |> + segmented_scan (+) 0 func_start_bools + + let instr_offsets = iota n |> + map (count_instr instrs symbol_registers enabled) |> + count_instr_add_preserve functions preserve_masks |> + scan (+) 0 |> + rotate (-1) |> + map2 (\i x -> if i == 0 then 0 else x) (iota n) + + let new_instr_num = i64.i32 (if length instr_offsets == 0 then 0 else instr_offsets[(length instr_offsets)-1]+1) + let new_instr = replicate new_instr_num EMPTY_INSTR + + let (new_instr_idx, new_instr_opcodes) = iota n |> + map (\i -> + if enabled[i] then + let instr = instrs[i] + let base_instr_offset = i64.i32 instr_offsets[i] + let (rs1_load_offset, rs1_stack_offset) = if instr.rs1 >= 64 && symbol_registers[instr.rs1 - 64].swapped then (base_instr_offset, u32.i64 spill_offsets[instr.rs1-64]) else (-1, 0) + let (rs2_load_offset, rs2_stack_offset) = + if instr.rs2 >= 64 && symbol_registers[instr.rs2 - 64].swapped then ( + base_instr_offset + + if rs1_load_offset > 0 then 1 else 0 + ,u32.i64 spill_offsets[instr.rs2-64] + ) + else (-1, 0) + let main_instr_offset = base_instr_offset + (if rs1_load_offset > 0 then 1 else 0) + (if rs2_load_offset > 0 then 1 else 0) + let (rd_offset, rd_stack_offset) = if instr.rd >= 64 && symbol_registers[instr.rd - 64].swapped then (main_instr_offset + 1, u32.i64 spill_offsets[instr.rd-64]) else (-1,0) + let func_id = reverse_func_id_map[i]-1 + + let allocated_rd = if instr.rd < 64 then instr.rd else i64.u8 symbol_registers[instr.rd - 64].register + let allocated_rs1 = if instr.rs1 < 64 then instr.rs1 else + let reg_data = symbol_registers[instr.rs1 - 64] + in + if reg_data.swapped then + if needs_float_register instr.instr 1 then + 37 + else + 5 + else + i64.u8 reg_data.register + let allocated_rs2 = if instr.rs2 < 64 then instr.rs2 else + let reg_data = symbol_registers[instr.rs2 - 64] + in + if reg_data.swapped then + if needs_float_register instr.instr 2 then + 38 + else + 6 + else + i64.u8 reg_data.register + + in + [ + (rs1_load_offset, regalloc_make_load 5 (rs1_stack_offset + stack_sizes[func_id])), --Load spill to rs1 + (rs2_load_offset, regalloc_make_load 6 (rs2_stack_offset + stack_sizes[func_id])), --Load spill to rs2 + (main_instr_offset, regalloc_make_instr instr allocated_rd allocated_rs1 allocated_rs2 instr_offsets), --Main instruction + (rd_offset, regalloc_make_store allocated_rd (rd_stack_offset + stack_sizes[func_id])) --Store spill + ] + else + [ + (-1, EMPTY_INSTR), + (-1, EMPTY_INSTR), + (-1, EMPTY_INSTR), + (-1, EMPTY_INSTR) + ] + ) |> + flatten |> + unzip2 + + let new_instr = scatter new_instr new_instr_idx new_instr_opcodes + + let overflows = replicate m 0u32 + + in + + ( + instr_offsets, + preserve_masks, + symbol_registers |> map (\i -> i.register), + overflows, + symbol_registers |> map (\i -> i.swapped), + new_instr + ) + +let make_empty_instr (opcode: u32) : Instr = + { + instr = opcode, + rd = 0, + rs1 = 0, + rs2 = 0, + jt = 0 + } + +let OPCODE_LUI_BP : u32 = 0b0000000_00000_00000_000_01000_0110111 +let OPCODE_ADDI_BP : u32 = 0b0000000_00000_01000_000_01000_0010011 +let OPCODE_STORE : u32 = 0b0000000_00000_01000_010_00000_0100011 +let OPCODE_STOREF : u32 = 0b0000000_00000_01000_010_00000_0100111 +let OPCODE_LOAD : u32 = 0b0000000_00000_01000_010_00000_0000011 +let OPCODE_LOADF : u32 = 0b0000000_00000_01000_010_00000_0000111 + +let fill_stack_frames [n] [m] (functions: [m]FuncInfo) (func_symbols: [m]u32) (func_overflows: [m]u32) (instr: [n]Instr) (preserve_masks: [m]u64) = + let scatter_info = iota m |> + map (\i -> + let preserve_count = u32.i32 (u64.popc preserve_masks[i]) + let stack_size = (func_symbols[i] + func_overflows[i] + preserve_count + 2) * 4 + let lower_bits = (stack_size & 0xFFF) << 20 + let upper_bits = stack_size - (signextend (stack_size & 0xFFF)) & 0xFFFFF000 + in + [ + --(i64.u32 functions[i].start, make_empty_instr functions[i].size), + (i64.u32 functions[i].start + 2, make_empty_instr (OPCODE_LUI_BP | upper_bits)), + (i64.u32 functions[i].start + 3, make_empty_instr (OPCODE_ADDI_BP | lower_bits)), + (i64.u32 functions[i].start + i64.u32 functions[i].size - 6, make_empty_instr (OPCODE_LUI_BP | upper_bits)), + (i64.u32 functions[i].start + i64.u32 functions[i].size - 5, make_empty_instr (OPCODE_ADDI_BP | lower_bits)) + ] + ) |> + flatten + + let preserve_info = iota m |> + map (\i -> + let preserve_stack_offset = (func_symbols[i] + func_overflows[i] + 2) * 4 + let p_mask = preserve_masks[i] + + in + iota 64 |> + map (\j -> + let leading_regs = u64.popc (p_mask & ((1u64 << (u64.i64 j)) - 1u64)) + let offset = -(preserve_stack_offset + (u32.i32 leading_regs) * 4) + let store_offset_high = (offset & 0xFE0u32) << 25 + let store_offset_low = (offset & 0x1Fu32) << 7 + let store_src = ((u32.i64 j) % 32) << 20 + let store_const = store_offset_high | store_offset_low | store_src + let opcode = if j >= 32 then OPCODE_STOREF else OPCODE_STORE + + in + if p_mask & (1 << u64.i64 j) > 0 then + (i64.u32 functions[i].start + i64.i32 leading_regs + 6, make_empty_instr (opcode | store_const)) + else + (-1, EMPTY_INSTR) + ) + ) + |> flatten + let load_info = iota m |> + map (\i -> + let preserve_stack_offset = (func_symbols[i] + func_overflows[i] + 2) * 4 + let p_mask = preserve_masks[i] + + in + iota 64 |> + map (\j -> + let leading_regs = u64.popc (p_mask & ((1u64 << (u64.i64 j)) - 1u64)) + let offset = -(preserve_stack_offset + (u32.i32 leading_regs) * 4) + + let load_offset = offset << 20 + let load_dst = ((u32.i64 j) % 32) << 7 + let load_const = load_offset | load_dst + let opcode = if j >= 32 then OPCODE_LOADF else OPCODE_LOAD + + in + if p_mask & (1 << u64.i64 j) > 0 then + (i64.u32 functions[i].start + i64.u32 functions[i].size - i64.i32 leading_regs - 7, make_empty_instr (opcode | load_const)) + else + (-1, EMPTY_INSTR) + ) + ) + |> flatten + + let all_info = concat (concat scatter_info preserve_info) load_info + let (all_offsets, all_data) = all_info |> unzip + in + scatter (copy instr) all_offsets all_data diff --git a/src/compiler/codegen/symtab.fut b/src/compiler/codegen/symtab.fut new file mode 100755 index 0000000..75b3d03 --- /dev/null +++ b/src/compiler/codegen/symtab.fut @@ -0,0 +1,13 @@ +import "datatypes" + +type Variable = { + decl_type: DataType, + offset: u32 +} + +type Symtab [symtab_var_size] = { + variables: [symtab_var_size]Variable +} + +let symtab_local_offset [var_size] (symtab: Symtab[var_size]) (var_id: u32) = + symtab.variables[i64.u32 var_id].offset diff --git a/src/compiler/codegen/tree.fut b/src/compiler/codegen/tree.fut new file mode 100644 index 0000000..6071757 --- /dev/null +++ b/src/compiler/codegen/tree.fut @@ -0,0 +1,74 @@ +import "datatypes" + +let INVALID_NODE_IDX : i32 = -1 + +--Node types +type NodeType = i32 + +let node_type_invalid : i32 = 0 +let node_type_statement_list : i32 = 1 +let node_type_empty_stat : i32 = 2 +let node_type_func_decl : i32 = 3 +let node_type_func_arg : i32 = 4 +let node_type_func_arg_list : i32 = 5 +let node_type_expr_stat : i32 = 6 +let node_type_if_stat : i32 = 7 +let node_type_if_else_stat : i32 = 8 +let node_type_while_stat : i32 = 9 +let node_type_func_call_expr : i32 = 10 +let node_type_func_call_arg : i32 = 11 +let node_type_func_call_arg_list : i32 = 12 +let node_type_add_expr : i32 = 13 +let node_type_sub_expr : i32 = 14 +let node_type_mul_expr : i32 = 15 +let node_type_div_expr : i32 = 16 +let node_type_mod_expr : i32 = 17 +let node_type_bitand_expr : i32 = 18 +let node_type_bitor_expr : i32 = 19 +let node_type_bitxor_expr : i32 = 20 +let node_type_lshift_expr : i32 = 21 +let node_type_rshift_expr : i32 = 22 +let node_type_urshift_expr : i32 = 23 +let node_type_land_expr : i32 = 24 +let node_type_lor_expr : i32 = 25 +let node_type_eq_expr : i32 = 26 +let node_type_neq_expr : i32 = 27 +let node_type_less_expr : i32 = 28 +let node_type_great_expr : i32 = 29 +let node_type_lesseq_expr : i32 = 30 +let node_type_greateq_expr : i32 = 31 +let node_type_bitnot_expr : i32 = 32 +let node_type_lnot_expr : i32 = 33 +let node_type_neg_expr : i32 = 34 +let node_type_lit_expr : i32 = 35 +let node_type_cast_expr : i32 = 36 +let node_type_deref_expr : i32 = 37 +let node_type_assign_expr : i32 = 38 +let node_type_decl_expr : i32 = 39 +let node_type_id_expr : i32 = 40 +let node_type_while_dummy : i32 = 41 +let node_type_func_decl_dummy : i32 = 42 +let node_type_return_stat : i32 = 43 +let node_type_func_call_arg_float_in_int : i32 = 44 +let node_type_func_call_arg_stack : i32 = 45 +let node_type_func_arg_float_in_int : i32 = 46 +let node_type_func_arg_stack : i32 = 47 + +--Node definition +type Node = { + node_type: NodeType, + resulting_type: DataType, + parent: i32, + depth: i32, + child_idx: i32, + node_data: u32 +} + +--Tree definition +type Tree [tree_size] = { + nodes: [tree_size]Node, --Nodes of the tree + max_depth: i32 --Tree depth +} + +let is_level (n : Node) (depth: i32) = + n.depth == depth diff --git a/src/compiler/instr.fut b/src/compiler/instr.fut deleted file mode 100644 index 2c849b7..0000000 --- a/src/compiler/instr.fut +++ /dev/null @@ -1,111 +0,0 @@ -import "tree" -import "datatypes" - -let node_instr_0(node_type: NodeType, data_type: DataType) : u32 = - match (node_type, data_type) - --Language constructs without instruction - case (#statement_list, _) -> 0b0000000_00000_00000_000_00000_0000000 -- ignored - case (#empty_stat, _) -> 0b0000000_00000_00000_000_00000_0000000 -- ignored - case (#expr_stat, _) -> 0b0000000_00000_00000_000_00000_0000000 -- ignored - - -- Scope control - case (#func_decl, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Control flow - case (#if_stat, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#if_else_stat, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#else_aux, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#while_stat, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - - -- Binary integer arithmetic - case (#add_expr, #int) -> 0b0000000_00000_00000_000_00000_0110011 -- ADD - case (#sub_expr, #int) -> 0b0100000_00000_00000_000_00000_0110011 -- SUB - case (#mul_expr, #int) -> 0b0000001_00000_00000_000_00000_0110011 -- MUL - case (#div_expr, #int) -> 0b0000001_00000_00000_100_00000_0110011 -- DIV - case (#mod_expr, #int) -> 0b0000001_00000_00000_110_00000_0110011 -- REM - case (#bitand_expr, #int) -> 0b0000000_00000_00000_111_00000_0110011 -- AND - case (#bitor_expr, #int) -> 0b0000000_00000_00000_110_00000_0110011 -- OR - case (#bitxor_expr, #int) -> 0b0000000_00000_00000_100_00000_0110011 -- XOR - case (#lshift_expr, #int) -> 0b0000000_00000_00000_001_00000_0110011 -- SLL - case (#rshift_expr, #int) -> 0b0100000_00000_00000_101_00000_0110011 -- SRA - case (#urshift_expr, #int) -> 0b0000000_00000_00000_101_00000_0110011 -- SRL - - -- Binary float arithmetic - case (#add_expr, #float) -> 0b0000000_00000_00000_111_00000_1010011 -- FADD.S - case (#sub_expr, #float) -> 0b0000100_00000_00000_111_00000_1010011 -- FSUB.S - case (#mul_expr, #float) -> 0b0001000_00000_00000_111_00000_1010011 -- FMUL.S - case (#div_expr, #float) -> 0b0001100_00000_00000_111_00000_1010011 -- FDIV.S - - -- Logical nodes - case (#land_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#lor_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Unary integer arithmetic - case (#bitnot_expr, #int) -> 0b1111111_11111_00000_100_00000_0010011 -- XORI -1 - case (#lnot_expr, #int) -> 0b0000000_00001_00000_011_00000_0010011 -- SLTUI 1 - case (#neg_expr, #int) -> 0b0100000_00000_00000_000_00000_0110011 -- SUB ri, x0 - - -- Unary float arithmetic - case (#neg_expr, #float) -> 0b0010000_00000_00000_001_00000_1010011 -- FSGNJN.S (ensure same operand twice) - - -- Integer comparision - case (#eq_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#neq_expr, #int) -> 0b0100000_00000_00000_000_00000_0110011 -- SUB - case (#less_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#great_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#lesseq_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#greateq_expr, #int) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Float comparision - case (#eq_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#neq_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#less_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#great_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#lesseq_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#greateq_expr, #float) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Assignment - case (#assign_expr, #int) -> 0b0000000_00000_00000_010_00000_0100011 -- SW offset 0 - - -- Function call - case (#func_call_expr, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#func_call_arg, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Literals - case (#lit_expr, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Casts - case (#cast_expr, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - -- Variables - case (#decl_expr, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - case (#id_expr, _) -> 0b0000000_00000_00000_000_00000_1110011 -- TODO - - --Invalid opcodes - case _ -> 0b0000000_00000_00000_000_00000_1110011 -- EBREAK - -type Instr = { - instr: u32, - rd: u32, - rs1: u32, - rs2: u32 -} - -let get_node_instr(node: Node, instr_no: u32) : Instr = - let node_type = node.node_type - let data_type = node.resulting_type - in - { - instr = match instr_no - case 0 -> node_instr_0(node_type, data_type) - case _ -> 0, - rd = 0, - rs1 = 0, - rs2 = 0 - } - -let compile_node [tree_size] (tree: Tree[tree_size]) (node_index: i64) : [2]Instr = - let node : Node = tree.nodes[node_index] - in - [get_node_instr(node, 0), get_node_instr(node, 1)] \ No newline at end of file