From d6efae4bddc9479bf55c74ddaf7a03a73bdbc14d Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 28 Oct 2000 22:32:34 +0000 Subject: [PATCH] API for concatenation expressions. --- ivl.def | 3 +++ ivl_target.h | 31 +++++++++++++++++++++++++++++-- t-dll-api.cc | 38 +++++++++++++++++++++++++++++++++++++- t-dll-expr.cc | 26 +++++++++++++++++++++----- t-dll.h | 11 ++++++++++- t-dll.txt | 26 ++++++++++++++++++++++++++ tgt-stub/stub.c | 13 ++++++++++--- 7 files changed, 136 insertions(+), 12 deletions(-) diff --git a/ivl.def b/ivl.def index f8f549fc3..ab9684c33 100644 --- a/ivl.def +++ b/ivl.def @@ -16,6 +16,9 @@ ivl_expr_opcode ivl_expr_oper1 ivl_expr_oper2 ivl_expr_oper3 +ivl_expr_parm +ivl_expr_parms +ivl_expr_repeat ivl_expr_signed ivl_expr_string ivl_expr_width diff --git a/ivl_target.h b/ivl_target.h index 5f2f4c2fc..fab645640 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.24 2000/10/28 17:55:03 steve Exp $" +#ident "$Id: ivl_target.h,v 1.25 2000/10/28 22:32:34 steve Exp $" #endif #ifdef __cplusplus @@ -258,12 +258,30 @@ extern ivl_nexus_t ivl_const_pin(ivl_net_const_t net, unsigned idx); extern unsigned ivl_const_pins(ivl_net_const_t net); extern int ivl_const_signed(ivl_net_const_t net); -/* EXPRESSION +/* EXPRESSIONS + * * These methods operate on expression objects from the * design. Expressions mainly exist in behavioral code. The * ivl_expr_type() function returns the type of the expression node, * and the remaining functions access value bits of the expression. + * + * ivl_expr_signed + * This method returns true (!= 0) if the expression node + * represents a signed expression. It is possible for sub- + * expressions to be unsigned even if a node is signed, but the + * IVL core figures all this out for you. At any rate, this method + * can be applied to any expression node. + * + * ivl_expr_type + * Get the type of the expression node. Every expression node has a + * type, which can affect how some of the other expression methods + * operate on the node + * + * ivl_expr_width + * This method returns the bit width of the expression at this + * node. It can be applied to any expression node. */ + extern ivl_expr_type_t ivl_expr_type(ivl_expr_t net); /* IVL_EX_NUMBER */ @@ -278,6 +296,12 @@ 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); + /* IVL_EX_CONCAT */ +extern ivl_expr_t ivl_expr_parm(ivl_expr_t net, unsigned idx); + /* IVL_EX_CONCAT */ +extern unsigned ivl_expr_parms(ivl_expr_t net); + /* IVL_EX_CONCAT */ +extern unsigned ivl_expr_repeat(ivl_expr_t net); /* any expression */ extern int ivl_expr_signed(ivl_expr_t net); /* IVL_EX_STRING */ @@ -524,6 +548,9 @@ _END_DECL /* * $Log: ivl_target.h,v $ + * Revision 1.25 2000/10/28 22:32:34 steve + * API for concatenation expressions. + * * Revision 1.24 2000/10/28 17:55:03 steve * stub for the concat operator. * diff --git a/t-dll-api.cc b/t-dll-api.cc index 7e95dab82..d3854a94f 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.15 2000/10/25 05:41:24 steve Exp $" +#ident "$Id: t-dll-api.cc,v 1.16 2000/10/28 22:32:34 steve Exp $" #endif # include "t-dll.h" @@ -152,6 +152,39 @@ extern "C" ivl_expr_t ivl_expr_oper3(ivl_expr_t net) return 0; } +extern "C" ivl_expr_t ivl_expr_parm(ivl_expr_t net, unsigned idx) +{ + assert(net); + switch (net->type_) { + case IVL_EX_CONCAT: + assert(idx < net->u_.concat_.parms); + return net->u_.concat_.parm[idx]; + default: + assert(0); + return 0; + } +} + +extern "C" unsigned ivl_expr_parms(ivl_expr_t net) +{ + assert(net); + switch (net->type_) { + case IVL_EX_CONCAT: + return net->u_.concat_.parms; + + default: + assert(0); + return 0; + } +} + +extern "C" unsigned ivl_expr_repeat(ivl_expr_t net) +{ + assert(net); + assert(net->type_ == IVL_EX_CONCAT); + return net->u_.concat_.rept; +} + extern "C" int ivl_expr_signed(ivl_expr_t net) { assert(net); @@ -503,6 +536,9 @@ extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net) /* * $Log: t-dll-api.cc,v $ + * Revision 1.16 2000/10/28 22:32:34 steve + * API for concatenation expressions. + * * Revision 1.15 2000/10/25 05:41:24 steve * Get target signal from nexus_ptr. * diff --git a/t-dll-expr.cc b/t-dll-expr.cc index 92d2f8a4c..ce22e433f 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.6 2000/10/28 17:55:03 steve Exp $" +#ident "$Id: t-dll-expr.cc,v 1.7 2000/10/28 22:32:34 steve Exp $" #endif # include "t-dll.h" @@ -59,11 +59,24 @@ void dll_target::expr_concat(const NetEConcat*net) { assert(expr_ == 0); - expr_ = new struct ivl_expr_s; - assert(expr_); + ivl_expr_t cur = new struct ivl_expr_s; + assert(cur); - expr_->type_ = IVL_EX_CONCAT; - expr_->width_= net->expr_width(); + cur->type_ = IVL_EX_CONCAT; + cur->width_= net->expr_width(); + + cur->u_.concat_.rept = net->repeat(); + cur->u_.concat_.parms = net->nparms(); + cur->u_.concat_.parm = new ivl_expr_t [net->nparms()]; + + for (unsigned idx = 0 ; idx < net->nparms() ; idx += 1) { + expr_ = 0; + net->parm(idx)->expr_scan(this); + assert(expr_); + cur->u_.concat_.parm[idx] = expr_; + } + + expr_ = cur; } void dll_target::expr_const(const NetEConst*net) @@ -133,6 +146,9 @@ void dll_target::expr_signal(const NetESignal*net) /* * $Log: t-dll-expr.cc,v $ + * Revision 1.7 2000/10/28 22:32:34 steve + * API for concatenation expressions. + * * Revision 1.6 2000/10/28 17:55:03 steve * stub for the concat operator. * diff --git a/t-dll.h b/t-dll.h index b00bd1d98..e685e8b62 100644 --- a/t-dll.h +++ b/t-dll.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: t-dll.h,v 1.16 2000/10/28 17:55:03 steve Exp $" +#ident "$Id: t-dll.h,v 1.17 2000/10/28 22:32:34 steve Exp $" #endif # include "target.h" @@ -108,6 +108,12 @@ struct ivl_expr_s { ivl_expr_t rig_; } binary_; + struct { + unsigned rept :16; + unsigned parms :16; + ivl_expr_t*parm; + } concat_; + struct { char*bits_; } number_; @@ -311,6 +317,9 @@ struct ivl_statement_s { /* * $Log: t-dll.h,v $ + * Revision 1.17 2000/10/28 22:32:34 steve + * API for concatenation expressions. + * * Revision 1.16 2000/10/28 17:55:03 steve * stub for the concat operator. * diff --git a/t-dll.txt b/t-dll.txt index 76a0b04d4..c7e4e52b1 100644 --- a/t-dll.txt +++ b/t-dll.txt @@ -28,3 +28,29 @@ The target module API is defined in the ivl_target.h header file. This declares all the type and functions that a loadable module needs to access the design. + +ABOUT SPECIFIC EXPRESSION TYPES + +In this section find notes about the various kinds of expression +nodes. The notes here are in addition to the more generation +documentation in the ivl_target.h header file. + +* IVL_EX_CONCAT + + The concatenation operator forms an expression node that holds the + repeat count and all the parameter expressions. The repeat count is + an integer that is calculated by the core compiler so it fully + evaluated, and *not* an expression. + + The parameter expressions are retrieved by the ivl_expr_parm method, + with the index increasing as parameters go from left to right, from + most significant to least significant. (Note that this is different + from the order of bits within an expression node.) + +* IVL_EX_NUMBER + + This is a constant number. The width is fully know, and the bit + values are all represented by the ascii characters 0, 1, x or z. The + ivl_expr_bits method returns a pointer to the least significant bit, + and the remaining bits are ordered from least significant to most + significant. For example, 5'b1zzx0 is the 5 character string "0xzz1". diff --git a/tgt-stub/stub.c b/tgt-stub/stub.c index 4b843a485..0166fffdc 100644 --- a/tgt-stub/stub.c +++ b/tgt-stub/stub.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: stub.c,v 1.22 2000/10/28 17:55:03 steve Exp $" +#ident "$Id: stub.c,v 1.23 2000/10/28 22:32:34 steve Exp $" #endif /* @@ -34,6 +34,7 @@ static FILE*out; static void show_expression(ivl_expr_t net, unsigned ind) { + unsigned idx; const ivl_expr_type_t code = ivl_expr_type(net); unsigned width = ivl_expr_width(net); const char*sign = ivl_expr_signed(net)? "signed" : "unsigned"; @@ -48,12 +49,15 @@ static void show_expression(ivl_expr_t net, unsigned ind) break; case IVL_EX_CONCAT: - fprintf(out, "%*s\n", ind, "", width, sign); + fprintf(out, "%*s\n", ind, "", + ivl_expr_repeat(net), width, sign); + for (idx = 0 ; idx < ivl_expr_parms(net) ; idx += 1) + show_expression(ivl_expr_parm(net, idx), ind+3); + break; case IVL_EX_NUMBER: { const char*bits = ivl_expr_bits(net); - unsigned idx; fprintf(out, "%*s 0 ; idx -= 1) @@ -336,6 +340,9 @@ DECLARE_CYGWIN_DLL(DllMain); /* * $Log: stub.c,v $ + * Revision 1.23 2000/10/28 22:32:34 steve + * API for concatenation expressions. + * * Revision 1.22 2000/10/28 17:55:03 steve * stub for the concat operator. *