From 68fbb94b3ace9b7c39e6155d347ba2f2bda834e4 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 22 Oct 2008 21:56:00 -0700 Subject: [PATCH] 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. --- AStatement.cc | 4 ---- AStatement.h | 28 ++++++---------------------- Makefile.in | 2 +- design_dump.cc | 28 ++++++++++++++++++++++++++++ elab_scope.cc | 9 --------- elab_sig_analog.cc | 4 ---- elaborate_analog.cc | 16 ++++++++++------ emit.cc | 9 +++++++++ net_analog.cc | 37 +++++++++++++++++++++++++++++++++++++ netlist.cc | 2 +- netlist.h | 29 ++++++++++++++++++++++------- parse.y | 3 +-- pform.h | 6 +++--- pform_analog.cc | 4 ++-- pform_dump.cc | 10 ---------- 15 files changed, 120 insertions(+), 71 deletions(-) create mode 100644 net_analog.cc diff --git a/AStatement.cc b/AStatement.cc index a3617d6bf..3cd9b0c4a 100644 --- a/AStatement.cc +++ b/AStatement.cc @@ -21,10 +21,6 @@ # include "AStatement.h" -AStatement::~AStatement() -{ -} - AContrib::AContrib(PExpr*lv, PExpr*rv) : lval_(lv), rval_(rv) { diff --git a/AStatement.h b/AStatement.h index b386b3398..a02e6d099 100644 --- a/AStatement.h +++ b/AStatement.h @@ -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 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 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&); diff --git a/Makefile.in b/Makefile.in index 47c1ad1f4..5e1a59a3d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ diff --git a/design_dump.cc b/design_dump.cc index 1ffcd10d7..cf1b5790e 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -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); } diff --git a/elab_scope.cc b/elab_scope.cc index 0e2820261..1adf85402 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -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 -{ -} - diff --git a/elab_sig_analog.cc b/elab_sig_analog.cc index d7da16fcf..82b8b9e68 100644 --- a/elab_sig_analog.cc +++ b/elab_sig_analog.cc @@ -24,7 +24,3 @@ # include # include -void AStatement::elaborate_sig(Design*des, NetScope*scope) const -{ -} - diff --git a/elaborate_analog.cc b/elaborate_analog.cc index 0688aa2b2..54a4a7d76 100644 --- a/elaborate_analog.cc +++ b/elaborate_analog.cc @@ -20,21 +20,25 @@ # include "config.h" # include "AStatement.h" +# include "netlist.h" +# include "netmisc.h" # include "util.h" # include -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; diff --git a/emit.cc b/emit.cc index 6d1be63a8..0daef461f 100644 --- a/emit.cc +++ b/emit.cc @@ -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); diff --git a/net_analog.cc b/net_analog.cc new file mode 100644 index 000000000..25fde3411 --- /dev/null +++ b/net_analog.cc @@ -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 +# include +# include +# 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() +{ +} diff --git a/netlist.cc b/netlist.cc index f23fbbe23..2e114ae21 100644 --- a/netlist.cc +++ b/netlist.cc @@ -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; diff --git a/netlist.h b/netlist.h index 63f9f032a..482d6c369 100644 --- a/netlist.h +++ b/netlist.h @@ -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; diff --git a/parse.y b/parse.y index d6c05e830..eb116cd7e 100644 --- a/parse.y +++ b/parse.y @@ -180,7 +180,6 @@ static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2) PEventStatement*event_statement; Statement*statement; svector*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_or_null %type statement_list -%type analog_statement +%type analog_statement %type spec_polarity %type specify_path_identifiers diff --git a/pform.h b/pform.h index 16ef2f9f9..14fc2f875 100644 --- a/pform.h +++ b/pform.h @@ -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); diff --git a/pform_analog.cc b/pform_analog.cc index fe5489b44..81571dfdd 100644 --- a/pform_analog.cc +++ b/pform_analog.cc @@ -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); diff --git a/pform_dump.cc b/pform_dump.cc index 4283620e0..4dca440d2 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -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) << "";