Skip to content

Commit

Permalink
hardware targets explicitly ignore non-synthesizable primitives (__di…
Browse files Browse the repository at this point in the history
…splay,__write,__finish) with a warning (#256)
  • Loading branch information
sylefeb committed Nov 8, 2023
1 parent d4fa1bd commit 088604c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
22 changes: 13 additions & 9 deletions frameworks/boards/formal/formal.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ List contributors with: git shortlog -n -s -- <filename>
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)
Expand All @@ -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
3 changes: 3 additions & 0 deletions frameworks/boards/icarus/icarus.v
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions frameworks/boards/verilator/verilator.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 27 additions & 16 deletions src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8134,24 +8134,28 @@ void Algorithm::writeBlock(std::string prefix, t_writer_context &w,
} {
auto display = dynamic_cast<siliceParser::DisplayContext *>(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<t_call_param> params;
getCallParams(display->callParamList(),params, &block->context);
for (auto p : params) {
if (std::holds_alternative<std::string>(p.what)) {
w.out << "," << rewriteIdentifier(prefix, std::get<std::string>(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<t_call_param> params;
getCallParams(display->callParamList(), params, &block->context);
for (auto p : params) {
if (std::holds_alternative<std::string>(p.what)) {
w.out << "," << rewriteIdentifier(prefix, std::get<std::string>(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<siliceParser::Inline_vContext *>(a.instr);
Expand Down Expand Up @@ -8187,7 +8191,14 @@ void Algorithm::writeBlock(std::string prefix, t_writer_context &w,
} {
auto finish = dynamic_cast<siliceParser::FinishContext *>(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<siliceParser::StallContext *>(a.instr);
Expand Down
4 changes: 4 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Makefile.icestick
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

.DEFAULT: [email protected]
silice-make.py -s [email protected] -b icestick -p basic -o BUILD_$(subst :,_,$@) $(ARGS)

clean:
rm -rf BUILD_*
6 changes: 6 additions & 0 deletions tests/nonsynth1.si
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
unit main(output uint8 leds)
{
algorithm {
__display("hello world");
}
}

0 comments on commit 088604c

Please sign in to comment.