dsp-asm/error.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

43 lines
952 B
C++

#pragma once
#include <iostream>
#include <string>
namespace dsp {
extern bool had_error;
static inline void report(const int line, const int col, const std::string where, const std::string message)
{
std::cerr << "[line " << line
<< " col " << col
<< "] error" << where << ": " << message
<< std::endl;
had_error = true;
}
static inline void error(std::string message, const int value)
{
std::cerr << "error " << message << ": " << value << std::endl;
had_error = true;
}
static inline void error(const int line, const int col, std::string message)
{
report(line, col, "", message);
}
static inline void error(const token_t& token, const std::string message)
{
using enum token_t::type_t;
if (token.type == eof) {
report(token.pos.line, token.pos.col, " at end", message);
} else {
report(token.pos.line, token.pos.col, " at '" + std::string(token.lexeme) + "'", message);
}
}
}