ivl_target API for class types with properties.

This commit is contained in:
Stephen Williams 2012-12-01 12:03:01 -08:00
parent 318a4033b8
commit 70dff035a2
14 changed files with 140 additions and 11 deletions

View File

@ -385,6 +385,10 @@ void NetScope::emit_scope(struct target_t*tgt) const
for (NetEvent*cur = events_ ; cur ; cur = cur->snext_)
tgt->event(cur);
for (map<perm_string,netclass_t*>::const_iterator cur = classes_.begin()
; cur != classes_.end() ; ++cur)
tgt->class_type(this, cur->second);
for (list<netenum_t*>::const_iterator cur = enum_sets_.begin()
; cur != enum_sets_.end() ; ++cur)
tgt->enumeration(this, *cur);

View File

@ -1741,6 +1741,8 @@ extern ivl_statement_t ivl_scope_def(ivl_scope_t net);
extern const char* ivl_scope_def_file(ivl_scope_t net);
extern unsigned ivl_scope_def_lineno(ivl_scope_t net);
extern unsigned ivl_scope_classes(ivl_scope_t net);
extern ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx);
extern unsigned ivl_scope_enumerates(ivl_scope_t net);
extern ivl_enumtype_t ivl_scope_enumerate(ivl_scope_t net, unsigned idx);
extern unsigned ivl_scope_events(ivl_scope_t net);
@ -2213,12 +2215,18 @@ extern unsigned ivl_switch_lineno(ivl_switch_t net);
* for array types.
*
* SEMANTIC NOTES
*
* Class types have names and properties.
*/
extern ivl_variable_type_t ivl_type_base(ivl_type_t net);
extern ivl_type_t ivl_type_element(ivl_type_t net);
extern unsigned ivl_type_packed_dimensions(ivl_type_t net);
extern int ivl_type_packed_lsb(ivl_type_t net, unsigned dim);
extern int ivl_type_packed_msb(ivl_type_t net, unsigned dim);
extern const char* ivl_type_name(ivl_type_t net);
extern unsigned ivl_type_properties(ivl_type_t net);
extern const char* ivl_type_prop_name(ivl_type_t net, unsigned idx);
extern ivl_type_t ivl_type_prop_type(ivl_type_t net, unsigned idx);
#if defined(__MINGW32__) || defined (__CYGWIN32__)

View File

@ -39,6 +39,7 @@ bool netclass_t::set_property(perm_string pname, ivl_type_s*ptype)
return false;
properties_[pname] = ptype;
property_table_.push_back(pname);
return true;
}
@ -56,3 +57,15 @@ const ivl_type_s* netclass_t::get_property(perm_string pname) const
else
return cur->second;
}
const char*netclass_t::get_prop_name(size_t idx) const
{
assert(idx < property_table_.size());
return property_table_[idx];
}
ivl_type_t netclass_t::get_prop_type(size_t idx) const
{
assert(idx < property_table_.size());
return get_property(property_table_[idx]);
}

View File

@ -43,10 +43,16 @@ class netclass_t : public ivl_type_s {
const ivl_type_s* get_property(perm_string pname) const;
inline size_t get_properties(void) const { return properties_.size(); }
const char*get_prop_name(size_t idx) const;
ivl_type_t get_prop_type(size_t idx) const;
private:
perm_string name_;
// Bind properties to their types.
std::map<perm_string,ivl_type_s*> properties_;
// This is to help the get_prop_name() method work.
std::vector<perm_string> property_table_;
};
#endif

View File

@ -21,6 +21,7 @@
# include "StringHeap.h"
# include "t-dll.h"
# include "discipline.h"
# include "netclass.h"
# include "netdarray.h"
# include "netenum.h"
# include "netvector.h"
@ -1855,6 +1856,18 @@ extern "C" int ivl_scope_children(ivl_scope_t net,
return 0;
}
extern "C" ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx)
{
assert(idx < net->classes.size());
return net->classes[idx];
}
extern "C" unsigned ivl_scope_classes(ivl_scope_t net)
{
return net->classes.size();
}
extern "C" ivl_statement_t ivl_scope_def(ivl_scope_t net)
{
assert(net);
@ -2841,3 +2854,36 @@ extern "C" int ivl_type_packed_msb(ivl_type_t net, unsigned dim)
assert(dim < slice.size());
return slice[dim].get_msb();
}
extern "C" const char* ivl_type_name(ivl_type_t net)
{
if (const netclass_t*class_type = dynamic_cast<const netclass_t*>(net)) {
return class_type->get_name();
}
return 0;
}
extern "C" unsigned ivl_type_properties(ivl_type_t net)
{
const netclass_t*class_type = dynamic_cast<const netclass_t*>(net);
assert(class_type);
return class_type->get_properties();
}
extern "C" const char* ivl_type_prop_name(ivl_type_t net, unsigned idx)
{
const netclass_t*class_type = dynamic_cast<const netclass_t*>(net);
assert(class_type);
return class_type->get_prop_name(idx);
}
extern "C" ivl_type_t ivl_type_prop_type(ivl_type_t net, unsigned idx)
{
const netclass_t*class_type = dynamic_cast<const netclass_t*>(net);
assert(class_type);
return class_type->get_prop_type(idx);
}

View File

@ -25,6 +25,7 @@
# include <cstdio> // sprintf()
# include "compiler.h"
# include "t-dll.h"
# include "netclass.h"
# include "netmisc.h"
# include "discipline.h"
# include <cstdlib>
@ -396,11 +397,6 @@ void scope_add_logic(ivl_scope_t scope, ivl_net_logic_t net)
}
static void scope_add_enumeration(ivl_scope_t scope, ivl_enumtype_t net)
{
scope->enumerations_.push_back(net);
}
void scope_add_event(ivl_scope_t scope, ivl_event_t net)
{
if (scope->nevent_ == 0) {
@ -786,10 +782,17 @@ bool dll_target::bufz(const NetBUFZ*net)
return true;
}
bool dll_target::class_type(const NetScope*in_scope, netclass_t*net)
{
ivl_scope_t use_scope = find_scope(des_, in_scope);
use_scope->classes.push_back(net);
return true;
}
bool dll_target::enumeration(const NetScope*in_scope, netenum_t*net)
{
ivl_scope_t scop = find_scope(des_, in_scope);
scope_add_enumeration(scop, net);
ivl_scope_t use_scope = find_scope(des_, in_scope);
use_scope->enumerations_.push_back(net);
return true;
}

View File

@ -58,6 +58,7 @@ struct dll_target : public target_t, public expr_scan_t {
bool bufz(const NetBUFZ*);
bool branch(const NetBranch*);
bool class_type(const NetScope*, netclass_t*);
bool enumeration(const NetScope*, netenum_t*);
void event(const NetEvent*);
void logic(const NetLogic*);
@ -638,6 +639,7 @@ struct ivl_scope_s {
unsigned def_lineno;
ivl_scope_type_t type_;
std::vector<ivl_type_t> classes;
std::vector<ivl_enumtype_t> enumerations_;
std::vector<ivl_signal_t> sigs_;

View File

@ -43,6 +43,13 @@ bool target_t::branch(const NetBranch*obj)
return false;
}
bool target_t::class_type(const NetScope*, netclass_t*obj)
{
cerr << "<>:0" << ": error: target (" << typeid(*this).name()
<< "): Unhandled class_type <" << obj << ">." << endl;
return false;
}
void target_t::event(const NetEvent*ev)
{
cerr << ev->get_fileline() << ": error: target (" << typeid(*this).name()

View File

@ -56,6 +56,8 @@ struct target_t {
anything else is called. */
virtual void scope(const NetScope*);
virtual bool class_type(const NetScope*, netclass_t*);
/* This is called to convert module ports from a NetNet* to an
* ivl_signal_t object. */
virtual void convert_module_ports(const NetScope*);

View File

@ -44,7 +44,7 @@ CPPFLAGS = $(INCLUDE_PATH) @CPPFLAGS@ @DEFS@ @PICFLAG@
CFLAGS = @WARNING_FLAGS@ @CFLAGS@
LDFLAGS = @LDFLAGS@
O = stub.o enumerate.o expression.o statement.o switches.o types.o
O = stub.o classes.o enumerate.o expression.o statement.o switches.o types.o
all: dep stub.tgt

34
tgt-stub/classes.c Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2012 Stephen Williams (steve@icarus.com)
*
* 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 "config.h"
# include "priv.h"
# include <string.h>
void show_class(ivl_type_t net)
{
unsigned idx;
fprintf(out, " class %s\n", ivl_type_name(net));
for (idx = 0 ; idx < ivl_type_properties(net) ; idx += 1) {
fprintf(out, " ");
show_net_type(ivl_type_prop_type(net,idx));
fprintf(out, " %s\n", ivl_type_prop_name(net,idx));
}
}

View File

@ -49,6 +49,7 @@ extern ivl_discipline_t discipline_of_nexus(ivl_nexus_t nex);
*/
extern void test_expr_is_delay(ivl_expr_t expr);
extern void show_class(ivl_type_t net);
extern void show_enumerate(ivl_enumtype_t net);
/*
@ -71,3 +72,5 @@ extern void show_switch(ivl_switch_t net);
/*
*/
extern const char*data_type_string(ivl_variable_type_t vtype);
extern void show_net_type(ivl_type_t net_type);

View File

@ -1588,6 +1588,9 @@ static int show_scope(ivl_scope_t net, void*x)
}
}
for (idx = 0 ; idx < ivl_scope_classes(net) ; idx += 1)
show_class(ivl_scope_class(net, idx));
for (idx = 0 ; idx < ivl_scope_params(net) ; idx += 1)
show_parameter(ivl_scope_param(net, idx));

View File

@ -21,8 +21,6 @@
# include "priv.h"
# include <string.h>
static void show_net_type(ivl_type_t net_type);
static void show_net_type_darray(ivl_type_t net_type)
{
/* Dynamic arrays have a single element type. */
@ -32,7 +30,7 @@ static void show_net_type_darray(ivl_type_t net_type)
show_net_type(element_type);
}
static void show_net_type(ivl_type_t net_type)
void show_net_type(ivl_type_t net_type)
{
ivl_variable_type_t data_type = ivl_type_base(net_type);