2006-08-26 11:35:28 +00:00
|
|
|
|
// $Id$ //-*- C++ -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Reading of Verilog files
|
|
|
|
|
//
|
|
|
|
|
// Code available from: http://www.veripool.com/verilator
|
|
|
|
|
//
|
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2008-01-15 14:29:08 +00:00
|
|
|
|
// Copyright 2003-2008 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#ifndef _V3READ_H_
|
|
|
|
|
#define _V3READ_H_ 1
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include "V3Error.h"
|
|
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
|
|
class AstNetlist;
|
|
|
|
|
class V3Lexer;
|
|
|
|
|
class V3Number;
|
|
|
|
|
class AstNode;
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
class V3Read {
|
|
|
|
|
AstNetlist* m_rootp; // Root of the design
|
|
|
|
|
V3Lexer* m_lexerp; // Current FlexLexer
|
|
|
|
|
static V3Read* s_readp; // Current THIS, bison() isn't class based
|
|
|
|
|
FileLine* m_fileline; // Filename/linenumber currently active
|
2007-05-16 12:55:25 +00:00
|
|
|
|
bool m_inCellDefine; // Inside a `celldefine
|
|
|
|
|
bool m_inLibrary; // Currently reading a library vs. regular file
|
2007-03-05 21:35:49 +00:00
|
|
|
|
int m_inBeginKwd; // Inside a `begin_keywords
|
2007-03-16 18:44:17 +00:00
|
|
|
|
int m_lastVerilogState; // Last LEX state in `begin_keywords
|
2006-08-26 11:35:28 +00:00
|
|
|
|
deque<string*> m_stringps; // Created strings for later cleanup
|
|
|
|
|
deque<V3Number*> m_numberps; // Created numbers for later cleanup
|
2007-04-19 14:21:37 +00:00
|
|
|
|
deque<FileLine> m_lintState; // Current lint state for save/restore
|
2008-01-31 14:49:27 +00:00
|
|
|
|
deque<string> m_ppBuffers; // Preprocessor->lex buffer of characters to process
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//int debug() { return 9; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// Functions called by lex rules:
|
|
|
|
|
friend class V3Lexer;
|
|
|
|
|
friend class V3LexerBase;
|
|
|
|
|
friend class FileLine;
|
2008-01-31 14:49:27 +00:00
|
|
|
|
friend class V3PreShellImp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
int yylexThis();
|
|
|
|
|
static bool optPsl();
|
|
|
|
|
static void ppline (const char* text);
|
|
|
|
|
static void incLineno() { s_readp->fileline()->incLineno(); }
|
|
|
|
|
static void verilatorCmtLint(const char* text, bool on);
|
2007-04-19 14:21:37 +00:00
|
|
|
|
static void verilatorCmtLintSave();
|
|
|
|
|
static void verilatorCmtLintRestore();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static void verilatorCmtBad(const char* text);
|
2007-03-16 18:44:17 +00:00
|
|
|
|
static void pushBeginKeywords(int state) { s_readp->m_inBeginKwd++; s_readp->m_lastVerilogState=state; }
|
2007-03-05 21:35:49 +00:00
|
|
|
|
static bool popBeginKeywords() { if (s_readp->m_inBeginKwd) { s_readp->m_inBeginKwd--; return true; } else return false; }
|
2007-03-16 18:44:17 +00:00
|
|
|
|
static int lastVerilogState() { return s_readp->m_lastVerilogState; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2008-01-31 14:49:27 +00:00
|
|
|
|
void ppPushText(const string& text) { m_ppBuffers.push_back(text); }
|
|
|
|
|
int ppInputToLex(char* buf, int max_size);
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
public: // But for internal use only
|
|
|
|
|
static string* newString(const string& text) {
|
|
|
|
|
// Allocate a string, remembering it so we can reclaim storage at lex end
|
|
|
|
|
string* strp = new string (text);
|
|
|
|
|
s_readp->m_stringps.push_back(strp);
|
|
|
|
|
return strp;
|
|
|
|
|
}
|
|
|
|
|
static string* newString(const char* text) {
|
|
|
|
|
// Allocate a string, remembering it so we can reclaim storage at lex end
|
|
|
|
|
string* strp = new string (text);
|
|
|
|
|
s_readp->m_stringps.push_back(strp);
|
|
|
|
|
return strp;
|
|
|
|
|
}
|
|
|
|
|
static string* newString(const char* text, int length) {
|
|
|
|
|
string* strp = new string (text, length);
|
|
|
|
|
s_readp->m_stringps.push_back(strp);
|
|
|
|
|
return strp;
|
|
|
|
|
}
|
|
|
|
|
static V3Number* newNumber(FileLine* fl, const char* text) {
|
|
|
|
|
V3Number* nump = new V3Number (fl, text);
|
|
|
|
|
s_readp->m_numberps.push_back(nump);
|
|
|
|
|
return nump;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return next token, for bison, since bison isn't class based, use a global THIS
|
|
|
|
|
static int yylex() { return s_readp->yylexThis(); };
|
|
|
|
|
static FileLine* fileline() { return s_readp->m_fileline; }
|
|
|
|
|
static AstNetlist* rootp() { return s_readp->m_rootp; }
|
|
|
|
|
static FileLine* copyOrSameFileLine() { return s_readp->fileline()->copyOrSameFileLine(); }
|
2007-05-16 12:55:25 +00:00
|
|
|
|
static bool inCellDefine() { return s_readp->m_inCellDefine; }
|
|
|
|
|
static void inCellDefine(bool flag) { s_readp->m_inCellDefine = flag; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static bool inLibrary() { return s_readp->m_inLibrary; }
|
|
|
|
|
static void stateExitPsl(); // Parser -> lexer communication
|
|
|
|
|
static void statePushVlg(); // Parser -> lexer communication
|
|
|
|
|
static void statePop(); // Parser -> lexer communication
|
2007-03-16 18:44:17 +00:00
|
|
|
|
static int stateVerilogRecent(); // Parser -> lexer communication
|
2008-01-31 14:49:27 +00:00
|
|
|
|
static int flexPpInputToLex(char* buf, int max_size) { return s_readp->ppInputToLex(buf,max_size); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CREATORS
|
|
|
|
|
V3Read(AstNetlist* rootp) {
|
|
|
|
|
m_rootp = rootp; m_lexerp = NULL;
|
2007-05-16 12:55:25 +00:00
|
|
|
|
m_inCellDefine = false;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_inLibrary = false;
|
2007-03-05 21:35:49 +00:00
|
|
|
|
m_inBeginKwd = 0;
|
2007-03-16 18:44:17 +00:00
|
|
|
|
m_lastVerilogState = stateVerilogRecent();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2007-11-02 11:23:03 +00:00
|
|
|
|
~V3Read();
|
|
|
|
|
void parserClear();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
// Preprocess and read the Verilog file specified into the netlist database
|
|
|
|
|
void readFile(FileLine* fileline, const string& modname, bool inLibrary);
|
|
|
|
|
|
|
|
|
|
private:
|
2008-01-31 14:49:27 +00:00
|
|
|
|
void lexFile(const string& modname);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // Guard
|