stmt: add constructor boilerplate
This commit is contained in:
parent
d05767d280
commit
663b1139c9
165
stmt.hpp
165
stmt.hpp
@ -4,16 +4,23 @@
|
|||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
|
|
||||||
/*
|
struct stmt_t
|
||||||
struct assign_t : stmt_accept_t<assign_t>
|
|
||||||
{
|
{
|
||||||
assign_t(token_t name, expr_t * value)
|
virtual void accept(visitor_t<void> const * visitor) const = 0;
|
||||||
: name(name), value(value) {}
|
virtual std::string accept(visitor_t<std::string> const * visitor) const = 0;
|
||||||
|
};
|
||||||
const token_t name;
|
|
||||||
const expr_t * value;
|
template <typename T>
|
||||||
|
struct stmt_accept_t : stmt_t {
|
||||||
|
virtual void accept(visitor_t<void> const * visitor) const {
|
||||||
|
return visitor->visit(static_cast<const T*>(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string accept(visitor_t<std::string> const * visitor) const
|
||||||
|
{
|
||||||
|
return visitor->visit(static_cast<const T*>(this));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
template <bool S, int N>
|
template <bool S, int N>
|
||||||
struct imm_t {
|
struct imm_t {
|
||||||
@ -45,7 +52,11 @@ enum alu_type_t {
|
|||||||
rl8,
|
rl8,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alu_t {
|
struct alu_t : stmt_accept_t<alu_t>
|
||||||
|
{
|
||||||
|
alu_t(alu_type_t type)
|
||||||
|
: type(type) {}
|
||||||
|
|
||||||
const alu_type_t type;
|
const alu_type_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,31 +65,54 @@ enum struct xy_src_t {
|
|||||||
m0 , m1 , m2 , m3,
|
m0 , m1 , m2 , m3,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct op_t {
|
struct op_t : stmt_accept_t<op_t>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_ram_x_t : op_t {
|
struct mov_ram_x_t : virtual op_t
|
||||||
|
{
|
||||||
|
mov_ram_x_t(xy_src_t src)
|
||||||
|
: src(src) {}
|
||||||
|
|
||||||
const xy_src_t src;
|
const xy_src_t src;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_mul_p_t : op_t {
|
struct mov_mul_p_t : op_t
|
||||||
|
{
|
||||||
|
mov_mul_p_t() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_ram_p_t : op_t {
|
struct mov_ram_p_t : op_t
|
||||||
|
{
|
||||||
|
mov_ram_p_t(xy_src_t src)
|
||||||
|
: src(src) {}
|
||||||
|
|
||||||
const xy_src_t src;
|
const xy_src_t src;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_ram_y_t : op_t {
|
struct mov_ram_y_t : op_t
|
||||||
|
{
|
||||||
|
mov_ram_y_t(xy_src_t src)
|
||||||
|
: src(src) {}
|
||||||
|
|
||||||
const xy_src_t src;
|
const xy_src_t src;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct clr_a_t : op_t {
|
struct clr_a_t : op_t
|
||||||
|
{
|
||||||
|
clr_a_t() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_alu_a_t : op_t {
|
struct mov_alu_a_t : op_t
|
||||||
|
{
|
||||||
|
mov_alu_a_t() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_ram_a_t : op_t {
|
struct mov_ram_a_t : op_t
|
||||||
|
{
|
||||||
|
mov_ram_a_t(xy_src_t src)
|
||||||
|
: src(src) {}
|
||||||
|
|
||||||
const xy_src_t src;
|
const xy_src_t src;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,17 +128,29 @@ enum struct d1_src_t {
|
|||||||
m0 , m1 , m2 , m3 ,
|
m0 , m1 , m2 , m3 ,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_imm_d1 : op_t {
|
struct mov_imm_d1 : op_t
|
||||||
|
{
|
||||||
|
mov_imm_d1(simm_t<8> imm, d1_dest_t dest)
|
||||||
|
: imm(imm), dest(dest) {}
|
||||||
|
|
||||||
const simm_t<8> imm;
|
const simm_t<8> imm;
|
||||||
const d1_dest_t dest;
|
const d1_dest_t dest;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mov_ram_d1 : op_t {
|
struct mov_ram_d1 : op_t
|
||||||
|
{
|
||||||
|
mov_ram_d1(d1_src_t src, d1_dest_t dest)
|
||||||
|
: src(src), dest(dest) {}
|
||||||
|
|
||||||
const d1_src_t src;
|
const d1_src_t src;
|
||||||
const d1_dest_t dest;
|
const d1_dest_t dest;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct instruction_t {
|
struct instruction_t : stmt_accept_t<instruction_t>
|
||||||
|
{
|
||||||
|
instruction_t(std::vector<op_t *> ops)
|
||||||
|
: ops(ops) {}
|
||||||
|
|
||||||
const std::vector<op_t *> ops;
|
const std::vector<op_t *> ops;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,11 +173,19 @@ enum struct cond_t {
|
|||||||
zs, nzs,
|
zs, nzs,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mvi_t {
|
struct mvi_t : stmt_accept_t<mvi_t>
|
||||||
|
{
|
||||||
|
mvi_t(uimm_t<25> imm)
|
||||||
|
: imm(imm) {}
|
||||||
|
|
||||||
const uimm_t<25> imm;
|
const uimm_t<25> imm;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mvi_cond_t {
|
struct mvi_cond_t : stmt_accept_t<mvi_cond_t>
|
||||||
|
{
|
||||||
|
mvi_cond_t(uimm_t<19> imm)
|
||||||
|
: imm(imm) {}
|
||||||
|
|
||||||
const uimm_t<19> imm;
|
const uimm_t<19> imm;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,13 +213,21 @@ enum struct egress_t {
|
|||||||
prg,
|
prg,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ingress_imm_t {
|
struct ingress_imm_t : stmt_accept_t<ingress_imm_t>
|
||||||
|
{
|
||||||
|
ingress_imm_t(bool hold, ingress_t ingress, simm_t<8> imm)
|
||||||
|
: hold(hold), ingress(ingress), imm(imm) {}
|
||||||
|
|
||||||
const bool hold;
|
const bool hold;
|
||||||
const ingress_t ingress;
|
const ingress_t ingress;
|
||||||
const simm_t<8> imm;
|
const simm_t<8> imm;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct egress_imm_t {
|
struct egress_imm_t : stmt_accept_t<egress_imm_t>
|
||||||
|
{
|
||||||
|
egress_imm_t(bool hold, egress_t egress, simm_t<8> imm)
|
||||||
|
: hold(hold), egress(egress), imm(imm) {}
|
||||||
|
|
||||||
const bool hold;
|
const bool hold;
|
||||||
const egress_t egress;
|
const egress_t egress;
|
||||||
const simm_t<8> imm;
|
const simm_t<8> imm;
|
||||||
@ -176,13 +238,21 @@ enum struct length_ram_t {
|
|||||||
mc0, mc1, mc2, mc3,
|
mc0, mc1, mc2, mc3,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ingress_ram_t {
|
struct ingress_ram_t : stmt_accept_t<ingress_ram_t>
|
||||||
|
{
|
||||||
|
ingress_ram_t(bool hold, ingress_t ingress, length_ram_t ram)
|
||||||
|
: hold(hold), ingress(ingress), ram(ram) {}
|
||||||
|
|
||||||
const bool hold;
|
const bool hold;
|
||||||
const ingress_t ingress;
|
const ingress_t ingress;
|
||||||
const length_ram_t ram;
|
const length_ram_t ram;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct egress_ram_t {
|
struct egress_ram_t : stmt_accept_t<egress_ram_t>
|
||||||
|
{
|
||||||
|
egress_ram_t(bool hold, egress_t egress, length_ram_t ram)
|
||||||
|
: hold(hold), egress(egress), ram(ram) {}
|
||||||
|
|
||||||
const bool hold;
|
const bool hold;
|
||||||
const egress_t egress;
|
const egress_t egress;
|
||||||
const length_ram_t ram;
|
const length_ram_t ram;
|
||||||
@ -201,35 +271,58 @@ enum struct cond_t {
|
|||||||
zs, nzs,
|
zs, nzs,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct jmp_t {
|
struct jmp_t : stmt_accept_t<jmp_t>
|
||||||
uimm_t<8> imm;
|
{
|
||||||
|
jmp_t(uimm_t<8> imm)
|
||||||
|
: imm(imm) {}
|
||||||
|
|
||||||
|
const uimm_t<8> imm;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct jmp_cond_t {
|
struct jmp_cond_t : stmt_accept_t<jmp_cond_t>
|
||||||
uimm_t<8> imm;
|
{
|
||||||
cond_t cond;
|
jmp_cond_t(uimm_t<8> imm, cond_t cond)
|
||||||
|
: imm(imm), cond(cond) {}
|
||||||
|
|
||||||
|
const uimm_t<8> imm;
|
||||||
|
const cond_t cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // jump
|
} // jump
|
||||||
|
|
||||||
namespace loop {
|
namespace loop {
|
||||||
|
|
||||||
struct btm_t {
|
struct btm_t : stmt_accept_t<btm_t>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lps_t {
|
struct lps_t : stmt_accept_t<lps_t>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
} // loop
|
} // loop
|
||||||
|
|
||||||
namespace end {
|
namespace end {
|
||||||
|
|
||||||
struct end_t {
|
struct end_t : stmt_accept_t<end_t>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct endi_t {
|
struct endi_t : stmt_accept_t<endi_t>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
} // loop
|
} // end
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct assign_t : stmt_accept_t<assign_t>
|
||||||
|
{
|
||||||
|
assign_t(token_t name, expr_t * value)
|
||||||
|
: name(name), value(value) {}
|
||||||
|
|
||||||
|
const token_t name;
|
||||||
|
const expr_t * value;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
} // dsp
|
} // dsp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user