-
Notifications
You must be signed in to change notification settings - Fork 15
(C backend) minting 16 or more short's by prefixing i creates potentially illegal C code #134
Copy link
Copy link
Open
Description
For foreach loops, Orcc pulls apart the condition expression and mints scalar variable names like i0, i1, j0, j1, and so on. E.g. the following CAL
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
Becomes
u16 x;
i16 i;
i16 i0;
x = 0;
i = 0;
while (i <= 2) {
x = x + i;
i = i + 1;
}
i0 = 0;
while (i0 <= 2) {
x = x + i0;
i0 = i0 + 1;
}
Where i16 is defined in libs/orcc-runtime/inclues/types.h.
typedef short i16;
There is a corner case when there exists more than 16 foreach statements in an action. Here, the variable name i16 is created, and the declaration for i16 inside the function hides the typedef declaration for i16 as a typedef name. E.g.
actor Foo() ==> :
my_action: action ==>
var uint(size=16) x := 0
do
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
foreach int(size=16) i in 0 .. 2 do x := x+i; end
println(x);
end
end
Gets compiled to:
static void my_action() {
u16 x;
i16 i;
i16 i0;
i16 i1;
i16 i2;
i16 i3;
i16 i4;
i16 i5;
i16 i6;
i16 i7;
i16 i8;
i16 i9;
i16 i10;
i16 i11;
i16 i12;
i16 i13;
i16 i14;
i16 i15;
i16 i16;
i16 i17;
x = 0;
i = 0;
while (i <= 2) {
x = x + i;
i = i + 1;
}
i0 = 0;
while (i0 <= 2) {
x = x + i0;
i0 = i0 + 1;
}
i1 = 0;
while (i1 <= 2) {
x = x + i1;
i1 = i1 + 1;
}
i2 = 0;
while (i2 <= 2) {
x = x + i2;
i2 = i2 + 1;
}
i3 = 0;
while (i3 <= 2) {
x = x + i3;
i3 = i3 + 1;
}
i4 = 0;
while (i4 <= 2) {
x = x + i4;
i4 = i4 + 1;
}
i5 = 0;
while (i5 <= 2) {
x = x + i5;
i5 = i5 + 1;
}
i6 = 0;
while (i6 <= 2) {
x = x + i6;
i6 = i6 + 1;
}
i7 = 0;
while (i7 <= 2) {
x = x + i7;
i7 = i7 + 1;
}
i8 = 0;
while (i8 <= 2) {
x = x + i8;
i8 = i8 + 1;
}
i9 = 0;
while (i9 <= 2) {
x = x + i9;
i9 = i9 + 1;
}
i10 = 0;
while (i10 <= 2) {
x = x + i10;
i10 = i10 + 1;
}
i11 = 0;
while (i11 <= 2) {
x = x + i11;
i11 = i11 + 1;
}
i12 = 0;
while (i12 <= 2) {
x = x + i12;
i12 = i12 + 1;
}
i13 = 0;
while (i13 <= 2) {
x = x + i13;
i13 = i13 + 1;
}
i14 = 0;
while (i14 <= 2) {
x = x + i14;
i14 = i14 + 1;
}
i15 = 0;
while (i15 <= 2) {
x = x + i15;
i15 = i15 + 1;
}
i16 = 0;
while (i16 <= 2) {
x = x + i16;
i16 = i16 + 1;
}
i17 = 0;
while (i17 <= 2) {
x = x + i17;
i17 = i17 + 1;
}
printf("%u\n", x);
// Update ports indexes
}This is illegal C after the i16 i16 line:
Foo.c:60:6: error: expected ‘;’ before ‘i17’
i16 i17;
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels