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 FireStatsbuy viagra pills

online cheap viagra

buy cialis on line

buy propecia online

canadian healthcare viagra

cialis price in canada

generic cialis canadian

buying viagra in canada

lowest price propecia costs us

online pharmacy cost levitra

cheap online levitra

online order viagra overnight delivery

get levitra online

cialis and diarrhea

cialis medication

cialis cost

brand name cialis overnight

cialis one a day

cialis medication

buy cialis canada

canadian healthcare

lowest propecia price

cialis no prescription

express viagra delivery

online prescription propecia

online propecia uk

buying cialis

canadian pharmacies cialis

canadian pharmacy

online order viagra overnight delivery

buy cheap generic levitra

canadian propecia rx

generic levitra pill

buy cialis 5 mg

levitra online

cialis india

lowest cost levitra

cialis daily

online viagra gel to buy

next day delivery cialis

discount brand name cialis

cialis and ketoconazole

cialis next day

generic viagra from china

cialis cost canada

cialis 5 mg buy

buy cialis fedex shipping

buy cialis online

cheap propecia uk

buy viagra in canada

cialis uk

cialis fast

buy generic propecia online

cheap cialis from india

cost levitra

canadian pharmacy viagra

cheap levitra prescription

buy generic cialis

drug generic propecia

cialis blood thinner

cheap propecia 5mg

canadian viagra

cheap levitra prescription

buying viagra in the us

cialis next day

lowest price levitra

buy pfizer viagra online

cialis and women

buy canada levitra

cialis for less 20 mg

drug propecia

buy now propecia

buy cheapest cialis

discount us propecia

ordering cialis gel

levitra online order

buy propecia where

indian cialis

herbal viagra

best price for propecia online

buy now online propecia

buy levitra us

best way to take cialis

cheap cialis

best levitra price

cheapest price propecia cheap

buy propecia online prescription

50 mg cialis dose

generic cialis sale

cialis refractory

discount levitra online

buy levitra online from canada

cheapest viagra

cialis no prescription

cialis 30 mg

buy generic viagra india rx

cialis trazodone

bio viagra herbal

cheepest cialis

generic propecia online pharmacy

buying viagra in the us

buy levitra online viagra

levitra tadalafil

lowest price levitra generic online

cialis for woman

canadian generic viagra online

levitra in mexico

5mg propecia

chip cialis

original brand cialis

buy online propecia

cialis delivered overnight

generic propecia india

low cost propecia

generic viagra canadian

best price for propecia

china viagra

cheap levitra

canadian propecia cheap

cost of cialis

canadian pharmacies cialis

fda levitra

name brand cialis

buy propecia uk

generic viagra propecia

cialis alternative

cialis c 50

cheap viagra generic

generic viagra 100 mg

buy propecia in canada

cheap price propecia

cheap cialis from india

buy pfizer viagra

no prescription viagra

best doses for propecia

generic viagra india

cost of daily cialis

cialis dosagem

buy propecia canada

cialis daily in canada

generic prescriptions propecia

cialis profesional

buy viagra online

buy propecia online from usa pharmacy

cialis tablets

cialis prices

bestellen levitra online

getting cialis from canada

cialis discount prices

levitra best price

best levitra prices

ordering cialis gel

about cialis

cialis daily dosing cost

cialis canadian cost

cialis price in canada

how much is viagra

how to get viagra

cialis

buying propecia online

cheap prescription propecia

cialis cost canada

cialis professional 100 mg

canadian healthcare pharmacy

cialis generic

cialis woman

discount levitra rx

how can i get some cialis

best price levitra

buy levitra us

how to get cialis in canada

levitra next day delivery

how much to buy viagra in pounds

generic viagra made in usa

cheap levitra without prescription

how much cialis

buy cialis on line

healthcare of canada pharmacy

hydrochlorothiazide cialis

cheapest prices for viagra

generic cialis in india

cialis daily

buy cheap propecia

cheap viagra generic

cialis and diarrhea

cialis on sale

buying cialis without a prescription

china viagra

canada levitra

original brand cialis

buying viagra

cheapest viagra online

cialisis in canada

canadian levitra

generic viagra in canada

cialis discount

order propecia

cialis india

buying cialis soft tabs 100 mg

cialis 100 mg generic

best price levitra

cialis from mexico

buy cialis next day delivery

buy cialis usa

get cialis

buying real viagra without prescription

cialis fast delivery

cheap cialis soft

levitra vs cialis

generic levitra overnight delivery

levitra in canada

generic propecia canada

cheapest cialis

cheap propecia online prescription

buy propecia pills

cialis dosage mg

canada pharmacy propecia

cialis daily in canada

cialis iop

cialis women

cialis dosage mg

canadian healthcare

cheap viagra pills

how strong is 5 mg of cialis

cialis arterial fibrillation

online levitra tablet

cialis discount

female viagra pills

buy mg propecia

buying viagra without prescription

indian generic levitra

buy drug propecia

healthcare canadian pharmacy

buy viagra in canada

buying cialis in canada

buy levitra online

lowest propecia prices in canada

cialis dosagem

order levitra online

cialis blood thinner

buy cialis professional

generic viagra in canada

buying cialis next day delivery

getting cialis from canada

buy 5 mg cialis

cialis by women

cheap viagra or cialis

cialis online without prescription

how much does cialis cost

cialis daily cost