Skip to content

Commit 0515b1e

Browse files
committed
improved error message following #108 (comment)
1 parent 5fa9ed9 commit 0515b1e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/Algorithm.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ Algorithm::t_combinational_block *Algorithm::gatherSubroutine(siliceParser::Subr
18781878
"cannot find subroutine '%s' declared called by subroutine '%s'",
18791879
P->IDENTIFIER()->getText().c_str(), nfo->name.c_str());
18801880
}
1881+
nfo->allowed_calls.insert(P->IDENTIFIER()->getText());
18811882
// add all inputs/outputs
18821883
for (auto ins : S->second->inputs) {
18831884
nfo->allowed_writes.insert(S->second->vios.at(ins));
@@ -2215,6 +2216,17 @@ Algorithm::t_combinational_block* Algorithm::gatherSyncExec(siliceParser::SyncEx
22152216
// are we calling a subroutine?
22162217
auto S = m_Subroutines.find(sync->joinExec()->IDENTIFIER()->getText());
22172218
if (S != m_Subroutines.end()) {
2219+
// are we in a subroutine?
2220+
if (_current->context.subroutine) {
2221+
// verify the call is allowed
2222+
if (_current->context.subroutine->allowed_calls.count(S->first) == 0) {
2223+
reportError(sync->getSourceInterval(), -1,
2224+
"subroutine '%s' calls other subroutine '%s' without permssion\n\
2225+
add 'calls %s' to declaration if that was intended.",
2226+
_current->context.subroutine->name.c_str(),
2227+
S->first.c_str(), S->first.c_str());
2228+
}
2229+
}
22182230
// yes! create a new block, call subroutine
22192231
t_combinational_block* after = addBlock(generateBlockName(), _current, nullptr, sync->getSourceInterval());
22202232
// has to be a state to return to

src/Algorithm.h

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ namespace Silice
275275
t_combinational_block *top_block;
276276
std::unordered_set<std::string> allowed_reads;
277277
std::unordered_set<std::string> allowed_writes;
278+
std::unordered_set<std::string> allowed_calls;
278279
std::unordered_map<std::string, std::string> vios; // [subroutine space => translated var name in host]
279280
std::vector<std::string> inputs; // ordered list of input names (subroutine space)
280281
std::vector<std::string> outputs; // ordered list of output names (subroutine space)

tests/issues/108_rw_perm.ice

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ algorithm main(output uint5 leds) {
66
leds = pattern;
77
}
88

9-
subroutine out_led_inverted(input uint5 pattern, calls out_led) {
9+
subroutine out_led_inverted(input uint5 pattern,
10+
// calls out_led // uncomment to fix
11+
) {
1012
() <- out_led <- (~pattern);
1113
}
1214

0 commit comments

Comments
 (0)