dsp-asm/parser.hpp
Zack Buhman ddf46ce8fd stmt_ins: refactor
The overall intent is to make writing a decompiler require less code
duplication.

"bits.hpp" and "stmt_enum.hpp" are replaced with "stmt_ins.hpp" which
is generated directly from dsp-notes.csv.
2023-09-03 04:46:34 +00:00

75 lines
1.7 KiB
C++

#include <stdexcept>
#include <string>
#include <vector>
#include <optional>
#include "token.hpp"
#include "expr.hpp"
#include "stmt.hpp"
#include "stmt_ins.hpp"
#include "control_word.hpp"
namespace dsp {
struct parse_error_t : std::runtime_error
{
parse_error_t(const std::string& msg)
: std::runtime_error(msg)
{ }
};
struct parser_t
{
int current_ix = 0;
std::vector<token_t> tokens;
parser_t(const std::vector<token_t>& tokens)
: tokens(tokens)
{ }
static parse_error_t error(const token_t& token, const std::string message);
bool at_end_p();
const token_t& previous();
const token_t& peek();
const token_t& peek(int n);
const token_t& advance();
bool check(enum token_t::type_t token_type);
bool match(enum token_t::type_t token_type);
template <typename... Targs>
bool match(enum token_t::type_t token_type, Targs... args);
token_t consume(enum token_t::type_t token_type, const std::string error_message);
expr_t * immediate();
expr_t * expression();
expr_t * term();
expr_t * factor();
expr_t * unary();
expr_t * shift();
expr_t * andl();
expr_t * orl();
expr_t * primary();
std::optional<op::op_t> alu();
bool xyd1_src();
std::optional<op::d1_dst_t> d1_dst();
std::optional<op::op_t> xyd1_bus();
std::optional<stmt_t *> op();
load::dst_t load_dst();
load::cond_t load_cond();
std::optional<stmt_t *> load();
dma::src_t dma_src();
dma::dst_t dma_dst();
std::optional<dma::ram_t> dma_ram();
std::optional<stmt_t *> dma();
std::optional<jump::cond_t> jump_cond();
std::optional<stmt_t *> jump();
std::optional<stmt_t *> loop();
std::optional<stmt_t *> end();
std::optional<stmt_t *> instruction();
std::optional<stmt_t *> statement();
};
}