diff --git a/ast.cpp b/ast.cpp index 8dbfc4f..e3079d4 100644 --- a/ast.cpp +++ b/ast.cpp @@ -38,4 +38,11 @@ void ast_printer_t::parenthesize(const std::string_view s, const expr_t * a, con os << ')'; } +// instructions + +void ast_printer_t::visit(const op::alu_t * alu) const +{ + (void)alu; +} + } diff --git a/ast.hpp b/ast.hpp index b1d3ad2..3c0bffd 100644 --- a/ast.hpp +++ b/ast.hpp @@ -6,6 +6,7 @@ #include "visitor.hpp" #include "expr.hpp" #include "num.hpp" +#include "stmt.hpp" namespace dsp { @@ -21,6 +22,35 @@ struct ast_printer_t : visitor_t void visit(const grouping_t * grouping) const; void visit(const literal_t * literal) const; + void visit(const op::alu_t * alu) const; + void visit(const op::mov_ram_x_t * mov_ram_x) const; + void visit(const op::mov_mul_p_t * mov_mul_p) const; + void visit(const op::mov_ram_p_t * mov_ram_p) const; + void visit(const op::mov_ram_y_t * mov_ram_y) const; + void visit(const op::clr_a_t * clr_a) const; + void visit(const op::mov_alu_a_t * mov_alu_a) const; + void visit(const op::mov_ram_a_t * mov_ram_a) const; + void visit(const op::mov_imm_d1_t * mov_imm_) const; + void visit(const op::mov_ram_d1_t * mov_ram_) const; + void visit(const op::instruction_t * instruction) const; + + void visit(const load::mvi_t * mvi) const; + void visit(const load::mvi_cond_t * mvi_cond) const; + + void visit(const dma::ingress_imm_t * ingress_imm) const; + void visit(const dma::egress_imm_t * egress_imm) const; + void visit(const dma::ingress_ram_t * ingress_ram) const; + void visit(const dma::egress_ram_t * egress_ram) const; + + void visit(const jump::jmp_t * jmp) const; + void visit(const jump::jmp_cond_t * jmp_cond) const; + + void visit(const loop::btm_t * btm) const; + void visit(const loop::lps_t * lps) const; + + void visit(const end::end_t * end) const; + void visit(const end::endi_t * endi) const; + void parenthesize(const std::string_view s, const expr_t * a) const; void parenthesize(const std::string_view s, const expr_t * a, const expr_t * b) const; }; diff --git a/build_radix_tree.py b/build_radix_tree.py index e1c4648..13c72cf 100644 --- a/build_radix_tree.py +++ b/build_radix_tree.py @@ -111,6 +111,10 @@ reg_keywords = [ "wa0", "lop", "top", + "ct0", + "ct1", + "ct2", + "ct3", ] cond_keywords = [ diff --git a/grammar.txt b/grammar.txt index 486dbbb..aa72b1c 100644 --- a/grammar.txt +++ b/grammar.txt @@ -4,7 +4,7 @@ xy_src → "mc0" | "mc1" | "mc2" | "mc3" | "m0" | "m1" | "m2" | "m3" mov_ram_x → "mov" xy_src "," "x" -mov_mul_p → "mov" "mul" "," "p" +mov_mul_p → "mov" "mul" "," "p" mov_ram_p → "mov" xy_src "," "p" x_bus → mov_ram_x | mov_mul_p | mov_ram_p @@ -25,8 +25,8 @@ d1_src → "mc0" | "mc1" | "mc2" | "mc3" | "m0" | "m1" | "m2" | "m3" | "alh" | "all" -mov_imm_d1 → "mov" simm8 d1_dest -mov_ram_d1 → "mov" d1_src d1_dest +mov_imm_d1 → "mov" simm8 "," d1_dest +mov_ram_d1 → "mov" d1_src "," d1_dest d1_bus → mov_imm_d1 → mov_ram_d1 @@ -94,7 +94,7 @@ assignment_statement → identifier "=" expression "\n" label → identifier ":" -instruction_statement → label? instruction "\n" +instruction_statement → label? instruction? "\n" statement → assignment_statement | instruction_statement diff --git a/keyword.case_inc b/keyword.case_inc index d9d9b71..e41bd03 100644 --- a/keyword.case_inc +++ b/keyword.case_inc @@ -8,6 +8,10 @@ case _and : return os << "AND"; case _btm : return os << "BTM"; case _c : return os << "C"; case _clr : return os << "CLR"; +case _ct0 : return os << "CT0"; +case _ct1 : return os << "CT1"; +case _ct2 : return os << "CT2"; +case _ct3 : return os << "CT3"; case _d0 : return os << "D0"; case _dma : return os << "DMA"; case _dmah : return os << "DMAH"; diff --git a/keyword.enum_inc b/keyword.enum_inc index cba7772..82b413c 100644 --- a/keyword.enum_inc +++ b/keyword.enum_inc @@ -8,6 +8,10 @@ _and, _btm, _c, _clr, +_ct0, +_ct1, +_ct2, +_ct3, _d0, _dma, _dmah, diff --git a/keyword.hpp b/keyword.hpp index 726668b..c2dbafe 100644 --- a/keyword.hpp +++ b/keyword.hpp @@ -99,6 +99,25 @@ find(const std::string_view s) } } break; + case 'T': [[fallthrough]]; + case 't': + if (ix < s.length()) { + switch (s[ix++]) { + case '0': + if (ix == s.length()) return { token_t::type_t::_ct0 }; + break; + case '1': + if (ix == s.length()) return { token_t::type_t::_ct1 }; + break; + case '2': + if (ix == s.length()) return { token_t::type_t::_ct2 }; + break; + case '3': + if (ix == s.length()) return { token_t::type_t::_ct3 }; + break; + } + } + break; } } break; diff --git a/parser.cpp b/parser.cpp index e117b7d..45b2232 100644 --- a/parser.cpp +++ b/parser.cpp @@ -12,6 +12,8 @@ primary → NUMBER */ #include +#include +#include #include "parser.hpp" #include "num.hpp" @@ -152,7 +154,7 @@ expr_t * parser_t::primary() if (match(left_paren)) { expr_t * expr = expression(); - consume(right_paren, "expected ')' after expression."); + consume(right_paren, "expected ')' after expression"); return new grouping_t(expr); } @@ -170,4 +172,161 @@ void parser_t::synchronize() } */ +std::optional parser_t::alu() +{ + using namespace dsp::op; + + if (match(_and)) return {new alu_t(alu_type_t::andl)}; + else if (match(_or )) return {new alu_t(alu_type_t::orl)}; + else if (match(_xor)) return {new alu_t(alu_type_t::xorl)}; + else if (match(_add)) return {new alu_t(alu_type_t::add)}; + else if (match(_sub)) return {new alu_t(alu_type_t::sub)}; + else if (match(_ad2)) return {new alu_t(alu_type_t::ad2)}; + else if (match(_sr )) return {new alu_t(alu_type_t::sr)}; + else if (match(_rr )) return {new alu_t(alu_type_t::rr)}; + else if (match(_sl )) return {new alu_t(alu_type_t::sl)}; + else if (match(_rl )) return {new alu_t(alu_type_t::rl)}; + else if (match(_rl8)) return {new alu_t(alu_type_t::rl8)}; + else return {}; +} + +bool parser_t::xyd1_src() +{ + const bool mc = match(_mc0) || match(_mc1) || match(_mc2) || match(_mc3); + const bool m = match(_m0 ) || match(_m1 ) || match(_m2 ) || match(_m3 ); + const bool al = match(_alh) || match(_all); + return mc || m || al; +} + +static op::xy_src_t xy_src(const token_t& token) +{ + using namespace dsp::op; + + switch (token.type) { + case _mc0: return xy_src_t::mc0; + case _mc1: return xy_src_t::mc1; + case _mc2: return xy_src_t::mc2; + case _mc3: return xy_src_t::mc3; + case _m0: return xy_src_t::m0; + case _m1: return xy_src_t::m1; + case _m2: return xy_src_t::m2; + case _m3: return xy_src_t::m3; + default: assert(false); __builtin_unreachable(); + } +} + +static op::d1_src_t d1_src(const token_t& token) +{ + using namespace dsp::op; + + switch (token.type) { + case _mc0: return d1_src_t::mc0; + case _mc1: return d1_src_t::mc1; + case _mc2: return d1_src_t::mc2; + case _mc3: return d1_src_t::mc3; + case _m0: return d1_src_t::m0; + case _m1: return d1_src_t::m1; + case _m2: return d1_src_t::m2; + case _m3: return d1_src_t::m3; + case _alh: return d1_src_t::alh; + case _all: return d1_src_t::all; + default: assert(false); __builtin_unreachable(); + } +} + +std::optional parser_t::d1_dest() +{ + using namespace dsp::op; + + if (match(_rx)) return {d1_dest_t::rx}; + else if (match(_pl)) return {d1_dest_t::pl}; + else if (match(_ra0)) return {d1_dest_t::ra0}; + else if (match(_wa0)) return {d1_dest_t::wa0}; + else if (match(_lop)) return {d1_dest_t::lop}; + else if (match(_top)) return {d1_dest_t::top}; + else if (match(_ct0)) return {d1_dest_t::ct0}; + else if (match(_ct1)) return {d1_dest_t::ct1}; + else if (match(_ct2)) return {d1_dest_t::ct2}; + else if (match(_ct3)) return {d1_dest_t::ct3}; + else return {}; +} + +std::optional parser_t::xyd1_bus() +{ + if (match(_mov)) { + if (match(_alu)) { + consume(comma, "expected `,` after `mov alu`"); + consume(_a, "expected `a` after `mov alu,`"); + return {new op::mov_alu_a_t()}; + } else if (match(_mul)) { + consume(comma, "expected ',' after `mov mul`"); + consume(_p, "expected 'p' after `mov mul,`"); + return {new op::mov_mul_p_t()}; + } else if (xyd1_src()) { + const token_t& src_token = previous(); + consume(comma, "expected `,` after mov src operand"); + // this is starting to feel a bit ugly... + bool d1 = src_token.type == _alh || src_token.type == _alh; + if (!d1 && match(_y)) return {new op::mov_ram_y_t(xy_src(src_token))}; + else if (!d1 && match(_a)) return {new op::mov_ram_a_t(xy_src(src_token))}; + else if (!d1 && match(_x)) return {new op::mov_ram_x_t(xy_src(src_token))}; + else if (!d1 && match(_p)) return {new op::mov_ram_p_t(xy_src(src_token))}; + else if (auto dest_o = d1_dest()) return {new op::mov_ram_d1_t(d1_src(src_token), *dest_o)}; + else + throw error(peek(), "expected x-bus, y-bus, or d-bus destination operand"); + } else { + expr_t * expr = expression(); + simm_t<8> simm = simm_t<8>(expr); + if (auto dest_o = d1_dest()) + return {new op::mov_imm_d1_t(simm, *dest_o)}; + else + throw error(peek(), "expected d1 destination operand"); + } + } else if (match(_clr)) { + consume(_a, "expected `a` after `clr`"); + return {new op::clr_a_t()}; + } else { + return {}; + } +} + +std::optional parser_t::op() +{ + std::vector ops; + while (true) { + if (auto stmt_o = alu() ) ops.emplace_back(*stmt_o); + else if (auto stmt_o = xyd1_bus()) ops.emplace_back(*stmt_o); + else break; + } + if (ops.size() != 0) + return {new op::instruction_t(ops)}; + else + return {}; +} + +std::optional parser_t::instruction() +{ + // "nop" + // op + // load + // dma + // jump + // loop + // end + return {}; +} + +std::optional parser_t::instruction_statement() +{ + // label + // instruction + // newline + return {}; +} + +stmt_t * parser_t::statement() +{ + return nullptr; +} + } diff --git a/parser.hpp b/parser.hpp index efe501e..7813c6a 100644 --- a/parser.hpp +++ b/parser.hpp @@ -1,9 +1,11 @@ #include #include #include +#include #include "token.hpp" #include "expr.hpp" +#include "stmt.hpp" namespace dsp { @@ -45,6 +47,14 @@ struct parser_t expr_t * orl(); expr_t * primary(); + std::optional alu(); + bool xyd1_src(); + std::optional d1_dest(); + std::optional xyd1_bus(); + std::optional op(); + std::optional instruction(); + std::optional instruction_statement(); + stmt_t * statement(); }; } diff --git a/stmt.hpp b/stmt.hpp index 0c9f9aa..37b2e0a 100644 --- a/stmt.hpp +++ b/stmt.hpp @@ -1,5 +1,9 @@ -#include +#pragma once +#include +#include + +#include "stmt_enum.hpp" #include "expr.hpp" namespace dsp { @@ -24,6 +28,9 @@ struct stmt_accept_t : stmt_t { template struct imm_t { + imm_t(expr_t * expr) + : expr(expr) {} + const expr_t * expr; static constexpr bool sign = S; @@ -38,21 +45,11 @@ using uimm_t = imm_t; namespace op { -enum alu_type_t { - andl, - orl, - xorl, - add, - sub, - ad2, - sr, - rr, - sl, - rl, - rl8, +struct op_t +{ }; -struct alu_t : stmt_accept_t +struct alu_t : op_t, stmt_accept_t { alu_t(alu_type_t type) : type(type) {} @@ -60,16 +57,7 @@ struct alu_t : stmt_accept_t const alu_type_t type; }; -enum struct xy_src_t { - mc0, mc1, mc2, mc3, - m0 , m1 , m2 , m3, -}; - -struct op_t : stmt_accept_t -{ -}; - -struct mov_ram_x_t : virtual op_t +struct mov_ram_x_t : op_t, stmt_accept_t { mov_ram_x_t(xy_src_t src) : src(src) {} @@ -77,12 +65,12 @@ struct mov_ram_x_t : virtual op_t const xy_src_t src; }; -struct mov_mul_p_t : op_t +struct mov_mul_p_t : op_t, stmt_accept_t { mov_mul_p_t() {} }; -struct mov_ram_p_t : op_t +struct mov_ram_p_t : op_t, stmt_accept_t { mov_ram_p_t(xy_src_t src) : src(src) {} @@ -90,7 +78,7 @@ struct mov_ram_p_t : op_t const xy_src_t src; }; -struct mov_ram_y_t : op_t +struct mov_ram_y_t : op_t, stmt_accept_t { mov_ram_y_t(xy_src_t src) : src(src) {} @@ -98,17 +86,17 @@ struct mov_ram_y_t : op_t const xy_src_t src; }; -struct clr_a_t : op_t +struct clr_a_t : op_t, stmt_accept_t { clr_a_t() {} }; -struct mov_alu_a_t : op_t +struct mov_alu_a_t : op_t, stmt_accept_t { mov_alu_a_t() {} }; -struct mov_ram_a_t : op_t +struct mov_ram_a_t : op_t, stmt_accept_t { mov_ram_a_t(xy_src_t src) : src(src) {} @@ -116,30 +104,18 @@ struct mov_ram_a_t : op_t const xy_src_t src; }; -enum struct d1_dest_t { - rx , pl , - ra0, wa0, - lop, top, - ct0, ct1, ct2, ct3, -}; - -enum struct d1_src_t { - mc0, mc1, mc2, mc3, - m0 , m1 , m2 , m3 , -}; - -struct mov_imm_d1 : op_t +struct mov_imm_d1_t : op_t, stmt_accept_t { - mov_imm_d1(simm_t<8> imm, d1_dest_t dest) + 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 : op_t +struct mov_ram_d1_t : op_t, stmt_accept_t { - mov_ram_d1(d1_src_t src, d1_dest_t dest) + mov_ram_d1_t(d1_src_t src, d1_dest_t dest) : src(src), dest(dest) {} const d1_src_t src; @@ -148,31 +124,16 @@ struct mov_ram_d1 : op_t struct instruction_t : stmt_accept_t { - instruction_t(std::vector ops) + instruction_t(std::vector ops) : ops(ops) {} - const std::vector ops; + const std::vector ops; }; } // op namespace load { -enum struct dest_t { - mc0, mc1, mc2, mc3, - rx , pl , - ra0, wa0, - lop, pc , -}; - -enum struct cond_t { - z , nz , - s , ns , - c , nc , - t0, nt0, - zs, nzs, -}; - struct mvi_t : stmt_accept_t { mvi_t(uimm_t<25> imm) @@ -193,26 +154,6 @@ struct mvi_cond_t : stmt_accept_t namespace dma { -enum struct add_mode_t { - _0 , - _1 , - _2 , - _4 , - _8 , - _16, - _32, - _64, -}; - -enum struct ingress_t { - m0, m1, m2, m3 -}; - -enum struct egress_t { - m0, m1, m2, m3, - prg, -}; - struct ingress_imm_t : stmt_accept_t { ingress_imm_t(bool hold, ingress_t ingress, simm_t<8> imm) @@ -233,11 +174,6 @@ struct egress_imm_t : stmt_accept_t const simm_t<8> imm; }; -enum struct length_ram_t { - m0 , m1 , m2 , m3 , - mc0, mc1, mc2, mc3, -}; - struct ingress_ram_t : stmt_accept_t { ingress_ram_t(bool hold, ingress_t ingress, length_ram_t ram) @@ -263,14 +199,6 @@ struct egress_ram_t : stmt_accept_t namespace jump { -enum struct cond_t { - z , nz, - s , ns, - c , nc, - t0, nt0, - zs, nzs, -}; - struct jmp_t : stmt_accept_t { jmp_t(uimm_t<8> imm) diff --git a/stmt_enum.hpp b/stmt_enum.hpp new file mode 100644 index 0000000..9d14f35 --- /dev/null +++ b/stmt_enum.hpp @@ -0,0 +1,101 @@ +#pragma once + +namespace dsp { + +namespace op { + +enum struct alu_type_t : int { + andl, + orl, + xorl, + add, + sub, + ad2, + sr, + rr, + sl, + rl, + rl8, +}; + +enum struct xy_src_t { + mc0, mc1, mc2, mc3, + m0 , m1 , m2 , m3, +}; + +enum struct d1_dest_t { + rx , pl , + ra0, wa0, + lop, top, + ct0, ct1, ct2, ct3, +}; + +enum struct d1_src_t { + mc0, mc1, mc2, mc3, + m0 , m1 , m2 , m3 , + alh, all, +}; + +} + +namespace load { + +enum struct dest_t { + mc0, mc1, mc2, mc3, + rx , pl , + ra0, wa0, + lop, pc , +}; + +enum struct cond_t { + z , nz , + s , ns , + c , nc , + t0, nt0, + zs, nzs, +}; + +} // load + +namespace dma { + +enum struct add_mode_t { + _0 , + _1 , + _2 , + _4 , + _8 , + _16, + _32, + _64, +}; + +enum struct ingress_t { + m0, m1, m2, m3 +}; + +enum struct egress_t { + m0, m1, m2, m3, + prg, +}; + +enum struct length_ram_t { + m0 , m1 , m2 , m3 , + mc0, mc1, mc2, mc3, +}; + +} // dma + +namespace jump { + +enum struct cond_t { + z , nz, + s , ns, + c , nc, + t0, nt0, + zs, nzs, +}; + +} // jump + +} diff --git a/stmt_string.cpp b/stmt_string.cpp new file mode 100644 index 0000000..ddd2606 --- /dev/null +++ b/stmt_string.cpp @@ -0,0 +1,153 @@ +#pragma once + +#include "stmt_string.hpp" +#include "stmt_enum.hpp" + +#define i(v) (static_cast(v)) + +namespace dsp { + +namespace op { + +const std::string alu_type_string[] = { + [i(alu_type_t::andl)] = "andl", + [i(alu_type_t::orl )] = "orl", + [i(alu_type_t::xorl)] = "xorl", + [i(alu_type_t::add )] = "add", + [i(alu_type_t::sub )] = "sub", + [i(alu_type_t::ad2 )] = "ad2", + [i(alu_type_t::sr )] = "sr", + [i(alu_type_t::rr )] = "rr", + [i(alu_type_t::sl )] = "sl", + [i(alu_type_t::rl )] = "rl", + [i(alu_type_t::rl8 )] = "rl8", +}; + +const std::string xy_src_string[] = { + [i(xy_src_t::mc0)] = "mc0", + [i(xy_src_t::mc1)] = "mc1", + [i(xy_src_t::mc2)] = "mc2", + [i(xy_src_t::mc3)] = "mc3", + [i(xy_src_t::m0 )] = "m0" , + [i(xy_src_t::m1 )] = "m1" , + [i(xy_src_t::m2 )] = "m2" , + [i(xy_src_t::m3 )] = "m3" , +}; + +const std::string d1_dest_string[] = { + [i(d1_dest_t::rx )] = "rx" , + [i(d1_dest_t::pl )] = "pl" , + [i(d1_dest_t::ra0)] = "ra0", + [i(d1_dest_t::wa0)] = "wa0", + [i(d1_dest_t::lop)] = "lop", + [i(d1_dest_t::top)] = "top", + [i(d1_dest_t::ct0)] = "ct0", + [i(d1_dest_t::ct1)] = "ct1", + [i(d1_dest_t::ct2)] = "ct2", + [i(d1_dest_t::ct3)] = "ct3", +}; + +const std::string d1_src_string[] = { + [i(d1_src_t::mc0)] = "mc0", + [i(d1_src_t::mc1)] = "mc1", + [i(d1_src_t::mc2)] = "mc2", + [i(d1_src_t::mc3)] = "mc3", + [i(d1_src_t::m0 )] = "m0" , + [i(d1_src_t::m1 )] = "m1" , + [i(d1_src_t::m2 )] = "m2" , + [i(d1_src_t::m3 )] = "m3" , +}; + +} + +namespace load { + +const std::string dest_string[] = { + [i(dest_t::mc0)] = "mc0", + [i(dest_t::mc1)] = "mc1", + [i(dest_t::mc2)] = "mc2", + [i(dest_t::mc3)] = "mc3", + [i(dest_t::rx )] = "rx" , + [i(dest_t::pl )] = "pl" , + [i(dest_t::ra0)] = "ra0", + [i(dest_t::wa0)] = "wa0", + [i(dest_t::lop)] = "lop", + [i(dest_t::pc )] = "pc" , +}; + +const std::string cond_string[] = { + [i(cond_t::z )] = "z" , + [i(cond_t::nz )] = "nz" , + [i(cond_t::s )] = "s" , + [i(cond_t::ns )] = "ns" , + [i(cond_t::c )] = "c" , + [i(cond_t::nc )] = "nc" , + [i(cond_t::t0 )] = "t0", + [i(cond_t::nt0)] = "nt0", + [i(cond_t::zs )] = "zs", + [i(cond_t::nzs)] = "nzs", +}; + +} // load + +namespace dma { + +const std::string add_mode_string[] = { + [i(add_mode_t::_0 )] = "0" , + [i(add_mode_t::_1 )] = "1" , + [i(add_mode_t::_2 )] = "2" , + [i(add_mode_t::_4 )] = "4" , + [i(add_mode_t::_8 )] = "8" , + [i(add_mode_t::_16)] = "16", + [i(add_mode_t::_32)] = "32", + [i(add_mode_t::_64)] = "64", +}; + +const std::string ingress_string[] = { + [i(ingress_t::m0)] = "m0", + [i(ingress_t::m1)] = "m1", + [i(ingress_t::m2)] = "m2", + [i(ingress_t::m3)] = "m3" +}; + +const std::string egress_string[] = { + [i(egress_t::m0 )] = "m0", + [i(egress_t::m1 )] = "m1", + [i(egress_t::m2 )] = "m2", + [i(egress_t::m3 )] = "m3", + [i(egress_t::prg)] = "prg", +}; + +const std::string length_ram_string[] = { + [i(length_ram_t::m0 )] = "m0" , + [i(length_ram_t::m1 )] = "m1" , + [i(length_ram_t::m2 )] = "m2" , + [i(length_ram_t::m3 )] = "m3" , + [i(length_ram_t::mc0)] = "mc0", + [i(length_ram_t::mc1)] = "mc1", + [i(length_ram_t::mc2)] = "mc2", + [i(length_ram_t::mc3)] = "mc3", +}; + +} // dma + +namespace jump { + +const std::string cond_string[] = { + [i(cond_t::z )] = "z" , + [i(cond_t::nz )] = "nz", + [i(cond_t::s )] = "s" , + [i(cond_t::ns )] = "ns", + [i(cond_t::c )] = "c" , + [i(cond_t::nc )] = "nc", + [i(cond_t::t0 )] = "t0", + [i(cond_t::nt0)] = "nt0", + [i(cond_t::zs )] = "zs", + [i(cond_t::nzs)] = "nzs", +}; + +} // jump + +} + +#undef i diff --git a/stmt_string.hpp b/stmt_string.hpp new file mode 100644 index 0000000..5bc9d9c --- /dev/null +++ b/stmt_string.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +namespace dsp { + +namespace op { + +extern const std::string alu_type_string[]; +extern const std::string xy_src_string[]; +extern const std::string d1_dest_string[]; +extern const std::string d1_src_string[]; + +} + +namespace load { + +extern const std::string dest_string[]; +extern const std::string cond_string[]; + +} // load + +namespace dma { + +extern const std::string add_mode_string[]; +extern const std::string ingress_string[]; +extern const std::string egress_string[]; +extern const std::string length_ram_string[]; + +} // dma + +namespace jump { + +extern const std::string cond_string[]; + +} + +} diff --git a/visitable.hpp b/visitable.hpp index 6ab5880..cb2e577 100644 --- a/visitable.hpp +++ b/visitable.hpp @@ -2,10 +2,55 @@ namespace dsp { +// expressions struct binary_t; struct grouping_t; struct literal_t; struct unary_t; struct assign_t; +// instructions +namespace op { +struct alu_t; +struct mov_ram_x_t; +struct mov_ram_x_t; +struct mov_mul_p_t; +struct mov_ram_p_t; +struct mov_ram_y_t; +struct clr_a_t; +struct mov_alu_a_t; +struct mov_ram_a_t; +struct mov_imm_d1_t; +struct mov_ram_d1_t; +struct instruction_t; +} + +namespace load{ +struct mvi_t; +struct mvi_cond_t; +} + +namespace dma { +struct ingress_imm_t; +struct egress_imm_t; +struct ingress_ram_t; +struct egress_ram_t; +} + +namespace jump { +struct jmp_t; +struct jmp_cond_t; +} + +namespace loop { +struct btm_t; +struct lps_t; +} + +namespace end { +struct end_t; +struct endi_t ; +} + + } diff --git a/visitor.hpp b/visitor.hpp index 6bcf7e1..2966ed2 100644 --- a/visitor.hpp +++ b/visitor.hpp @@ -12,6 +12,36 @@ struct visitor_t virtual T visit(const binary_t * expr) const = 0; virtual T visit(const grouping_t * expr) const = 0; virtual T visit(const literal_t * expr) const = 0; + + virtual T visit(const op::alu_t * stmt) const = 0; + virtual T visit(const op::mov_ram_x_t * mov_ram_x) const = 0; + virtual T visit(const op::mov_mul_p_t * mov_mul_p) const = 0; + virtual T visit(const op::mov_ram_p_t * mov_ram_p) const = 0; + virtual T visit(const op::mov_ram_y_t * mov_ram_y) const = 0; + virtual T visit(const op::clr_a_t * clr_a) const = 0; + virtual T visit(const op::mov_alu_a_t * mov_alu_a) const = 0; + virtual T visit(const op::mov_ram_a_t * mov_ram_a) const = 0; + virtual T visit(const op::mov_imm_d1_t * mov_imm_) const = 0; + virtual T visit(const op::mov_ram_d1_t * mov_ram_) const = 0; + virtual T visit(const op::instruction_t * instruction) const = 0; + + virtual T visit(const load::mvi_t * mvi) const = 0; + virtual T visit(const load::mvi_cond_t * mvi_cond) const = 0; + + virtual T visit(const dma::ingress_imm_t * ingress_imm) const = 0; + virtual T visit(const dma::egress_imm_t * egress_imm) const = 0; + virtual T visit(const dma::ingress_ram_t * ingress_ram) const = 0; + virtual T visit(const dma::egress_ram_t * egress_ram) const = 0; + + virtual T visit(const jump::jmp_t * jmp) const = 0; + virtual T visit(const jump::jmp_cond_t * jmp_cond) const = 0; + + virtual T visit(const loop::btm_t * btm) const = 0; + virtual T visit(const loop::lps_t * lps) const = 0; + + virtual T visit(const end::end_t * end) const = 0; + virtual T visit(const end::endi_t * endi) const = 0; + }; }