diff --git a/ast_emitter.cpp b/ast_emitter.cpp index c75881d..1d660ee 100644 --- a/ast_emitter.cpp +++ b/ast_emitter.cpp @@ -145,7 +145,7 @@ uint32_t emitter_t::visit(const op::mov_ram_d1_t * mov_ram_d1) const uint32_t emitter_t::visit(const op::control_word_t * control_word) const { - uint32_t word = 0; + uint32_t word = control_word->code() | control_word->bits(); for (auto& op : control_word->ops) { word |= dynamic_cast(op)->accept(this); } return word; } diff --git a/stmt.hpp b/stmt.hpp index 262166e..a22c807 100644 --- a/stmt.hpp +++ b/stmt.hpp @@ -64,9 +64,6 @@ using uimm_t = imm_t; namespace op { -static uint32_t op_mask(uint32_t mask) { return (0b11 << 30) | mask; } -static uint32_t op_code(uint32_t code) { return (0b00 << 30) | code; } - struct op_t { virtual uint32_t mask() const = 0; @@ -81,9 +78,9 @@ struct alu_t : op_t, stmt_accept_t const alu_type_t type; - uint32_t mask() const { return op_mask(0b1111 << 26); } - uint32_t code() const { return op_code(0b0000 << 26); } - uint32_t bits() const { return alu_bits(type); } + uint32_t mask() const { return 0b1111 << 26; } + uint32_t code() const { return 0b0000 << 26; } + uint32_t bits() const { return alu_bits(type); } }; struct mov_ram_x_t : op_t, stmt_accept_t @@ -93,18 +90,18 @@ struct mov_ram_x_t : op_t, stmt_accept_t const xy_src_t src; - uint32_t mask() const { return op_mask(0b100'111 << 20); } - uint32_t code() const { return op_code(0b100'000 << 20); } - uint32_t bits() const { return xy_src_bits(src, 20); } + uint32_t mask() const { return 0b100'111 << 20; } + uint32_t code() const { return 0b100'000 << 20; } + uint32_t bits() const { return xy_src_bits(src, 20); } }; struct mov_mul_p_t : op_t, stmt_accept_t { mov_mul_p_t() {} - uint32_t mask() const { return op_mask(0b011'000 << 20); } - uint32_t code() const { return op_code(0b010'000 << 20); } - uint32_t bits() const { return 0; } + uint32_t mask() const { return 0b011'000 << 20; } + uint32_t code() const { return 0b010'000 << 20; } + uint32_t bits() const { return 0; } }; struct mov_ram_p_t : op_t, stmt_accept_t @@ -114,9 +111,9 @@ struct mov_ram_p_t : op_t, stmt_accept_t const xy_src_t src; - uint32_t mask() const { return op_mask(0b011'111 << 20); } - uint32_t code() const { return op_code(0b011'000 << 20); } - uint32_t bits() const { return xy_src_bits(src, 20); } + uint32_t mask() const { return 0b011'111 << 20; } + uint32_t code() const { return 0b011'000 << 20; } + uint32_t bits() const { return xy_src_bits(src, 20); } }; struct mov_ram_y_t : op_t, stmt_accept_t @@ -126,27 +123,27 @@ struct mov_ram_y_t : op_t, stmt_accept_t const xy_src_t src; - uint32_t mask() const { return op_mask(0b100'111 << 14); } - uint32_t code() const { return op_code(0b100'000 << 14); } - uint32_t bits() const { return xy_src_bits(src, 14); } + uint32_t mask() const { return 0b100'111 << 14; } + uint32_t code() const { return 0b100'000 << 14; } + uint32_t bits() const { return xy_src_bits(src, 14); } }; struct clr_a_t : op_t, stmt_accept_t { clr_a_t() {} - uint32_t mask() const { return op_mask(0b011'000 << 14); } - uint32_t code() const { return op_code(0b001'000 << 14); } - uint32_t bits() const { return 0; } + uint32_t mask() const { return 0b011'000 << 14; } + uint32_t code() const { return 0b001'000 << 14; } + uint32_t bits() const { return 0; } }; struct mov_alu_a_t : op_t, stmt_accept_t { mov_alu_a_t() {} - uint32_t mask() const { return op_mask(0b011'000 << 14); } - uint32_t code() const { return op_code(0b010'000 << 14); } - uint32_t bits() const { return 0; } + uint32_t mask() const { return 0b011'000 << 14; } + uint32_t code() const { return 0b010'000 << 14; } + uint32_t bits() const { return 0; } }; struct mov_ram_a_t : op_t, stmt_accept_t @@ -156,9 +153,9 @@ struct mov_ram_a_t : op_t, stmt_accept_t const xy_src_t src; - uint32_t mask() const { return op_mask(0b011'111 << 14); } - uint32_t code() const { return op_code(0b011'000 << 14); } - uint32_t bits() const { return xy_src_bits(src, 14); } + uint32_t mask() const { return 0b011'111 << 14; } + uint32_t code() const { return 0b011'000 << 14; } + uint32_t bits() const { return xy_src_bits(src, 14); } }; struct mov_imm_d1_t : op_t, stmt_accept_t @@ -169,9 +166,9 @@ struct mov_imm_d1_t : op_t, stmt_accept_t const uimm_t<8> imm; const d1_dest_t dest; - uint32_t mask() const { return op_mask(0b11'1111'1111'1111 << 0); } - uint32_t code() const { return op_code(0b01'0000'0000'0000 << 0); } - uint32_t bits() const { return d1_dest_bits(dest); } + uint32_t mask() const { return 0b11'1111'1111'1111 << 0; } + uint32_t code() const { return 0b01'0000'0000'0000 << 0; } + uint32_t bits() const { return d1_dest_bits(dest); } }; struct mov_ram_d1_t : op_t, stmt_accept_t @@ -182,8 +179,8 @@ struct mov_ram_d1_t : op_t, stmt_accept_t const d1_src_t src; const d1_dest_t dest; - uint32_t mask() const { return op_mask(0b11'1111'0000'1111 << 0); } - uint32_t code() const { return op_code(0b11'0000'0000'0000 << 0); } + uint32_t mask() const { return 0b11'1111'0000'1111 << 0; } + uint32_t code() const { return 0b11'0000'0000'0000 << 0; } uint32_t bits() const { return d1_dest_bits(dest) | d1_src_bits(src); } }; @@ -196,9 +193,9 @@ struct control_word_t : stmt_accept_t const std::vector ops; - uint32_t mask() const { return 0xffff'ffff; } - uint32_t code() const { return 0; } - uint32_t bits() const { return 0; } + uint32_t mask() const { return 0b11 << 30; } + uint32_t code() const { return 0b00 << 30; } + uint32_t bits() const { return 0; } }; } // op