mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-18 11:58:32 +00:00
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#ifndef VERILOG_LEXER_H
|
|
#define VERILOG_LEXER_H
|
|
|
|
#include "kernel/yosys.h"
|
|
#include "frontends/ast/ast.h"
|
|
#include "frontends/verilog/verilog_parser.tab.hh"
|
|
|
|
YOSYS_NAMESPACE_BEGIN
|
|
|
|
namespace VERILOG_FRONTEND {
|
|
// lexer input stream
|
|
using parser = frontend_verilog_yy::parser;
|
|
class VerilogLexer : public frontend_verilog_yyFlexLexer {
|
|
ParseState* extra;
|
|
ParseMode* mode;
|
|
public:
|
|
VerilogLexer(ParseState* e, ParseMode* m) : frontend_verilog_yyFlexLexer(e->lexin), extra(e), mode(m) {}
|
|
~VerilogLexer() override {}
|
|
// autogenerated body due to YY_DECL
|
|
parser::symbol_type nextToken();
|
|
// get rid of override virtual function warning
|
|
using FlexLexer::yylex;
|
|
parser::symbol_type terminate() {
|
|
return parser::make_FRONTEND_VERILOG_YYEOF(out_loc);
|
|
}
|
|
parser::location_type out_loc;
|
|
[[noreturn]]
|
|
void err(char const *fmt, ...)
|
|
{
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
verr_at(AST::current_filename, yylineno, fmt, args);
|
|
}
|
|
private:
|
|
std::vector<std::string> fn_stack;
|
|
std::vector<int> ln_stack;
|
|
parser::location_type real_loc;
|
|
parser::location_type old_loc;
|
|
int LexerInput(char* buf, int max_size) override {
|
|
return readsome(*extra->lexin, buf, max_size);
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
#endif
|