Set Top Function name based on define

89 Views Asked by At

Is it possible to set the name of the Top Function in the Project Settings based on a define? I have an IP which uses different parameters and a different Top Function name based on a define, but I don't want to change the name of the Top Function in the Project Settings every time when I change the define. I want to change the Top Function name based on a define because the name of the generated IP block is the same as the name of the Top Function.

For example I have these defines:

#ifdef CONV1
#define INPUT_LENGTH    32
#define IN_CHAN         2
#define OUT_CHAN        8
#define CONV_FUNC       conv_8x2x5x5
#else
#ifdef CONV2
#define INPUT_LENGTH    28
#define IN_CHAN         8
#define OUT_CHAN        16
#define CONV_FUNC       conv_16x8x5x5
#else
#define INPUT_LENGTH    24
#define IN_CHAN         16
#define OUT_CHAN        20
#define CONV_FUNC       conv_20x16x5x5
#endif
#endif

And the Top Function is defined as:

void CONV_FUNC (...) {
    ...
}

I define for example CONV1, the name of the Top Function becomes conv_8x2x5x5 and thus the name of the generated IP block becomes conv_8x2x5x5. How can I make the Synthesis automatically pick the correct Top Function name?

1

There are 1 best solutions below

0
Stefano Ribes On BEST ANSWER

I'm not sure I understood the details of the question, but you can use the C preprocessor to achieve what you want (and even get rid of the CONV_FUNC macro):

#include <stdio.h>

#ifdef CONV1
#define INPUT_LENGTH    32
#define IN_CHAN         2
#define OUT_CHAN        8
// #define CONV_FUNC       conv_8x2x5x5
#else
#ifdef CONV2
#define INPUT_LENGTH    28
#define IN_CHAN         8
#define OUT_CHAN        16
// #define CONV_FUNC       conv_16x8x5x5
#else
#define INPUT_LENGTH    24
#define IN_CHAN         16
#define OUT_CHAN        20
// #define CONV_FUNC       conv_20x16x5x5
#endif
#endif

#define MAKE_FUNC_NAME(o, i) conv_##o##x##i##x5x5
#define TOP_FUNC(o, i) MAKE_FUNC_NAME(o, i)
#define TOP TOP_FUNC(OUT_CHAN, IN_CHAN)

int TOP(int x) {
  printf("Top function: %s\n", __func__);
  return x + 1;
}

int main(int argc, char const *argv[]) {
  int dummy_ret = TOP(41);
  return 0;
}

Which will print:

Top function: conv_20x16x5x5

Search for "token concatenation" for more information.