From: Christian Collberg <collberg@gm...> - 2011-05-06 19:00:45
The documentation says the following:
The following extensions are handled, typically by compiling them away:
Labels as values and computed goto. This allows a program to take the
address of a label
and to manipulate it as any value and also to perform a computed goto.
We compile this by
assigning each label whose address is taken a small integer that acts
as its address.
Every computed goto in the body of the function is replaced with a
If you want to invoke the label from another function, you are on your
own (the gcc
documentation says the same.)
I actually need to be able to manipulate labels-as-values directly, compiling
them away into a switch is not an option. Is there some way to hack CIL
to do this? Has anyone tried?
From: Gabriel Kerneis <kerneis@pp...> - 2011-05-06 20:27:42
On Fri, May 06, 2011 at 12:00:17PM -0700, Christian Collberg wrote:
> I actually need to be able to manipulate labels-as-values directly, compiling
> them away into a switch is not an option. Is there some way to hack CIL
> to do this?
What you would need to do:
- design an extension of the CIL AST to encode labels-as-values : this is the
creative part, where you have to think hard in order to get something easy to
use yet expressive enough. This involves modifying cil.mli and cil.ml.
- change frontc/cabs2cil.ml in order to use those new constructs : this is the
hard part, you have to find out where CIL currently transforms the
labels-as-values into switch statements, and change the code accordingly.
- fix every pattern-matching in CIL's source code to handle your new constructs :
this is the tedious part. If you manage to only need to add new constructors
to sum types (like statement kind) this is straightfoward, just look at "not
exhaustive pattern matching" warnings and fix them ; you shouldn't need to change
anything else. If you happen to need new fields to product types (like stmt), it
might a bit more involved, but compiler warnings and errors should still provide
a lot of help. This involves fixing a dozen of files (roughly).
I did something similar when I extended CIL to handle my own superset of C. This is
definitely possible, and not as hard as it might seem. Do not hesistate to ask if
you need more help (and share the patch if you get some result :-).
Get latest updates about Open Source Projects, Conferences and News.