2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_netclass_H
|
|
|
|
|
#define IVL_netclass_H
|
2012-11-12 02:42:31 +01:00
|
|
|
/*
|
2021-11-04 17:12:04 +01:00
|
|
|
* Copyright (c) 2012-2021 Stephen Williams (steve@icarus.com)
|
2012-11-12 02:42:31 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "LineInfo.h"
|
|
|
|
|
# include "ivl_target.h"
|
|
|
|
|
# include "nettypes.h"
|
2013-06-26 15:16:24 +02:00
|
|
|
# include "property_qual.h"
|
2013-03-15 04:08:32 +01:00
|
|
|
# include <iostream>
|
2012-11-25 19:13:05 +01:00
|
|
|
# include <map>
|
2012-11-12 02:42:31 +01:00
|
|
|
|
2013-03-15 04:08:32 +01:00
|
|
|
class Design;
|
2022-02-19 12:58:27 +01:00
|
|
|
class NetExpr;
|
2013-07-03 04:41:58 +02:00
|
|
|
class NetNet;
|
2013-03-15 04:08:32 +01:00
|
|
|
class NetScope;
|
|
|
|
|
class PClass;
|
2013-11-04 00:20:30 +01:00
|
|
|
class PExpr;
|
2013-03-15 04:08:32 +01:00
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
class netclass_t : public ivl_type_s {
|
|
|
|
|
public:
|
2022-03-17 12:25:28 +01:00
|
|
|
netclass_t(perm_string class_name, const netclass_t*super);
|
2012-11-12 02:42:31 +01:00
|
|
|
~netclass_t();
|
|
|
|
|
|
2012-11-25 19:13:05 +01:00
|
|
|
// Set the property of the class during elaboration. Set the
|
|
|
|
|
// name and type, and return true. If the name is already
|
|
|
|
|
// present, then return false.
|
2022-03-12 23:05:11 +01:00
|
|
|
bool set_property(perm_string pname, property_qualifier_t qual, ivl_type_t ptype);
|
2012-11-25 19:13:05 +01:00
|
|
|
|
2013-03-15 04:08:32 +01:00
|
|
|
// Set the scope for the class. The scope has no parents and
|
2014-09-02 18:22:41 +02:00
|
|
|
// is used for the elaboration of methods
|
|
|
|
|
// (tasks/functions). In other words, this is the class itself.
|
2013-03-15 04:08:32 +01:00
|
|
|
void set_class_scope(NetScope*cscope);
|
|
|
|
|
|
2014-09-16 02:33:56 +02:00
|
|
|
inline const NetScope* class_scope(void) const { return class_scope_; }
|
|
|
|
|
|
2014-09-02 18:22:41 +02:00
|
|
|
// Set the scope for the class definition. This is the scope
|
|
|
|
|
// where the class definition was encountered, and may be used
|
|
|
|
|
// to locate symbols that the class definition may inherit
|
|
|
|
|
// from its context. This can be nil, or a package or module
|
|
|
|
|
// where a class is defined.
|
|
|
|
|
void set_definition_scope(NetScope*dscope);
|
|
|
|
|
|
|
|
|
|
NetScope*definition_scope(void);
|
|
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
// As an ivl_type_s object, the netclass is always an
|
|
|
|
|
// ivl_VT_CLASS object.
|
|
|
|
|
ivl_variable_type_t base_type() const;
|
|
|
|
|
|
2012-11-25 19:13:05 +01:00
|
|
|
// This is the name of the class type
|
2012-11-12 02:42:31 +01:00
|
|
|
inline perm_string get_name() const { return name_; }
|
|
|
|
|
|
2013-10-31 02:35:00 +01:00
|
|
|
// If this is derived from another class, then this method
|
|
|
|
|
// returns a pointer to the super-class.
|
|
|
|
|
inline const netclass_t* get_super() const { return super_; }
|
|
|
|
|
|
|
|
|
|
// Get the number of properties in this class. Include
|
|
|
|
|
// properties in the parent class.
|
|
|
|
|
size_t get_properties(void) const;
|
2013-06-26 15:16:24 +02:00
|
|
|
// Get information about each property.
|
2012-12-01 21:03:01 +01:00
|
|
|
const char*get_prop_name(size_t idx) const;
|
2013-06-26 15:16:24 +02:00
|
|
|
property_qualifier_t get_prop_qual(size_t idx) const;
|
2012-12-01 21:03:01 +01:00
|
|
|
ivl_type_t get_prop_type(size_t idx) const;
|
|
|
|
|
|
2013-06-28 16:57:35 +02:00
|
|
|
// These methods are used by the elaborator to note the
|
|
|
|
|
// initializer for constant properties. Properties start out
|
|
|
|
|
// as not initialized, and when elaboration detects an
|
|
|
|
|
// assignment to the property, it is marked initialized.
|
|
|
|
|
bool get_prop_initialized(size_t idx) const;
|
|
|
|
|
void set_prop_initialized(size_t idx) const;
|
|
|
|
|
|
|
|
|
|
bool test_for_missing_initializers(void) const;
|
|
|
|
|
|
2014-09-05 05:52:51 +02:00
|
|
|
// Map the name of a property to its index. Return <0 if the
|
|
|
|
|
// name is not a property in the class.
|
2012-12-10 02:59:16 +01:00
|
|
|
int property_idx_from_name(perm_string pname) const;
|
|
|
|
|
|
2013-03-15 04:08:32 +01:00
|
|
|
// The task method scopes from the method name.
|
2013-04-15 03:03:21 +02:00
|
|
|
NetScope*method_from_name(perm_string mname) const;
|
2013-03-15 04:08:32 +01:00
|
|
|
|
2013-07-03 04:41:58 +02:00
|
|
|
// Find the elaborated signal (NetNet) for a static
|
|
|
|
|
// property. Search by name. The signal is created by the
|
|
|
|
|
// elaborate_sig pass.
|
|
|
|
|
NetNet*find_static_property(perm_string name) const;
|
|
|
|
|
|
2013-06-26 15:16:24 +02:00
|
|
|
// Test if this scope is a method within the class. This is
|
|
|
|
|
// used to check scope for handling data protection keywords
|
|
|
|
|
// "local" and "protected".
|
|
|
|
|
bool test_scope_is_method(const NetScope*scope) const;
|
|
|
|
|
|
2013-03-15 04:08:32 +01:00
|
|
|
void elaborate_sig(Design*des, PClass*pclass);
|
|
|
|
|
void elaborate(Design*des, PClass*pclass);
|
|
|
|
|
|
2013-03-18 01:44:15 +01:00
|
|
|
void emit_scope(struct target_t*tgt) const;
|
2014-09-07 02:39:52 +02:00
|
|
|
bool emit_defs(struct target_t*tgt) const;
|
2013-03-18 01:44:15 +01:00
|
|
|
|
2014-09-14 06:12:39 +02:00
|
|
|
std::ostream& debug_dump(std::ostream&fd) const;
|
2021-11-04 17:12:04 +01:00
|
|
|
void dump_scope(std::ostream&fd) const;
|
2013-03-15 04:08:32 +01:00
|
|
|
|
2022-02-19 12:58:27 +01:00
|
|
|
const NetExpr* get_parameter(Design *des, perm_string name,
|
|
|
|
|
ivl_type_t &par_type) const;
|
|
|
|
|
|
2022-09-19 20:23:02 +02:00
|
|
|
void set_virtual(bool virtual_class) { virtual_class_ = virtual_class; }
|
|
|
|
|
bool is_virtual() const { return virtual_class_; }
|
|
|
|
|
|
2022-09-17 22:01:58 +02:00
|
|
|
protected:
|
|
|
|
|
bool test_compatibility(ivl_type_t that) const;
|
|
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
private:
|
|
|
|
|
perm_string name_;
|
2013-10-31 02:35:00 +01:00
|
|
|
// If this is derived from another base class, point to it
|
2013-11-10 04:45:03 +01:00
|
|
|
// here.
|
2022-03-17 12:25:28 +01:00
|
|
|
const netclass_t*super_;
|
2013-11-10 04:45:03 +01:00
|
|
|
// Map property names to property table index.
|
2012-12-10 02:59:16 +01:00
|
|
|
std::map<perm_string,size_t> properties_;
|
|
|
|
|
// Vector of properties.
|
|
|
|
|
struct prop_t {
|
|
|
|
|
perm_string name;
|
2013-06-26 15:16:24 +02:00
|
|
|
property_qualifier_t qual;
|
2022-03-12 23:05:11 +01:00
|
|
|
ivl_type_t type;
|
2013-06-28 16:57:35 +02:00
|
|
|
mutable bool initialized_flag;
|
2012-12-10 02:59:16 +01:00
|
|
|
};
|
|
|
|
|
std::vector<prop_t> property_table_;
|
2013-03-15 04:08:32 +01:00
|
|
|
|
|
|
|
|
// This holds task/function definitions for methods.
|
|
|
|
|
NetScope*class_scope_;
|
2014-09-02 18:22:41 +02:00
|
|
|
|
|
|
|
|
// This holds the context for the class type definition.
|
|
|
|
|
NetScope*definition_scope_;
|
2022-09-19 20:23:02 +02:00
|
|
|
|
|
|
|
|
bool virtual_class_;
|
2012-11-12 02:42:31 +01:00
|
|
|
};
|
|
|
|
|
|
2014-09-02 18:22:41 +02:00
|
|
|
inline NetScope*netclass_t::definition_scope(void)
|
|
|
|
|
{
|
|
|
|
|
return definition_scope_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_netclass_H */
|