//************************************************************************* // DESCRIPTION: Verilator: Netlist (top level) functions // // Code available from: http://www.veripool.org/verilator // // AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli // //************************************************************************* // // Copyright 2003-2008 by Wilson Snyder. This program is free software; you can // redistribute it and/or modify it under the terms of either the GNU // General Public License or the Perl Artistic License. // // Verilator is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // //************************************************************************* #include "config_build.h" #include "verilatedos.h" #include #include #include #include #include "V3Error.h" #include "V3Global.h" #include "V3Ast.h" #include "V3File.h" #include "V3Read.h" #include "V3PreShell.h" //====================================================================== // Build in LEX script #define yyFlexLexer V3LexerBase #include "V3Lexer.yy.cpp" #undef yyFlexLexer //YYSTYPE yylval; //====================================================================== // Globals V3Read* V3Read::s_readp = NULL; extern bool yyparse(); extern int yydebug; //###################################################################### // Lex-derived class /// Override the base lexer class so we can add some access functions class V3Lexer : public V3LexerBase { public: // CONSTRUCTORS V3Lexer() : V3LexerBase(NULL) {} ~V3Lexer() {} // METHODS void stateExitPsl() { if (YY_START != PSL) yyerrorf("Internal error: Exiting PSL state when not in PSL state"); yy_pop_state(); } void statePushVlg() { yy_push_state(STATE_VERILOG_RECENT); } void statePop() { yy_pop_state(); } }; void V3Read::stateExitPsl() { s_readp->m_lexerp->stateExitPsl(); } void V3Read::statePushVlg() { s_readp->m_lexerp->stateExitPsl(); } void V3Read::statePop() { s_readp->m_lexerp->statePop(); } //###################################################################### // Read class functions V3Read::~V3Read() { for (deque::iterator it = m_stringps.begin(); it != m_stringps.end(); ++it) { delete (*it); } m_stringps.clear(); for (deque::iterator it = m_numberps.begin(); it != m_numberps.end(); ++it) { delete (*it); } m_numberps.clear(); if (m_lexerp) { delete m_lexerp; m_lexerp = NULL; } parserClear(); } int V3Read::ppInputToLex(char* buf, int max_size) { int got = 0; while (got < max_size // Haven't got enough && !m_ppBuffers.empty()) { // And something buffered string front = m_ppBuffers.front(); m_ppBuffers.pop_front(); int len = front.length(); if (len > (max_size-got)) { // Front string too big string remainder = front.substr(max_size-got); front = front.substr(0, max_size-got); m_ppBuffers.push_front(remainder); // Put back remainder for next time len = (max_size-got); } strncpy(buf+got, front.c_str(), len); got += len; } if (debug()>=9) { string out = string(buf,got); cout<<" inputToLex got="<fail()) { fileline->v3error("Cannot write preprocessor output: "+vppfilename); return; } else { for (deque::iterator it = m_ppBuffers.begin(); it!=m_ppBuffers.end(); ++it) { *osp << *it; } if (ofp) { ofp->close(); delete ofp; ofp = NULL; } } } // Parse it if (!v3Global.opt.preprocOnly()) { lexFile (modfilename); } } void V3Read::lexFile(const string& modname) { // Prepare for lexing UINFO(3,"Lexing "<warnResetDefault(); // Reenable warnings on each file if (m_lexerp) delete m_lexerp; // Restart from clean slate. m_lexerp = new V3Lexer(); // if (debug()) { m_lexerp->set_debug(~0); } // if (debug()) yydebug = 1; UINFO(4,"Lexing Done "<yylex(); UINFO(5,m_fileline<<" TOKEN="<