dimitriv / Ziria

A domain-specific-language and compiler for low-level bitstream processing.
92 stars 18 forks source link

Serious bug in code generation #102

Open dimitriv opened 9 years ago

dimitriv commented 9 years ago

When compiled with --autolut the following program:

fun f(x : int) { 
  var bar : arr[8] bit;

  bar[0] := bit(x);
  bar[1,3] := {'0,'0,'0}

  for i in [4:7] {
     bar[i] := '1
  };

  return bar;

}
let comp main = read >>> map f >>> write

Produces completely wrong C Code returning a pointer in the stack! Ddump-autolut reveals that:

fun f{_r1}(x{_r3} : int32) =
      var bar{_r4} : arr[8] bit in
      bar{_r4}[0] := -- (earrwrite)
        bit(x{_r3});
      LUT bar{_r4}[1:+3] := -- (earrwrite)
            {'0, '0, '0};
          for i{_r12} in [4, 4] {
            bar{_r4}[i{_r12}] := -- (earrwrite)
              '1
          };
          bar{_r4}
in
((read[int32] >>>
  map f{_r1}) >>>
 write[arr[8] bit])

So the function has not been LUT-ted in its entirety, but rather only a part of it has. The code in CgFun does not deal correctly with it and should be revised ASAP!!