[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Modifying CFG
>>>>> "marco.bakera" == Marco Bakera <marco.bakera@uni-dortmund.de> writes:
marco.bakera> is there any possibility to change the CFG
marco.bakera> - which seems to be represented in the
marco.bakera> Unitgraph - without having to do it with the
marco.bakera> units? I just want to insert a Unit (a kind of
marco.bakera> AssignStmt) in the Unitgraph between to other
marco.bakera> units. Is there an elegant method to do this
marco.bakera> without having to check which kind of statement
marco.bakera> the unit belongs to and just inserting it?
I'm not certain I understand exactly what you wish to do, but I
think the answer is "no" (or, more precisely, "no" unless you're
willing to make major modifications to Soot in order to change
the answer to "yes" :-))
The CFG building classes provide no mechanism for changing a CFG
once it has been constructed. I believe this reflects how
program transformations (or at least intraprocedural
transformations) have traditionally been structured in Soot: you
get an input Body and create a CFG from that Body to perform
some analysis. If the analysis suggests some transformation is
desirable, you perform the transformation by changing the Body.
The old CFG is now trash; if you want a CFG corresponding to the
transformed Body, you need to generate a new one.
Put more succinctly, the intermediate representation Soot works
on is the Body, not its graph.
One can imagine a system where you transform the CFG instead, and
ultimately generate code from the CFG, but I think it would take
a lot of work to turn Soot into such a system.
But perhaps you're not interested in changing the code that
ultimately gets generated, but are interested in the graph itself
(for human code understanding, for example), and just want to
insert a node to change its shape. That would be easier, but
would still require creating your own variant of UnitGraph that
allows changes after the graph is constructed.
Or perhaps I am inappropriately focussing on your mentioning of
CFGs (because of my own reimplementation of some of the CFG
construction code). It could be you are just asking, "how do I
add a statement to the Body that the CFG corresponds to?". In
that case, I'd suggest looking at the examples in the Soot
tutorial. The example goto-instrumenter
(http://www.sable.mcgill.ca/soot/tutorial/profiler/index.html)
adds AssignStmts.
- References:
- Modifying CFG
- From: "Marco Bakera" <marco.bakera@uni-dortmund.de>