1 19 20 25 26 package soot; 27 28 29 import soot.toolkits.astmetrics.ClassData; 30 import java.util.*; 31 import soot.options.Options; 32 33 import java.io.*; 34 35 36 public class Main { 37 public Main(Singletons.Global g) { 38 } 39 public static Main v() { 40 return G.v().soot_Main(); 41 } 42 public final String versionString = "2.2.3"; 46 47 private Date start; 48 private Date finish; 49 50 private void printVersion() { 51 G.v().out.println("Soot version " + versionString); 52 53 G.v().out.println( 54 "Copyright (C) 1997-2003 Raja Vallee-Rai and others."); 55 G.v().out.println("All rights reserved."); 56 G.v().out.println(""); 57 G.v().out.println( 58 "Contributions are copyright (C) 1997-2003 by their respective contributors."); 59 G.v().out.println("See the file 'credits' for a list of contributors."); 60 G.v().out.println("See individual source files for details."); 61 G.v().out.println(""); 62 G.v().out.println( 63 "Soot comes with ABSOLUTELY NO WARRANTY. Soot is free software,"); 64 G.v().out.println( 65 "and you are welcome to redistribute it under certain conditions."); 66 G.v().out.println( 67 "See the accompanying file 'COPYING-LESSER.txt' for details."); 68 G.v().out.println(); 69 G.v().out.println("Visit the Soot website:"); 70 G.v().out.println(" http://www.sable.mcgill.ca/soot/"); 71 G.v().out.println(); 72 G.v().out.println("For a list of command line options, enter:"); 73 G.v().out.println(" java soot.Main --help"); 74 } 75 76 private void processCmdLine(String [] args) { 77 78 if (!Options.v().parse(args)) 79 throw new CompilationDeathException( 80 CompilationDeathException.COMPILATION_ABORTED, 81 "Option parse error"); 82 83 if( PackManager.v().onlyStandardPacks() ) { 84 for( Iterator packIt = PackManager.v().allPacks().iterator(); packIt.hasNext(); ) { 85 final Pack pack = (Pack) packIt.next(); 86 Options.v().warnForeignPhase(pack.getPhaseName()); 87 for( Iterator trIt = pack.iterator(); trIt.hasNext(); ) { 88 final Transform tr = (Transform) trIt.next(); 89 Options.v().warnForeignPhase(tr.getPhaseName()); 90 } 91 } 92 } 93 Options.v().warnNonexistentPhase(); 94 95 if (Options.v().help()) { 96 G.v().out.println(Options.v().getUsage()); 97 throw new CompilationDeathException(CompilationDeathException.COMPILATION_SUCCEEDED); 98 } 99 100 if (Options.v().phase_list()) { 101 G.v().out.println(Options.v().getPhaseList()); 102 throw new CompilationDeathException(CompilationDeathException.COMPILATION_SUCCEEDED); 103 } 104 105 if(!Options.v().phase_help().isEmpty()) { 106 for( Iterator phaseIt = Options.v().phase_help().iterator(); phaseIt.hasNext(); ) { 107 final String phase = (String ) phaseIt.next(); 108 G.v().out.println(Options.v().getPhaseHelp(phase)); 109 } 110 throw new CompilationDeathException(CompilationDeathException.COMPILATION_SUCCEEDED); 111 } 112 113 if (args.length == 0 || Options.v().version()) { 114 printVersion(); 115 throw new CompilationDeathException(CompilationDeathException.COMPILATION_SUCCEEDED); 116 } 117 118 postCmdLineCheck(); 119 } 120 121 private void exitCompilation(int status) { 122 exitCompilation(status, ""); 123 } 124 125 private void exitCompilation(int status, String msg) { 126 if(status == CompilationDeathException.COMPILATION_ABORTED) { 127 G.v().out.println("compilation failed: "+msg); 128 } 129 } 130 131 private void postCmdLineCheck() { 132 if (Options.v().classes().isEmpty() 133 && Options.v().process_dir().isEmpty()) { 134 throw new CompilationDeathException( 135 CompilationDeathException.COMPILATION_ABORTED, 136 "No main class specified!"); 137 } 138 } 139 140 public String [] cmdLineArgs; 141 144 public static void main(String [] args) { 145 try { 146 Main.v().run(args); 147 } catch( OutOfMemoryError e ) { 148 G.v().out.println( "Soot has run out of the memory allocated to it by the Java VM." ); 149 G.v().out.println( "To allocate more memory to Soot, use the -Xmx switch to Java." ); 150 G.v().out.println( "For example (for 400MB): java -Xmx400m soot.Main ..." ); 151 throw e; 152 } 153 } 154 155 158 public int run(String [] args) { 159 cmdLineArgs = args; 160 161 start = new Date(); 162 163 try { 164 Timers.v().totalTimer.start(); 165 166 processCmdLine(cmdLineArgs); 167 168 G.v().out.println("Soot started on " + start); 169 170 Scene.v().loadNecessaryClasses(); 171 172 177 if(Options.v().ast_metrics()){ 178 try{ 179 OutputStream streamOut = new FileOutputStream("../astMetrics.xml"); 180 PrintWriter writerOut = new PrintWriter(new OutputStreamWriter(streamOut)); 181 writerOut.println("<?xml version='1.0'?>"); 182 writerOut.println("<ASTMetrics>"); 183 184 Iterator it = G.v().ASTMetricsData.iterator(); 185 while(it.hasNext()){ 186 ClassData cData = (ClassData)it.next(); 188 writerOut.println(cData.toString()); 189 } 190 191 writerOut.println("</ASTMetrics>"); 192 writerOut.flush(); 193 streamOut.close(); 194 } catch (IOException e) { 195 throw new CompilationDeathException("Cannot output file astMetrics"); 196 } 197 exitCompilation(CompilationDeathException.COMPILATION_SUCCEEDED); 198 return CompilationDeathException.COMPILATION_SUCCEEDED; 199 200 } 201 202 203 PackManager.v().runPacks(); 204 PackManager.v().writeOutput(); 205 206 Timers.v().totalTimer.end(); 207 208 if (Options.v().time()) 210 Timers.v().printProfilingInformation(); 211 212 } catch (CompilationDeathException e) { 213 Timers.v().totalTimer.end(); 214 exitCompilation(e.getStatus(), e.getMessage()); 215 return e.getStatus(); 216 } 217 218 finish = new Date(); 219 220 G.v().out.println("Soot finished on " + finish); 221 long runtime = finish.getTime() - start.getTime(); 222 G.v().out.println( 223 "Soot has run for " 224 + (runtime / 60000) 225 + " min. " 226 + ((runtime % 60000) / 1000) 227 + " sec."); 228 229 exitCompilation(CompilationDeathException.COMPILATION_SUCCEEDED); 230 return CompilationDeathException.COMPILATION_SUCCEEDED; 231 } 232 } 233 | Popular Tags |