right tool for the job ? / code expander / auto C loop unrolling
While I'd normally program in C++
I've a small task that I think might be better solved in Perl or similar. I'm looking for advice. I need to make a code expander. What i have to do is parse a set of C/C++ files and for all occurrences of a function call. (MADD192(a,b,c,rp); (or MADD256(a,b,c,rp); or MADD512(a,b,c,rp); etc.) I need to swap in a block of code (using the the 'N' ). This code body being an large unwound loop based on the function parameters and the N (192, 256 etc.). so madd192(a,b,c,rp); is expanded to something like rp[1] = a[1] * b[1] + c[1]; rp[2] = a[2] * b[2] + c[2]; . . rp[192] = a[192] * b[192] + c[192]; its actually a bit more complicated than my example so the compiler can't do it automatically. Is a job for perl or is there anything else I should look at ? I'll be doing this a lot for other, similar, functions. anyone care to to have a go ? -ds |
Have you looked at the Sun Studio C compiler? It has many more capabilities in that area than gcc, etc...
|
Quote:
Code:
#define MEGAFUNC(a, b, c, d) \ |
Quote:
Its actually for an architecture (the cell) not supported by Sun. Its because of the immaturity (non optimal code generation) of the compilers that i am hand optimising /ds |
[QUOTE=David1357;3002946]Unless I am missing something, you can do it with macros like the rest of us.
thank you for your response My example was small to illustrate the idea the real problem is a little more complicated. I considered macros and have used them to prototype the idea what I need to do will introduce 1000s of lines. I'm thinking that 'something else' would ease maintenance and hopefully reduce the possibility of introducing subtle but hard to find bugs. /ds |
Quote:
|
I've been looking a bit more at this
found a book on code generation (http://www.manning.com/herrington/) and settled on Ruby (http://www.ruby-lang.org/en/) to do parsing and text manipulation. got powerful regexp . I'm pretty happy with the results. One run made a c source file with 67,000 lines One of the advantages over the preprocessor is that you get more power to name variables in unrolling which helps in debugging compared to my experience with macros -ds |
All times are GMT -5. The time now is 10:35 PM. |