sylefeb / Silice

Silice is an easy-to-learn, powerful hardware description language, that simplifies designing hardware algorithms with parallelism and pipelines.
Other
1.3k stars 78 forks source link

Possible preprocessor problem. #232

Closed at91rm9200 closed 2 years ago

at91rm9200 commented 2 years ago

Hello Sylvain,

the following source for the icestick results in a preprocessor error. This worked with an earlier Silice version from May 2022.

$$if ICESTICK then
   algorithm main(output uint5 leds, inout uint8 pmod)
$$else
   algorithm main(output uint5 leds)
$$end
{
  while (1) {
  }
}
silice-make.py -s blinky1.si -b icestick -p basic,pmod -o BUILD_icestick
* Source file                :  /home/bernd/fpga/silice/2208/Silice/mue/project/test_icestick/blinky1.si    [ok]
* Silice bin directory       :  /home/bernd/fpga/silice/2208/Silice/bin
* Build output directory     :  /home/bernd/fpga/silice/2208/Silice/mue/project/test_icestick/BUILD_icestick  (exists)
* Silice frameworks directory:  /home/bernd/fpga/silice/2208/Silice/frameworks [ok]
* boards description file    :  /home/bernd/fpga/silice/2208/Silice/frameworks/boards/boards.json   [ok]
<<=- compiling blinky1.si for icestick -=>>
using default variant  configurable
using variant          configurable
using build system     edalize
assembling source /home/bernd/fpga/silice/2208/Silice/frameworks/libraries/memory_ports.si.
assembling source /home/bernd/fpga/silice/2208/Silice/mue/project/test_icestick/blinky1.si.
functionalizing unit main
error: [parser] Pre-processor directives are unbalanced within the unit, this is not supported.

Regards, Bernd.

sylefeb commented 2 years ago

Hello Bernd,

Sorry, you stumbled on one of the very few breaking changes I had to make thus far (I try very hard not to introduce any). The fix is very simple but requires a code change:

algorithm main(
$$if ICESTICK then
  output uint5 leds, inout uint8 pmod
$$else
  output uint5 leds
$$end
) {
  while (1) {
  }
}

The rule is that you can freely have preprocessor if-then-else between the '(' and ')' of the algorithm (or unit) in/out declaration, and between the '{' and '}' of the algorithm block. However there should not be an if-then-else enclosing and repeating these parentheses and braces.

I had to introduce this constraint when implementing the new preprocessor (that allows instantiation time preprocessing). There is a technical constraint there that the preprocessor has to be able to extract a 'simple' form of the algorithm or unit, free of top level if-then-else.

I was hopeful no one would encounter this breaking change, but you just prove me wrong ;-) I'll revise the documentation and try to clarify the error message.

Thanks for the report! Best regards, Sylvain

sylefeb commented 2 years ago

New documentation section: https://github.com/sylefeb/Silice/blob/master/learn-silice/Documentation.md#preprocessor-constraints

at91rm9200 commented 2 years ago

Hello Sylvain,

thank you for the explanation.

Regards, Bernd.