Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ill-formed initializer issue #14

Open
nanoeng opened this issue Jun 20, 2022 · 3 comments
Open

ill-formed initializer issue #14

nanoeng opened this issue Jun 20, 2022 · 3 comments

Comments

@nanoeng
Copy link

nanoeng commented Jun 20, 2022

Howdy,

I'm trying to generate run a 4 tap FIR filter and I'm getting the error message shown below

Would appreciate any help to find a potential solution.

command:
./bin/vericert fir_4tap.c -o fir_4tap.o

error message
fir_4tap.c:5:31: syntax error after '{' and before '}'.
Ill-formed initializer.
At this point, an optional designation, followed with an initializer, is expected.
Fatal error; compilation aborted.
1 error detected.

code
The FIR filter I'm trying to implement is described below (example taken from the Parallel Programming for FPGAs' book)

#define NUM_TAPS 4
void fir ( int input, int *output, int taps [NUM_TAPS] ) {
static int delay_line [NUM_TAPS] = {};
int result = 0;
for ( int i = NUM_TAPS -1 ; i > 0 ; i--) {
delay_line[i] = delay_line[i - 1];
}
delay_line[0] = input;
for ( int i = 0 ; i < NUM_TAPS ; i ++ ) {
result += delay_line[i] * taps[i];
}
*output = result;
}

@ymherklotz
Copy link
Owner

ymherklotz commented Jun 20, 2022

Hi, the first issue you mention is actually a parsing issue with CompCert, it just doesn't allow empty initialiser lists. Instead the following will actually parse and compile with CompCert:

#define NUM_TAPS 4
void fir ( int input, int *output, int taps [NUM_TAPS] ) {

    static int delay_line [NUM_TAPS] = {0};

    int result = 0;

    for ( int i = NUM_TAPS -1 ; i > 0 ; i--) {
        delay_line[i] = delay_line[i - 1];
    }

    delay_line[0] = input;

    for ( int i = 0 ; i < NUM_TAPS ; i ++ ) {
        result += delay_line[i] * taps[i];
    }

    *output = result;
}

Finally though, unfortunavely Vericert doesn't support a large subset of C yet, so the designs that you can compile at the moment don't really look like typical HLS designs as you have written here. The below function will at least compile and kind of do what you want:

#define NUM_TAPS 4
int main ( int input ) {

    int taps [NUM_TAPS] = {1, 2, 3, 4};

    int delay_line [NUM_TAPS] = {0};

    int result = 0;

    for ( int i = NUM_TAPS -1 ; i > 0 ; i--) {
        delay_line[i] = delay_line[i - 1];
    }

    delay_line[0] = input;

    for ( int i = 0 ; i < NUM_TAPS ; i ++ ) {
        result += delay_line[i] * taps[i];
    }

    return result;
}

In general though, the things that you are using which are not supported in Vericert but used all the time in HLS are (which actually incidentally all have to do with the simplistic memory handling in Vericert:

  • Static variables, very useful for persistent state. This is related to the simplistic memory layout that Vericert supports.
  • Passing arrays into functions as arguments.
  • Returning a value by modifying a pointer.
  • Supporting not having a main function. This one is also quite difficult to tackle, but would be necessary for the HLS tool to be usable in practice.

Thanks for trying out Vericert though! I'm happy you managed to compile it in the first place. I hope this helps, and let me know if you have any thoughts.

@ymherklotz
Copy link
Owner

But I will admit, without static the second design I posted does not implement an FIR filter.

@nanoeng
Copy link
Author

nanoeng commented Jun 20, 2022

Thanks a lot for the detailed reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants