mirror of
https://github.com/steveicarus/iverilog.git
synced 2026-08-29 01:03:29 +02:00
This patch is based on one from "bruce <[email protected]>". I've applied all but the elaboration code, which I rewrote to properly work with the elaboration work queue. I also constrained the implementation so that the parameter name must have exactly two components: the root scope name and the parameter name. This is necessary to keep the defparm processing sane. The comments from bruce's original patch are as follows: -- This patch would provide function to define parameter from command line. This serves the same functionality as 'defparam' in Verilog source code, but provide much more ease for using. Parameter definition can be write in command file, with following syntax: +parameter+<scope>.<parameter>=<val> *Do not apply any space between them* The scope name should be full hierachical name with root name at the begining. The following example would override test.T1 with new value 2'b01: +parameter+test.T1=2'b01 'test' here is the root module name. The parameter value here should be constant. Parameter definition can also be write in the command line: iverilog -Ptest.T1=2'b01 This serves the same functionality with the previous example. If we define the same parameter in command file and command line, the one in command line would over-write all others.
109 lines
2.6 KiB
C++
109 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 1998-2009 Stephen Williams ([email protected])
|
|
*
|
|
* 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 "Module.h"
|
|
# include "PGate.h"
|
|
# include "PWire.h"
|
|
# include <assert.h>
|
|
|
|
list<Module::named_expr_t> Module::user_defparms;
|
|
|
|
/* n is a permallocated string. */
|
|
Module::Module(perm_string n)
|
|
: PScope(n)
|
|
{
|
|
library_flag = false;
|
|
is_cell = false;
|
|
uc_drive = UCD_NONE;
|
|
default_nettype = NetNet::NONE;
|
|
timescale_warn_done = false;
|
|
}
|
|
|
|
Module::~Module()
|
|
{
|
|
}
|
|
|
|
void Module::add_gate(PGate*gate)
|
|
{
|
|
gates_.push_back(gate);
|
|
}
|
|
|
|
unsigned Module::port_count() const
|
|
{
|
|
return ports.size();
|
|
}
|
|
|
|
/*
|
|
* Return the array of PEIdent object that are at this port of the
|
|
* module. If the port is internally unconnected, return an empty
|
|
* array.
|
|
*/
|
|
const vector<PEIdent*>& Module::get_port(unsigned idx) const
|
|
{
|
|
assert(idx < ports.size());
|
|
static const vector<PEIdent*> zero;
|
|
|
|
if (ports[idx])
|
|
return ports[idx]->expr;
|
|
else
|
|
return zero;
|
|
}
|
|
|
|
unsigned Module::find_port(const char*name) const
|
|
{
|
|
assert(name != 0);
|
|
for (unsigned idx = 0 ; idx < ports.size() ; idx += 1) {
|
|
if (ports[idx] == 0) {
|
|
/* It is possible to have undeclared ports. These
|
|
are ports that are skipped in the declaration,
|
|
for example like so: module foo(x ,, y); The
|
|
port between x and y is unnamed and thus
|
|
inaccessible to binding by name. */
|
|
continue;
|
|
}
|
|
assert(ports[idx]);
|
|
if (ports[idx]->name == name)
|
|
return idx;
|
|
}
|
|
|
|
return ports.size();
|
|
}
|
|
|
|
|
|
PGate* Module::get_gate(perm_string name)
|
|
{
|
|
for (list<PGate*>::iterator cur = gates_.begin()
|
|
; cur != gates_.end()
|
|
; cur ++ ) {
|
|
|
|
if ((*cur)->get_name() == name)
|
|
return *cur;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
const list<PGate*>& Module::get_gates() const
|
|
{
|
|
return gates_;
|
|
}
|
|
|