1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2000-2020 by Wilson Snyder. This program is free software;
// you can redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.
//
// This program 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.
//
//*************************************************************************
/// \file
/// \brief Verilog::Parse: Parseess verilog code
///
/// Authors: Wilson Snyder
///
/// Code available from: https://www.veripool.org/verilog-perl
///
//*************************************************************************
#ifndef _VPARSEGRAMMAR_H_
#define _VPARSEGRAMMAR_H_ 1
#include <string>
#include <map>
#include <deque>
#include <iostream>
using namespace std;
#include "VFileLine.h"
#include "VParse.h"
#include "VAst.h"
//============================================================================
// Containers of things to put out later
struct VParseGPin {
VFileLine* m_fl;
string m_name;
string m_conn;
int m_number;
VParseGPin(VFileLine* fl, const string& name, const string& conn, int number)
: m_fl(fl), m_name(name), m_conn(conn), m_number(number) {}
};
struct VParseNet {
string m_name;
string m_msb;
string m_lsb;
VParseNet(const string& net, const string& msb, const string& lsb)
: m_name(net), m_msb(msb), m_lsb(lsb) {}
VParseNet(const string& net)
: m_name(net), m_msb(""), m_lsb("") {}
};
//============================================================================
// We can't use bison's %union as the string type doesn't fit in a union.
// It's fine to use a struct though!
struct VParseBisonYYSType {
string str;
VFileLine* fl;
VAstEnt* scp; // Symbol table scope for future lookups
};
#define YYSTYPE VParseBisonYYSType
//============================================================================
class VParseGrammar {
static VParseGrammar* s_grammarp; ///< Current THIS, bison() isn't class based
VParse* m_parsep;
//int debug() { return 9; }
public: // Only for VParseBison
int m_pinNum; ///< Pin number being parsed
string m_varDecl;
string m_varNet;
string m_varIO;
string m_varDType;
string m_varRange;
string m_cellMod;
bool m_cellParam;
bool m_portNextNetValid;
string m_portNextNetName;
string m_portNextNetMsb;
string m_portNextNetLsb;
bool m_withinPin;
bool m_withinInst;
deque<VParseGPin> m_pinStack;
deque<VParseNet> m_portStack;
public: // But for internal use only
static VParseGrammar* staticGrammarp() { return s_grammarp; }
static VParse* staticParsep() { return staticGrammarp()->m_parsep; }
static void bisonError(const char* text) {
staticParsep()->error(text);
}
//static VFileLine* fileline() { return s_grammarp->m_fileline; }
public:
// CREATORS
VParseGrammar(VParse* parsep) : m_parsep(parsep) {
s_grammarp = this;
m_pinNum = 0;
m_cellParam = false;
m_portNextNetValid = false;
m_withinInst = false;
m_withinPin = false;
}
~VParseGrammar() {
s_grammarp = NULL;
}
// ACCESSORS
void debug(int level);
int pinNum() const { return m_pinNum; }
void pinNum(int flag) { m_pinNum = flag; }
void pinNumInc() { m_pinNum++; }
// METHODS
int parse(); // See VParseBison.y
static const char* tokenName(int token);
};
#endif // Guard
|