4 import MCC.IR.DebugItem;
5 import MCC.IR.RepairGenerator;
8 * A generic command-line interface for 6.035 compilers. This class
9 * provides command-line parsing for student projects. It recognizes
10 * the required <tt>-target</tt>, <tt>-debug</tt>, <tt>-opt</tt>, and
11 * <tt>-o</tt> switches, and generates a name for input and output
14 * @author le01, 6.035 Staff (<tt>6.035-staff@mit.edu</tt>)
15 * @version <tt>$Id: CLI.java,v 1.21 2005/11/09 21:06:29 bdemsky Exp $</tt>
19 * Array indicating which optimizations should be performed. If
20 * a particular element is true, it indicates that the optimization
21 * named in the optnames[] parameter to parse with the same index
22 * should be performed.
24 public boolean opts[];
27 * Vector of String containing the command-line arguments which could
28 * not otherwise be parsed.
33 * Vector of String containing the optimizations which could not be
34 * parsed. It is okay to complain about anything in this list, even
35 * without the <tt>-debug</tt> flag.
37 public Vector extraopts;
40 * Name of the file to put the output in.
42 public String outfile;
45 * Name of the file to get input from. This is null if the user didn't
46 * provide a file name.
51 * The debug flag. This is true if <tt>-debug</tt> was passed on
52 * the command line, requesting debugging output.
62 * Public constructor. Sets up default values for all of the
63 * result fields. Specifically, sets the input and output files
64 * to null, the target to DEFAULT, and the extras and extraopts
65 * arrays to new empty Vectors.
70 extras = new Vector();
71 extraopts = new Vector();
76 * Parse the command-line arguments. Sets all of the result fields
79 * <li><TT>-target <I>target</I></TT> sets the CLI.target field based
80 * on the <I>target</I> specified. </li>
81 * <li><TT>scan</TT> or <TT>scanner</TT> specifies CLI.SCAN</li>
82 * <li><TT>parse</TT> specifies CLI.PARSE</li>
83 * <li><TT>inter</TT> specifies CLI.INTER</li>
84 * <li><TT>lowir</TT> specifies CLI.LOWIR</li>
85 * <TT>assembly</TT> or <TT>codegen</TT> specifies CLI.ASSEMBLY</li>
87 * The boolean array opts[] indicates which, if any, of the
88 * optimizations in optnames[] should be performed; these arrays
89 * are in the same order.
91 * @param args Array of arguments passed in to the program's Main
93 * @param optnames Ordered array of recognized optimization names. */
94 public void parse(String args[]) {
96 String optnames[] = {};
100 opts = new boolean[optnames.length];
102 if (args.length==0) {
103 System.out.println("-debugcompiler -- print out debug messages");
104 System.out.println("-depth depthnum constraintnum -- generate dependency graph from constraintnum with depth of depthnum");
105 System.out.println("-depthconj depthnum constraintnum conjunctionnum -- generate dependency graph from constraintnum with depth of depthnum");
106 System.out.println("-instrument -- generate instrumentation code");
107 System.out.println("-removeconj constr,conj");
108 System.out.println("-aggressivesearch -- search for one repair per constraint");
109 System.out.println("-prunequantifiernodes -- prune nodes that satisfy constraint by decreasing scope");
110 System.out.println("-cplusplus -- properly set up c++ classes");
111 System.out.println("-time -- generate timing code");
112 System.out.println("-omitcomp -- omit compensation updates");
113 System.out.println("-mergenodes -- omit nodes for simpler role dependence graphs");
114 System.out.println("-debuggraph -- add edge labels and support to debug graph");
115 System.out.println("-rejectlengthchanges -- reject all updates which change the length of an array");
116 System.out.println("-printrepairs -- print log of repair actions");
117 System.out.println("-exactallocation -- application calls malloc for each struct and");
118 System.out.println(" allocates exactly the right amount of space.");
119 System.out.println("-name -- set name");
123 for (int i = 0; i < args.length; i++) {
124 if (args[i].equals("-debugcompiler")) {
127 } else if (args[i].equals("-checkonly")) {
128 Compiler.REPAIR=false;
129 } else if (args[i].equals("-removeconj")) {
130 if ((i+1)==args.length) {
131 throw new Error("No fieldname");
133 Compiler.removeconj.add(args[i+1]);
135 } else if (args[i].equals("-exactallocation")) {
136 Compiler.EXACTALLOCATION=true;
137 } else if (args[i].equals("-omitcomp")) {
138 Compiler.OMITCOMP=true;
139 } else if (args[i].equals("-debuggraph")) {
140 Compiler.DEBUGGRAPH=true;
141 } else if (args[i].equals("-mergenodes")) {
142 Compiler.MERGENODES=true;
143 } else if (args[i].equals("-printrepairs")) {
144 Compiler.PRINTREPAIRS=true;
145 } else if (args[i].equals("-depth")) {
146 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2])));
148 } else if (args[i].equals("-depthconj")) {
149 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2]),Integer.parseInt(args[i+3])));
151 } else if (args[i].equals("-rejectlengthchanges")) {
152 Compiler.REJECTLENGTH=true;
153 } else if (args[i].equals("-debug")) {
154 Compiler.GENERATEDEBUGHOOKS=true;
155 } else if (args[i].equals("-time")) {
157 } else if (args[i].equals("-instrument")) {
158 Compiler.GENERATEINSTRUMENT=true;
159 } else if (args[i].equals("-aggressivesearch")) {
160 Compiler.AGGRESSIVESEARCH=true;
161 } else if (args[i].equals("-prunequantifiernodes")) {
162 Compiler.PRUNEQUANTIFIERS=true;
163 } else if (args[i].equals("-cplusplus")) {
164 Compiler.ALLOCATECPLUSPLUS=true;
165 } else if (args[i].equals("-name")) {
167 RepairGenerator.name=args[i];
168 RepairGenerator.postfix=args[i];
169 } else if (args[i].equals("-verbose") || args[i].equals("-v")) {
172 } else if (args[i].equals("-opt"))
174 else if (args[i].equals("-o"))
176 else if (context == 1) {
178 for (int j = 0; j < optnames.length; j++) {
179 if (args[i].equals("all") ||
180 (args[i].equals(optnames[j]))) {
184 if (args[i].equals("-" + optnames[j])) {
190 extraopts.addElement(args[i]);
191 } else if (context == 2) {
196 for (int j = 0; j < optnames.length; j++) {
197 if (args[i].equals("-" + optnames[j])) {
203 extras.addElement(args[i]);
208 // grab infile and lose extra args
210 while (infile == null && i < extras.size()) {
211 String fn = (String) extras.elementAt(i);
213 if (fn.charAt(0) != '-')
216 extras.removeElementAt(i);