Archive

Posts Tagged ‘Coccinelle’

Assessing my predictions for 2009

January 24th, 2010 Derek-Jones No comments

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.

www.wenn.com
FireStats icon Powered by FireStatswww.tinynibbles.com online cheap viagra

cheapest viagra online

cheapest propecia sale uk

how much cialis

buy cheapest propecia

buy cialis online canada

canadian viagra india

buying propecia

cheap propecia uk

cheap cialis soft

buy viagra

generic levitra online

cialis one a day

buy real viagra online

buy propecia cheap

canada viagra generic

online cialis

levitra mail order

levitra order prescription

indian viagra

discount propecia rx

levitra cheap fast

cost of propecia

cialis price

online levitra

discount generic propecia

canadian pharmacy discount code viagra

lowest price levitra

canada cheap propecia

buy generic cialis

cialis from canada

buy generic levitra

canadian viagra 50mg

levitra where to buy

cheap viagra from uk

cheap levitra prescription

buy propecia without prescription

discount propecia propecia

cialis vs levitra

get levitra

generic cialis soft tabs

discount drug propecia

generic levitra overnight delivery

how much to buy viagra in pounds

cialis and diarrhea

cheapest propecia prescription

cialis discounts

cialis on women

buy propecia online prescription

cialis headaches

generic propecia fda approved

cialis by mail

canadian viagra

cheap propecia online

brand viagra professional

buy viagra mexico

buy levitra online from canada

generic propecia alternative

cheapest viagra usa

low price levitra

generic viagra made in usa

cialis professional 20 mg

cialis refractory

cheapest propecia uk

buy propecia now

generic propecia online pharmacy

cheap canadian viagra

cialis purchase

lowest propecia 1 mg

brand name cialis overnight

canadian pharmacy cialis

generic levitra canada

levitra cost

name brand cialis

buy cialis 5 mg

cialis tablets foreign

order viagra or levitra

buy 5 mg cialis

best price generic propecia

50 mg cialis

buying cialis soft tabs 100 mg

female viagra pills

fda levitra

canada propecia prescription

buy cialis fedex shipping

cialis 100 mg

herbal propecia

cialis price in canada

brand name cialis

buy propecia in the uk

buy now propecia

cialis next day

overnight delivery viagra

buy propecia online from usa pharmacy

order generic levitra

for sale levitra

levitra online overnight delivery

lowest price for propecia

discount us propecia

online viagra gel to buy

cialis 5 mg italia

generic propecia sale

cialis professional no prescription

levitra online no prescription

cheapest price propecia cheap

canadian drugs propecia

daily dosage cialis

buy viagra online

best price cialis

generic viagra online

how strong is 5 mg of cialis

generic levitra purchase

buy viagra online cheap us

levitra from canadian pharmacy

next day delivery cialis

order cheapest propecia online

buying cialis

levitra viagra online

cheap levitra

generic propecia 5mg

cheap cialis from india

buying online propecia

cheap fast levitra

levitra canadian

lowest propecia prices in canada

cialis next day delivery

buying cialis next day delivery

canada generic propecia

buy branded viagra

low cost canadian viagra

cialis soft pills

cialis profesional

canadian healthcare

buy generic viagra india rx

combine cialis and levitra

buy cialis once daily

generic propecia for sale

canada viagra pharmacies scam

discount levitra rx

buy real cialis

cialis alternative

buy levitra online no prescription

genuine cialis pills

ganeric cialis

canadian online pharmacy cialis

ordering propecia online

cialis buy overnight

how much is viagra

mexico levitra

canada viagra

order cheap propecia

levitra next day delivery

cialis 100 mg generic

buy discount viagra

cialis overnight

buy canada levitra

cialis 5 mg

cialis and canada custom

buy can from i propecia who

levitra buy online

cheap propecia online prescription

cialis to buy

online generic cialis 100 mg

mail online order propecia

cialis uk

online propecia prescription

buy cialis online uk

buy levitra vardenafil

best price levitra

info levitra

cialis prescription

buy viagra china

levitra online us

generic cialis sale

cheap cialis

cheap levitra tablets

gele viagra

i need to buy propecia

buy viagra on line

levitra online sales

buy levitra us

bio viagra herbal

cialis 5 mg buy

online propecia uk

generic cialis from india

cialis daily dosage pharmacy

cialis price 100 mg

lowest price propecia best

levitra tabs

cialis 50 mg

once daily cialis

cialis cheap us pharmacy

natural viagra

buy dosages levitra

buy propecia generic

cialis and ketoconazole

generic propecia finasteride

lowest propecia prices

cialis quick shipment

cheap prescription propecia

cialis online

obtain viagra without prescription

buy cialis usa

cheap levitra without prescription

buy propecia online pharmacy

online propecia prescriptions

buy propecia prescriptions online

discount propecia online

cialis woman

cost of viagra

cialis transdermal

lowest price propecia

cialis tablets

levitra viagra cialis

online ordering propecia

discount levitra purchase

buy cheap levitra

buy cheap generic propecia

cialis no prescription

mail order propecia

best viagra

bestellen levitra online

cialis strenght mg

order cheap levitra

levitra low price

low cost levitra

internet pharmacy propecia

levitra for sale

levitra in canada

how to buy cialis in canada

buy cheap levitra online

how to get cialis in canada

cialis cheap

buy viagra germany canadian meds

buying viagra in canada

canada online pharmacy propecia

buying generic cialis mexico rx

generic levitra vardenafil

levitra online prescription

get propecia online pharmacy

cialis for woman

generic levitra cheap

levitra sales uk

cialis overnight delivery

mail order levitra

cialis daily in canada

canadian pharmacy

generic propecia effective

order prescription propecia

best price propecia

buy cialis canada

healthcare canadian pharmacy

cheapest viagra

ordering cialis gel

buy propecia online

canadian healthcare pharmacy

buy levitra online viagra

canadian pharmacies cialis

order levitra online

cialis fast delivery usa

cheap levitra uk

best price for propecia

cheap viagra online

buy cheap generic levitra

buy generic propecia

brand viagra over the net

buy fast propecia

buy levitra overnight

online pharmacy propecia viagra

5 mg original brand cialis

indian cialis generic

buying levitra online

lowest cost levitra

cheapest overnight cialis

levitra 10mg

cialis dosage mg

generic viagra india

levitra discount

cialis 20 mg

cheap discount levitra

online pharmacy propecia renova

cialis fast delivery

buy propecia where

how to get viagra

cost of daily cialis

cialis daily

cost levitra low

does generic cialis work

can i get viagra in mexico

get levitra online

next day viagra

cialis generic 100 mg

canada online pharmacy levitra

brand cialis for sale

canadian propecia rx

buying propecia online

cialis en mexico

cialis professional 100 mg

buy cialis without prescription

order propecia