c2v
c2v copied to clipboard
Error when translating multiple variable assignments on one line
Seems like c2v has a hard time with multiple, comma separated variable assignments on the same line
Test case
fn aes256_set_encryption_key(key &u8, expandedkey &u32) {
nb := 4, nr := 14, nk := 8, i := u32(0)
tmp := u32(0)
// ...
}
Output
C to V translator 0.3.1
translating ./tgcrypto/aes256.c ... tgcrypto/aes256.v:119:9: error: this number has unsuitable digit `n`
117 |
118 | fn aes256_set_encryption_key(key &u8, expandedkey &u32) {
119 | nb := 4nr := 14nk := 8i := u32(0)
| ^
120 | tmp := u32(0)
121 |
Similarly, it tried to translate this:
for (i = 0, j = 56; i < j; i += 4, j -= 4)
for (k = 0; k < 4; ++k) {
tmp = expandedKey[i + k];
expandedKey[i + k] = expandedKey[j + k];
expandedKey[j + k] = tmp;
}
to this:
for i = 0; j = 56
j = i = 0 ; i < j ; i += 4 , j -= 4 {
for k = 0 ; k < 4 ; k ++ {
tmp = expandedkey [i + k]
expandedkey [i + k] = expandedkey [j + k]
expandedkey [j + k] = tmp
}
}
Maybe we should consider allowing comma separated assignments in the case of translated C code? Seeing as it's a perfectly legal thing to do in C like i++,
This fails:
void f1()
{
double efs = 0.1, hoff = 8.5;
}
but this works:
double efs = 0.1, hoff = 8.5;
The latter is translated to 2 globals.