4 import MCC.IR.DebugItem;
7 * A generic command-line interface for 6.035 compilers. This class
8 * provides command-line parsing for student projects. It recognizes
9 * the required <tt>-target</tt>, <tt>-debug</tt>, <tt>-opt</tt>, and
10 * <tt>-o</tt> switches, and generates a name for input and output
13 * @author le01, 6.035 Staff (<tt>6.035-staff@mit.edu</tt>)
14 * @version <tt>$Id: CLI.java,v 1.13 2005/02/04 20:14:52 bdemsky Exp $</tt>
18 * Array indicating which optimizations should be performed. If
19 * a particular element is true, it indicates that the optimization
20 * named in the optnames[] parameter to parse with the same index
21 * should be performed.
23 public boolean opts[];
26 * Vector of String containing the command-line arguments which could
27 * not otherwise be parsed.
32 * Vector of String containing the optimizations which could not be
33 * parsed. It is okay to complain about anything in this list, even
34 * without the <tt>-debug</tt> flag.
36 public Vector extraopts;
39 * Name of the file to put the output in.
41 public String outfile;
44 * Name of the file to get input from. This is null if the user didn't
45 * provide a file name.
50 * The debug flag. This is true if <tt>-debug</tt> was passed on
51 * the command line, requesting debugging output.
61 * Public constructor. Sets up default values for all of the
62 * result fields. Specifically, sets the input and output files
63 * to null, the target to DEFAULT, and the extras and extraopts
64 * arrays to new empty Vectors.
69 extras = new Vector();
70 extraopts = new Vector();
75 * Parse the command-line arguments. Sets all of the result fields
78 * <li><TT>-target <I>target</I></TT> sets the CLI.target field based
79 * on the <I>target</I> specified. </li>
80 * <li><TT>scan</TT> or <TT>scanner</TT> specifies CLI.SCAN</li>
81 * <li><TT>parse</TT> specifies CLI.PARSE</li>
82 * <li><TT>inter</TT> specifies CLI.INTER</li>
83 * <li><TT>lowir</TT> specifies CLI.LOWIR</li>
84 * <TT>assembly</TT> or <TT>codegen</TT> specifies CLI.ASSEMBLY</li>
86 * The boolean array opts[] indicates which, if any, of the
87 * optimizations in optnames[] should be performed; these arrays
88 * are in the same order.
90 * @param args Array of arguments passed in to the program's Main
92 * @param optnames Ordered array of recognized optimization names. */
93 public void parse(String args[]) {
95 String optnames[] = {};
99 opts = new boolean[optnames.length];
101 if (args.length==0) {
102 System.out.println("-debugcompiler -- print out debug messages");
103 System.out.println("-depth depthnum constraintnum -- generate dependency graph from constraintnum with depth of depthnum");
104 System.out.println("-depthconj depthnum constraintnum conjunctionnum -- generate dependency graph from constraintnum with depth of depthnum");
105 System.out.println("-instrument -- generate instrumentation code");
106 System.out.println("-aggressivesearch");
107 System.out.println("-prunequantifiernodes");
108 System.out.println("-cplusplus");
109 System.out.println("-time");
110 System.out.println("-omitcomp");
114 for (int i = 0; i < args.length; i++) {
115 if (args[i].equals("-debugcompiler")) {
118 } else if (args[i].equals("-checkonly")) {
119 Compiler.REPAIR=false;
120 } else if (args[i].equals("-omitcomp")) {
121 Compiler.OMITCOMP=true;
122 } else if (args[i].equals("-depth")) {
123 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2])));
125 } else if (args[i].equals("-depthconj")) {
126 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2]),Integer.parseInt(args[i+3])));
128 } else if (args[i].equals("-debug")) {
129 Compiler.GENERATEDEBUGHOOKS=true;
130 } else if (args[i].equals("-time")) {
132 } else if (args[i].equals("-instrument")) {
133 Compiler.GENERATEINSTRUMENT=true;
134 } else if (args[i].equals("-aggressivesearch")) {
135 Compiler.AGGRESSIVESEARCH=true;
136 } else if (args[i].equals("-prunequantifiernodes")) {
137 Compiler.PRUNEQUANTIFIERS=true;
138 } else if (args[i].equals("-cplusplus")) {
139 Compiler.ALLOCATECPLUSPLUS=true;
140 } else if (args[i].equals("-verbose") || args[i].equals("-v")) {
143 } else if (args[i].equals("-opt"))
145 else if (args[i].equals("-o"))
147 else if (context == 1) {
149 for (int j = 0; j < optnames.length; j++) {
150 if (args[i].equals("all") ||
151 (args[i].equals(optnames[j]))) {
155 if (args[i].equals("-" + optnames[j])) {
161 extraopts.addElement(args[i]);
162 } else if (context == 2) {
167 for (int j = 0; j < optnames.length; j++) {
168 if (args[i].equals("-" + optnames[j])) {
174 extras.addElement(args[i]);
179 // grab infile and lose extra args
181 while (infile == null && i < extras.size()) {
182 String fn = (String) extras.elementAt(i);
184 if (fn.charAt(0) != '-')
187 extras.removeElementAt(i);