aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--frontends/ast/ast.cc173
-rw-r--r--frontends/ast/ast.h5
-rw-r--r--frontends/ast/genrtlil.cc37
-rw-r--r--passes/hierarchy/hierarchy.cc44
-rw-r--r--techlibs/ecp5/Makefile.inc1
-rw-r--r--techlibs/ecp5/cells_bb.v95
-rw-r--r--techlibs/ecp5/synth_ecp5.cc2
-rwxr-xr-xtests/svinterfaces/run-test.sh1
-rwxr-xr-xtests/svinterfaces/runone.sh7
-rw-r--r--tests/svinterfaces/svinterface_at_top.sv125
-rw-r--r--tests/svinterfaces/svinterface_at_top_ref.v120
-rw-r--r--tests/svinterfaces/svinterface_at_top_tb.v68
-rw-r--r--tests/svinterfaces/svinterface_at_top_tb_wrapper.v68
-rw-r--r--tests/svinterfaces/svinterface_at_top_wrapper.v33
14 files changed, 702 insertions, 77 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc
index 7600e2912..cc275959a 100644
--- a/frontends/ast/ast.cc
+++ b/frontends/ast/ast.cc
@@ -904,7 +904,7 @@ RTLIL::Const AstNode::realAsConst(int width)
}
// create a new AstModule from an AST_MODULE AST node
-static AstModule* process_module(AstNode *ast, bool defer)
+static AstModule* process_module(AstNode *ast, bool defer, AstNode *original_ast = NULL)
{
log_assert(ast->type == AST_MODULE || ast->type == AST_INTERFACE);
@@ -920,7 +920,11 @@ static AstModule* process_module(AstNode *ast, bool defer)
current_module->set_bool_attribute("\\cells_not_processed");
current_ast_mod = ast;
- AstNode *ast_before_simplify = ast->clone();
+ AstNode *ast_before_simplify;
+ if (original_ast != NULL)
+ ast_before_simplify = original_ast;
+ else
+ ast_before_simplify = ast->clone();
if (flag_dump_ast1) {
log("Dumping Verilog AST before simplification:\n");
@@ -1087,6 +1091,84 @@ AstModule::~AstModule()
delete ast;
}
+
+// An interface port with modport is specified like this:
+// <interface_name>.<modport_name>
+// This function splits the interface_name from the modport_name, and fails if it is not a valid combination
+std::pair<std::string,std::string> AST::split_modport_from_type(std::string name_type)
+{
+ std::string interface_type = "";
+ std::string interface_modport = "";
+ size_t ndots = std::count(name_type.begin(), name_type.end(), '.');
+ // Separate the interface instance name from any modports:
+ if (ndots == 0) { // Does not have modport
+ interface_type = name_type;
+ }
+ else {
+ std::stringstream name_type_stream(name_type);
+ std::string segment;
+ std::vector<std::string> seglist;
+ while(std::getline(name_type_stream, segment, '.')) {
+ seglist.push_back(segment);
+ }
+ if (ndots == 1) { // Has modport
+ interface_type = seglist[0];
+ interface_modport = seglist[1];
+ }
+ else { // Erroneous port type
+ log_error("More than two '.' in signal port type (%s)\n", name_type.c_str());
+ }
+ }
+ return std::pair<std::string,std::string>(interface_type, interface_modport);
+
+}
+
+AstNode * AST::find_modport(AstNode *intf, std::string name)
+{
+ for (auto &ch : intf->children)
+ if (ch->type == AST_MODPORT)
+ if (ch->str == name) // Modport found
+ return ch;
+ return NULL;
+}
+
+// Iterate over all wires in an interface and add them as wires in the AST module:
+void AST::explode_interface_port(AstNode *module_ast, RTLIL::Module * intfmodule, std::string intfname, AstNode *modport)
+{
+ for (auto &wire_it : intfmodule->wires_){
+ AstNode *wire = new AstNode(AST_WIRE, new AstNode(AST_RANGE, AstNode::mkconst_int(wire_it.second->width -1, true), AstNode::mkconst_int(0, true)));
+ std::string origname = log_id(wire_it.first);
+ std::string newname = intfname + "." + origname;
+ wire->str = newname;
+ if (modport != NULL) {
+ bool found_in_modport = false;
+ // Search for the current wire in the wire list for the current modport
+ for (auto &ch : modport->children) {
+ if (ch->type == AST_MODPORTMEMBER) {
+ std::string compare_name = "\\" + origname;
+ if (ch->str == compare_name) { // Found signal. The modport decides whether it is input or output
+ found_in_modport = true;
+ wire->is_input = ch->is_input;
+ wire->is_output = ch->is_output;
+ break;
+ }
+ }
+ }
+ if (found_in_modport) {
+ module_ast->children.push_back(wire);
+ }
+ else { // If not found in modport, do not create port
+ delete wire;
+ }
+ }
+ else { // If no modport, set inout
+ wire->is_input = true;
+ wire->is_output = true;
+ module_ast->children.push_back(wire);
+ }
+ }
+}
+
// When an interface instance is found in a module, the whole RTLIL for the module will be rederived again
// from AST. The interface members are copied into the AST module with the prefix of the interface.
void AstModule::reprocess_module(RTLIL::Design *design, dict<RTLIL::IdString, RTLIL::Module*> local_interfaces)
@@ -1105,6 +1187,49 @@ void AstModule::reprocess_module(RTLIL::Design *design, dict<RTLIL::IdString, RT
}
}
+ AstNode *ast_before_replacing_interface_ports = new_ast->clone();
+
+ // Explode all interface ports. Note this will only have an effect on 'top
+ // level' modules. Other sub-modules will have their interface ports
+ // exploded via the derive(..) function
+ for (size_t i =0; i<new_ast->children.size(); i++)
+ {
+ AstNode *ch2 = new_ast->children[i];
+ if (ch2->type == AST_INTERFACEPORT) { // Is an interface port
+ std::string name_port = ch2->str; // Name of the interface port
+ if (ch2->children.size() > 0) {
+ for(size_t j=0; j<ch2->children.size();j++) {
+ AstNode *ch = ch2->children[j];
+ if(ch->type == AST_INTERFACEPORTTYPE) { // Found the AST node containing the type of the interface
+ std::pair<std::string,std::string> res = split_modport_from_type(ch->str);
+ std::string interface_type = res.first;
+ std::string interface_modport = res.second; // Is "", if no modport
+ if (design->modules_.count(interface_type) > 0) {
+ // Add a cell to the module corresponding to the interface port such that
+ // it can further propagated down if needed:
+ AstNode *celltype_for_intf = new AstNode(AST_CELLTYPE);
+ celltype_for_intf->str = interface_type;
+ AstNode *cell_for_intf = new AstNode(AST_CELL, celltype_for_intf);
+ cell_for_intf->str = name_port + "_inst_from_top_dummy";
+ new_ast->children.push_back(cell_for_intf);
+
+ // Get all members of this non-overridden dummy interface instance:
+ RTLIL::Module *intfmodule = design->modules_[interface_type]; // All interfaces should at this point in time (assuming
+ // reprocess_module is called from the hierarchy pass) be
+ // present in design->modules_
+ AstModule *ast_module_of_interface = (AstModule*)intfmodule;
+ std::string interface_modport_compare_str = "\\" + interface_modport;
+ AstNode *modport = find_modport(ast_module_of_interface->ast, interface_modport_compare_str); // modport == NULL if no modport
+ // Iterate over all wires in the interface and add them to the module:
+ explode_interface_port(new_ast, intfmodule, name_port, modport);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+
// The old module will be deleted. Rename and mark for deletion:
std::string original_name = this->name.str();
std::string changed_name = original_name + "_before_replacing_local_interfaces";
@@ -1119,7 +1244,8 @@ void AstModule::reprocess_module(RTLIL::Design *design, dict<RTLIL::IdString, RT
}
// Generate RTLIL from AST for the new module and add to the design:
- AstModule *newmod = process_module(new_ast, false);
+ AstModule *newmod = process_module(new_ast, false, ast_before_replacing_interface_ports);
+ delete(new_ast);
design->add(newmod);
RTLIL::Module* mod = design->module(original_name);
if (is_top)
@@ -1164,47 +1290,10 @@ RTLIL::IdString AstModule::derive(RTLIL::Design *design, dict<RTLIL::IdString, R
std::string interface_modport = modports.at(intfname).str();
AstModule *ast_module_of_interface = (AstModule*)intfmodule;
AstNode *ast_node_of_interface = ast_module_of_interface->ast;
- for (auto &ch : ast_node_of_interface->children) {
- if (ch->type == AST_MODPORT) {
- if (ch->str == interface_modport) { // Modport found
- modport = ch;
- }
- }
- }
+ modport = find_modport(ast_node_of_interface, interface_modport);
}
// Iterate over all wires in the interface and add them to the module:
- for (auto &wire_it : intfmodule->wires_){
- AstNode *wire = new AstNode(AST_WIRE, new AstNode(AST_RANGE, AstNode::mkconst_int(wire_it.second->width -1, true), AstNode::mkconst_int(0, true)));
- std::string origname = log_id(wire_it.first);
- std::string newname = intfname + "." + origname;
- wire->str = newname;
- if (modport != NULL) {
- bool found_in_modport = false;
- // Search for the current wire in the wire list for the current modport
- for (auto &ch : modport->children) {
- if (ch->type == AST_MODPORTMEMBER) {
- std::string compare_name = "\\" + origname;
- if (ch->str == compare_name) { // Found signal. The modport decides whether it is input or output
- found_in_modport = true;
- wire->is_input = ch->is_input;
- wire->is_output = ch->is_output;
- break;
- }
- }
- }
- if (found_in_modport) {
- new_ast->children.push_back(wire);
- }
- else { // If not found in modport, do not create port
- delete wire;
- }
- }
- else { // If no modport, set inout
- wire->is_input = true;
- wire->is_output = true;
- new_ast->children.push_back(wire);
- }
- }
+ explode_interface_port(new_ast, intfmodule, intfname, modport);
}
design->add(process_module(new_ast, false));
diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h
index 8187b1ac6..08f91c9c3 100644
--- a/frontends/ast/ast.h
+++ b/frontends/ast/ast.h
@@ -308,6 +308,11 @@ namespace AST
// call a DPI function
AstNode *dpi_call(const std::string &rtype, const std::string &fname, const std::vector<std::string> &argtypes, const std::vector<AstNode*> &args);
+
+ // Helper functions related to handling SystemVerilog interfaces
+ std::pair<std::string,std::string> split_modport_from_type(std::string name_type);
+ AstNode * find_modport(AstNode *intf, std::string name);
+ void explode_interface_port(AstNode *module_ast, RTLIL::Module * intfmodule, std::string intfname, AstNode *modport);
}
namespace AST_INTERNAL
diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc
index 32b9af6e9..59c309665 100644
--- a/frontends/ast/genrtlil.cc
+++ b/frontends/ast/genrtlil.cc
@@ -870,27 +870,10 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
if (children.size() > 0) {
for(size_t i=0; i<children.size();i++) {
if(children[i]->type == AST_INTERFACEPORTTYPE) {
- std::string name_type = children[i]->str;
- size_t ndots = std::count(name_type.begin(), name_type.end(), '.');
- // Separate the interface instance name from any modports:
- if (ndots == 0) { // Does not have modport
- wire->attributes["\\interface_type"] = name_type;
- }
- else {
- std::stringstream name_type_stream(name_type);
- std::string segment;
- std::vector<std::string> seglist;
- while(std::getline(name_type_stream, segment, '.')) {
- seglist.push_back(segment);
- }
- if (ndots == 1) { // Has modport
- wire->attributes["\\interface_type"] = seglist[0];
- wire->attributes["\\interface_modport"] = seglist[1];
- }
- else { // Erroneous port type
- log_error("More than two '.' in signal port type (%s)\n", name_type.c_str());
- }
- }
+ std::pair<std::string,std::string> res = AST::split_modport_from_type(children[i]->str);
+ wire->attributes["\\interface_type"] = res.first;
+ if (res.second != "")
+ wire->attributes["\\interface_modport"] = res.second;
break;
}
}
@@ -1100,8 +1083,8 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
log_file_warning(filename, linenum, "Range select out of bounds on signal `%s': Setting result bit to undef.\n",
str.c_str());
else
- log_file_warning(filename, linenum, "Range select out of bounds on signal `%s': Setting all %d result bits to undef.\n",
- str.c_str(), chunk.width);
+ log_file_warning(filename, linenum, "Range select [%d:%d] out of bounds on signal `%s': Setting all %d result bits to undef.\n",
+ children[0]->range_left, children[0]->range_right, str.c_str(), chunk.width);
chunk = RTLIL::SigChunk(RTLIL::State::Sx, chunk.width);
} else {
if (chunk.width + chunk.offset > source_width) {
@@ -1114,11 +1097,11 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
chunk.offset += add_undef_bits_lsb;
}
if (add_undef_bits_lsb)
- log_file_warning(filename, linenum, "Range select out of bounds on signal `%s': Setting %d LSB bits to undef.\n",
- str.c_str(), add_undef_bits_lsb);
+ log_file_warning(filename, linenum, "Range [%d:%d] select out of bounds on signal `%s': Setting %d LSB bits to undef.\n",
+ children[0]->range_left, children[0]->range_right, str.c_str(), add_undef_bits_lsb);
if (add_undef_bits_msb)
- log_file_warning(filename, linenum, "Range select out of bounds on signal `%s': Setting %d MSB bits to undef.\n",
- str.c_str(), add_undef_bits_msb);
+ log_file_warning(filename, linenum, "Range [%d:%d] select out of bounds on signal `%s': Setting %d MSB bits to undef.\n",
+ children[0]->range_left, children[0]->range_right, str.c_str(), add_undef_bits_msb);
}
}
}
diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc
index 7e93a6f9a..0c782b8ab 100644
--- a/passes/hierarchy/hierarchy.cc
+++ b/passes/hierarchy/hierarchy.cc
@@ -146,6 +146,17 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
std::map<RTLIL::Cell*, std::pair<int, int>> array_cells;
std::string filename;
+ bool has_interface_ports = false;
+
+ // If any of the ports are actually interface ports, we will always need to
+ // reprocess the module:
+ if(!module->get_bool_attribute("\\interfaces_replaced_in_module")) {
+ for (auto &wire : module->wires_) {
+ if ((wire.second->port_input || wire.second->port_output) && wire.second->get_bool_attribute("\\is_interface"))
+ has_interface_ports = true;
+ }
+ }
+
// Always keep track of all derived interfaces available in the current module in 'interfaces_in_module':
dict<RTLIL::IdString, RTLIL::Module*> interfaces_in_module;
for (auto &cell_it : module->cells_)
@@ -244,8 +255,17 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
RTLIL::IdString interface_name = interface_name_str;
bool not_found_interface = false;
if(module->get_bool_attribute("\\interfaces_replaced_in_module")) { // If 'interfaces' in the cell have not be been handled yet, there is no need to derive the sub-module either
- if (interfaces_in_module.count(interface_name) > 0) { // Check if the interface instance is present in module
- RTLIL::Module *mod_replace_ports = interfaces_in_module.at(interface_name);
+ // Check if the interface instance is present in module:
+ // Interface instances may either have the plain name or the name appended with '_inst_from_top_dummy'.
+ // Check for both of them here
+ int nexactmatch = interfaces_in_module.count(interface_name) > 0;
+ std::string interface_name_str2 = interface_name_str + "_inst_from_top_dummy";
+ RTLIL::IdString interface_name2 = interface_name_str2;
+ int nmatch2 = interfaces_in_module.count(interface_name2) > 0;
+ if (nexactmatch > 0 || nmatch2 > 0) {
+ if (nexactmatch != 0) // Choose the one with the plain name if it exists
+ interface_name2 = interface_name;
+ RTLIL::Module *mod_replace_ports = interfaces_in_module.at(interface_name2);
for (auto &mod_wire : mod_replace_ports->wires_) { // Go over all wires in interface, and add replacements to lists.
std::string signal_name1 = conn.first.str() + "." + log_id(mod_wire.first);
std::string signal_name2 = interface_name.str() + "." + log_id(mod_wire.first);
@@ -259,7 +279,7 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
}
}
connections_to_remove.push_back(conn.first);
- interfaces_to_add_to_submodule[conn.first] = interfaces_in_module.at(interface_name);
+ interfaces_to_add_to_submodule[conn.first] = interfaces_in_module.at(interface_name2);
// Add modports to a dict which will be passed to AstModule::derive
if (interface_modport != "") {
@@ -363,8 +383,8 @@ bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check
module->attributes.erase("\\cells_not_processed");
- // If any interface instances were found in the module, we need to rederive it completely:
- if (interfaces_in_module.size() > 0 && !module->get_bool_attribute("\\interfaces_replaced_in_module")) {
+ // If any interface instances or interface ports were found in the module, we need to rederive it completely:
+ if ((interfaces_in_module.size() > 0 || has_interface_ports) && !module->get_bool_attribute("\\interfaces_replaced_in_module")) {
module->reprocess_module(design, interfaces_in_module);
return did_something;
}
@@ -438,6 +458,20 @@ void hierarchy_clean(RTLIL::Design *design, RTLIL::Module *top, bool purge_lib)
for (auto &it : design->modules_)
if (used.count(it.second) == 0)
del_modules.push_back(it.second);
+ else {
+ // Now all interface ports must have been exploded, and it is hence
+ // safe to delete all of the remaining dummy interface ports:
+ pool<RTLIL::Wire*> del_wires;
+ for(auto &wire : it.second->wires_) {
+ if ((wire.second->port_input || wire.second->port_output) && wire.second->get_bool_attribute("\\is_interface")) {
+ del_wires.insert(wire.second);
+ }
+ }
+ if (del_wires.size() > 0) {
+ it.second->remove(del_wires);
+ it.second->fixup_ports();
+ }
+ }
int del_counter = 0;
for (auto mod : del_modules) {
diff --git a/techlibs/ecp5/Makefile.inc b/techlibs/ecp5/Makefile.inc
index 9b6f061bd..b23d5c70e 100644
--- a/techlibs/ecp5/Makefile.inc
+++ b/techlibs/ecp5/Makefile.inc
@@ -3,6 +3,7 @@ OBJS += techlibs/ecp5/synth_ecp5.o
$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/cells_map.v))
$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/cells_sim.v))
+$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/cells_bb.v))
$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/drams_map.v))
$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/dram.txt))
$(eval $(call add_share_file,share/ecp5,techlibs/ecp5/brams_map.v))
diff --git a/techlibs/ecp5/cells_bb.v b/techlibs/ecp5/cells_bb.v
new file mode 100644
index 000000000..8644abecd
--- /dev/null
+++ b/techlibs/ecp5/cells_bb.v
@@ -0,0 +1,95 @@
+// ECP5 Blackbox cells
+// FIXME: Create sim models
+
+(* blackbox *)
+module MULT18X18D(
+ input A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17,
+ input B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17,
+ input C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17,
+ input SIGNEDA, SIGNEDB, SOURCEA, SOURCEB,
+ input CLK0, CLK1, CLK2, CLK3,
+ input CE0, CE1, CE2, CE3,
+ input RST0, RST1, RST2, RST3,
+ input SRIA0, SRIA1, SRIA2, SRIA3, SRIA4, SRIA5, SRIA6, SRIA7, SRIA8, SRIA9, SRIA10, SRIA11, SRIA12, SRIA13, SRIA14, SRIA15, SRIA16, SRIA17,
+ input SRIB0, SRIB1, SRIB2, SRIB3, SRIB4, SRIB5, SRIB6, SRIB7, SRIB8, SRIB9, SRIB10, SRIB11, SRIB12, SRIB13, SRIB14, SRIB15, SRIB16, SRIB17,
+ output SROA0, SROA1, SROA2, SROA3, SROA4, SROA5, SROA6, SROA7, SROA8, SROA9, SROA10, SROA11, SROA12, SROA13, SROA14, SROA15, SROA16, SROA17,
+ output SROB0, SROB1, SROB2, SROB3, SROB4, SROB5, SROB6, SROB7, SROB8, SROB9, SROB10, SROB11, SROB12, SROB13, SROB14, SROB15, SROB16, SROB17,
+ output ROA0, ROA1, ROA2, ROA3, ROA4, ROA5, ROA6, ROA7, ROA8, ROA9, ROA10, ROA11, ROA12, ROA13, ROA14, ROA15, ROA16, ROA17,
+ output ROB0, ROB1, ROB2, ROB3, ROB4, ROB5, ROB6, ROB7, ROB8, ROB9, ROB10, ROB11, ROB12, ROB13, ROB14, ROB15, ROB16, ROB17,
+ output ROC0, ROC1, ROC2, ROC3, ROC4, ROC5, ROC6, ROC7, ROC8, ROC9, ROC10, ROC11, ROC12, ROC13, ROC14, ROC15, ROC16, ROC17,
+ output P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23, P24, P25, P26, P27, P28, P29, P30, P31, P32, P33, P34, P35,
+ output SIGNEDP
+);
+ parameter REG_INPUTA_CLK = "NONE";
+ parameter REG_INPUTA_CE = "CE0";
+ parameter REG_INPUTA_RST = "RST0";
+ parameter REG_INPUTB_CLK = "NONE";
+ parameter REG_INPUTB_CE = "CE0";
+ parameter REG_INPUTB_RST = "RST0";
+ parameter REG_INPUTC_CLK = "NONE";
+ parameter REG_PIPELINE_CLK = "NONE";
+ parameter REG_PIPELINE_CE = "CE0";
+ parameter REG_PIPELINE_RST = "RST0";
+ parameter REG_OUTPUT_CLK = "NONE";
+ parameter [127:0] CLK0_DIV = "ENABLED";
+ parameter [127:0] CLK1_DIV = "ENABLED";
+ parameter [127:0] CLK2_DIV = "ENABLED";
+ parameter [127:0] CLK3_DIV = "ENABLED";
+ parameter [127:0] GSR = "ENABLED";
+ parameter [127:0] SOURCEB_MODE = "B_SHIFT";
+ parameter [127:0] RESETMODE = "SYNC";
+endmodule
+
+(* blackbox *)
+module ALU54B(
+ input CLK0, CLK1, CLK2, CLK3,
+ input CE0, CE1, CE2, CE3,
+ input RST0, RST1, RST2, RST3,
+ input SIGNEDIA, SIGNEDIB, SIGNEDCIN,
+ input A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29, A30, A31, A32, A33, A34, A35,
+ input B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, B30, B31, B32, B33, B34, B35,
+ input C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26, C27, C28, C29, C30, C31, C32, C33, C34, C35, C36, C37, C38, C39, C40, C41, C42, C43, C44, C45, C46, C47, C48, C49, C50, C51, C52, C53,
+ input CFB0, CFB1, CFB2, CFB3, CFB4, CFB5, CFB6, CFB7, CFB8, CFB9, CFB10, CFB11, CFB12, CFB13, CFB14, CFB15, CFB16, CFB17, CFB18, CFB19, CFB20, CFB21, CFB22, CFB23, CFB24, CFB25, CFB26, CFB27, CFB28, CFB29, CFB30, CFB31, CFB32, CFB33, CFB34, CFB35, CFB36, CFB37, CFB38, CFB39, CFB40, CFB41, CFB42, CFB43, CFB44, CFB45, CFB46, CFB47, CFB48, CFB49, CFB50, CFB51, CFB52, CFB53,
+ input MA0, MA1, MA2, MA3, MA4, MA5, MA6, MA7, MA8, MA9, MA10, MA11, MA12, MA13, MA14, MA15, MA16, MA17, MA18, MA19, MA20, MA21, MA22, MA23, MA24, MA25, MA26, MA27, MA28, MA29, MA30, MA31, MA32, MA33, MA34, MA35,
+ input MB0, MB1, MB2, MB3, MB4, MB5, MB6, MB7, MB8, MB9, MB10, MB11, MB12, MB13, MB14, MB15, MB16, MB17, MB18, MB19, MB20, MB21, MB22, MB23, MB24, MB25, MB26, MB27, MB28, MB29, MB30, MB31, MB32, MB33, MB34, MB35,
+ input CIN0, CIN1, CIN2, CIN3, CIN4, CIN5, CIN6, CIN7, CIN8, CIN9, CIN10, CIN11, CIN12, CIN13, CIN14, CIN15, CIN16, CIN17, CIN18, CIN19, CIN20, CIN21, CIN22, CIN23, CIN24, CIN25, CIN26, CIN27, CIN28, CIN29, CIN30, CIN31, CIN32, CIN33, CIN34, CIN35, CIN36, CIN37, CIN38, CIN39, CIN40, CIN41, CIN42, CIN43, CIN44, CIN45, CIN46, CIN47, CIN48, CIN49, CIN50, CIN51, CIN52, CIN53,
+ input OP0, OP1, OP2, OP3, OP4, OP5, OP6, OP7, OP8, OP9, OP10,
+ output R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, R26, R27, R28, R29, R30, R31, R32, R33, R34, R35, R36, R37, R38, R39, R40, R41, R42, R43, R44, R45, R46, R47, R48, R49, R50, R51, R52, R53,
+ output CO0, CO1, CO2, CO3, CO4, CO5, CO6, CO7, CO8, CO9, CO10, CO11, CO12, CO13, CO14, CO15, CO16, CO17, CO18, CO19, CO20, CO21, CO22, CO23, CO24, CO25, CO26, CO27, CO28, CO29, CO30, CO31, CO32, CO33, CO34, CO35, CO36, CO37, CO38, CO39, CO40, CO41, CO42, CO43, CO44, CO45, CO46, CO47, CO48, CO49, CO50, CO51, CO52, CO53,
+ output EQZ, EQZM, EQOM, EQPAT, EQPATB,
+ output OVER, UNDER, OVERUNDER,
+ output SIGNEDR
+);
+ parameter REG_INPUTC0_CLK = "NONE";
+ parameter REG_INPUTC1_CLK = "NONE";
+ parameter REG_OPCODEOP0_0_CLK = "NONE";
+ parameter REG_OPCODEOP0_0_CE = "CE0";
+ parameter REG_OPCODEOP0_0_RST = "RST0";
+ parameter REG_OPCODEOP1_0_CLK = "NONE";
+ parameter REG_OPCODEOP0_1_CLK = "NONE";
+ parameter REG_OPCODEOP0_1_CE = "CE0";
+ parameter REG_OPCODEOP0_1_RST = "RST0";
+ parameter REG_OPCODEIN_0_CLK = "NONE";
+ parameter REG_OPCODEIN_0_CE = "CE0";
+ parameter REG_OPCODEIN_0_RST = "RST0";
+ parameter REG_OPCODEIN_1_CLK = "NONE";
+ parameter REG_OPCODEIN_1_CE = "CE0";
+ parameter REG_OPCODEIN_1_RST = "RST0";
+ parameter REG_OUTPUT0_CLK = "NONE";
+ parameter REG_OUTPUT1_CLK = "NONE";
+ parameter REG_FLAG_CLK = "NONE";
+ parameter [127:0] MCPAT_SOURCE = "STATIC";
+ parameter [127:0] MASKPAT_SOURCE = "STATIC";
+ parameter MASK01 = "0x00000000000000";
+ parameter [127:0] CLK0_DIV = "ENABLED";
+ parameter [127:0] CLK1_DIV = "ENABLED";
+ parameter [127:0] CLK2_DIV = "ENABLED";
+ parameter [127:0] CLK3_DIV = "ENABLED";
+ parameter MCPAT = "0x00000000000000";
+ parameter MASKPAT = "0x00000000000000";
+ parameter RNDPAT = "0x00000000000000";
+ parameter [127:0] GSR = "ENABLED";
+ parameter [127:0] RESETMODE = "SYNC";
+ parameter FORCE_ZERO_BARREL_SHIFT = "DISABLED";
+ parameter LEGACY = "DISABLED";
+endmodule
diff --git a/techlibs/ecp5/synth_ecp5.cc b/techlibs/ecp5/synth_ecp5.cc
index cb6a4c3d8..825e131c4 100644
--- a/techlibs/ecp5/synth_ecp5.cc
+++ b/techlibs/ecp5/synth_ecp5.cc
@@ -203,7 +203,7 @@ struct SynthEcp5Pass : public ScriptPass
{
if (check_label("begin"))
{
- run("read_verilog -lib +/ecp5/cells_sim.v");
+ run("read_verilog -lib +/ecp5/cells_sim.v +/ecp5/cells_bb.v");
run(stringf("hierarchy -check %s", help_mode ? "-top <top>" : top_opt.c_str()));
}
diff --git a/tests/svinterfaces/run-test.sh b/tests/svinterfaces/run-test.sh
index 1630859bd..86567d1c1 100755
--- a/tests/svinterfaces/run-test.sh
+++ b/tests/svinterfaces/run-test.sh
@@ -3,3 +3,4 @@
./runone.sh svinterface1
+./runone.sh svinterface_at_top
diff --git a/tests/svinterfaces/runone.sh b/tests/svinterfaces/runone.sh
index 345801389..0adecc797 100755
--- a/tests/svinterfaces/runone.sh
+++ b/tests/svinterfaces/runone.sh
@@ -22,11 +22,14 @@ iverilog -g2012 ${TESTNAME}_syn.v
iverilog -g2012 ${TESTNAME}_ref_syn.v
set +e
-
iverilog -g2012 ${TESTNAME}_tb.v ${TESTNAME}_ref_syn.v
./a.out
mv output.txt reference_result.txt
-iverilog -g2012 ${TESTNAME}_tb.v ${TESTNAME}_syn.v
+if [ -f ${TESTNAME}_wrapper.v ] ; then
+ iverilog -g2012 ${TESTNAME}_tb_wrapper.v ${TESTNAME}_syn.v
+else
+ iverilog -g2012 ${TESTNAME}_tb.v ${TESTNAME}_syn.v
+fi
./a.out
mv output.txt dut_result.txt
diff --git a/tests/svinterfaces/svinterface_at_top.sv b/tests/svinterfaces/svinterface_at_top.sv
new file mode 100644
index 000000000..b5aa8c8f5
--- /dev/null
+++ b/tests/svinterfaces/svinterface_at_top.sv
@@ -0,0 +1,125 @@
+
+
+module TopModule(
+ input logic clk,
+ input logic rst,
+ output logic [21:0] outOther,
+ input logic [1:0] sig,
+ input logic flip,
+ output logic [1:0] sig_out,
+ MyInterface.submodule1 interfaceInstanceAtTop,
+ output logic [15:0] passThrough);
+
+ MyInterface #(.WIDTH(4)) MyInterfaceInstance();
+
+ SubModule1 u_SubModule1 (
+ .clk(clk),
+ .rst(rst),
+ .u_MyInterface(MyInterfaceInstance),
+ .u_MyInterfaceFromTop(interfaceInstanceAtTop),
+ .outOther(outOther),
+ .sig (sig)
+ );
+
+ assign sig_out = MyInterfaceInstance.mysig_out;
+
+
+ assign MyInterfaceInstance.setting = flip;
+
+ assign passThrough = MyInterfaceInstance.passThrough;
+
+endmodule
+
+interface MyInterface #(
+ parameter WIDTH = 3)(
+ );
+
+ logic setting;
+ logic [WIDTH-1:0] other_setting;
+
+ logic [1:0] mysig_out;
+
+ logic [15:0] passThrough;
+
+ modport submodule1 (
+ input setting,
+ output other_setting,
+ output mysig_out,
+ output passThrough
+ );
+
+ modport submodule2 (
+ input setting,
+ output other_setting,
+ input mysig_out,
+ output passThrough
+ );
+
+endinterface
+
+
+module SubModule1(
+ input logic clk,
+ input logic rst,
+ MyInterface.submodule1 u_MyInterface,
+ MyInterface.submodule1 u_MyInterfaceFromTop,
+ input logic [1:0] sig,
+ output logic [21:0] outOther
+
+ );
+
+
+ always_ff @(posedge clk or posedge rst)
+ if(rst)
+ u_MyInterface.mysig_out <= 0;
+ else begin
+ if(u_MyInterface.setting)
+ u_MyInterface.mysig_out <= sig;
+ else
+ u_MyInterface.mysig_out <= ~sig;
+ end
+
+ MyInterface #(.WIDTH(22)) MyInterfaceInstanceInSub();
+
+ SubModule2 u_SubModule2 (
+ .clk(clk),
+ .rst(rst),
+ .u_MyInterfaceFromTopDown(u_MyInterfaceFromTop),
+ .u_MyInterfaceInSub2(u_MyInterface),
+ .u_MyInterfaceInSub3(MyInterfaceInstanceInSub)
+ );
+
+ assign outOther = MyInterfaceInstanceInSub.other_setting;
+
+ assign MyInterfaceInstanceInSub.setting = 0;
+ assign MyInterfaceInstanceInSub.mysig_out = sig;
+
+endmodule
+
+module SubModule2(
+
+ input logic clk,
+ input logic rst,
+ MyInterface.submodule2 u_MyInterfaceInSub2,
+ MyInterface.submodule1 u_MyInterfaceFromTopDown,
+ MyInterface.submodule2 u_MyInterfaceInSub3
+
+ );
+
+ assign u_MyInterfaceFromTopDown.mysig_out = u_MyInterfaceFromTop.setting ? 10 : 20;
+
+ always_comb begin
+ if (u_MyInterfaceInSub3.mysig_out == 2'b00)
+ u_MyInterfaceInSub3.other_setting[21:0] = 1000;
+ else if (u_MyInterfaceInSub3.mysig_out == 2'b01)
+ u_MyInterfaceInSub3.other_setting[21:0] = 2000;
+ else if (u_MyInterfaceInSub3.mysig_out == 2'b10)
+ u_MyInterfaceInSub3.other_setting[21:0] = 3000;
+ else
+ u_MyInterfaceInSub3.other_setting[21:0] = 4000;
+ end
+
+ assign u_MyInterfaceInSub2.passThrough[7:0] = 124;
+ assign u_MyInterfaceInSub2.passThrough[15:8] = 200;
+
+endmodule
diff --git a/tests/svinterfaces/svinterface_at_top_ref.v b/tests/svinterfaces/svinterface_at_top_ref.v
new file mode 100644
index 000000000..7b54a26d6
--- /dev/null
+++ b/tests/svinterfaces/svinterface_at_top_ref.v
@@ -0,0 +1,120 @@
+
+module TopModule(
+ input logic clk,
+ input logic rst,
+ input logic [1:0] sig,
+ input logic flip,
+ output logic [15:0] passThrough,
+ output logic [21:0] outOther,
+ input logic interfaceInstanceAtTop_setting,
+ output logic [2:0] interfaceInstanceAtTop_other_setting,
+ output logic [1:0] interfaceInstanceAtTop_mysig_out,
+ output logic [15:0] interfaceInstanceAtTop_passThrough,
+ output logic [1:0] sig_out);
+
+
+ logic MyInterfaceInstance_setting;
+ logic [3:0] MyInterfaceInstance_other_setting;
+ logic [1:0] MyInterfaceInstance_mysig_out;
+
+ SubModule1 u_SubModule1 (
+ .clk(clk),
+ .rst(rst),
+ .u_MyInterface_setting(MyInterfaceInstance_setting),
+ .u_MyInterface_mysig_out(MyInterfaceInstance_mysig_out),
+ .u_MyInterface_other_setting(MyInterfaceInstance_other_setting),
+ .u_MyInterfaceFromTop_setting(interfaceInstanceAtTop_setting),
+ .u_MyInterfaceFromTop_other_setting(interfaceInstanceAtTop_other_setting),
+ .u_MyInterfaceFromTop_mysig_out(interfaceInstanceAtTop_mysig_out),
+ .u_MyInterfaceFromTop_passThrough(interfaceInstanceAtTop_passThrough),
+ .outOther(outOther),
+ .passThrough (passThrough),
+ .sig (sig)
+ );
+
+ assign sig_out = MyInterfaceInstance_mysig_out;
+
+
+ assign MyInterfaceInstance_setting = flip;
+
+endmodule
+
+
+module SubModule1(
+ input logic clk,
+ input logic rst,
+ input logic u_MyInterface_setting,
+ output logic [3:0] u_MyInterface_other_setting,
+ output logic [1:0] u_MyInterface_mysig_out,
+ output logic [21:0] outOther,
+ input logic [1:0] sig,
+ input logic u_MyInterfaceFromTop_setting,
+ output logic [2:0] u_MyInterfaceFromTop_other_setting,
+ output logic [1:0] u_MyInterfaceFromTop_mysig_out,
+ output logic [14:0] u_MyInterfaceFromTop_passThrough,
+ output logic [15:0] passThrough
+ );
+
+ always @(posedge clk or posedge rst)
+ if(rst)
+ u_MyInterface_mysig_out <= 0;
+ else begin
+ if(u_MyInterface_setting)
+ u_MyInterface_mysig_out <= sig;
+ else
+ u_MyInterface_mysig_out <= ~sig;
+ end
+
+ logic MyInterfaceInstanceInSub_setting;
+ logic [21:0] MyInterfaceInstanceInSub_other_setting;
+ logic [1:0] MyInterfaceInstanceInSub_mysig_out;
+
+ assign u_MyInterfaceFromTop_mysig_out = u_MyInterfaceFromTop_setting ? 10 : 20;
+
+ SubModule2 u_SubModule2 (
+ .clk(clk),
+ .rst(rst),
+ .u_MyInterfaceInSub2_setting(u_MyInterface_setting),
+ .u_MyInterfaceInSub2_mysig_out(u_MyInterface_mysig_out),
+ .u_MyInterfaceInSub2_other_setting(u_MyInterface_other_setting),
+ .u_MyInterfaceInSub3_setting(MyInterfaceInstanceInSub_setting),
+ .u_MyInterfaceInSub3_mysig_out(MyInterfaceInstanceInSub_mysig_out),
+ .u_MyInterfaceInSub3_other_setting(MyInterfaceInstanceInSub_other_setting),
+ .passThrough (passThrough)
+ );
+ assign outOther = MyInterfaceInstanceInSub_other_setting;
+
+ assign MyInterfaceInstanceInSub_setting = 0;
+ assign MyInterfaceInstanceInSub_mysig_out = sig;
+
+endmodule
+
+module SubModule2(
+
+ input logic clk,
+ input logic rst,
+ input logic u_MyInterfaceInSub2_setting,
+ output logic [3:0] u_MyInterfaceInSub2_other_setting,
+ input logic [1:0] u_MyInterfaceInSub2_mysig_out,
+ input logic u_MyInterfaceInSub3_setting,
+ output logic [21:0] u_MyInterfaceInSub3_other_setting,
+ input logic [1:0] u_MyInterfaceInSub3_mysig_out,
+ output logic [15:0] passThrough
+
+ );
+
+ always @(u_MyInterfaceInSub3_mysig_out) begin
+ if (u_MyInterfaceInSub3_mysig_out == 2'b00)
+ u_MyInterfaceInSub3_other_setting[21:0] = 1000;
+ else if (u_MyInterfaceInSub3_mysig_out == 2'b01)
+ u_MyInterfaceInSub3_other_setting[21:0] = 2000;
+ else if (u_MyInterfaceInSub3_mysig_out == 2'b10)
+ u_MyInterfaceInSub3_other_setting[21:0] = 3000;
+ else
+ u_MyInterfaceInSub3_other_setting[21:0] = 4000;
+ end
+
+ assign passThrough[7:0] = 124;
+ assign passThrough[15:8] = 200;
+
+endmodule
diff --git a/tests/svinterfaces/svinterface_at_top_tb.v b/tests/svinterfaces/svinterface_at_top_tb.v
new file mode 100644
index 000000000..bf37a148d
--- /dev/null
+++ b/tests/svinterfaces/svinterface_at_top_tb.v
@@ -0,0 +1,68 @@
+`timescale 1ns/10ps
+
+module svinterface_at_top_tb;
+
+
+ logic clk;
+ logic rst;
+ logic [21:0] outOther;
+ logic [1:0] sig;
+ logic [1:0] sig_out;
+ logic flip;
+ logic [15:0] passThrough;
+ integer outfile;
+
+ logic interfaceInstanceAtTop_setting;
+ logic [2:0] interfaceInstanceAtTop_other_setting;
+ logic [1:0] interfaceInstanceAtTop_mysig_out;
+ logic [15:0] interfaceInstanceAtTop_passThrough;
+
+
+ TopModule u_dut (
+ .clk(clk),
+ .rst(rst),
+ .outOther(outOther),
+ .sig(sig),
+ .flip(flip),
+ .passThrough(passThrough),
+ .interfaceInstanceAtTop_setting(interfaceInstanceAtTop_setting),
+ .interfaceInstanceAtTop_other_setting(interfaceInstanceAtTop_other_setting),
+ .interfaceInstanceAtTop_mysig_out(interfaceInstanceAtTop_mysig_out),
+ .interfaceInstanceAtTop_passThrough(interfaceInstanceAtTop_passThrough),
+ .sig_out(sig_out)
+ );
+
+ initial begin
+ clk = 0;
+ while(1) begin
+ clk = ~clk;
+ #50;
+ end
+ end
+
+ initial begin
+ outfile = $fopen("output.txt");
+ rst = 1;
+ interfaceInstanceAtTop_setting = 0;
+ sig = 0;
+ flip = 0;
+ @(posedge clk);
+ #(2);
+ rst = 0;
+ @(posedge clk);
+ for(int j=0;j<2;j++) begin
+ for(int i=0;i<20;i++) begin
+ #(2);
+ flip = j;
+ sig = i;
+ @(posedge clk);
+ end
+ end
+ $finish;
+ end
+
+ always @(negedge clk) begin
+ $fdisplay(outfile, "%d %d %d %d", outOther, sig_out, passThrough, interfaceInstanceAtTop_mysig_out);
+ end
+
+endmodule
diff --git a/tests/svinterfaces/svinterface_at_top_tb_wrapper.v b/tests/svinterfaces/svinterface_at_top_tb_wrapper.v
new file mode 100644
index 000000000..b344a7b88
--- /dev/null
+++ b/tests/svinterfaces/svinterface_at_top_tb_wrapper.v
@@ -0,0 +1,68 @@
+`timescale 1ns/10ps
+
+module svinterface_at_top_tb_wrapper;
+
+
+ logic clk;
+ logic rst;
+ logic [21:0] outOther;
+ logic [1:0] sig;
+ logic [1:0] sig_out;
+ logic flip;
+ logic [15:0] passThrough;
+ integer outfile;
+
+ logic interfaceInstanceAtTop_setting;
+ logic [2:0] interfaceInstanceAtTop_other_setting;
+ logic [1:0] interfaceInstanceAtTop_mysig_out;
+ logic [15:0] interfaceInstanceAtTop_passThrough;
+
+
+ TopModule u_dut (
+ .clk(clk),
+ .rst(rst),
+ .outOther(outOther),
+ .sig(sig),
+ .flip(flip),
+ .passThrough(passThrough),
+ .\interfaceInstanceAtTop.setting (interfaceInstanceAtTop_setting),
+ .\interfaceInstanceAtTop.other_setting (interfaceInstanceAtTop_other_setting),
+ .\interfaceInstanceAtTop.mysig_out (interfaceInstanceAtTop_mysig_out),
+ .\interfaceInstanceAtTop.passThrough (interfaceInstanceAtTop_passThrough),
+ .sig_out(sig_out)
+ );
+
+ initial begin
+ clk = 0;
+ while(1) begin
+ clk = ~clk;
+ #50;
+ end
+ end
+
+ initial begin
+ outfile = $fopen("output.txt");
+ rst = 1;
+ sig = 0;
+ interfaceInstanceAtTop_setting = 0;
+ flip = 0;
+ @(posedge clk);
+ #(2);
+ rst = 0;
+ @(posedge clk);
+ for(int j=0;j<2;j++) begin
+ for(int i=0;i<20;i++) begin
+ #(2);
+ flip = j;
+ sig = i;
+ @(posedge clk);
+ end
+ end
+ $finish;
+ end
+
+ always @(negedge clk) begin
+ $fdisplay(outfile, "%d %d %d %d", outOther, sig_out, passThrough, interfaceInstanceAtTop_mysig_out);
+ end
+
+endmodule
diff --git a/tests/svinterfaces/svinterface_at_top_wrapper.v b/tests/svinterfaces/svinterface_at_top_wrapper.v
new file mode 100644
index 000000000..64f906c07
--- /dev/null
+++ b/tests/svinterfaces/svinterface_at_top_wrapper.v
@@ -0,0 +1,33 @@
+`timescale 1ns/10ps
+
+module svinterface_at_top_wrapper(
+ input logic clk,
+ input logic rst,
+ output logic [21:0] outOther,
+ input logic [1:0] sig,
+ output logic [1:0] sig_out,
+ input logic flip,
+ output logic [15:0] passThrough,
+
+ input logic interfaceInstanceAtTop_setting,
+ output logic [2:0] interfaceInstanceAtTop_other_setting,
+ output logic [1:0] interfaceInstanceAtTop_mysig_out,
+ output logic [15:0] interfaceInstanceAtTop_passThrough,
+ );
+
+
+ TopModule u_dut (
+ .clk(clk),
+ .rst(rst),
+ .outOther(outOther),
+ .sig(sig),
+ .flip(flip),
+ .passThrough(passThrough),
+ .\interfaceInstanceAtTop.setting(interfaceInstanceAtTop_setting),
+ .\interfaceInstanceAtTop.other_setting(interfaceInstanceAtTop_other_setting),
+ .\interfaceInstanceAtTop.mysig_out(interfaceInstanceAtTop_mysig_out),
+ .\interfaceInstanceAtTop.passThrough(interfaceInstanceAtTop_passThrough),
+ .sig_out(sig_out)
+ );
+
+endmodule