verilog parser

commit aa52884df77545280835532c21cb4d024eda5573
Author: James Cherry <cherry@parallaxsw.com>
Date:   Sat Jan 25 11:20:33 2025 -0700

    zlib optional

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

commit 5a46e0e5d1d9fe806d290fa34a4ad4aa0a9e4899
Author: James Cherry <cherry@parallaxsw.com>
Date:   Fri Jan 24 19:19:33 2025 -0700

    verilog prefix

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

commit 1b1fbf41c96f96a4c4b9f8b66f16f27688cb47a8
Author: James Cherry <cherry@parallaxsw.com>
Date:   Fri Jan 24 17:09:32 2025 -0700

    blank

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

commit 72488094a4696414ce5c37a4ab5bb78f4a9750c1
Author: James Cherry <cherry@parallaxsw.com>
Date:   Fri Jan 24 16:47:55 2025 -0700

    verilog parse reorg

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2025-01-25 11:21:40 -07:00
parent eb7fe84055
commit fafbcb216e
6 changed files with 36 additions and 44 deletions

View File

@ -307,7 +307,7 @@ flex_target(VerilogLex ${STA_HOME}/verilog/VerilogLex.ll
bison_target(VerilogParse ${STA_HOME}/verilog/VerilogParse.yy bison_target(VerilogParse ${STA_HOME}/verilog/VerilogParse.yy
${CMAKE_CURRENT_BINARY_DIR}/VerilogParse.cc ${CMAKE_CURRENT_BINARY_DIR}/VerilogParse.cc
# centos7 bison 3.0.4 < 3.3.0 uses parser_class_name instead of api.parsr.class # centos7 bison 3.0.4 < 3.3.0 uses parser_class_name instead of api.parsr.class
COMPILE_FLAGS -Wno-deprecated) COMPILE_FLAGS "-Wno-deprecated")
add_flex_bison_dependency(VerilogLex VerilogParse) add_flex_bison_dependency(VerilogLex VerilogParse)
# Sdf scan/parse. # Sdf scan/parse.
@ -319,7 +319,6 @@ bison_target(SdfParse ${STA_HOME}/sdf/SdfParse.yy ${CMAKE_CURRENT_BINARY_DIR}/Sd
) )
add_flex_bison_dependency(SdfLex SdfParse) add_flex_bison_dependency(SdfLex SdfParse)
# Saif scan/parse. # Saif scan/parse.
flex_target(SaifLex ${STA_HOME}/power/SaifLex.ll ${CMAKE_CURRENT_BINARY_DIR}/SaifLex.cc flex_target(SaifLex ${STA_HOME}/power/SaifLex.ll ${CMAKE_CURRENT_BINARY_DIR}/SaifLex.cc
COMPILE_FLAGS --prefix=SaifLex_ COMPILE_FLAGS --prefix=SaifLex_

View File

@ -32,10 +32,12 @@
#ifdef ZLIB_FOUND #ifdef ZLIB_FOUND
#include <zlib.h> #include <zlib.h>
#include "util/gzstream.hh"
#else // ZLIB_FOUND #else // ZLIB_FOUND
#include <cstdio> #include <cstdio>
#include <fstream>
#define gzFile FILE* #define gzFile FILE*
#define gzopen fopen #define gzopen fopen
@ -44,4 +46,8 @@
#define gzprintf fprintf #define gzprintf fprintf
#define Z_NULL nullptr #define Z_NULL nullptr
namespace gzstream {
typedef std::ifstream igzstream;
}
#endif // ZLIB_FOUND #endif // ZLIB_FOUND

View File

@ -23,31 +23,33 @@
// //
// This notice may not be removed or altered from any source distribution. // This notice may not be removed or altered from any source distribution.
#include "util/FlexDisableRegister.hh"
#include "VerilogNamespace.hh" #include "VerilogNamespace.hh"
#include "verilog/VerilogReader.hh" #include "verilog/VerilogReader.hh"
#include "verilog/VerilogReaderPvt.hh" #include "verilog/VerilogReaderPvt.hh"
#include "VerilogParse.hh" #include "VerilogParse.hh"
#include "verilog/VerilogScanner.hh" #include "verilog/VerilogScanner.hh"
#include "util/FlexDisableRegister.hh"
#undef YY_DECL #undef YY_DECL
#define YY_DECL \ #define YY_DECL \
int \ int \
sta::VerilogScanner::yylex(sta::VerilogParse::semantic_type *const yylval, \ sta::VerilogScanner::lex(sta::VerilogParse::semantic_type *const yylval, \
sta::VerilogParse::location_type *loc) sta::VerilogParse::location_type *loc)
// update location on matching // update location on matching
#define YY_USER_ACTION loc->step(); loc->columns(yyleng); #define YY_USER_ACTION loc->step(); loc->columns(yyleng);
typedef sta::VerilogParse::token token; typedef sta::VerilogParse::token token;
%} %}
%option c++ %option c++
%option yyclass="sta::VerilogScanner" %option yyclass="sta::VerilogScanner"
%option prefix="Verilog"
%option noyywrap %option noyywrap
%option never-interactive %option never-interactive
%option stack %option stack
%option yylineno
/* %option debug */
%x COMMENT %x COMMENT
%x QSTRING %x QSTRING

View File

@ -22,45 +22,18 @@
// //
// This notice may not be removed or altered from any source distribution. // This notice may not be removed or altered from any source distribution.
%require "3.0"
%skeleton "lalr1.cc"
%debug
%defines
%define api.namespace {sta}
// bison 3.0.4 for centos7
%define parser_class_name {VerilogParse}
// bison 3.3.2
//%define api.parser.class {VerilogParse}
%code requires {
namespace sta {
class VerilogReadcer;
class VerilogScanner;
}
}
%locations
%parse-param { VerilogScanner *scanner }
%parse-param { VerilogReader *reader }
%{ %{
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include <iostream>
#include "Report.hh" #include "Report.hh"
#include "PortDirection.hh" #include "PortDirection.hh"
#include "verilog/VerilogReader.hh" #include "verilog/VerilogReader.hh"
#include "verilog/VerilogReaderPvt.hh" #include "verilog/VerilogReaderPvt.hh"
#include "verilog/VerilogScanner.hh" #include "verilog/VerilogScanner.hh"
%}
%code {
#undef yylex #undef yylex
#define yylex scanner->yylex #define yylex scanner->lex
// warning: variable 'yynerrs_' set but not used // warning: variable 'yynerrs_' set but not used
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
@ -73,10 +46,21 @@ sta::VerilogParse::error(const location_type &loc,
{ {
reader->report()->fileError(164,reader->filename(),loc.begin.line,"%s",msg.c_str()); reader->report()->fileError(164,reader->filename(),loc.begin.line,"%s",msg.c_str());
} }
%}
} %require "3.0"
%skeleton "lalr1.cc"
%debug
%define api.namespace {sta}
%locations
%define parse.assert %define parse.assert
%parse-param { VerilogScanner *scanner }
%parse-param { VerilogReader *reader }
// bison 3.0.4 for centos7
%define parser_class_name {VerilogParse}
// bison 3.3.2
//%define api.parser.class {VerilogParse}
%union { %union {
int ival; int ival;

View File

@ -26,8 +26,7 @@
#include <cstdlib> #include <cstdlib>
#include "util/gzstream.hh" #include "Zlib.hh"
#include "Debug.hh" #include "Debug.hh"
#include "Report.hh" #include "Report.hh"
#include "Error.hh" #include "Error.hh"
@ -2262,7 +2261,7 @@ VerilogScanner::VerilogScanner(std::istream *stream,
void void
VerilogScanner::error(const char *msg) VerilogScanner::error(const char *msg)
{ {
report_->fileError(1866, "foo", lineno(), "%s", msg); report_->fileError(1866, filename_, lineno(), "%s", msg);
} }
} // namespace } // namespace

View File

@ -25,6 +25,8 @@
#pragma once #pragma once
#ifndef __FLEX_LEXER_H #ifndef __FLEX_LEXER_H
#undef yyFlexLexer
#define yyFlexLexer VerilogFlexLexer
#include <FlexLexer.h> #include <FlexLexer.h>
#endif #endif
@ -35,7 +37,7 @@ namespace sta {
class Report; class Report;
class VerilogScanner : public yyFlexLexer class VerilogScanner : public VerilogFlexLexer
{ {
public: public:
VerilogScanner(std::istream *stream, VerilogScanner(std::istream *stream,
@ -43,15 +45,15 @@ public:
Report *report); Report *report);
virtual ~VerilogScanner() {} virtual ~VerilogScanner() {}
virtual int yylex(VerilogParse::semantic_type *const yylval, virtual int lex(VerilogParse::semantic_type *const yylval,
VerilogParse::location_type *yylloc); VerilogParse::location_type *yylloc);
// YY_DECL defined in VerilogLex.ll // YY_DECL defined in VerilogLex.ll
// Method body created by flex in VerilogLex.yy.cc // Method body created by flex in VerilogLex.cc
void error(const char *msg); void error(const char *msg);
// Get rid of override virtual function warning. // Get rid of override virtual function warning.
using FlexLexer::yylex; using yyFlexLexer::yylex;
private: private:
const char *filename_; const char *filename_;