Bring analog contribution statements to the ivl_target API.

Add support for analog processes with analog contributation statements
all the way down to the ivl_target code generator API.
This commit is contained in:
Stephen Williams 2008-11-06 21:31:34 -08:00
parent 0d88d3a798
commit 13aaaab783
15 changed files with 214 additions and 15 deletions

View File

@ -113,7 +113,7 @@ distclean: clean
rm -f Makefile config.status config.log config.cache config.h rm -f Makefile config.status config.log config.cache config.h
rm -f _pli_types.h rm -f _pli_types.h
TT = t-dll.o t-dll-api.o t-dll-expr.o t-dll-proc.o TT = t-dll.o t-dll-api.o t-dll-expr.o t-dll-proc.o t-dll-analog.o
FF = cprop.o nodangle.o synth.o synth2.o syn-rules.o FF = cprop.o nodangle.o synth.o synth2.o syn-rules.o
O = main.o async.o design_dump.o discipline.o dup_expr.o \ O = main.o async.o design_dump.o discipline.o dup_expr.o \

View File

@ -192,9 +192,7 @@ bool NetProcTop::emit(struct target_t*tgt) const
bool NetAnalogTop::emit(struct target_t*tgt) const bool NetAnalogTop::emit(struct target_t*tgt) const
{ {
cerr << get_fileline() << ": sorry: " return tgt->process(this);
<< "I don't know how to emit for analog processes." << endl;
return false;
} }
bool NetProc::emit_proc(struct target_t*tgt) const bool NetProc::emit_proc(struct target_t*tgt) const
@ -241,6 +239,11 @@ bool NetCondit::emit_proc(struct target_t*tgt) const
return tgt->proc_condit(this); return tgt->proc_condit(this);
} }
bool NetContribution::emit_proc(struct target_t*tgt) const
{
return tgt->proc_contribution(this);
}
bool NetDeassign::emit_proc(struct target_t*tgt) const bool NetDeassign::emit_proc(struct target_t*tgt) const
{ {
return tgt->proc_deassign(this); return tgt->proc_deassign(this);

View File

@ -196,6 +196,7 @@ ivl_signal_width
ivl_path_delay ivl_path_delay
ivl_path_source ivl_path_source
ivl_process_analog
ivl_process_attr_cnt ivl_process_attr_cnt
ivl_process_attr_val ivl_process_attr_val
ivl_process_file ivl_process_file
@ -221,6 +222,7 @@ ivl_stmt_delay_val
ivl_stmt_events ivl_stmt_events
ivl_stmt_file ivl_stmt_file
ivl_stmt_lineno ivl_stmt_lineno
ivl_stmt_lexp
ivl_stmt_lval ivl_stmt_lval
ivl_stmt_lvals ivl_stmt_lvals
ivl_stmt_lwidth ivl_stmt_lwidth

View File

@ -361,6 +361,7 @@ typedef enum ivl_statement_type_e {
IVL_ST_CASEZ = 7, IVL_ST_CASEZ = 7,
IVL_ST_CASSIGN = 8, IVL_ST_CASSIGN = 8,
IVL_ST_CONDIT = 9, IVL_ST_CONDIT = 9,
IVL_ST_CONTRIB = 27,
IVL_ST_DEASSIGN = 10, IVL_ST_DEASSIGN = 10,
IVL_ST_DELAY = 11, IVL_ST_DELAY = 11,
IVL_ST_DELAYX = 12, IVL_ST_DELAYX = 12,
@ -1718,9 +1719,13 @@ extern ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx);
* is translated into a type and a single statement. (The statement * is translated into a type and a single statement. (The statement
* may be a compound statement.) * may be a compound statement.)
* *
* The ivl_process_type function gets the type of the process, * ivl_process_type
* an "initial" or "always" statement. * ivl_process_analog
* The ivl_process_type function returns the type of the process,
* an "initial" or "always" statement. The ivl_process_analog
* returns true if the process is analog.
* *
* ivl_process_scope
* A process is placed in a scope. The statement within the process * A process is placed in a scope. The statement within the process
* operates within the scope of the process unless there are calls * operates within the scope of the process unless there are calls
* outside the scope. * outside the scope.
@ -1733,6 +1738,7 @@ extern ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx);
* attr_val methods return those attributes. * attr_val methods return those attributes.
*/ */
extern ivl_process_type_t ivl_process_type(ivl_process_t net); extern ivl_process_type_t ivl_process_type(ivl_process_t net);
extern int ivl_process_analog(ivl_process_t net);
extern ivl_scope_t ivl_process_scope(ivl_process_t net); extern ivl_scope_t ivl_process_scope(ivl_process_t net);
@ -1828,6 +1834,12 @@ extern unsigned ivl_stmt_lineno(ivl_statement_t net);
* that constant value. If the expression is non-constant, the code * that constant value. If the expression is non-constant, the code
* generator is supposed to know what to do about that, too. * generator is supposed to know what to do about that, too.
* *
* - IVL_ST_CONTRIB
* This is an analog contribution statement. The ivl_stmt_lexp
* function returns the l-value expression which is guaranteed to be a
* branch access expression. The ivl_stmt_rval returns the r-value
* expression for the assignment.
*
* - IVL_ST_DELAY, IVL_ST_DELAYX * - IVL_ST_DELAY, IVL_ST_DELAYX
* These statement types are delay statements. They are a way to * These statement types are delay statements. They are a way to
* attach a delay to a statement. The ivl_stmt_sub_stmt() function * attach a delay to a statement. The ivl_stmt_sub_stmt() function
@ -1893,6 +1905,8 @@ extern uint64_t ivl_stmt_delay_val(ivl_statement_t net);
/* IVL_ST_WAIT IVL_ST_TRIGGER */ /* IVL_ST_WAIT IVL_ST_TRIGGER */
extern unsigned ivl_stmt_nevent(ivl_statement_t net); extern unsigned ivl_stmt_nevent(ivl_statement_t net);
extern ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx); extern ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx);
/* IVL_ST_CONTRIB */
extern ivl_expr_t ivl_stmt_lexp(ivl_statement_t net);
/* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_DEASSIGN
IVL_ST_FORCE IVL_ST_RELEASE */ IVL_ST_FORCE IVL_ST_RELEASE */
extern ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx); extern ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx);
@ -1907,7 +1921,8 @@ extern const char* ivl_stmt_name(ivl_statement_t net);
extern ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx); extern ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx);
/* IVL_ST_STASK */ /* IVL_ST_STASK */
extern unsigned ivl_stmt_parm_count(ivl_statement_t net); extern unsigned ivl_stmt_parm_count(ivl_statement_t net);
/* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_FORCE */ /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN IVL_ST_CONTRIB
IVL_ST_FORCE */
extern ivl_expr_t ivl_stmt_rval(ivl_statement_t net); extern ivl_expr_t ivl_stmt_rval(ivl_statement_t net);
/* IVL_ST_DELAY, IVL_ST_DELAYX, IVL_ST_FOREVER, IVL_ST_REPEAT /* IVL_ST_DELAY, IVL_ST_DELAYX, IVL_ST_FOREVER, IVL_ST_REPEAT
IVL_ST_WAIT, IVL_ST_WHILE */ IVL_ST_WAIT, IVL_ST_WHILE */

View File

@ -35,3 +35,13 @@ NetContribution::NetContribution(NetEAccess*l, NetExpr*r)
NetContribution::~NetContribution() NetContribution::~NetContribution()
{ {
} }
const NetEAccess* NetContribution::lval() const
{
return lval_;
}
const NetExpr* NetContribution::rval() const
{
return rval_;
}

View File

@ -874,6 +874,11 @@ NetScope* NetProcTop::scope()
return scope_; return scope_;
} }
const NetScope* NetProcTop::scope() const
{
return scope_;
}
NetAnalogTop::NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetProc*st) NetAnalogTop::NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetProc*st)
: type_(t), statement_(st), scope_(scope) : type_(t), statement_(st), scope_(scope)
{ {
@ -884,7 +889,22 @@ NetAnalogTop::~NetAnalogTop()
{ {
} }
const NetScope* NetProcTop::scope() const NetProc* NetAnalogTop::statement()
{
return statement_;
}
const NetProc* NetAnalogTop::statement() const
{
return statement_;
}
NetScope* NetAnalogTop::scope()
{
return scope_;
}
const NetScope* NetAnalogTop::scope() const
{ {
return scope_; return scope_;
} }

View File

@ -2439,6 +2439,10 @@ class NetContribution : public NetProc {
explicit NetContribution(NetEAccess*lval, NetExpr*rval); explicit NetContribution(NetEAccess*lval, NetExpr*rval);
~NetContribution(); ~NetContribution();
const NetEAccess* lval() const;
const NetExpr* rval() const;
virtual bool emit_proc(struct target_t*) const;
virtual void dump(ostream&, unsigned ind) const; virtual void dump(ostream&, unsigned ind) const;
private: private:

87
t-dll-analog.cc Normal file
View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2008 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.will need a Picture Elements Binary Software
* License.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
# include "config.h"
# include <iostream>
# include <cstring>
# include "target.h"
# include "ivl_target.h"
# include "compiler.h"
# include "t-dll.h"
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
# include <stdlib.h>
bool dll_target::process(const NetAnalogTop*net)
{
bool rc_flag = true;
ivl_process_t obj = (struct ivl_process_s*)
calloc(1, sizeof(struct ivl_process_s));
obj->type_ = net->type();
obj->analog_flag = 1;
FILE_NAME(obj, net);
/* Save the scope of the process. */
obj->scope_ = lookup_scope_(net->scope());
obj->nattr = net->attr_cnt();
obj->attr = fill_in_attributes(net);
assert(stmt_cur_ == 0);
stmt_cur_ = (struct ivl_statement_s*)calloc(1, sizeof*stmt_cur_);
assert(stmt_cur_);
rc_flag = net->statement()->emit_proc(this) && rc_flag;
assert(stmt_cur_);
obj->stmt_ = stmt_cur_;
stmt_cur_ = 0;
/* Save the process in the design. */
obj->next_ = des_.threads_;
des_.threads_ = obj;
return rc_flag;
}
bool dll_target::proc_contribution(const NetContribution*net)
{
assert(stmt_cur_);
assert(stmt_cur_->type_ == IVL_ST_NONE);
FILE_NAME(stmt_cur_, net);
stmt_cur_->type_ = IVL_ST_CONTRIB;
assert(expr_ == 0);
net->lval()->expr_scan(this);
stmt_cur_->u_.contrib_.lval = expr_;
expr_ = 0;
net->rval()->expr_scan(this);
stmt_cur_->u_.contrib_.rval = expr_;
expr_ = 0;
return true;
}

View File

@ -1478,6 +1478,11 @@ extern "C" ivl_process_type_t ivl_process_type(ivl_process_t net)
return net->type_; return net->type_;
} }
extern "C" int ivl_process_analog(ivl_process_t net)
{
return net->analog_flag != 0;
}
extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net) extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net)
{ {
return net->scope_; return net->scope_;
@ -2112,6 +2117,17 @@ extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx)
return 0; return 0;
} }
extern "C" ivl_expr_t ivl_stmt_lexp(ivl_statement_t net)
{
switch (net->type_) {
case IVL_ST_CONTRIB:
return net->u_.contrib_.lval;
default:
assert(0);
}
return 0;
}
extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx) extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx)
{ {
switch (net->type_) { switch (net->type_) {
@ -2225,6 +2241,8 @@ extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net)
case IVL_ST_CASSIGN: case IVL_ST_CASSIGN:
case IVL_ST_FORCE: case IVL_ST_FORCE:
return net->u_.assign_.rval_; return net->u_.assign_.rval_;
case IVL_ST_CONTRIB:
return net->u_.contrib_.rval;
default: default:
assert(0); assert(0);
} }

View File

@ -40,6 +40,7 @@ bool dll_target::process(const NetProcTop*net)
calloc(1, sizeof(struct ivl_process_s)); calloc(1, sizeof(struct ivl_process_s));
obj->type_ = net->type(); obj->type_ = net->type();
obj->analog_flag = 0;
FILE_NAME(obj, net); FILE_NAME(obj, net);

10
t-dll.h
View File

@ -102,6 +102,7 @@ struct dll_target : public target_t, public expr_scan_t {
bool sign_extend(const NetSignExtend*); bool sign_extend(const NetSignExtend*);
bool process(const NetProcTop*); bool process(const NetProcTop*);
bool process(const NetAnalogTop*);
void scope(const NetScope*); void scope(const NetScope*);
void signal(const NetNet*); void signal(const NetNet*);
bool signal_paths(const NetNet*); bool signal_paths(const NetNet*);
@ -122,6 +123,7 @@ struct dll_target : public target_t, public expr_scan_t {
void proc_case(const NetCase*); void proc_case(const NetCase*);
bool proc_cassign(const NetCAssign*); bool proc_cassign(const NetCAssign*);
bool proc_condit(const NetCondit*); bool proc_condit(const NetCondit*);
bool proc_contribution(const NetContribution*);
bool proc_deassign(const NetDeassign*); bool proc_deassign(const NetDeassign*);
bool proc_delay(const NetPDelay*); bool proc_delay(const NetPDelay*);
bool proc_disable(const NetDisable*); bool proc_disable(const NetDisable*);
@ -553,7 +555,8 @@ struct ivl_parameter_s {
* that generally only matters for VPI calls. * that generally only matters for VPI calls.
*/ */
struct ivl_process_s { struct ivl_process_s {
ivl_process_type_t type_; ivl_process_type_t type_ : 2;
int analog_flag : 1;
ivl_scope_t scope_; ivl_scope_t scope_;
ivl_statement_t stmt_; ivl_statement_t stmt_;
perm_string file; perm_string file;
@ -707,6 +710,11 @@ struct ivl_statement_s {
struct ivl_statement_s*stmt_; struct ivl_statement_s*stmt_;
} condit_; } condit_;
struct { /* IVL_ST_CONTRIB */
ivl_expr_t lval;
ivl_expr_t rval;
} contrib_;
struct { /* IVL_ST_DELAY */ struct { /* IVL_ST_DELAY */
uint64_t delay_; uint64_t delay_;
ivl_statement_t stmt_; ivl_statement_t stmt_;

View File

@ -240,7 +240,16 @@ bool target_t::sign_extend(const NetSignExtend*net)
bool target_t::process(const NetProcTop*top) bool target_t::process(const NetProcTop*top)
{ {
return top->statement()->emit_proc(this); cerr << "target (" << typeid(*this).name() << "): "
"Unhandled process(NetProcTop)." << endl;
return false;
}
bool target_t::process(const NetAnalogTop*top)
{
cerr << "target (" << typeid(*this).name() << "): "
"Unhandled process(NetAnalogTop)." << endl;
return false;
} }
void target_t::proc_alloc(const NetAlloc*) void target_t::proc_alloc(const NetAlloc*)
@ -292,6 +301,14 @@ bool target_t::proc_condit(const NetCondit*condit)
return false; return false;
} }
bool target_t::proc_contribution(const NetContribution*net)
{
cerr << "target (" << typeid(*this).name() << "): "
"Unhandled contribution:" << endl;
net->dump(cerr, 6);
return false;
}
bool target_t::proc_deassign(const NetDeassign*dev) bool target_t::proc_deassign(const NetDeassign*dev)
{ {
cerr << dev->get_fileline() << ": internal error: " cerr << dev->get_fileline() << ": internal error: "

View File

@ -103,6 +103,7 @@ struct target_t {
/* Output a process (called for each process). It is up to the /* Output a process (called for each process). It is up to the
target to recurse if desired. */ target to recurse if desired. */
virtual bool process(const NetProcTop*); virtual bool process(const NetProcTop*);
virtual bool process(const NetAnalogTop*);
/* Various kinds of process nodes are dispatched through these. */ /* Various kinds of process nodes are dispatched through these. */
virtual void proc_alloc(const NetAlloc*); virtual void proc_alloc(const NetAlloc*);
@ -112,6 +113,7 @@ struct target_t {
virtual void proc_case(const NetCase*); virtual void proc_case(const NetCase*);
virtual bool proc_cassign(const NetCAssign*); virtual bool proc_cassign(const NetCAssign*);
virtual bool proc_condit(const NetCondit*); virtual bool proc_condit(const NetCondit*);
virtual bool proc_contribution(const NetContribution*);
virtual bool proc_deassign(const NetDeassign*); virtual bool proc_deassign(const NetDeassign*);
virtual bool proc_delay(const NetPDelay*); virtual bool proc_delay(const NetPDelay*);
virtual bool proc_disable(const NetDisable*); virtual bool proc_disable(const NetDisable*);

View File

@ -287,6 +287,12 @@ void show_statement(ivl_statement_t net, unsigned ind)
break; break;
} }
case IVL_ST_CONTRIB:
fprintf(out, "%*sCONTRIBUTION ( <+ )\n", ind, "");
show_expression(ivl_stmt_lexp(net), ind+4);
show_expression(ivl_stmt_rval(net), ind+4);
break;
case IVL_ST_DEASSIGN: case IVL_ST_DEASSIGN:
fprintf(out, "%*sDEASSIGN <lwidth=%u>\n", ind, "", fprintf(out, "%*sDEASSIGN <lwidth=%u>\n", ind, "",
ivl_stmt_lwidth(net)); ivl_stmt_lwidth(net));

View File

@ -999,9 +999,15 @@ static int show_process(ivl_process_t net, void*x)
switch (ivl_process_type(net)) { switch (ivl_process_type(net)) {
case IVL_PR_INITIAL: case IVL_PR_INITIAL:
if (ivl_process_analog(net))
fprintf(out, "analog initial\n");
else
fprintf(out, "initial\n"); fprintf(out, "initial\n");
break; break;
case IVL_PR_ALWAYS: case IVL_PR_ALWAYS:
if (ivl_process_analog(net))
fprintf(out, "analog\n");
else
fprintf(out, "always\n"); fprintf(out, "always\n");
break; break;
} }