From 088604c2f1a45f1187b60312afca8a115377bd64 Mon Sep 17 00:00:00 2001 From: Sylvain Lefebvre Date: Wed, 8 Nov 2023 19:47:12 +0100 Subject: [PATCH] hardware targets explicitly ignore non-synthesizable primitives (__display,__write,__finish) with a warning (#256) --- frameworks/boards/formal/formal.v | 22 +++++++------ frameworks/boards/icarus/icarus.v | 3 ++ frameworks/boards/verilator/verilator.v | 3 ++ src/Algorithm.cpp | 43 ++++++++++++++++--------- src/Config.cpp | 4 +++ tests/Makefile.icestick | 6 ++++ tests/nonsynth1.si | 6 ++++ 7 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 tests/Makefile.icestick create mode 100644 tests/nonsynth1.si diff --git a/frameworks/boards/formal/formal.v b/frameworks/boards/formal/formal.v index 1d47706f..bbf2b5b5 100644 --- a/frameworks/boards/formal/formal.v +++ b/frameworks/boards/formal/formal.v @@ -5,21 +5,21 @@ List contributors with: git shortlog -n -s -- MIT license -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (header_2_M) @@ -29,6 +29,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. $$FORMAL=1 $$NUM_LEDS=8 +$$config['__display_supported'] = 'yes' +$$config['__write_supported'] = 'yes' +$$config['__finish_supported'] = 'yes' + module top(); // do nothing endmodule diff --git a/frameworks/boards/icarus/icarus.v b/frameworks/boards/icarus/icarus.v index 4c78ccde..99daec37 100644 --- a/frameworks/boards/icarus/icarus.v +++ b/frameworks/boards/icarus/icarus.v @@ -37,6 +37,9 @@ $$config['bram_wenable_width'] = '1' $$config['dualport_bram_wenable0_width'] = 'data' $$config['dualport_bram_wenable1_width'] = 'data' $$config['reg_init_zero'] = '1' +$$config['__display_supported'] = 'yes' +$$config['__write_supported'] = 'yes' +$$config['__finish_supported'] = 'yes' `timescale 1ns / 1ps diff --git a/frameworks/boards/verilator/verilator.v b/frameworks/boards/verilator/verilator.v index 29713348..c9bb0dee 100644 --- a/frameworks/boards/verilator/verilator.v +++ b/frameworks/boards/verilator/verilator.v @@ -35,6 +35,9 @@ $$NUM_LEDS = 8 $$SIMULATION = 1 $$color_depth = 6 $$color_max = 63 +$$config['__display_supported'] = 'yes' +$$config['__write_supported'] = 'yes' +$$config['__finish_supported'] = 'yes' `timescale 1ns / 1ps `default_nettype none diff --git a/src/Algorithm.cpp b/src/Algorithm.cpp index 77ec74a2..42723bbe 100644 --- a/src/Algorithm.cpp +++ b/src/Algorithm.cpp @@ -8134,24 +8134,28 @@ void Algorithm::writeBlock(std::string prefix, t_writer_context &w, } { auto display = dynamic_cast(a.instr); if (display) { - if (display->DISPLAY() != nullptr) { - w.out << "$display("; - } else if (display->DISPLWRITE() != nullptr) { - w.out << "$write("; - } - w.out << display->STRING()->getText(); - if (display->callParamList() != nullptr) { - std::vector params; - getCallParams(display->callParamList(),params, &block->context); - for (auto p : params) { - if (std::holds_alternative(p.what)) { - w.out << "," << rewriteIdentifier(prefix, std::get(p.what), "", &block->context, ictx, sourceloc(display), FF_Q, true, _dependencies, _ff_usage); - } else { - w.out << "," << rewriteExpression(prefix, p.expression, a.__id, &block->context, ictx, FF_Q, true, _dependencies, _ff_usage); + // check support + std::string instr = display->DISPLAY() != nullptr ? "display" : "write"; + auto C = CONFIG.keyValues().find("__" + instr + "_supported"); + if (C->second != "yes") { + warn(Standard, sourceloc(display), ("__" + instr + " not supported on this target, ignored").c_str()); + } else { + // add to code + w.out << "$" << instr << "("; + w.out << display->STRING()->getText(); + if (display->callParamList() != nullptr) { + std::vector params; + getCallParams(display->callParamList(), params, &block->context); + for (auto p : params) { + if (std::holds_alternative(p.what)) { + w.out << "," << rewriteIdentifier(prefix, std::get(p.what), "", &block->context, ictx, sourceloc(display), FF_Q, true, _dependencies, _ff_usage); + } else { + w.out << "," << rewriteExpression(prefix, p.expression, a.__id, &block->context, ictx, FF_Q, true, _dependencies, _ff_usage); + } } } + w.out << ");" << nxl; } - w.out << ");" << nxl; } } { auto inline_v = dynamic_cast(a.instr); @@ -8187,7 +8191,14 @@ void Algorithm::writeBlock(std::string prefix, t_writer_context &w, } { auto finish = dynamic_cast(a.instr); if (finish) { - w.out << "$finish();" << nxl; + // check support + auto C = CONFIG.keyValues().find("__finish_supported"); + if (C->second != "yes") { + warn(Standard, sourceloc(finish), "__finish not supported on this target, ignored"); + } else { + // add to code + w.out << "$finish();" << nxl; + } } } { auto stall = dynamic_cast(a.instr); diff --git a/src/Config.cpp b/src/Config.cpp index e6f44ee5..6cfc9f3f 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -66,6 +66,10 @@ Config::Config() m_KeyValues["simple_dualport_bram_wenable1_type"] = "uint"; // uint | int | data m_KeyValues["simple_dualport_bram_wenable1_width"] = "1"; // 1 | data + m_KeyValues["__display_supported"] = "no"; + m_KeyValues["__write_supported"] = "no"; + m_KeyValues["__finish_supported"] = "no"; + // internal options m_KeyValues["output_fsm_graph"] = "1"; } diff --git a/tests/Makefile.icestick b/tests/Makefile.icestick new file mode 100644 index 00000000..ec3c61c7 --- /dev/null +++ b/tests/Makefile.icestick @@ -0,0 +1,6 @@ + +.DEFAULT: $@.si.lpp + silice-make.py -s $@.si -b icestick -p basic -o BUILD_$(subst :,_,$@) $(ARGS) + +clean: + rm -rf BUILD_* diff --git a/tests/nonsynth1.si b/tests/nonsynth1.si new file mode 100644 index 00000000..70437865 --- /dev/null +++ b/tests/nonsynth1.si @@ -0,0 +1,6 @@ +unit main(output uint8 leds) +{ + algorithm { + __display("hello world"); + } +}