1 #ifndef IVL_netclass_H
2 #define IVL_netclass_H
3 /*
4  * Copyright (c) 2012-2014 Stephen Williams (steve@icarus.com)
5  *
6  *    This source code is free software; you can redistribute it
7  *    and/or modify it in source code form under the terms of the GNU
8  *    General Public License as published by the Free Software
9  *    Foundation; either version 2 of the License, or (at your option)
10  *    any later version.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with this program; if not, write to the Free Software
19  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 # include  "LineInfo.h"
23 # include  "ivl_target.h"
24 # include  "nettypes.h"
25 # include  "property_qual.h"
26 # include  <iostream>
27 # include  <map>
28 
29 class Design;
30 class NetNet;
31 class NetScope;
32 class PClass;
33 class PExpr;
34 
35 class netclass_t : public ivl_type_s {
36     public:
37       netclass_t(perm_string class_name, netclass_t*par);
38       ~netclass_t();
39 
40 	// Set the property of the class during elaboration. Set the
41 	// name and type, and return true. If the name is already
42 	// present, then return false.
43       bool set_property(perm_string pname, property_qualifier_t qual, ivl_type_s*ptype);
44 
45 	// Set the scope for the class. The scope has no parents and
46 	// is used for the elaboration of methods
47 	// (tasks/functions). In other words, this is the class itself.
48       void set_class_scope(NetScope*cscope);
49 
class_scope(void)50       inline const NetScope* class_scope(void) const { return class_scope_; }
51 
52 	// Set the scope for the class definition. This is the scope
53 	// where the class definition was encountered, and may be used
54 	// to locate symbols that the class definition may inherit
55 	// from its context. This can be nil, or a package or module
56 	// where a class is defined.
57       void set_definition_scope(NetScope*dscope);
58 
59       NetScope*definition_scope(void);
60 
61 	// As an ivl_type_s object, the netclass is always an
62 	// ivl_VT_CLASS object.
63       ivl_variable_type_t base_type() const;
64 
65 	// This is the name of the class type
get_name()66       inline perm_string get_name() const { return name_; }
67 
68 	// If this is derived from another class, then this method
69 	// returns a pointer to the super-class.
get_super()70       inline const netclass_t* get_super() const { return super_; }
71 
72 	// Get the number of properties in this class. Include
73 	// properties in the parent class.
74       size_t get_properties(void) const;
75 	// Get information about each property.
76       const char*get_prop_name(size_t idx) const;
77       property_qualifier_t get_prop_qual(size_t idx) const;
78       ivl_type_t get_prop_type(size_t idx) const;
79 
80 	// These methods are used by the elaborator to note the
81 	// initializer for constant properties. Properties start out
82 	// as not initialized, and when elaboration detects an
83 	// assignment to the property, it is marked initialized.
84       bool get_prop_initialized(size_t idx) const;
85       void set_prop_initialized(size_t idx) const;
86 
87       bool test_for_missing_initializers(void) const;
88 
89 	// Map the name of a property to its index. Return <0 if the
90 	// name is not a property in the class.
91       int property_idx_from_name(perm_string pname) const;
92 
93 	// The task method scopes from the method name.
94       NetScope*method_from_name(perm_string mname) const;
95 
96 	// Find the elaborated signal (NetNet) for a static
97 	// property. Search by name. The signal is created by the
98 	// elaborate_sig pass.
99       NetNet*find_static_property(perm_string name) const;
100 
101 	// Test if this scope is a method within the class. This is
102 	// used to check scope for handling data protection keywords
103 	// "local" and "protected".
104       bool test_scope_is_method(const NetScope*scope) const;
105 
106       void elaborate_sig(Design*des, PClass*pclass);
107       void elaborate(Design*des, PClass*pclass);
108 
109       void emit_scope(struct target_t*tgt) const;
110       bool emit_defs(struct target_t*tgt) const;
111 
112       std::ostream& debug_dump(std::ostream&fd) const;
113       void dump_scope(ostream&fd) const;
114 
115     private:
116       perm_string name_;
117 	// If this is derived from another base class, point to it
118 	// here.
119       netclass_t*super_;
120 	// Map property names to property table index.
121       std::map<perm_string,size_t> properties_;
122 	// Vector of properties.
123       struct prop_t {
124 	    perm_string name;
125 	    property_qualifier_t qual;
126 	    ivl_type_s* type;
127 	    mutable bool initialized_flag;
128       };
129       std::vector<prop_t> property_table_;
130 
131 	// This holds task/function definitions for methods.
132       NetScope*class_scope_;
133 
134 	// This holds the context for the class type definition.
135       NetScope*definition_scope_;
136 };
137 
definition_scope(void)138 inline NetScope*netclass_t::definition_scope(void)
139 {
140       return definition_scope_;
141 }
142 
143 #endif /* IVL_netclass_H */
144