Skip to content

Commit

Permalink
Bring analog contribution statements to the ivl_target API.
Browse files Browse the repository at this point in the history
Add support for analog processes with analog contributation statements
all the way down to the ivl_target code generator API.
  • Loading branch information
steveicarus committed Nov 7, 2008
1 parent 0d88d3a commit 13aaaab
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -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 \
Expand Down
9 changes: 6 additions & 3 deletions emit.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ivl.def
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 21 additions & 6 deletions ivl_target.h
Expand Up @@ -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,
Expand Down Expand Up @@ -1718,12 +1719,16 @@ 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.
* *
* A process is placed in a scope. The statement within the process * ivl_process_scope
* operates within the scope of the process unless there are calls * A process is placed in a scope. The statement within the process
* outside the scope. * operates within the scope of the process unless there are calls
* outside the scope.
* *
* The ivl_process_stmt function gets the statement that forms the * The ivl_process_stmt function gets the statement that forms the
* process. See the statement related functions for how to manipulate * process. See the statement related functions for how to manipulate
Expand All @@ -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);


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions net_analog.cc
Expand Up @@ -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_;
}
22 changes: 21 additions & 1 deletion netlist.cc
Expand Up @@ -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)
{ {
Expand All @@ -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_;
} }
Expand Down
4 changes: 4 additions & 0 deletions netlist.h
Expand Up @@ -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:
Expand Down
87 changes: 87 additions & 0 deletions t-dll-analog.cc
@@ -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;
}
18 changes: 18 additions & 0 deletions t-dll-api.cc
Expand Up @@ -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_;
Expand Down Expand Up @@ -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_) {
Expand Down Expand Up @@ -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);
} }
Expand Down
1 change: 1 addition & 0 deletions t-dll-proc.cc
Expand Up @@ -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);


Expand Down
10 changes: 9 additions & 1 deletion t-dll.h
Expand Up @@ -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*);
Expand All @@ -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*);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_;
Expand Down
19 changes: 18 additions & 1 deletion target.cc
Expand Up @@ -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*)
Expand Down Expand Up @@ -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: "
Expand Down

0 comments on commit 13aaaab

Please sign in to comment.