Related articles |
---|
Automatic "code-pattern" recognition, in DSP codes Miguel.CasasSanchez@ucd.ie (=?ISO-8859-15?Q?Miguel_Cas=E1s-S=E1nchez?=) (2005-07-05) |
Re: Automatic "code-pattern" recognition, in DSP codes jle@ural.owlnet.rice.edu (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes bsheff2@yahoo.com (Bob Sheff) (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes codeworker@free.fr (=?iso-8859-1?q?C=E9dric_LEMAIRE?=) (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes darius@raincode.com (Darius Blasband) (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes drizzle76@gmail.com (drizzle) (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes oliver@first.in-berlin.de (Oliver Bandel) (2005-07-11) |
Re: Automatic "code-pattern" recognition, in DSP codes pohjalai@cc.helsinki.fi (A Pietu Pohjalainen) (2005-07-11) |
From: | "=?iso-8859-1?q?C=E9dric_LEMAIRE?=" <codeworker@free.fr> |
Newsgroups: | comp.compilers |
Date: | 11 Jul 2005 06:57:59 -0400 |
Organization: | http://groups.google.com |
References: | 05-07-024 |
Keywords: | DSP, analysis |
Posted-Date: | 11 Jul 2005 06:57:59 EDT |
I propose you a syntactic solution, using CodeWorker, a parsing tool
and a source code generator. The example of script below detects your
coding pattern, put it into comments and translates it to a call to
your function :
code_pattern_recognition ::=
#ignore(C++)
#implicitCopy
[
->[
=> local iPosition = getOutputLocation();
[
// insert here all alternatives of
// code patterns
FIR(iPosition)
]
]
]*
->#empty
;
FIR(iPosition : value) ::=
"for" '(' #readIdentifier:sIndex '=' '0' ','
#readIdentifier:sAcc '=' '0' [".0"]? ';'
#readText(sIndex) '<' #readIdentifier:sN ';'
#readText(sIndex) "++" ')' '{'
#readText(sAcc) "+=" #readIdentifier:sH
'[' #readText(sIndex) ']' '*' #readIdentifier:sX '['
#readText(sN) '-' #readText(sIndex) ']' ';' '}'
=> {
insertText(iPosition, "/*");
@*/@endl()@fir(@sH@, @sX@, @sAcc@);@
}
;
If the script is saved to "CodePatterns.cwp", type:
codeworker -translate CodePatterns.cwp your-c-file.c your-c-file.c
Note that I've corrected your sample to:
for(n=0, acc = 0; n < N; n++) {
acc += h[n] * X[N-n];
}
Of course, the main drawback stems from that it explores the source
code, and so, is sensitive to variants. Here, if acc isn't initialised
in the for statement, the coding pattern isn't recognized, for
instance!
Return to the
comp.compilers page.
Search the
comp.compilers archives again.