From e59f28d659c5d10ddc6b52eab70f5f783415936f Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 22 May 2008 18:40:29 -0700 Subject: [PATCH] work interrupted --- design_dump.cc | 31 ++++++++++++++++++++++++++----- elaborate.cc | 12 ++++++------ ivl_target.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ net_tran.cc | 19 ++++++++++++++++--- netlist.h | 5 ++--- t-dll.h | 11 +++++++++++ 6 files changed, 108 insertions(+), 17 deletions(-) diff --git a/design_dump.cc b/design_dump.cc index 1d408ffd8..b191a25fe 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -88,6 +88,31 @@ ostream& operator << (ostream&o, ivl_variable_type_t val) return o; } +ostream& operator << (ostream&o, ivl_switch_type_t val) +{ + switch (val) { + case IVL_SW_TRAN: + o << "tran"; + break; + case IVL_SW_TRANIF0: + o << "tranif0"; + break; + case IVL_SW_TRANIF1: + o << "tranif1"; + break; + case IVL_SW_RTRAN: + o << "rtran"; + break; + case IVL_SW_RTRANIF0: + o << "rtranif0"; + break; + case IVL_SW_RTRANIF1: + o << "rtranif1"; + break; + } + return o; +} + static inline void dump_scope_path(ostream&o, const NetScope*scope) { if (const NetScope*parent = scope->parent()) { @@ -613,11 +638,7 @@ void NetTaskDef::dump(ostream&o, unsigned ind) const void NetTran::dump_node(ostream&o, unsigned ind) const { - const char*r = resistive_? "r" : ""; - const char*ifx = enable_==0? "" : enable_>0? "if1" : "if0"; - - o << setw(ind) << "" << r << "tran" << ifx << " " << name() << endl; - + o << setw(ind) << "" << type_ << " " << name() << endl; dump_node_pins(o, ind+4); dump_obj_attr(o, ind+4); } diff --git a/elaborate.cc b/elaborate.cc index d4ca9b9df..d7180f4b5 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -666,7 +666,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, false, 0); + cur[idx] = new NetTran(scope, inm, IVL_SW_TRAN); } break; case RTRAN: @@ -676,7 +676,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, true, 0); + cur[idx] = new NetTran(scope, inm, IVL_SW_RTRAN); return; } break; @@ -687,7 +687,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, false, -1); + cur[idx] = new NetTran(scope, inm, IVL_SW_TRANIF0); } break; case RTRANIF0: @@ -697,7 +697,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, true, -1); + cur[idx] = new NetTran(scope, inm, IVL_SW_RTRANIF0); } break; case TRANIF1: @@ -707,7 +707,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, false, 1); + cur[idx] = new NetTran(scope, inm, IVL_SW_TRANIF1); } break; case RTRANIF1: @@ -717,7 +717,7 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const des->errors += 1; return; } else { - cur[idx] = new NetTran(scope, inm, true, 1); + cur[idx] = new NetTran(scope, inm, IVL_SW_RTRANIF1); } break; default: diff --git a/ivl_target.h b/ivl_target.h index 785fd0dcb..c0c16c2a2 100644 --- a/ivl_target.h +++ b/ivl_target.h @@ -123,6 +123,9 @@ _BEGIN_DECL * ivl_process_t object holds one of these, but a statement may in * turn contain other statements. * + * ivl_switch_t + * Switches are the tran/tranif devices in the design. + * * -- A Note About Bit Sets -- * Some objects hold a value as an array of bits. In these cases there * is some method that retrieves the width of the value and another @@ -155,6 +158,7 @@ typedef struct ivl_parameter_s*ivl_parameter_t; typedef struct ivl_process_s *ivl_process_t; typedef struct ivl_scope_s *ivl_scope_t; typedef struct ivl_signal_s *ivl_signal_t; +typedef struct ivl_switch_s *ivl_switch_t; typedef struct ivl_memory_s *ivl_memory_t; /* DEPRECATED */ typedef struct ivl_statement_s*ivl_statement_t; @@ -226,6 +230,16 @@ typedef enum ivl_logic_e { IVL_LO_UDP = 21 } ivl_logic_t; +/* This is the type of a ivl_switch_t object */ +typedef enum ivl_switch_type_e { + IVL_SW_TRAN = 0, + IVL_SW_TRANIF0 = 1, + IVL_SW_TRANIF1 = 2, + IVL_SW_RTRAN = 3, + IVL_SW_RTRANIF0 = 4, + IVL_SW_RTRANIF1 = 5 +} ivl_switch_type_t; + /* This is the type of an LPM object. */ typedef enum ivl_lpm_type_e { IVL_LPM_ABS = 32, @@ -1826,6 +1840,39 @@ extern ivl_expr_t ivl_stmt_rval(ivl_statement_t net); IVL_ST_WAIT, IVL_ST_WHILE */ extern ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net); +/* SWITCHES + * + * The switches represent the tran devices in the design. + * + * FUNCTION SUMMARY + * + * ivl_switch_type + * Return the enumerated value that is the type of the switch. + * + * ivl_switch_basename + * This is the name given to the device in the source code. + * + * ivl_switch_scope + * The scope where the switch device appears. + * + * ivl_switch_a + * ivl_switch_b + * The a and b ports are the two ports of the switch. + * + * ivl_switch_enable + * If the device has an enable (tranifX) then this is the enable + * port. + * + * SEMANTIC NOTES + * The a/b ports can be any type, but the types must exactly + * match. The enable must be a scalar. + */ +extern ivl_switch_type_t ivl_switch_type(ivl_switch_t net); +extern const char*ivl_switch_basename(ivl_switch_t net); +extern ivl_scope_t ivl_switch_scope(ivl_switch_t net); +extern ivl_nexus_t ivl_switch_a(ivl_switch_t net); +extern ivl_nexus_t ivl_switch_b(ivl_switch_t net); +extern ivl_nexus_t ivl_switch_enable(ivl_switch_t net); #if defined(__MINGW32__) || defined (__CYGWIN32__) # define DLLEXPORT __declspec(dllexport) diff --git a/net_tran.cc b/net_tran.cc index 60be74ad2..88067769b 100644 --- a/net_tran.cc +++ b/net_tran.cc @@ -28,12 +28,25 @@ # include "netmisc.h" # include "ivl_assert.h" -NetTran::NetTran(NetScope*scope, perm_string n, bool resistive, int enable) -: NetNode(scope, n, enable? 3 : 2) +static bool has_enable(ivl_switch_type_t tt) +{ + switch (tt) { + case IVL_SW_TRANIF0: + case IVL_SW_TRANIF1: + case IVL_SW_RTRANIF0: + case IVL_SW_RTRANIF1: + return true; + default: + return false; + } +} + +NetTran::NetTran(NetScope*scope, perm_string n, ivl_switch_type_t tt) +: NetNode(scope, n, has_enable(tt)? 3 : 2) { pin(0).set_dir(Link::PASSIVE); pin(0).set_name(perm_string::literal("A"), 0); pin(1).set_dir(Link::PASSIVE); pin(1).set_name(perm_string::literal("B"), 0); - if (enable) { + if (pin_count() == 3) { pin(2).set_dir(Link::INPUT); pin(2).set_name(perm_string::literal("E"), 0); } diff --git a/netlist.h b/netlist.h index da6bb196a..c7fabd138 100644 --- a/netlist.h +++ b/netlist.h @@ -1362,15 +1362,14 @@ class NetSysFunc : public NetNode { class NetTran : public NetNode { public: - NetTran(NetScope*scope, perm_string n, bool resistive, int enable); + NetTran(NetScope*scope, perm_string n, ivl_switch_type_t type); ~NetTran(); virtual void dump_node(ostream&, unsigned ind) const; virtual bool emit_node(struct target_t*) const; private: - bool resistive_; - bool enable_; + ivl_switch_type_t type_; }; /* ========= diff --git a/t-dll.h b/t-dll.h index ae0ce2986..3bfc4915e 100644 --- a/t-dll.h +++ b/t-dll.h @@ -446,6 +446,17 @@ struct ivl_net_logic_s { ivl_expr_t delay[3]; }; +struct ivl_switch_s { + ivl_switch_type_t type; + + perm_string name; + ivl_scope_t scope; + + struct ivl_attribute_s*attr; + unsigned nattr; + + ivl_nexus_t pins[3]; +}; /* * UDP definition.