3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-08 15:13:24 +00:00

ast, read_verilog: ownership in AST, use C++ styles for parser and lexer

This commit is contained in:
Emil J. Tywoniak 2025-05-21 12:14:50 +02:00
parent 4b8d42d22c
commit 73122921f5
22 changed files with 2496 additions and 2615 deletions

View file

@ -31,6 +31,18 @@
#include "kernel/yosys.h"
#include "frontends/ast/ast.h"
#if ! defined(yyFlexLexerOnce)
#define yyFlexLexer frontend_verilog_yyFlexLexer
#include <FlexLexer.h>
#endif
YOSYS_NAMESPACE_BEGIN
namespace VERILOG_FRONTEND {
class VerilogLexer;
};
YOSYS_NAMESPACE_END
#include "frontends/verilog/verilog_parser.tab.hh"
#include <stdio.h>
#include <stdint.h>
#include <list>
@ -43,7 +55,7 @@ namespace VERILOG_FRONTEND
extern struct AST::AstNode *current_ast;
// this function converts a Verilog constant to an AST_CONSTANT node
AST::AstNode *const2ast(std::string code, char case_type = 0, bool warn_z = false);
std::unique_ptr<AST::AstNode> const2ast(std::string code, char case_type = 0, bool warn_z = false);
// names of locally typedef'ed types in a stack
typedef std::map<std::string, AST::AstNode*> UserTypeMap;
@ -84,17 +96,32 @@ namespace VERILOG_FRONTEND
// lexer input stream
extern std::istream *lexin;
}
using parser = frontend_verilog_yy::parser;
class VerilogLexer : public frontend_verilog_yyFlexLexer {
public:
VerilogLexer(std::istream* in = nullptr) : frontend_verilog_yyFlexLexer(in) {}
~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;
private:
std::vector<std::string> fn_stack;
std::vector<int> ln_stack;
parser::location_type real_loc;
parser::location_type old_loc;
};
extern void frontend_verilog_yyerror(char const *fmt, ...);
// parser::symbol_type frontend_verilog_yylex(VerilogLexer& lexer) {
// return lexer.nextToken();
// };
};
YOSYS_NAMESPACE_END
// the usual bison/flex stuff
extern int frontend_verilog_yydebug;
void frontend_verilog_yyerror(char const *fmt, ...);
void frontend_verilog_yyrestart(FILE *f);
int frontend_verilog_yyparse(void);
int frontend_verilog_yylex_destroy(void);
int frontend_verilog_yyget_lineno(void);
void frontend_verilog_yyset_lineno (int);
#endif