Skip to content

Commit bec171d

Browse files
committed
check illegal cells at end of synthesis
1 parent 3a08bd1 commit bec171d

1 file changed

Lines changed: 122 additions & 5 deletions

File tree

src/synth_fpga.cc

Lines changed: 122 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,10 @@ struct SynthFpgaPass : public ScriptPass {
841841
log_error("Please select a correct BRAM architecture.\n");
842842
}
843843

844-
if ((sc_syn_lut_size != "4") && (sc_syn_lut_size != "6")) {
845-
log_error("Lut sizes can be only 4 or 6.\n");
844+
if ((sc_syn_lut_size != "4") &&
845+
(sc_syn_lut_size != "5") &&
846+
(sc_syn_lut_size != "6")) {
847+
log_error("Lut sizes can be only 4, 5 or 6.\n");
846848
}
847849

848850
if ((sc_syn_fsm_encoding != "one-hot") &&
@@ -2059,12 +2061,12 @@ struct SynthFpgaPass : public ScriptPass {
20592061
}
20602062

20612063
// -------------------------
2062-
// checkDLatch
2064+
// check_DLatch
20632065
// -------------------------
20642066
// Check presence of Latch and either error out or continue with
20652067
// warning.
20662068
//
2067-
void checkDLatch() {
2069+
void check_DLatch() {
20682070

20692071
int foundLatch = 0;
20702072

@@ -2095,6 +2097,116 @@ struct SynthFpgaPass : public ScriptPass {
20952097
}
20962098
}
20972099

2100+
// -------------------------
2101+
// check_illegal_cells
2102+
// -------------------------
2103+
// Check presence of illegal cells (typicaly $DFF/$SDFF) in the
2104+
// final netlist that would fail the P&R downstream flow.
2105+
//
2106+
// Error out if this is the case.
2107+
//
2108+
void check_illegal_cells() {
2109+
2110+
int nb_cells_to_list = 10;
2111+
int found_illegal = 0;
2112+
2113+
pool<string> cell_exact_name; // set of exact illegal cell names to check
2114+
pool<string> cell_substr_name; // set of sub string illegal cell names to check
2115+
2116+
// exact name case to check
2117+
//cell_exact_name.insert("dffer");
2118+
2119+
// substr name case to check
2120+
//
2121+
cell_substr_name.insert("$");
2122+
2123+
if (!yosys_get_design()) {
2124+
log_warning("Design seems empty ! (did you define the -top or use "
2125+
"'hierarchy -auto-top' before)\n");
2126+
return;
2127+
}
2128+
2129+
log("Check for illegal cells in the design ...\n");
2130+
2131+
// Fo all the cells ...
2132+
//
2133+
for (auto cell : yosys_get_design()->top_module()->cells()) {
2134+
2135+
#if 1
2136+
if (cell->type == "$lut") { // The only acceptable case with cell name
2137+
// starting with '$'.
2138+
continue;
2139+
}
2140+
#endif
2141+
2142+
// Check cell name in substr name case
2143+
//
2144+
for (auto s : cell_substr_name) {
2145+
2146+
// Flag error for any cells starting with 's'.
2147+
//
2148+
if ((cell->type).substr(0, s.size()) == s) {
2149+
2150+
// List only the first 'nb_cells_to_list' cells ...
2151+
//
2152+
if (found_illegal > nb_cells_to_list) {
2153+
log("...\n");
2154+
break;
2155+
}
2156+
2157+
found_illegal++;
2158+
2159+
log("Found illegal cell '%s' (%s)\n", log_id(cell),
2160+
log_id(cell->type));
2161+
}
2162+
2163+
if (found_illegal > nb_cells_to_list) {
2164+
break;
2165+
}
2166+
}
2167+
2168+
if (found_illegal > nb_cells_to_list) {
2169+
break;
2170+
}
2171+
2172+
// Check cell name in exact name case
2173+
//
2174+
for (auto s : cell_exact_name) {
2175+
2176+
// Flag error for any cells with exact name 's'.
2177+
//
2178+
if (log_id(cell->type) == s) {
2179+
2180+
// List only the first 'nb_cells_to_list' cells ...
2181+
//
2182+
if (found_illegal > nb_cells_to_list) {
2183+
log("...\n");
2184+
break;
2185+
}
2186+
2187+
found_illegal++;
2188+
2189+
log("Found illegal cell '%s' (%s)\n", log_id(cell),
2190+
log_id(cell->type));
2191+
}
2192+
2193+
if (found_illegal > nb_cells_to_list) {
2194+
break;
2195+
}
2196+
}
2197+
2198+
if (found_illegal > nb_cells_to_list) {
2199+
break;
2200+
}
2201+
2202+
}
2203+
2204+
if (found_illegal) {
2205+
log_error("Cannot proceed further : some illegal cells found in the design.\n");
2206+
}
2207+
2208+
}
2209+
20982210
// -------------------------
20992211
// optimize_DFFs
21002212
// -------------------------
@@ -3424,7 +3536,7 @@ struct SynthFpgaPass : public ScriptPass {
34243536
// Make sure we have no LATCH otherwise eventually error out depending on
34253537
// the command line option '-continue_if_latch'.
34263538
//
3427-
checkDLatch();
3539+
check_DLatch();
34283540

34293541
// Try to detect stuck-at DFF either through SAT solver or constant
34303542
// detection at DFF inputs.
@@ -3597,6 +3709,11 @@ struct SynthFpgaPass : public ScriptPass {
35973709
dump_csv_file("stat.csv", (int)totalTime);
35983710
}
35993711

3712+
// Error out if illegal cells are in the netlist instead of erroring out
3713+
// in P&R.
3714+
//
3715+
check_illegal_cells();
3716+
36003717
log("\n");
36013718
log("***********************************\n");
36023719
log("** Zero Asic FPGA Synthesis Done **\n");

0 commit comments

Comments
 (0)