Archive

Posts Tagged ‘Coccinelle’

Assessing my predictions for 2009

January 24th, 2010 Derek-Jones 1 comment

I have been rather remiss in revisiting the predictions I made for 2009 to see how they fared. Only two out of the six predictions were sufficiently precise to enable an assessment one year later; the other four talking more about trends. What of these two predictions?

The LLVM project will die. Ok, the project is still going and at the end of December the compiler could build itself but the build is not yet in a state to self host (i.e., llvm compiler creates an executable of itself from its own source and this executable can build an executable from source that is identical to itself {modulo date/time stamps etc}). Self hosting is a major event and on some of the projects I have worked on it has been a contractual payment milestone.

Is llvm competition for gcc? While there might not be much commercial competition as such (would Apple be providing funding to gcc if it were not involved in llvm?), I’m sure that developers working on both projects want their respective compiler to be the better one. According to some llvm benchmarks they compile code twice as fast as gcc. If this performance difference holds up across lots of source how might the gcc folk respond? Is gcc compiler time performance an issue that developers care about or is quality of generated code more important? For me the latter is more important and I have not been able to find a reliable, recent, performance comparison. I understand that almost all gcc funding is targeted at code generation related development, so if compile time is an issue gcc may be in a hole.

I still don’t see the logic behind Apple funding this project and continue to think that this funding will be withdrawn sometime, perhaps I was just a year off. I do wish the llvm developers well and look forward to them celebrating a self hosted compiler.

Static analysis will go mainstream. Ok, I was overly optimistic here. There do not seem to have been any casualties in 2009 among the commercial vendors selling static analysis tools and the growth of PHP has resulted in a number of companies selling tools that scan for source security vulnerabilities (.e.g, SQL injection attacks).

I was hoping that the availability of Treehydra would spark the development of static analysis plugins for gcc. Perhaps the neatness of the idea blinded me to what I already knew; many developers dislike the warnings generated by the -Wall option and therefore might be expected to dislike any related kind of warning. One important usability issue is that Treehydra operates on the abstract syntax tree representation used internally by gcc, GIMPLE. Learning about this representation requires a big investment before a plugin developer becomes productive.

One tool that did experience a lot of growth in 2009 was Coccinelle, at least judged by the traffic on its mailing list. The Coccinelle developers continue to improve it and are responsive the questions. Don’t be put off by the low version number (currently 0.2), it is much better than most tools with larger version numbers.

Using Coccinelle to match if sequences

August 31st, 2009 Derek-Jones No comments

I have been using Coccinelle to obtain measurements of various properties of C if and switch statements. It is rare to find a tool that does exactly what is desired but it is often possible to combine various tools to achieve the desired result.

I am interested in measuring sequences of if-else-if statements and one of the things I wanted to know was how many sequences of a given length occurred. Writing a pattern for each possible sequence was the obvious solution, but what is the longest sequence I should search for? A better solution is to use a pattern that matches short sequences and writes out the position (line/column number) where they occur in the code, as in the following Coccinelle pattern:

@ if_else_if_else @
expression E_1, E_2; 
statement S_1, S_2, S_3;
position p_1, p_2;
@@
if@p_1 (E_1)
   S_1
else if@p_2 (E_2)
   S_2
else
   S_3
@
script:python @ expr_1 << if_else_if_else.E_1;
                expr_2 << if_else_if_else.E_2;
                loc_1 << if_else_if_else.p_1;
                loc_2 << if_else_if_else.p_2;
              @@
print "--- ifelseifelse"
print loc_1[0].line, " ", loc_1[0].column, " ", expr_1
print loc_2[0].line, " ", loc_2[0].column, " ", expr_2

noting that in a sequence of source such as:

if (x == 1)
   stmt_1;
else
   if (x == 2)
      stmt_2;
   else
      if (x == 3)
         stmt_3;

the tokens if (x == 2) will be matched twice, the first setting the position metavariable p_2 and then setting p_1. An awk script was written to read the Coccinelle output and merge together adjacent pairs of matches that were part of a longer if-else-if sequence.

The first pattern did not concern itself with the form of the controlling expression, it simply wrote it out. A second set of patterns was used to match those forms of controlling expression I was interested in, but first I had to convert the output into syntactically correct C so that it could be processed by Coccinelle. Again awk came to the rescue, converting the output:

--- ifelseifelse
186   2   op == FFEBLD_opSUBRREF
191   7   op == FFEBLD_opFUNCREF
--- ifelseifelse
1094   3   anynum && commit
1111   8   ( c [ colon + 1 ] == '*' ) && commit

into a separate function for each matched sequence:

void f_1(void) {
// --- ifelseifelse
/* 186   2 */   op == FFEBLD_opSUBRREF ;
/* 191   7 */   op == FFEBLD_opFUNCREF ;
}
void f_2(void) {
// --- ifelseifelse
/* 1094   3 */   anynum && commit ;
/* 1111   8 */   ( c [ colon + 1 ] == '*' ) && commit ;
}

The Coccinelle pattern:

@ if_eq_1 @
expression E_1;
constant C_1, C_2;
position p_1, p_2;
@@
 
E_1 == C_1@p_1 ;
E_1 == C_2@p_2 ;
 
@
script:python @ expr_1<< if_eq_1.E_1;
                const_1 << if_eq_1.C_1;
                const_2 << if_eq_1.C_2;
                loc_1 << if_eq_1.p_1;
                loc_2 << if_eq_1.p_2;
              @@
print loc_1[0].line, " ", loc_1[0].column, " 3 ", expr_1, " == ", const_1
print loc_2[0].line, " ", loc_2[0].column, " 2 ", expr_1, " == ", const_2

matches a sequence of two statements which consist of an expression being compared for equality against a constant, with the expression being identical in both statements. Again positions were written out for post-processing, i.e., joining together matched sequences.

I was interested in any sequence of if-else-if that could be converted to an equivalent switch-statement. Equality tests against a constant is just one form of controlling expression that meets this requirement, another is the between operation. Separate patterns could be written and run over the generated C source containing the extracted controlling expressions.

Breaking down the measuring process into smaller steps reduced the amount of time needed to get a final result (with Coccinelle 0.1.19 the first pattern takes round 70 minutes, thanks to Julia Lawall’s work to speed things up, an overhead that only has to occur once) and allows the same controlling expression patterns to be run against the output of both the if-else-if and if-if patterns.

At the end of this process I ended up with a list information (line numbers in source code and form of controlling expression) on if-statement sequences that could be rewritten as a switch-statement.

FireStats icon Powered by FireStatscheapest price propecia cheap

cialis levitra

levitra viagra online

cialis cheap us pharmacy

generic cialis

cialis daily canada

buying viagra in the us

canadian pharmacy

ordering viagra overnight delivery

cheap online levitra

cialis alternitives

cheap levitra online

cialis blood thinner

get propecia online pharmacy

cheap viagra from uk

best price cialis

cialis for sale

generic cialis soft tabs

buy cialis canada

best propecia prices

how much to buy viagra in pounds

generic viagra made in india

buy propecia where

cialis alternative

buying cialis soft tabs 100 mg

chip cialis

cheap order prescription propecia

5 mg cialis

buy levitra american pharmacy

cialis arterial fibrillation

cialis 5 mg

generic cialis india discount

buying levitra online

buy cheap levitra online

cheap levitra uk

cialis at real low prices

for sale levitra

buy cheap levitra

levitra in canada

buy levitra online viagra

cheap viagra pills

cialis woman

cheap generic levitra

cialis price

cialis fast delivery

buy now viagra

buy levitra with no prescription

cialis price in canada

buying generic propecia

effect of cialis on women

generic levitra canada

buy propecia cheap

cialis and diarrhea

low price propecia

buy discount viagra

cialis samples in canada

cialis to buy

cialis

cheapest price propecia cheap

get levitra

female viagra pills

cheap viagra from uk

canadian healthcare

cialis professional 100 mg

generic cialis canadian

healthcare canadian pharmacy

generic propecia fda approved

50 mg cialis

get cialis online

cialis 100 mg generic

cost of daily cialis

levitra prescription

cialis profesional

buy online prescription propecia

female viagra pills

levitra sex pill

info levitra

generic levitra vardenafil

low cost canadian viagra

non pescription cialis

cialis online without prescription

canadian pharmacy cialis

cialis trazodone

cost levitra

generic cialis

cheap cialis from india

buy cialis on line

best way to take cialis

cialis soft

buy propecia and proscar

buy propecia on line

buy viagra china

buy viagra online canada

best doses for propecia

levitra tabs

buy prescription propecia

cheap viagra

cialis brand name

buying cialis next day delivery

cialis canada illegal buy

cialis 50 mg

cialis from india

cialis discount

buy viagra in canada no prescription

get propecia cheap

cheap propecia online prescription

online cheap viagra

cheepest cialis

canadian online pharmacy cialis

buying online propecia

mail order propecia

china viagra

cialis delivered overnight

buying generic cialis mexico rx

buy vardenafil levitra

best prices for propecia

buy levitra online viagra

cheap viagra canada or india

cialis canadian cost

overnight delivery cialis

buy viagra germany canadian meds

buy canada levitra

buying propecia online

cialis professional 20 mg

canadian pharmacy viagra

buy cialis without a prescription

buy branded viagra online

cialis 100 mg

cialis quick shipment

can i order viagra from the chemist

best levitra prices

buy levitra overnight

brand cialis

lowest price for propecia

cialis from mexico

buy cialis online uk

how can i get some cialis

online pharmacy cost levitra

cheap viagra

buy prescription propecia

non pescription cialis

cheap online propecia

levitra vs viagra

healthcare of canada pharmacy

buy cialis in canada

buy cialis online

non prescription viagra

cialis canada illegal buy

cialis daily price

bestellen levitra online

canadian propecia rx

levitra online

cialis 100 mg

buy propecia without a prescription

canadian viagra 50mg

get viagra

cialis angioplasty

buy generic viagra india rx

generic levitra india

low cost levitra

buy viagra online

generic viagra in canada

express viagra delivery

buy cialis fedex shipping

buy propecia online

cialis at real low prices

levitra online overnight delivery

50 mg cialis

buy propecia now

generic propecia canada

levitra mg

discount real viagra

cialis daily cost

buy cheapest propecia

cialis low price

cialis tablets

buy discount viagra

order propecia online

buy now propecia

canadian propecia cheap

order levitra

cialis daily canada

cialis and women

cialis for woman

canadian healthcare pharmacy

cheapest cialis

drug hair loss propecia

buy cheap propecia

cialis generic

cialis dose

cheap discount levitra

generic propecia cheap

buy generic levitra

no prescription viagra

best cialis price

daily cialis

buying cialis

cialis samples

cialis alternitives

cialis angioplasty

best price for propecia online

buying viagra without prescription

cialis once daily

cialis c 50

5 mg original brand cialis

cialis canada

cheap levitra prescription

best price for generic cialis

drug generic propecia

cialis discount

cialis soft tablets

levitra

generic cialis soft tabs

healthcare of canada pharmacy

buy levitra online

buy propecia generic

discount generic propecia

canada cheap propecia

cialis dosage

cialis in canada

buy real viagra online without prescription

best price cialis

buy cheap online propecia

canada propecia prescription

buy cialis next day delivery

online levitra us

cialis germany

cialis 50 mg dose

online propecia prescriptions

buy generic propecia online

best price for generic cialis

cheapest viagra usa

order propecia prescriptions

indian cialis generic

indian cialis canada

buy cialis online uk

canadian pharmacy viagra legal

buy cialis online canada

map of france with cialis

levitra canadian

cheap propecia uk

cialis brand

canadian drugs propecia

buy levitra online us

online order propecia

cialisis in canada

cheap price propecia

discount viagra

cheap levitra tablets

cialis and diarrhea