File: VParseGrammar.h

package info (click to toggle)
libverilog-perl 3.422-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,996 kB
  • ctags: 1,835
  • sloc: perl: 8,355; yacc: 3,192; cpp: 2,199; lex: 1,468; makefile: 8; fortran: 3
file content (110 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download
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
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2000-2016 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: http://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"

//============================================================================
// Container 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) {}
};

//============================================================================
// 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;


    deque<VParseGPin> m_pinStack;

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;
    }
    ~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