File: VAst.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 (157 lines) | stat: -rw-r--r-- 4,742 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// -*- C++ -*-
//*************************************************************************
//
// Copyright 2009-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: Symbol table accessing
///
/// Authors: Wilson Snyder
///
/// Code available from: http://www.veripool.org/verilog-perl
///
//*************************************************************************

#ifndef _VAST_H_
#define _VAST_H_ 1

#include <string>
#include <cstdlib>
#include <cassert>
using namespace std;

// We don't include perl.h as it gets upset when merged with bison
// code.  So just grab a minimal set.
struct av;
struct hv;

//######################################################################
// Enumeration that indicates what type of symbol is in the symbol tree.
// We may later change to use a different object for each type

class VAstType {
public:
    enum en {
	NOT_FOUND = 0,
	NETLIST = 1,	// Top of structure, created by Parser.pm:sub new{}
	AN_ERROR = 2,	// Consistency error in internal tables (ERROR alone is a #define on some systems)
	UNKNOWN = 3,	// Things that need scope, but don't know type yet
	//
	BLOCK,
	CHECKER,
	CLASS,		// For yaID__CLASS
	CLOCKING,
	COVERGROUP,	// For yaID__COVERGROUP
	ENUM,
	FORK,
	FUNCTION,
	INTERFACE,
	LET,
	MODPORT,
	MODULE,
	PACKAGE,	// For yaID__PACKAGE
	PROGRAM,
	PROPERTY,
	SEQUENCE,
	STRUCT,
	TASK,
	TYPE,		// For yaID__TYPE
	UNION,
	_MAX
    };
    enum en m_e;
    inline VAstType () {};
    inline VAstType (en _e) : m_e(_e) {};
    explicit inline VAstType (int _e) : m_e(static_cast<en>(_e)) {};
    operator en () const { return m_e; };
    const char* ascii() const {
	static const char* names[] = {
	"NOT_FOUND", "netlist", "error", "unknown",
	"block", "checker", "class", "clocking", "covergroup",
	"enum", "fork", "function", "interface", "let",
	"modport", "module", "package", "program", "property",
	"sequence", "struct", "task", "type", "union",
	"_MAX"
	};
	return names[m_e];
    }
  };
  inline bool operator== (VAstType lhs, VAstType rhs) { return (lhs.m_e == rhs.m_e); }
  inline bool operator== (VAstType lhs, VAstType::en rhs) { return (lhs.m_e == rhs); }
  inline bool operator== (VAstType::en lhs, VAstType rhs) { return (lhs == rhs.m_e); }

//######################################################################
// Single symbol table

class VAstEnt {
private:
    // MEMBERS
    // NOT ALLOWED - this class really has this==AV*

    // STATIC MEMBERS
    static int s_debug;
public:
    static void debug(int flag) { s_debug=flag; }
    static int debug() { return s_debug; }

private:
    // CREATORS
    VAstEnt() { assert(0); }	// Not made by users, it's an AV*
    ~VAstEnt() { assert(0); }	// Not made by users, it's an AV*

    av* newAVEnt (VAstType type);
    static void initAVEnt (struct av* avp, VAstType type, struct av* parentp);

    // ACCESSORS
    inline struct av* castAVp() { return (struct av*)(this); }
    inline VAstEnt* avToSymEnt(struct av* avp) { return (VAstEnt*)(avp); }

    /// $self->[2]: For current entry, the hash of symbols under it
    struct hv* subhash();

    /// Insert into current table
    void replaceInsert(VAstEnt* newentp, const string& name);

public:
    // ACCESSORS

    /// $self->[0]: For current entry, the node type
    VAstType type();

    /// $self->[1]: For current entry, what node it is under or NULL if netlist
    VAstEnt* parentp();

    /// type() indicates we shouldn't report this as a containing object
    bool typeIgnoreObjof() { VAstType t=type(); return t==VAstType::BLOCK || t==VAstType::FORK; }

    /// Info on current node, for debug
    string ascii(const string& name="");

    // METHODS
    /// Return internal pointer for given name or null
    VAstEnt* findSym (const string& name);

    /// Find or create a symbol under current entry
    VAstEnt* findInsert (VAstType type, const string& name);

    /// Replace or create a symbol entry under current entry
    VAstEnt* replaceInsert (VAstType type, const string& name);

    /// Insert into current table from another imported package's table
    void import(VAstEnt* fromEntp, const string& id_or_star);

protected:
    friend class VSymStack;
    void initNetlist(VFileLine* fl);
};

#endif // guard