2012-04-13 01:08:20 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2009-10-31 14:08:38 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Netlist (top level) functions
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2009-10-31 14:08:38 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2021-01-01 15:29:54 +00:00
|
|
|
// Copyright 2003-2021 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-10-31 14:08:38 +00:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2009-10-31 14:08:38 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2009-10-31 14:08:38 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
#include "V3ParseImp.h"
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2009-10-31 14:08:38 +00:00
|
|
|
//======================================================================
|
|
|
|
// Build in LEX script
|
|
|
|
|
|
|
|
#define yyFlexLexer V3LexerBase
|
|
|
|
#include "V3Lexer.yy.cpp"
|
|
|
|
#undef yyFlexLexer
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Lex-derived class
|
|
|
|
|
|
|
|
/// Override the base lexer class so we can add some access functions
|
2020-11-19 02:32:16 +00:00
|
|
|
class V3Lexer final : public V3LexerBase {
|
2009-10-31 14:08:38 +00:00
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
2020-04-14 02:51:35 +00:00
|
|
|
V3Lexer()
|
2020-08-16 13:55:36 +00:00
|
|
|
: V3LexerBase{nullptr} {}
|
2020-11-17 00:56:16 +00:00
|
|
|
~V3Lexer() override = default;
|
2009-10-31 14:08:38 +00:00
|
|
|
// METHODS
|
2014-03-11 23:07:58 +00:00
|
|
|
void unputString(const char* textp, size_t length) {
|
2018-10-14 22:39:33 +00:00
|
|
|
// Add characters to input stream in back-to-front order
|
|
|
|
const char* cp = textp;
|
2020-04-14 02:51:35 +00:00
|
|
|
for (cp += length - 1; length--; cp--) unput(*cp);
|
2014-03-11 23:07:58 +00:00
|
|
|
}
|
2009-10-31 14:08:38 +00:00
|
|
|
};
|
2014-03-11 23:07:58 +00:00
|
|
|
|
2020-06-07 16:18:23 +00:00
|
|
|
void V3ParseImp::lexUnputString(const char* textp, size_t length) {
|
2018-10-14 22:39:33 +00:00
|
|
|
parsep()->m_lexerp->unputString(textp, length);
|
|
|
|
}
|
2014-03-11 23:07:58 +00:00
|
|
|
|
2020-06-07 19:35:36 +00:00
|
|
|
void V3ParseImp::yylexReadTok() {
|
2014-03-11 23:07:58 +00:00
|
|
|
// Call yylex() remembering last non-whitespace token
|
2020-06-07 17:45:50 +00:00
|
|
|
parsep()->lexFileline()->startToken();
|
2014-03-11 23:07:58 +00:00
|
|
|
int token = parsep()->m_lexerp->yylex();
|
2020-06-07 16:18:23 +00:00
|
|
|
m_lexPrevToken = token; // Save so can find '#' to parse following number
|
2020-06-07 19:35:36 +00:00
|
|
|
yylval.token = token;
|
2014-03-11 23:07:58 +00:00
|
|
|
}
|
2009-10-31 14:08:38 +00:00
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Read class functions
|
|
|
|
|
2018-10-14 22:39:33 +00:00
|
|
|
void V3ParseImp::lexNew() {
|
|
|
|
if (m_lexerp) delete m_lexerp; // Restart from clean slate.
|
2009-10-31 14:08:38 +00:00
|
|
|
m_lexerp = new V3Lexer();
|
2021-02-22 02:25:21 +00:00
|
|
|
if (debugFlex() >= 9) m_lexerp->set_debug(~0);
|
2009-10-31 14:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void V3ParseImp::lexDestroy() {
|
2020-08-15 14:12:55 +00:00
|
|
|
if (m_lexerp) VL_DO_CLEAR(delete m_lexerp, m_lexerp = nullptr);
|
2009-10-31 14:08:38 +00:00
|
|
|
}
|