diff --git a/ivl_target.h b/ivl_target.h index 2ca50bc45..79503397a 100644 --- a/ivl_target.h +++ b/ivl_target.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: ivl_target.h,v 1.13 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: ivl_target.h,v 1.14 2000/09/30 02:18:15 steve Exp $" #endif #ifdef __cplusplus @@ -79,6 +79,7 @@ typedef struct ivl_statement_s*ivl_statement_t; /* This is the type of an ivl_expr_t object. */ typedef enum ivl_expr_type_e { IVL_EX_NONE = 0, + IVL_EX_BINARY, IVL_EX_NUMBER, IVL_EX_SIGNAL, IVL_EX_STRING, @@ -177,6 +178,10 @@ extern ivl_expr_type_t ivl_expr_type(ivl_expr_t net); extern const char* ivl_expr_bits(ivl_expr_t net); extern const char* ivl_expr_name(ivl_expr_t net); +extern char ivl_expr_opcode(ivl_expr_t net); +extern ivl_expr_t ivl_expr_oper1(ivl_expr_t net); +extern ivl_expr_t ivl_expr_oper2(ivl_expr_t net); +extern ivl_expr_t ivl_expr_oper3(ivl_expr_t net); extern int ivl_expr_signed(ivl_expr_t net); extern const char* ivl_expr_string(ivl_expr_t net); extern unsigned ivl_expr_width(ivl_expr_t net); @@ -253,6 +258,7 @@ extern unsigned ivl_stmt_block_count(ivl_statement_t net); /* IVL_ST_BLOCK */ extern ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net, unsigned i); /* IVL_ST_CONDIT */ +extern ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net); extern ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net); extern ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net); /* IVL_ST_DELAY */ @@ -372,6 +378,10 @@ _END_DECL /* * $Log: ivl_target.h,v $ + * Revision 1.14 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.13 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. * diff --git a/t-dll-api.cc b/t-dll-api.cc index 35babc040..6aa406901 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-dll-api.cc,v 1.7 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: t-dll-api.cc,v 1.8 2000/09/30 02:18:15 steve Exp $" #endif # include "t-dll.h" @@ -33,12 +33,12 @@ extern "C" ivl_expr_type_t ivl_expr_type(ivl_expr_t net) extern "C" const char*ivl_get_flag(ivl_design_t des, const char*key) { - return ((const Design*)des)->get_flag(key).c_str(); + return des->self->get_flag(key).c_str(); } extern "C" const char*ivl_get_root_name(ivl_design_t des) { - return ((const Design*)des)->find_root_scope()->name().c_str(); + return des->root_->self->basename(); } extern "C" const char* ivl_expr_bits(ivl_expr_t net) @@ -53,6 +53,47 @@ extern "C" const char* ivl_expr_name(ivl_expr_t net) return net->u_.subsig_.name_; } +extern "C" char ivl_expr_opcode(ivl_expr_t net) +{ + assert(net); + switch (net->type_) { + case IVL_EX_BINARY: + return net->u_.binary_.op_; + + default: + assert(0); + } + return 0; +} + +extern "C" ivl_expr_t ivl_expr_oper1(ivl_expr_t net) +{ + assert(net); + switch (net->type_) { + case IVL_EX_BINARY: + return net->u_.binary_.lef_; + + default: + assert(0); + } + + return 0; +} + +extern "C" ivl_expr_t ivl_expr_oper2(ivl_expr_t net) +{ + assert(net); + switch (net->type_) { + case IVL_EX_BINARY: + return net->u_.binary_.rig_; + + default: + assert(0); + } + + return 0; +} + extern "C" int ivl_expr_signed(ivl_expr_t net) { assert(net); @@ -197,6 +238,12 @@ extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net, return net->u_.block_.stmt_ + i; } +extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net) +{ + assert(net && (net->type_ == IVL_ST_CONDIT)); + return net->u_.condit_.cond_; +} + extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net) { assert(net->type_ == IVL_ST_CONDIT); @@ -275,6 +322,10 @@ extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net) /* * $Log: t-dll-api.cc,v $ + * Revision 1.8 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.7 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. * diff --git a/t-dll-expr.cc b/t-dll-expr.cc index 9f651cc51..8f65d2f64 100644 --- a/t-dll-expr.cc +++ b/t-dll-expr.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) & !defined(macintosh) -#ident "$Id: t-dll-expr.cc,v 1.3 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: t-dll-expr.cc,v 1.4 2000/09/30 02:18:15 steve Exp $" #endif # include "t-dll.h" @@ -25,6 +25,36 @@ # include # include +/* + * These methods implement the expression scan that generates the + * ivl_expr_t representing the expression. Each method leaves the + * expr_ member filled with the ivl_expr_t that represents it. Each + * method expects that the expr_ member empty (0) when it starts. + */ + + +void dll_target::expr_binary(const NetEBinary*net) +{ + assert(expr_ == 0); + + net->left()->expr_scan(this); + ivl_expr_t left = expr_; + + expr_ = 0; + net->right()->expr_scan(this); + ivl_expr_t rght = expr_; + + expr_ = (ivl_expr_t)calloc(1, sizeof(struct ivl_expr_s)); + assert(expr_); + + expr_->type_ = IVL_EX_BINARY; + expr_->width_= net->expr_width(); + + expr_->u_.binary_.op_ = net->op(); + expr_->u_.binary_.lef_ = left; + expr_->u_.binary_.rig_ = rght; +} + void dll_target::expr_const(const NetEConst*net) { assert(expr_ == 0); @@ -80,6 +110,10 @@ void dll_target::expr_signal(const NetESignal*net) /* * $Log: t-dll-expr.cc,v $ + * Revision 1.4 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.3 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. * diff --git a/t-dll-proc.cc b/t-dll-proc.cc index 8152edb7b..4d24c44d4 100644 --- a/t-dll-proc.cc +++ b/t-dll-proc.cc @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-dll-proc.cc,v 1.5 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: t-dll-proc.cc,v 1.6 2000/09/30 02:18:15 steve Exp $" #endif # include "target.h" @@ -148,6 +148,11 @@ void dll_target::proc_condit(const NetCondit*net) stmt_cur_->u_.condit_.stmt_ = (struct ivl_statement_s*) calloc(2, sizeof(struct ivl_statement_s)); + assert(expr_ == 0); + net->expr()->expr_scan(this); + stmt_cur_->u_.condit_.cond_ = expr_; + expr_ = 0; + ivl_statement_t save_cur_ = stmt_cur_; stmt_cur_ = save_cur_->u_.condit_.stmt_+0; @@ -263,6 +268,10 @@ void dll_target::proc_while(const NetWhile*net) /* * $Log: t-dll-proc.cc,v $ + * Revision 1.6 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.5 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. * diff --git a/t-dll.cc b/t-dll.cc index a230a9e1a..b2553467b 100644 --- a/t-dll.cc +++ b/t-dll.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-dll.cc,v 1.8 2000/09/24 15:46:00 steve Exp $" +#ident "$Id: t-dll.cc,v 1.9 2000/09/30 02:18:15 steve Exp $" #endif # include "compiler.h" @@ -37,7 +37,10 @@ bool dll_target::start_design(const Design*des) stmt_cur_ = 0; - des_ = (ivl_design_t)des; + // Initialize the design object. + des_.self = des; + des_.root_ = (ivl_scope_t)calloc(1, sizeof(struct ivl_scope_s)); + des_.root_->self = des->find_root_scope(); start_design_ = (start_design_f)dlsym(dll_, "target_start_design"); end_design_ = (end_design_f) dlsym(dll_, "target_end_design"); @@ -51,13 +54,13 @@ bool dll_target::start_design(const Design*des) process_ = (process_f) dlsym(dll_, LU "target_process" TU); scope_ = (scope_f) dlsym(dll_, LU "target_scope" TU); - (start_design_)(des_); + (start_design_)(&des_); return true; } void dll_target::end_design(const Design*) { - (end_design_)(des_); + (end_design_)(&des_); dlclose(dll_); } @@ -139,10 +142,46 @@ void dll_target::net_probe(const NetEvProbe*net) return; } +static ivl_scope_t find_scope(ivl_scope_t root, const NetScope*cur) +{ + ivl_scope_t parent, tmp; + + if (const NetScope*par = cur->parent()) { + parent = find_scope(root, par); + + } else { + assert(root->self == cur); + return root; + } + + for (tmp = parent->child_ ; tmp ; tmp = tmp->sibling_) + if (tmp->self == cur) + return tmp; + + return 0; +} + void dll_target::scope(const NetScope*net) { + ivl_scope_t scope; + + if (net->parent() == 0) { + assert(des_.root_->self == net); + scope = des_.root_; + + } else { + scope = (ivl_scope_t)calloc(1, sizeof(struct ivl_scope_s)); + scope->self = net; + + ivl_scope_t parent = find_scope(des_.root_, net->parent()); + assert(parent != 0); + + scope->sibling_= parent->child_; + parent->child_ = scope; + } + if (scope_) - (scope_)( (ivl_scope_t)net ); + (scope_)(scope); } void dll_target::signal(const NetNet*net) @@ -163,6 +202,10 @@ extern const struct target tgt_dll = { "dll", &dll_target_obj }; /* * $Log: t-dll.cc,v $ + * Revision 1.9 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.8 2000/09/24 15:46:00 steve * API access to signal type and port type. * diff --git a/t-dll.h b/t-dll.h index 0b6a42042..36119db98 100644 --- a/t-dll.h +++ b/t-dll.h @@ -19,12 +19,17 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-dll.h,v 1.6 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: t-dll.h,v 1.7 2000/09/30 02:18:15 steve Exp $" #endif # include "target.h" # include "ivl_target.h" +struct ivl_design_s { + ivl_scope_t root_; + const Design*self; +}; + /* * The DLL target type loads a named object file to handle the process * of scanning the netlist. When it is time to start the design, I @@ -50,7 +55,7 @@ struct dll_target : public target_t, public expr_scan_t { void*dll_; string dll_path_; - ivl_design_t des_; + ivl_design_s des_; start_design_f start_design_; end_design_f end_design_; @@ -78,6 +83,7 @@ struct dll_target : public target_t, public expr_scan_t { void proc_while(const NetWhile*); struct ivl_expr_s*expr_; + void expr_binary(const NetEBinary*); void expr_const(const NetEConst*); void expr_signal(const NetESignal*); }; @@ -99,6 +105,12 @@ struct ivl_expr_s { unsigned signed_ : 1; union { + struct { + char op_; + ivl_expr_t lef_; + ivl_expr_t rig_; + } binary_; + struct { char*bits_; } number_; @@ -128,6 +140,12 @@ struct ivl_process_s { ivl_statement_t stmt_; }; +struct ivl_scope_s { + ivl_scope_t child_, sibling_; + + const NetScope*self; +}; + /* * The ivl_statement_t represents any statement. The type of statement * is defined by the ivl_statement_type_t enumeration. Given the type, @@ -142,6 +160,9 @@ struct ivl_statement_s { } block_; struct { /* IVL_ST_CONDIT */ + /* This is the condition expression */ + ivl_expr_t cond_; + /* This is two statements, the true and false. */ struct ivl_statement_s*stmt_; } condit_; @@ -179,6 +200,10 @@ struct ivl_statement_s { /* * $Log: t-dll.h,v $ + * Revision 1.7 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.6 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. * diff --git a/tgt-verilog/verilog.c b/tgt-verilog/verilog.c index 4a8e5348b..6345578db 100644 --- a/tgt-verilog/verilog.c +++ b/tgt-verilog/verilog.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: verilog.c,v 1.4 2000/09/26 00:30:07 steve Exp $" +#ident "$Id: verilog.c,v 1.5 2000/09/30 02:18:15 steve Exp $" #endif /* @@ -109,7 +109,19 @@ int target_net_probe(const char*name, ivl_net_probe_t net) int target_net_signal(const char*name, ivl_signal_t net) { - fprintf(out, "STUB: %s: signal [%u]\n", name, ivl_signal_pins(net)); + unsigned cnt = ivl_signal_pins(net); + + switch (ivl_signal_type(net)) { + + case IVL_SIT_WIRE: + fprintf(out, " wire [%u:0] %s;\n", cnt-1, name); + break; + + default: + fprintf(out, " [%u:0] %s;\n", cnt-1, name); + break; + } + return 0; } @@ -120,6 +132,13 @@ static void show_expression(ivl_expr_t net) switch (ivl_expr_type(net)) { + case IVL_EX_BINARY: { + show_expression(ivl_expr_oper1(net)); + fprintf(out, "%c", ivl_expr_opcode(net)); + show_expression(ivl_expr_oper2(net)); + break; + } + case IVL_EX_NUMBER: { int sigflag = ivl_expr_signed(net); unsigned idx, width = ivl_expr_width(net); @@ -169,7 +188,10 @@ static void show_statement(ivl_statement_t net, unsigned ind) ivl_statement_t t = ivl_stmt_cond_true(net); ivl_statement_t f = ivl_stmt_cond_false(net); - fprintf(out, "%*sif (...)\n", ind, ""); + fprintf(out, "%*sif (", ind, ""); + show_expression(ivl_stmt_cond_expr(net)); + fprintf(out, ")\n"); + if (t) show_statement(t, ind+4); else @@ -241,6 +263,10 @@ int target_process(ivl_process_t net) /* * $Log: verilog.c,v $ + * Revision 1.5 2000/09/30 02:18:15 steve + * ivl_expr_t support for binary operators, + * Create a proper ivl_scope_t object. + * * Revision 1.4 2000/09/26 00:30:07 steve * Add EX_NUMBER and ST_TRIGGER to dll-api. *