From: Matt Harren <matth@cs...> - 2005-06-29 22:51:29
> -----Original Message-----
> From: cil-users-admin@...
> [mailto:cil-users-admin@...] On Behalf Of
> Nathan Cooprider
> I am doing some static analysis of C code using CIL and would
> like to add comments about the information I figure out at
> various points in the code. It does not appear that this
> functionality is supported in CIL (adding comments at certain
> spaces). Is this correct? If this is not correct, then how
> do I add comments above a statement or an instruction?
GText global values will let you add comments at the top level, but
there's no way to add them inside a function. You could always add a new
instr type to cil.ml to hold comments. If if you'd rather not modify
cil.ml, one thing that I've done in the past is to generate a fake
function, and store comments as arguments to that function:
let commentFunc = makeGlobalVar "COMMENT"
Some([("", charPtrType, ) ]),
false, )) in
let makeComment (message:string) : instr =
Call (None, Lval(var commentFunc),
[mkString message], !currentLoc)
Now you can use makeComment to generate instructions that will appear in
the output as
COMMENT("your message here.");
Use GText to add "#define COMMENT(x)" to the beginning of the file, so
that these calls will be ignored by gcc.