From 2dd010dc044e1116bc17548b07434d32fe98c0f9 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 1 Apr 2000 19:31:57 +0000 Subject: [PATCH] Named events as far as the pform. --- Makefile.in | 5 +++-- Module.h | 10 +++++++++- PEvent.cc | 45 +++++++++++++++++++++++++++++++++++++++++ PEvent.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ PExpr.cc | 34 ++++++++++++++++++++++++++++++- PExpr.h | 27 +++++++++++++++++++------ Statement.cc | 31 ++++++++++++++++++++++++++++- Statement.h | 36 ++++++++++++++++++++++++++++----- elaborate.cc | 13 +++++++++++- parse.y | 20 +++++++++++++------ pform.cc | 25 ++++++++++++++++++++++- pform.h | 8 +++++++- pform_dump.cc | 47 ++++++++++++++++++++++++++++++------------- 13 files changed, 317 insertions(+), 39 deletions(-) create mode 100644 PEvent.cc create mode 100644 PEvent.h diff --git a/Makefile.in b/Makefile.in index 239867998..221fba7a8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -18,7 +18,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.41 2000/03/29 04:37:10 steve Exp $" +#ident "$Id: Makefile.in,v 1.42 2000/04/01 19:31:57 steve Exp $" # # SHELL = /bin/sh @@ -75,7 +75,8 @@ expr_synth.o functor.o lexor.o lexor_keyword.o mangle.o netlist.o \ net_design.o net_udp.o nexus_from_link.o pad_to_width.o \ parse.o parse_misc.o pform.o pform_dump.o \ set_width.o \ -verinum.o verireal.o target.o targets.o Module.o PDelays.o PExpr.o PGate.o \ +verinum.o verireal.o target.o targets.o Module.o PDelays.o PEvent.o \ +PExpr.o PGate.o \ PTask.o PFunction.o PWire.o Statement.o \ $(FF) $(TT) diff --git a/Module.h b/Module.h index f50b25351..1bde23915 100644 --- a/Module.h +++ b/Module.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: Module.h,v 1.16 2000/03/12 17:09:40 steve Exp $" +#ident "$Id: Module.h,v 1.17 2000/04/01 19:31:57 steve Exp $" #endif # include @@ -27,6 +27,7 @@ # include "svector.h" # include "named.h" # include +class PEvent; class PExpr; class PGate; class PTask; @@ -81,6 +82,10 @@ class Module { a parameter-index to its name. */ list param_names; + /* Keep a table of named events declared in the module. */ + mapevents; + + const string&get_name() const { return name_; } void add_gate(PGate*gate); @@ -130,6 +135,9 @@ class Module { /* * $Log: Module.h,v $ + * Revision 1.17 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.16 2000/03/12 17:09:40 steve * Support localparam. * diff --git a/PEvent.cc b/PEvent.cc new file mode 100644 index 000000000..4c7c2c926 --- /dev/null +++ b/PEvent.cc @@ -0,0 +1,45 @@ +/* + * Copyright (c) 200Stephen 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 + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: PEvent.cc,v 1.1 2000/04/01 19:31:57 steve Exp $" +#endif + +# include "PEvent.h" + +PEvent::PEvent(const string&n) +: name_(n) +{ +} + +PEvent::~PEvent() +{ +} + +string PEvent::name() const +{ + return name_; +} + +/* + * $Log: PEvent.cc,v $ + * Revision 1.1 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * + */ + diff --git a/PEvent.h b/PEvent.h new file mode 100644 index 000000000..2e7a54b21 --- /dev/null +++ b/PEvent.h @@ -0,0 +1,55 @@ +#ifndef __PEvent_H +#define __PEvent_H +/* + * Copyright (c) 2000 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 + */ +#if !defined(WINNT) && !defined(macintosh) +#ident "$Id: PEvent.h,v 1.1 2000/04/01 19:31:57 steve Exp $" +#endif + +# include "LineInfo.h" +# include +class ostream; + +/* + * The PEvent class represents event objects. These are things that + * are declared in Verilog as ``event foo;'' + */ +class PEvent : public LineInfo { + + public: + explicit PEvent(const string&name); + ~PEvent(); + + string name() const; + + private: + string name_; + + private: // not implemented + PEvent(const PEvent&); + PEvent& operator= (const PEvent&); +}; + +/* + * $Log: PEvent.h,v $ + * Revision 1.1 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * + */ +#endif diff --git a/PExpr.cc b/PExpr.cc index ab1256539..34eea00ea 100644 --- a/PExpr.cc +++ b/PExpr.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: PExpr.cc,v 1.14 2000/03/12 18:22:11 steve Exp $" +#ident "$Id: PExpr.cc,v 1.15 2000/04/01 19:31:57 steve Exp $" #endif # include "PExpr.h" @@ -83,6 +83,35 @@ PEConcat::~PEConcat() delete repeat_; } +PEEvent::PEEvent(NetNEvent::Type t, PExpr*e) +: type_(t), expr_(e) +{ +} + +PEEvent::PEEvent(const string&n) +: name_(n) +{ +} + +PEEvent::~PEEvent() +{ +} + +NetNEvent::Type PEEvent::type() const +{ + return type_; +} + +PExpr* PEEvent::expr() const +{ + return expr_; +} + +string PEEvent::name() const +{ + return name_; +} + /* * An identifier can be in a constant expresion if (and only if) it is * a parameter. @@ -135,6 +164,9 @@ bool PETernary::is_constant(Module*) const /* * $Log: PExpr.cc,v $ + * Revision 1.15 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.14 2000/03/12 18:22:11 steve * Binary and unary operators in parameter expressions. * diff --git a/PExpr.h b/PExpr.h index 185422c14..ca6b6869c 100644 --- a/PExpr.h +++ b/PExpr.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: PExpr.h,v 1.32 2000/03/12 18:22:11 steve Exp $" +#ident "$Id: PExpr.h,v 1.33 2000/04/01 19:31:57 steve Exp $" #endif # include @@ -112,21 +112,33 @@ class PEConcat : public PExpr { PExpr*repeat_; }; +/* + * Event expressions are expressions that can be combined with the + * event "or" operator. These include "posedge foo" and similar, and + * also include named events. "edge" events are associated with an + * expression, whereas named events simply have a name, which + * represents an event variable. + */ class PEEvent : public PExpr { public: - PEEvent(NetNEvent::Type t, PExpr*e) - : type_(t), expr_(e) - { } + // Use this constructor to create events based on edges or levels. + PEEvent(NetNEvent::Type t, PExpr*e); + // Use this to create named events. + PEEvent(const string&n); - NetNEvent::Type type() const { return type_; } - PExpr* expr() const { return expr_; } + ~PEEvent(); + + NetNEvent::Type type() const; + PExpr* expr() const; + string name() const; virtual void dump(ostream&) const; private: NetNEvent::Type type_; PExpr*expr_; + string name_; }; class PEIdent : public PExpr { @@ -341,6 +353,9 @@ class PECallFunction : public PExpr { /* * $Log: PExpr.h,v $ + * Revision 1.33 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.32 2000/03/12 18:22:11 steve * Binary and unary operators in parameter expressions. * diff --git a/Statement.cc b/Statement.cc index 0cfdb7e9b..d4ae77d4d 100644 --- a/Statement.cc +++ b/Statement.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: Statement.cc,v 1.17 2000/02/23 02:56:54 steve Exp $" +#ident "$Id: Statement.cc,v 1.18 2000/04/01 19:31:57 steve Exp $" #endif # include "Statement.h" @@ -129,6 +129,23 @@ PCondit::~PCondit() delete else_; } +PEventStatement::PEventStatement(const svector&ee) +: expr_(ee), statement_(0) +{ +} + + +PEventStatement::PEventStatement(PEEvent*ee) +: expr_(1), statement_(0) +{ + expr_[0] = ee; +} + +PEventStatement::~PEventStatement() +{ + // delete the events and the statement? +} + PForever::PForever(Statement*s) : statement_(s) { @@ -155,6 +172,15 @@ PRepeat::~PRepeat() delete statement_; } +PTrigger::PTrigger(const string&e) +: event_(e) +{ +} + +PTrigger::~PTrigger() +{ +} + PWhile::~PWhile() { delete cond_; @@ -163,6 +189,9 @@ PWhile::~PWhile() /* * $Log: Statement.cc,v $ + * Revision 1.18 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.17 2000/02/23 02:56:54 steve * Macintosh compilers do not support ident. * diff --git a/Statement.h b/Statement.h index 56b97295f..419618503 100644 --- a/Statement.h +++ b/Statement.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: Statement.h,v 1.22 2000/03/11 03:25:51 steve Exp $" +#ident "$Id: Statement.h,v 1.23 2000/04/01 19:31:57 steve Exp $" #endif # include @@ -258,15 +258,21 @@ class PDelayStatement : public Statement { Statement*statement_; }; +/* + * The event statement represents the event delay in behavioral + * code. It comes from such things as: + * + * @name ; + * @(expr) ; + */ class PEventStatement : public Statement { public: - PEventStatement(const svector&ee) - : expr_(ee), statement_(0) { } + explicit PEventStatement(const svector&ee); + explicit PEventStatement(PEEvent*ee); - PEventStatement(PEEvent*ee) - : expr_(1), statement_(0) { expr_[0] = ee; } + ~PEventStatement(); void set_statement(Statement*st) { statement_ = st; } @@ -341,6 +347,23 @@ class PRepeat : public Statement { Statement*statement_; }; +/* + * The PTrigger statement sends a trigger to a named event. Take the + * name here. + */ +class PTrigger : public Statement { + + public: + explicit PTrigger(const string&ev); + ~PTrigger(); + + virtual NetProc* elaborate(Design*des, const string&path) const; + virtual void dump(ostream&out, unsigned ind) const; + + private: + string event_; +}; + class PWhile : public Statement { public: @@ -359,6 +382,9 @@ class PWhile : public Statement { /* * $Log: Statement.h,v $ + * Revision 1.23 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.22 2000/03/11 03:25:51 steve * Locate scopes in statements. * diff --git a/elaborate.cc b/elaborate.cc index 9737af896..21b9e01a5 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: elaborate.cc,v 1.151 2000/03/29 04:37:11 steve Exp $" +#ident "$Id: elaborate.cc,v 1.152 2000/04/01 19:31:57 steve Exp $" #endif /* @@ -1828,6 +1828,14 @@ void PTask::elaborate_2(Design*des, const string&path) const def->set_proc(st); } +NetProc* PTrigger::elaborate(Design*des, const string&path) const +{ + cerr << get_line() << ": sorry: named event trigger not supported." + << endl; + des->errors += 1; + return 0; +} + /* * The while loop is fairly directly represented in the netlist. */ @@ -2003,6 +2011,9 @@ Design* elaborate(const map&modules, /* * $Log: elaborate.cc,v $ + * Revision 1.152 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.151 2000/03/29 04:37:11 steve * New and improved combinational primitives. * diff --git a/parse.y b/parse.y index 56d53f369..1015f98d7 100644 --- a/parse.y +++ b/parse.y @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: parse.y,v 1.86 2000/03/12 17:09:41 steve Exp $" +#ident "$Id: parse.y,v 1.87 2000/04/01 19:31:57 steve Exp $" #endif # include "parse_misc.h" @@ -388,8 +388,14 @@ dr_strength1 : K_supply1 | K_strong1 | K_pull1 | K_weak1 ; event_control : '@' IDENTIFIER - { yyerror(@1, "sorry: event control not supported."); - $$ = 0; + { PEEvent*tmpe = new PEEvent($2); + tmpe->set_file(@2.text); + tmpe->set_lineno(@2.first_line); + delete[]$2; + PEventStatement*tmps = new PEventStatement(tmpe); + tmps->set_file(@1.text); + tmps->set_lineno(@1.first_line); + $$ = tmps; } | '@' '(' event_expression_list ')' { PEventStatement*tmp = new PEventStatement(*$3); @@ -1093,7 +1099,7 @@ module_item | block_item_decl | K_defparam defparam_assign_list ';' | K_event list_of_variables ';' - { yyerror(@1, "sorry: named events not supported."); + { pform_make_events($2, @1.text, @1.first_line); delete $2; } | K_parameter parameter_assign_list ';' @@ -1642,8 +1648,10 @@ statement $$ = 0; } | K_TRIGGER IDENTIFIER ';' - { yyerror(@1, "sorry: event trigger not supported."); - $$ = 0; + { PTrigger*tmp = new PTrigger($2); + tmp->set_file(@2.text); + tmp->set_lineno(@2.first_line); + $$ = tmp; } | K_forever statement { PForever*tmp = new PForever($2); diff --git a/pform.cc b/pform.cc index abe95dbe0..e91be538a 100644 --- a/pform.cc +++ b/pform.cc @@ -17,12 +17,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: pform.cc,v 1.56 2000/03/12 17:09:41 steve Exp $" +#ident "$Id: pform.cc,v 1.57 2000/04/01 19:31:57 steve Exp $" #endif # include "compiler.h" # include "pform.h" # include "parse_misc.h" +# include "PEvent.h" # include "PUdp.h" # include # include @@ -265,6 +266,25 @@ void pform_make_udp(const char*name, list*parms, delete init_expr; } +/* + * This is invoked to make a named event. This is the declaration of + * the event, and not necessarily the use of it. + */ +static void pform_make_event(const string&name, const string&fn, unsigned ln) +{ + PEvent*event = new PEvent(name); + event->set_file(fn); + event->set_lineno(ln); + pform_cur_module->events[name] = event; +} + +void pform_make_events(const list*names, const string&fn, unsigned ln) +{ + list::const_iterator cur; + for (cur = names->begin() ; cur != names->end() ; cur++) + pform_make_event(*cur, fn, ln); +} + /* * pform_makegates is called when a list of gates (with the same type) * are ready to be instantiated. The function runs through the list of @@ -833,6 +853,9 @@ int pform_parse(const char*path, map&modules, /* * $Log: pform.cc,v $ + * Revision 1.57 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.56 2000/03/12 17:09:41 steve * Support localparam. * diff --git a/pform.h b/pform.h index 06aad3685..c439934d9 100644 --- a/pform.h +++ b/pform.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: pform.h,v 1.37 2000/03/12 17:09:41 steve Exp $" +#ident "$Id: pform.h,v 1.38 2000/04/01 19:31:57 steve Exp $" #endif # include "netlist.h" @@ -141,6 +141,9 @@ extern svector* pform_make_udp_input_ports(list*); extern bool pform_expression_is_constant(const PExpr*); +extern void pform_make_events(const list*names, + const string&file, unsigned lineno); + /* * The makegate function creates a new gate (which need not have a * name) and connects it to the specified wires. @@ -182,6 +185,9 @@ extern void pform_dump(ostream&out, Module*mod); /* * $Log: pform.h,v $ + * Revision 1.38 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.37 2000/03/12 17:09:41 steve * Support localparam. * diff --git a/pform_dump.cc b/pform_dump.cc index 04e541bbe..276e0c605 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: pform_dump.cc,v 1.51 2000/03/12 17:09:41 steve Exp $" +#ident "$Id: pform_dump.cc,v 1.52 2000/04/01 19:31:57 steve Exp $" #endif /* @@ -27,6 +27,7 @@ * module in question. */ # include "pform.h" +# include "PEvent.h" # include # include # include @@ -80,20 +81,24 @@ void PECallFunction::dump(ostream &out) const void PEEvent::dump(ostream&out) const { - switch (type_) { - case NetNEvent::ANYEDGE: - break; - case NetNEvent::POSEDGE: - out << "posedge "; - break; - case NetNEvent::NEGEDGE: - out << "negedge "; - break; - case NetNEvent::POSITIVE: - out << "positive "; - break; + if (expr_) { + switch (type_) { + case NetNEvent::ANYEDGE: + break; + case NetNEvent::POSEDGE: + out << "posedge "; + break; + case NetNEvent::NEGEDGE: + out << "negedge "; + break; + case NetNEvent::POSITIVE: + out << "positive "; + break; + } + out << *expr_; + } else { + out << ""; } - out << *expr_; } void PENumber::dump(ostream&out) const @@ -541,6 +546,10 @@ void PTask::dump(ostream&out, unsigned ind) const out << setw(ind) << "" << "/* NOOP */" << endl; } +void PTrigger::dump(ostream&out, unsigned ind) const +{ + out << setw(ind) << "" << "-> " << event_ << ";" << endl; +} void PWhile::dump(ostream&out, unsigned ind) const { @@ -627,6 +636,13 @@ void Module::dump(ostream&out) const out << "/* ERROR */;" << endl; } + for (map::const_iterator cur = events.begin() + ; cur != events.end() ; cur ++ ) { + PEvent*ev = (*cur).second; + out << " event " << ev->name() << "; // " + << ev->get_line() << endl; + } + // Iterate through and display all the wires. for (map::const_iterator wire = wires_.begin() ; wire != wires_.end() @@ -720,6 +736,9 @@ void PUdp::dump(ostream&out) const /* * $Log: pform_dump.cc,v $ + * Revision 1.52 2000/04/01 19:31:57 steve + * Named events as far as the pform. + * * Revision 1.51 2000/03/12 17:09:41 steve * Support localparam. *