Skip to content

Commit

Permalink
Basic elaboration of analog contribution statements.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steveicarus committed Oct 23, 2008
1 parent 5aa810d commit 68fbb94
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 71 deletions.
4 changes: 0 additions & 4 deletions AStatement.cc
Expand Up @@ -21,10 +21,6 @@

# include "AStatement.h"

AStatement::~AStatement()
{
}

AContrib::AContrib(PExpr*lv, PExpr*rv)
: lval_(lv), rval_(rv)
{
Expand Down
28 changes: 6 additions & 22 deletions AStatement.h
Expand Up @@ -23,43 +23,27 @@
# include "ivl_target.h"
# include "StringHeap.h"
# include "LineInfo.h"
# include "Statement.h"
# include "PExpr.h"

class PExpr;
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_;
Expand All @@ -74,15 +58,15 @@ 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();

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;

Expand All @@ -91,7 +75,7 @@ class AProcess : public LineInfo {

private:
ivl_process_type_t type_;
AStatement*statement_;
Statement*statement_;

private: // not implemented
AProcess(const AProcess&);
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -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 \
Expand Down
28 changes: 28 additions & 0 deletions design_dump.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ";
Expand Down Expand Up @@ -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);
}
9 changes: 0 additions & 9 deletions elab_scope.cc
Expand Up @@ -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
{
}

4 changes: 0 additions & 4 deletions elab_sig_analog.cc
Expand Up @@ -24,7 +24,3 @@
# include <cstdlib>
# include <iostream>

void AStatement::elaborate_sig(Design*des, NetScope*scope) const
{
}

16 changes: 10 additions & 6 deletions elaborate_analog.cc
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions emit.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
37 changes: 37 additions & 0 deletions 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 <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()
{
}
2 changes: 1 addition & 1 deletion netlist.cc
Expand Up @@ -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;
Expand Down
29 changes: 22 additions & 7 deletions netlist.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions parse.y
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pform.h
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions pform_analog.cc
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions pform_dump.cc
Expand Up @@ -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) << "";
Expand Down

0 comments on commit 68fbb94

Please sign in to comment.