Basic elaboration of analog contribution statements.

Get at least basic elaboration of analog processes and contribution
statements. Bring the statements and analog statements together and
net future elaboration work sort out which statements are valid in
a given context. This makes sense because there really is a lot of
syntactic overlap, and analog behavioral code is processed somewhat
sequentially.
This commit is contained in:
Stephen Williams 2008-10-22 21:56:00 -07:00
parent 5aa810dde7
commit 68fbb94b3a
15 changed files with 120 additions and 71 deletions

View File

@ -21,10 +21,6 @@
# include "AStatement.h"
AStatement::~AStatement()
{
}
AContrib::AContrib(PExpr*lv, PExpr*rv)
: lval_(lv), rval_(rv)
{

View File

@ -23,6 +23,7 @@
# include "ivl_target.h"
# include "StringHeap.h"
# include "LineInfo.h"
# include "Statement.h"
# include "PExpr.h"
class PExpr;
@ -30,36 +31,19 @@ class NetAnalog;
class NetScope;
class Design;
class AStatement : public LineInfo {
public:
AStatement() { }
virtual ~AStatement() =0;
virtual void dump(ostream&out, unsigned ind) const;
virtual NetAnalog* elaborate(Design*des, NetScope*scope) const;
virtual void elaborate_scope(Design*des, NetScope*scope) const;
virtual void elaborate_sig(Design*des, NetScope*scope) const;
map<perm_string,PExpr*> attributes;
private: // not implemented
AStatement(const AStatement&);
AStatement& operator= (const AStatement&);
};
/*
* A contribution statement is like an assignment: there is an l-value
* expression and an r-value expression. The l-value is a branch probe
* expression.
*/
class AContrib : public AStatement {
class AContrib : public Statement {
public:
AContrib(PExpr*lval, PExpr*rval);
~AContrib();
virtual void dump(ostream&out, unsigned ind) const;
virtual NetProc* elaborate(Design*des, NetScope*scope) const;
private:
PExpr*lval_;
@ -74,7 +58,7 @@ class AContrib : public AStatement {
class AProcess : public LineInfo {
public:
AProcess(ivl_process_type_t t, AStatement*st)
AProcess(ivl_process_type_t t, Statement*st)
: type_(t), statement_(st) { }
~AProcess();
@ -82,7 +66,7 @@ class AProcess : public LineInfo {
bool elaborate(Design*des, NetScope*scope) const;
ivl_process_type_t type() const { return type_; }
AStatement*statement() { return statement_; }
Statement*statement() { return statement_; }
map<perm_string,PExpr*> attributes;
@ -91,7 +75,7 @@ class AProcess : public LineInfo {
private:
ivl_process_type_t type_;
AStatement*statement_;
Statement*statement_;
private: // not implemented
AProcess(const AProcess&);

View File

@ -121,7 +121,7 @@ elaborate.o elab_expr.o elaborate_analog.o \
elab_lval.o elab_net.o elab_pexpr.o elab_scope.o \
elab_sig.o elab_sig_analog.o emit.o eval.o eval_attrib.o \
eval_tree.o expr_synth.o functor.o lexor.o lexor_keyword.o link_const.o \
load_module.o netlist.o netmisc.o net_assign.o \
load_module.o netlist.o netmisc.o net_analog.o net_assign.o \
net_design.o net_event.o net_expr.o net_func.o \
net_link.o net_modulo.o net_nex_input.o net_nex_output.o \
net_proc.o net_scope.o net_tran.o net_udp.o pad_to_width.o \

View File

@ -720,6 +720,23 @@ void NetProcTop::dump(ostream&o, unsigned ind) const
statement_->dump(o, ind+2);
}
void NetAnalogTop::dump(ostream&o, unsigned ind) const
{
switch (type_) {
case IVL_PR_INITIAL:
o << "analog initial /* " << get_fileline() << " in "
<< scope_path(scope_) << " */" << endl;
break;
case IVL_PR_ALWAYS:
o << "analog /* " << get_fileline() << " in "
<< scope_path(scope_) << " */" << endl;
break;
}
statement_->dump(o, ind+2);
}
void NetAlloc::dump(ostream&o, unsigned ind) const
{
o << setw(ind) << "// allocate storage : " << scope_path(scope_) << endl;
@ -868,6 +885,15 @@ void NetCondit::dump(ostream&o, unsigned ind) const
}
}
void NetContribution::dump(ostream&o, unsigned ind) const
{
o << setw(ind) << "";
lval_->dump(o);
o << " <+ ";
rval_->dump(o);
o << ";" << endl;
}
void NetDeassign::dump(ostream&o, unsigned ind) const
{
o << setw(ind) << "" << "deassign ";
@ -1494,4 +1520,6 @@ void Design::dump(ostream&o) const
for (const NetProcTop*idx = procs_ ; idx ; idx = idx->next_)
idx->dump(o, 0);
for (const NetAnalogTop*idx = aprocs_ ; idx ; idx = idx->next_)
idx->dump(o, 0);
}

View File

@ -1243,12 +1243,3 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const
if (statement_)
statement_ -> elaborate_scope(des, scope);
}
/*
* The base statement does not have sub-statements and does not
* introduce any scope, so this is a no-op.
*/
void AStatement::elaborate_scope(Design*, NetScope*) const
{
}

View File

@ -24,7 +24,3 @@
# include <cstdlib>
# include <iostream>
void AStatement::elaborate_sig(Design*des, NetScope*scope) const
{
}

View File

@ -20,21 +20,25 @@
# include "config.h"
# include "AStatement.h"
# include "netlist.h"
# include "netmisc.h"
# include "util.h"
# include <typeinfo>
NetAnalog* AStatement::elaborate(Design*des, NetScope*scope) const
NetProc* AContrib::elaborate(Design*des, NetScope*scope) const
{
cerr << get_fileline() << ": sorry: I don't yet know how to elaborate"
<< " his kind of analog statement." << endl;
cerr << get_fileline() << ": : typeid = " << typeid(*this).name() << endl;
return 0;
NetExpr*lval = elab_and_eval(des, scope, lval_, -1);
NetExpr*rval = elab_and_eval(des, scope, rval_, -1);
NetContribution*st = new NetContribution(lval, rval);
st->set_line(*this);
return st;
}
bool AProcess::elaborate(Design*des, NetScope*scope) const
{
NetAnalog*statement = statement_->elaborate(des, scope);
NetProc*statement = statement_->elaborate(des, scope);
if (statement == 0)
return false;

View File

@ -190,6 +190,13 @@ bool NetProcTop::emit(struct target_t*tgt) const
return tgt->process(this);
}
bool NetAnalogTop::emit(struct target_t*tgt) const
{
cerr << get_fileline() << ": sorry: "
<< "I don't know how to emit for analog processes." << endl;
return false;
}
bool NetProc::emit_proc(struct target_t*tgt) const
{
cerr << "EMIT: Proc type? " << typeid(*this).name() << endl;
@ -459,6 +466,8 @@ int Design::emit(struct target_t*tgt) const
bool proc_rc = true;
for (const NetProcTop*idx = procs_ ; idx ; idx = idx->next_)
proc_rc &= idx->emit(tgt);
for (const NetAnalogTop*idx = aprocs_ ; idx ; idx = idx->next_)
proc_rc &= idx->emit(tgt);
rc = tgt->end_design(this);

37
net_analog.cc Normal file
View File

@ -0,0 +1,37 @@
/*
* 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.
*
* 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 <typeinfo>
# include <cstdlib>
# include <climits>
# include "compiler.h"
# include "netlist.h"
# include "netmisc.h"
# include "ivl_assert.h"
NetContribution::NetContribution(NetExpr*l, NetExpr*r)
: lval_(l), rval_(r)
{
}
NetContribution::~NetContribution()
{
}

View File

@ -875,7 +875,7 @@ NetScope* NetProcTop::scope()
return scope_;
}
NetAnalogTop::NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetAnalog*st)
NetAnalogTop::NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetProc*st)
: type_(t), statement_(st), scope_(scope)
{
next_ = 0;

View File

@ -2434,6 +2434,24 @@ class NetCondit : public NetProc {
NetProc*else_;
};
/*
* This represents the analog contribution statement. The l-val is a
* branch expression, and the r-value is an arbitrary expression that
* may include branches and real values.
*/
class NetContribution : public NetProc {
public:
explicit NetContribution(NetExpr*lval, NetExpr*rval);
~NetContribution();
virtual void dump(ostream&, unsigned ind) const;
private:
NetExpr*lval_;
NetExpr*rval_;
};
/*
* The procedural deassign statement (the opposite of assign) releases
* any assign expressions attached to the bits of the reg. The
@ -3080,19 +3098,16 @@ class NetProcTop : public LineInfo, public Attrib {
NetProcTop*next_;
};
class NetAnalog : public LineInfo, public Attrib {
};
class NetAnalogTop : public LineInfo, public Attrib {
public:
NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetAnalog*st);
NetAnalogTop(NetScope*scope, ivl_process_type_t t, NetProc*st);
~NetAnalogTop();
ivl_process_type_t type() const { return type_; }
NetAnalog*statement();
const NetAnalog*statement() const;
NetProc*statement();
const NetProc*statement() const;
NetScope*scope();
const NetScope*scope() const;
@ -3102,7 +3117,7 @@ class NetAnalogTop : public LineInfo, public Attrib {
private:
const ivl_process_type_t type_;
NetAnalog* statement_;
NetProc* statement_;
NetScope*scope_;
friend class Design;

View File

@ -180,7 +180,6 @@ static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
PEventStatement*event_statement;
Statement*statement;
svector<Statement*>*statement_list;
AStatement*astatement;
PTaskFuncArg function_type;
@ -304,7 +303,7 @@ static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
%type <statement> statement statement_or_null
%type <statement_list> statement_list
%type <astatement> analog_statement
%type <statement> analog_statement
%type <letter> spec_polarity
%type <perm_strings> specify_path_identifiers

View File

@ -396,10 +396,10 @@ extern void pform_dump(ostream&out, const discipline_t*);
/* ** pform_analog.cc
*/
extern void pform_make_analog_behavior(const struct vlltype&loc,
ivl_process_type_t type, AStatement*st);
ivl_process_type_t type, Statement*st);
extern AStatement*pform_contribution_statement(const struct vlltype&loc,
PExpr*lval, PExpr*rval);
extern AContrib*pform_contribution_statement(const struct vlltype&loc,
PExpr*lval, PExpr*rval);
extern PExpr* pform_make_branch_probe_expression(const struct vlltype&loc,
char*name, char*n1, char*n2);

View File

@ -23,7 +23,7 @@
# include "parse_misc.h"
# include "AStatement.h"
AStatement* pform_contribution_statement(const struct vlltype&loc,
AContrib* pform_contribution_statement(const struct vlltype&loc,
PExpr*lval, PExpr*rval)
{
AContrib*tmp = new AContrib(lval, rval);
@ -32,7 +32,7 @@ AStatement* pform_contribution_statement(const struct vlltype&loc,
}
void pform_make_analog_behavior(const struct vlltype&loc, ivl_process_type_t pt,
AStatement*statement)
Statement*statement)
{
AProcess*proc = new AProcess(pt, statement);
FILE_NAME(proc, loc);

View File

@ -564,16 +564,6 @@ void Statement::dump(ostream&out, unsigned ind) const
dump_attributes_map(out, attributes, ind+2);
}
void AStatement::dump(ostream&out, unsigned ind) const
{
/* I give up. I don't know what type this statement is,
so just print the C++ typeid and let the user figure
it out. */
out << setw(ind) << "";
out << "/* " << get_fileline() << ": " << typeid(*this).name()
<< " */ ;" << endl;
}
void AContrib::dump(ostream&out, unsigned ind) const
{
out << setw(ind) << "";