Tools to compile pointers to arrays of static size

c

Are there any static code analyzing tools for C that convert pointers to arrays of a static size? It is a marginal pain and I just figured I'd check with the community. A quick google search did not turn up anything useful because "to" in the phrase "pointer to array" generally means something completely different from what I'm looking for here… Any suggestions or keywords would be helpful.

P.s. I'm trying to convert some code into synthesizable C for a hardware implementation.

So for instance, this code is not synthesizable:

void sum(float *a, int size, float *out) {
    int i;
    for (i=0;i<size;i++)
        *out += a+1;
}

It is not synthesizable since the size of a is not statically declared at runtime. (Note, that out should be ok since it is not an array – though I'm not 100% sure on that.) It would be lovely if there was a tool to convert use of variable sized arrays to arrays whose sizes were known at compile time.

Furthermore, this code must be transformed (currently manually) to something like this:

// Not 100% sure if float * is still allowed.
void sum(float a[SIZE], float *out) {
    int i;
    for (i=0;i<SIZE;i++)
        *out += a[i]; // Not sure if this is necessary.
}

Right now, I would have to do this manually. I have to resolve all usages of dynamic arrays. This is how HLS works. It is a serious issue. It is hard (or at least time-consuming) to do when you did not write the original code. It must be converted so that you can synthesize the code to hardware.

All array sizes must be resolved – they may not have been explicitly declared initially. Then these array sizes must be propagated to all affected functions/references.

Finally, for those of you confused by "synthesizable", feel free to check out these two links that describe it much better than I can…

http://www.cse.psu.edu/~xydong/files/proceedings/DAC2010/data/1964-2006_papers/PAPERS/1988/DAC88_330.PDF
http://www.xilinx.com/support/documentation/sw_manuals/ug998-vivado-intro-fpga-design-hls.pdf

Best Answer

you can declare an array of fixed size and then access it using a pointer, take for instance you can declare

float a[10];

and access it as

*(a+index)= <value>;

*a representing a[0].

for your sum function, you can leave the following function intact

`    void sum(float *a, int size, float *out) {
        int i;
        for (i=0;i<size;i++)
            *out += a+1;
    }

and make changes in the calling program preprocessor directive

#define size <yourchoice>

variable declaration

float a[size];
float out[size];

function call

sum((float*)a,int size,(float*)out);

m not sure what your function is trying to achieve block addition or sum of consecutive floats...but hope this helps