#pragma once #include #include #include "stmt_enum.hpp" #include "expr.hpp" namespace dsp { struct stmt_t { virtual void accept(visitor_t const * visitor) const = 0; virtual std::string accept(visitor_t const * visitor) const = 0; }; template struct stmt_accept_t : stmt_t { virtual void accept(visitor_t const * visitor) const { return visitor->visit(static_cast(this)); } virtual std::string accept(visitor_t const * visitor) const { return visitor->visit(static_cast(this)); } }; template struct imm_t { imm_t(expr_t * expr) : expr(expr) {} const expr_t * expr; static constexpr bool sign = S; static constexpr int bits = N; }; template using simm_t = imm_t; template using uimm_t = imm_t; namespace op { struct op_t { }; struct alu_t : op_t, stmt_accept_t { alu_t(alu_type_t type) : type(type) {} const alu_type_t type; }; struct mov_ram_x_t : op_t, stmt_accept_t { mov_ram_x_t(xy_src_t src) : src(src) {} const xy_src_t src; }; struct mov_mul_p_t : op_t, stmt_accept_t { mov_mul_p_t() {} }; struct mov_ram_p_t : op_t, stmt_accept_t { mov_ram_p_t(xy_src_t src) : src(src) {} const xy_src_t src; }; struct mov_ram_y_t : op_t, stmt_accept_t { mov_ram_y_t(xy_src_t src) : src(src) {} const xy_src_t src; }; struct clr_a_t : op_t, stmt_accept_t { clr_a_t() {} }; struct mov_alu_a_t : op_t, stmt_accept_t { mov_alu_a_t() {} }; struct mov_ram_a_t : op_t, stmt_accept_t { mov_ram_a_t(xy_src_t src) : src(src) {} const xy_src_t src; }; struct mov_imm_d1_t : op_t, stmt_accept_t { mov_imm_d1_t(simm_t<8> imm, d1_dest_t dest) : imm(imm), dest(dest) {} const simm_t<8> imm; const d1_dest_t dest; }; struct mov_ram_d1_t : op_t, stmt_accept_t { mov_ram_d1_t(d1_src_t src, d1_dest_t dest) : src(src), dest(dest) {} const d1_src_t src; const d1_dest_t dest; }; struct instruction_t : stmt_accept_t { instruction_t(std::vector ops) : ops(ops) {} const std::vector ops; }; } // op namespace load { struct mvi_t : stmt_accept_t { mvi_t(uimm_t<25> imm) : imm(imm) {} const uimm_t<25> imm; }; struct mvi_cond_t : stmt_accept_t { mvi_cond_t(uimm_t<19> imm) : imm(imm) {} const uimm_t<19> imm; }; } // load namespace dma { struct ingress_imm_t : stmt_accept_t { ingress_imm_t(bool hold, ingress_t ingress, simm_t<8> imm) : hold(hold), ingress(ingress), imm(imm) {} const bool hold; const ingress_t ingress; const simm_t<8> imm; }; struct egress_imm_t : stmt_accept_t { egress_imm_t(bool hold, egress_t egress, simm_t<8> imm) : hold(hold), egress(egress), imm(imm) {} const bool hold; const egress_t egress; const simm_t<8> imm; }; struct ingress_ram_t : stmt_accept_t { ingress_ram_t(bool hold, ingress_t ingress, length_ram_t ram) : hold(hold), ingress(ingress), ram(ram) {} const bool hold; const ingress_t ingress; const length_ram_t ram; }; struct egress_ram_t : stmt_accept_t { egress_ram_t(bool hold, egress_t egress, length_ram_t ram) : hold(hold), egress(egress), ram(ram) {} const bool hold; const egress_t egress; const length_ram_t ram; }; } // dma namespace jump { struct jmp_t : stmt_accept_t { jmp_t(uimm_t<8> imm) : imm(imm) {} const uimm_t<8> imm; }; struct jmp_cond_t : stmt_accept_t { jmp_cond_t(uimm_t<8> imm, cond_t cond) : imm(imm), cond(cond) {} const uimm_t<8> imm; const cond_t cond; }; } // jump namespace loop { struct btm_t : stmt_accept_t { }; struct lps_t : stmt_accept_t { }; } // loop namespace end { struct end_t : stmt_accept_t { }; struct endi_t : stmt_accept_t { }; } // end /* struct assign_t : stmt_accept_t { assign_t(token_t name, expr_t * value) : name(name), value(value) {} const token_t name; const expr_t * value; }; */ } // dsp