[Soot-list] counting number of lines in jimple
Eric Bodden
bodden at st.informatik.tu-darmstadt.de
Thu May 27 03:32:46 EDT 2010
Hi there.
I am afraid my answer won't be very helpful... I just wanted to let
you know that I am not aware of any tags that would tell you Jimple
line numbers. There may be some, but I am not sure. Actually I think
that it would make little sense ot have such tags because the line
numbers change whenever modifying the Jimple, which happens quite
often.
Eric
--
Dr. Eric Bodden
Software Technology Group, Technische Universität Darmstadt, Germany
Tel: +49 6151 16-5478 Fax: +49 6151 16-5410
Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt
On 26 May 2010 18:27, DIVYA IYER <sirius.strider at gmail.com> wrote:
> Hello everybody,
>
> I am trying to write a program that takes a java class file...converts it
> into corresponding jimple code and prints out the jimple statements along
> with their line numbers. Then I would like to pick out those lines from the
> jimple code which have a "virtual invoke". The code that I have written
> looks like below:
>
> import soot.*;
> import java.util.*;
> import soot.util.*;
> import soot.jimple.Stmt;
> import soot.tagkit.LineNumberTag;
> import soot.baf.*;
> import java.io.*;
>
> public class GetStmts4 extends BodyTransformer implements RetInst
> {
> private static GetStmts4 instance = new GetStmts4();
>
> private GetStmts4() {};
>
> public static GetStmts4 v()
> {
> return instance;
> }
>
> public static void main(String args[])
> {
> soot.options.Options.v().set_keep_line_number(true);
> //soot.options.Options.v().set_whole_program(true);
> //soot.options.Options.v().setPhaseOption("cg","verbose:true");
> PackManager.v().getPack("jtp").add(new Transform
> ("jtp.annotexample",GetStmts4.v()));
> soot.Main.main(args);
>
> }
>
> protected void internalTransform(Body b, String phaseName, Map options)
> {
> int linenum = 0;
> int count = 0;
> int array[] = new int[20];
> PatchingChain units = b.getUnits();
> Iterator unitsIt = units.iterator();
>
> while(unitsIt.hasNext())
> {
> Unit unit = (Unit)unitsIt.next();
> LineNumberTag tag = (LineNumberTag) unit.getTag("LineNumberTag");
> int index = rt.getIndex(); //to get the index of the jimple
> line??is this correct??
> System.out.println("Index is :" + index);
> System.out.println(unit);
> if (tag != null)
>
> //wrote the following piece of code but it gives me the line number in the
> source code...and not the jimple line number
> {
> System.out.println("java line number:"+tag.getLineNumber());
> //System.out.println("tag name:"+tag.getName());
> String string = unit.toString();
> if(string.matches("\\s*.*virtualinvoke.*"))
> {
> count++;
> System.out.println("line number with
> virtualinvoke:"+tag.getLineNumber());
> array[count] = tag.getLineNumber();
> System.out.println("the " +count+ " element in array is : "
> +array[count]);
> }
> }
> }
> for(int k = 1;k <= count; k++)
> {
> System.out.println(array[k]);
> }
> }
> }
>
> Would be really grateful if somebody could help me out with this.
> Thanks!!!
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>
More information about the Soot-list
mailing list