[Soot-list] Counting exits in a loop - understanding Jimple "goto [?= nop]"
David Given
dg at cowlark.com
Tue Jul 17 05:07:22 EDT 2012
John Dean wrote:
[...]
> You say "When you operating at runtime, the targets of the goto instructions
> will be two disctinct Units." So for the "goto nop" that shows up in my list
> of statements, what are the "targets," that are "two distinct Units"?
> Likewise, for the "goto [?= nop]" statement: What are the "targets," that
> are "two distinct Units"?
You're being misled by the way it's being printed --- I ran into this
with cowjac.
Each body is a graph of statements. The goto statement's target is just
another statement. The naive way to turn a goto instruction to a string
just prints 'goto' followed by the string value of the target statement.
So 'goto nop' is appearing because the target of the goto is a nop
instruction *which is somewhere else in the graph*.
When you actually do this for real, then instead of just turning the
goto's target into a string you want to generate a label reference
instead. The pseudocode something like this:
when generating code for a goto:
print "goto "
print label for goto's target statement
for all statements in method body
does this statement need a label?
print label for statement
generate code for statement
The code Soot uses to emit Jimple, which does this, is here:
https://github.com/Sable/soot/blob/master/src/soot/Printer.java
...in the printStatementsInBody() method.
(What would actually be kinda nice is a soot postprocessing phase that
walked the instruction graph and added label tags to each Unit; this
area is a bit counterintuitive...)
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that
│ cursing is more dangerous than being hit by a car." --- Scott Adams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
Url : http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120717/3e1d09ca/attachment.bin
More information about the Soot-list
mailing list