Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for unconnected multiport and bank reactor bug #1953

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ private static String deferredInitializeNonNested(
CTypes types) {
var code = new CodeBuilder();
code.pr("// **** Start non-nested deferred initialize for " + reactor.getFullName());
// Initialization within a for loop iterating
// over bank members of reactor
code.startScopedBlock(reactor);
// Initialize the num_destinations fields of port structs on the self struct.
// This needs to be outside the above scoped block because it performs
// its own iteration over ranges.
Expand All @@ -830,6 +833,7 @@ private static String deferredInitializeNonNested(
for (ReactorInstance child : reactor.children) {
code.pr(deferredInitializeNonNested(child, main, child.reactions, types));
}
code.endScopedBlock();
code.pr("// **** End of non-nested deferred initialize for " + reactor.getFullName());
return code.toString();
}
Expand Down
44 changes: 44 additions & 0 deletions test/C/src/multiport/MultiBank_UnconnectedOutput_Test.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
target C {
workers: 1
}

reactor echo<entry_T>(bank_index: int = 0) {
input request: entry_T
output response: entry_T

output unconnected: entry_T

reaction(request) -> response {=
int req = request->value;
lf_set (response, request->value);
=}
}

reactor testing_echo(bank_index: int = 0) {
output req: int
input resp: int

state seed: uint32_t = 0

reaction(startup) -> req {=
lf_set (req, 42 + self->bank_index);
=}

reaction(resp) {=
int sum = self->bank_index + 42;
int received = resp->value;
printf("Bank index: %d, received: %d\n", self->bank_index, received);
if (received != sum) {
printf("Wrong value. Should have been %d.\n", sum);
exit(1);
}
=}
}

main reactor MultiBank_UnconnectedOutput_Test {
test = new[2] testing_echo()
e = new[2] echo<int>()

test.req -> e.request
e.response -> test.resp
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
target C {
workers: 1
}

reactor adder<entry_T>(n_ports: int = 1) {
input[n_ports] add_request: entry_T
output add_response: entry_T

output[n_ports] unconnected: entry_T

state sum: entry_T = 0

reaction(add_request) -> add_response {=
for (int i = 0; i < add_request_width; ++i) {
if (add_request[i]->is_present) {
self->sum += add_request[i]->value;
}
}
lf_set (add_response, self->sum);
self->sum = 0;
=}
}

reactor testing_adder(bank_index: int = 0, bank_width: int = 1) {
output add_req: int
output result_req: int

input add_resp: int
input unconnected: int

reaction(startup) -> add_req {=
lf_set (add_req, 42);
=}

reaction(add_resp) {=
int sum = self->bank_width * 42;
int received = add_resp->value;
printf("Bank index: %d, received: %d\n", self->bank_index, received);
if (received != sum) {
printf("Wrong value. Should have been %d.\n", sum);
exit(1);
}
=}
}

main reactor MultiPort_MultiBankTest_UnconnectedOutput_Test {
test = new[2] testing_adder(bank_width=2)
a = new adder<int>(n_ports=2)

test.add_req -> a.add_request
(a.add_response)+ -> test.add_resp
}