c2v icon indicating copy to clipboard operation
c2v copied to clipboard

Error when translating multiple variable assignments on one line

Open watzon opened this issue 3 years ago • 2 comments

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 |

watzon avatar Jun 25 '22 18:06 watzon

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++,

watzon avatar Jun 25 '22 18:06 watzon

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.

freevryheid avatar Jul 14 '22 19:07 freevryheid