3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-22 05:43:40 +00:00

ast, read_verilog: refactoring

This commit is contained in:
Emil J. Tywoniak 2025-06-18 12:39:32 +02:00
parent 5af4e05125
commit 242853f1f2
7 changed files with 16 additions and 21 deletions

View file

@ -1339,8 +1339,6 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
// be instantiated for this type of AST node. // be instantiated for this type of AST node.
IdString type_name; IdString type_name;
current_filename = filename;
switch (type) switch (type)
{ {
// simply ignore this nodes. // simply ignore this nodes.

View file

@ -1038,8 +1038,6 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
return false; return false;
} }
current_filename = filename;
// we do not look inside a task or function // we do not look inside a task or function
// (but as soon as a task or function is instantiated we process the generated AST as usual) // (but as soon as a task or function is instantiated we process the generated AST as usual)
if (type == AST_FUNCTION || type == AST_TASK) { if (type == AST_FUNCTION || type == AST_TASK) {
@ -1840,8 +1838,6 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
current_scope[it->first] = it->second; current_scope[it->first] = it->second;
} }
current_filename = filename;
if (type == AST_MODULE || type == AST_INTERFACE) if (type == AST_MODULE || type == AST_INTERFACE)
current_scope.clear(); current_scope.clear();

View file

@ -3,6 +3,9 @@ GENFILES += frontends/verilog/verilog_parser.tab.cc
GENFILES += frontends/verilog/verilog_parser.tab.hh GENFILES += frontends/verilog/verilog_parser.tab.hh
GENFILES += frontends/verilog/verilog_parser.output GENFILES += frontends/verilog/verilog_parser.output
GENFILES += frontends/verilog/verilog_lexer.cc GENFILES += frontends/verilog/verilog_lexer.cc
GENFILES += frontends/verilog/location.hh
GENFILES += frontends/verilog/position.hh
GENFILES += frontends/verilog/stack.hh
frontends/verilog/verilog_parser.tab.cc: frontends/verilog/verilog_parser.y frontends/verilog/verilog_parser.tab.cc: frontends/verilog/verilog_parser.y
$(Q) mkdir -p $(dir $@) $(Q) mkdir -p $(dir $@)

View file

@ -787,15 +787,6 @@ void VERILOG_FRONTEND::verr_at(std::string filename, int begin_line, char const
exit(1); exit(1);
} }
[[noreturn]]
void VERILOG_FRONTEND::err_at_loc(parser::location_type loc, char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
verr_at(AST::current_filename, loc.begin.line, fmt, args);
va_end(args);
}
[[noreturn]] [[noreturn]]
void VERILOG_FRONTEND::err_at_ast(AstSrcLocType loc, char const *fmt, ...) void VERILOG_FRONTEND::err_at_ast(AstSrcLocType loc, char const *fmt, ...)
{ {

View file

@ -31,7 +31,6 @@
#include "kernel/yosys.h" #include "kernel/yosys.h"
#include "frontends/ast/ast.h" #include "frontends/ast/ast.h"
#include "frontends/verilog/location.hh"
#if ! defined(yyFlexLexerOnce) #if ! defined(yyFlexLexerOnce)
#define yyFlexLexer frontend_verilog_yyFlexLexer #define yyFlexLexer frontend_verilog_yyFlexLexer
@ -66,10 +65,6 @@ namespace VERILOG_FRONTEND
}; };
[[noreturn]] [[noreturn]]
extern void verr_at(std::string filename, int begin_line, char const *fmt, va_list ap);
[[noreturn]]
extern void err_at_loc(frontend_verilog_yy::location loc, char const *fmt, ...);
[[noreturn]]
extern void err_at_ast(AST::AstSrcLocType loc, char const *fmt, ...); extern void err_at_ast(AST::AstSrcLocType loc, char const *fmt, ...);
}; };

View file

@ -8,7 +8,8 @@
YOSYS_NAMESPACE_BEGIN YOSYS_NAMESPACE_BEGIN
namespace VERILOG_FRONTEND { namespace VERILOG_FRONTEND {
// lexer input stream [[noreturn]]
extern void verr_at(std::string filename, int begin_line, char const *fmt, va_list ap);
using parser = frontend_verilog_yy::parser; using parser = frontend_verilog_yy::parser;
class VerilogLexer : public frontend_verilog_yyFlexLexer { class VerilogLexer : public frontend_verilog_yyFlexLexer {
ParseState* extra; ParseState* extra;

View file

@ -244,6 +244,17 @@
node->children.push_back(std::move(rangeNode)); node->children.push_back(std::move(rangeNode));
} }
[[noreturn]]
extern void verr_at(std::string filename, int begin_line, char const *fmt, va_list ap);
[[noreturn]]
static void err_at_loc(frontend_verilog_yy::parser::location_type loc, char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
verr_at(AST::current_filename, loc.begin.line, fmt, args);
va_end(args);
}
static void checkLabelsMatch(const frontend_verilog_yy::parser::location_type& loc, const char *element, const std::string* before, const std::string *after) static void checkLabelsMatch(const frontend_verilog_yy::parser::location_type& loc, const char *element, const std::string* before, const std::string *after)
{ {
if (!before && after) if (!before && after)