Minres / CoreDSL

Xtext project to parse CoreDSL files
Apache License 2.0
14 stars 2 forks source link

Make bit range operator more versatile #57

Closed jopperm closed 1 year ago

jopperm commented 2 years ago

The bit range operator must have a fixed size. Do achieve this, it is currently limited to compile-time-constant expressions comprised only of literals and parameters. However, this semantic precludes using it e.g. in a loop:

for (i = 0; i < sizeof(x); i += 3)
  x[i+2:i] = ... // prohibited

The proposed solution is to relax the restriction and allow arbitrary expressions, under the condition that the frontend is able to evaluate (from)-(to) at compile-time to a constant value. In the example above, this would mean to determine that i+2 - i evaluates to 2 and the variable reference expression cancels out.

jopperm commented 1 year ago

Decided to keep the [start:end] syntax (see #52), but we'll relax the compile-time-constness-constraint. Instead, arbitrary expression are allowed as long as the range size is compile-time constant. A limited set of patterns that an frontend must understand will be specified.

jopperm commented 1 year ago

See: https://github.com/Minres/CoreDSL/wiki/Expressions#range-operator (diff)

jopperm commented 1 year ago

Implemented and successfully used in the MLIR code generator.