Skip to content

Commit

Permalink
improved error message following #108 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylefeb committed Dec 25, 2021
1 parent 5fa9ed9 commit 0515b1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,7 @@ Algorithm::t_combinational_block *Algorithm::gatherSubroutine(siliceParser::Subr
"cannot find subroutine '%s' declared called by subroutine '%s'",
P->IDENTIFIER()->getText().c_str(), nfo->name.c_str());
}
nfo->allowed_calls.insert(P->IDENTIFIER()->getText());
// add all inputs/outputs
for (auto ins : S->second->inputs) {
nfo->allowed_writes.insert(S->second->vios.at(ins));
Expand Down Expand Up @@ -2215,6 +2216,17 @@ Algorithm::t_combinational_block* Algorithm::gatherSyncExec(siliceParser::SyncEx
// are we calling a subroutine?
auto S = m_Subroutines.find(sync->joinExec()->IDENTIFIER()->getText());
if (S != m_Subroutines.end()) {
// are we in a subroutine?
if (_current->context.subroutine) {
// verify the call is allowed
if (_current->context.subroutine->allowed_calls.count(S->first) == 0) {
reportError(sync->getSourceInterval(), -1,
"subroutine '%s' calls other subroutine '%s' without permssion\n\
add 'calls %s' to declaration if that was intended.",
_current->context.subroutine->name.c_str(),
S->first.c_str(), S->first.c_str());
}
}
// yes! create a new block, call subroutine
t_combinational_block* after = addBlock(generateBlockName(), _current, nullptr, sync->getSourceInterval());
// has to be a state to return to
Expand Down
1 change: 1 addition & 0 deletions src/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace Silice
t_combinational_block *top_block;
std::unordered_set<std::string> allowed_reads;
std::unordered_set<std::string> allowed_writes;
std::unordered_set<std::string> allowed_calls;
std::unordered_map<std::string, std::string> vios; // [subroutine space => translated var name in host]
std::vector<std::string> inputs; // ordered list of input names (subroutine space)
std::vector<std::string> outputs; // ordered list of output names (subroutine space)
Expand Down
4 changes: 3 additions & 1 deletion tests/issues/108_rw_perm.ice
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ algorithm main(output uint5 leds) {
leds = pattern;
}

subroutine out_led_inverted(input uint5 pattern, calls out_led) {
subroutine out_led_inverted(input uint5 pattern,
// calls out_led // uncomment to fix
) {
() <- out_led <- (~pattern);
}

Expand Down

0 comments on commit 0515b1e

Please sign in to comment.