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.20 2005/11/09 16:47:42 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("-aggressivesearch -- search for one repair per constraint");
108 System.out.println("-prunequantifiernodes -- prune nodes that satisfy constraint by decreasing scope");
109 System.out.println("-cplusplus -- properly set up c++ classes");
110 System.out.println("-time -- generate timing code");
111 System.out.println("-omitcomp -- omit compensation updates");
112 System.out.println("-mergenodes -- omit nodes for simpler role dependence graphs");
113 System.out.println("-debuggraph -- add edge labels and support to debug graph");
114 System.out.println("-rejectlengthchanges -- reject all updates which change the length of an array");
115 System.out.println("-printrepairs -- print log of repair actions");
116 System.out.println("-exactallocation -- application calls malloc for each struct and");
117 System.out.println(" allocates exactly the right amount of space.");
118 System.out.println("-name -- set name");
122 for (int i = 0; i < args.length; i++) {
123 if (args[i].equals("-debugcompiler")) {
126 } else if (args[i].equals("-checkonly")) {
127 Compiler.REPAIR=false;
128 } else if (args[i].equals("-exactallocation")) {
129 Compiler.EXACTALLOCATION=true;
130 } else if (args[i].equals("-omitcomp")) {
131 Compiler.OMITCOMP=true;
132 } else if (args[i].equals("-debuggraph")) {
133 Compiler.DEBUGGRAPH=true;
134 } else if (args[i].equals("-mergenodes")) {
135 Compiler.MERGENODES=true;
136 } else if (args[i].equals("-printrepairs")) {
137 Compiler.PRINTREPAIRS=true;
138 } else if (args[i].equals("-depth")) {
139 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2])));
141 } else if (args[i].equals("-depthconj")) {
142 Compiler.debuggraphs.add(new DebugItem(Integer.parseInt(args[i+1]),Integer.parseInt(args[i+2]),Integer.parseInt(args[i+3])));
144 } else if (args[i].equals("-rejectlengthchanges")) {
145 Compiler.REJECTLENGTH=true;
146 } else if (args[i].equals("-debug")) {
147 Compiler.GENERATEDEBUGHOOKS=true;
148 } else if (args[i].equals("-time")) {
150 } else if (args[i].equals("-instrument")) {
151 Compiler.GENERATEINSTRUMENT=true;
152 } else if (args[i].equals("-aggressivesearch")) {
153 Compiler.AGGRESSIVESEARCH=true;
154 } else if (args[i].equals("-prunequantifiernodes")) {
155 Compiler.PRUNEQUANTIFIERS=true;
156 } else if (args[i].equals("-cplusplus")) {
157 Compiler.ALLOCATECPLUSPLUS=true;
158 } else if (args[i].equals("-name")) {
160 RepairGenerator.name=args[i];
161 RepairGenerator.postfix=args[i];
162 } else if (args[i].equals("-verbose") || args[i].equals("-v")) {
165 } else if (args[i].equals("-opt"))
167 else if (args[i].equals("-o"))
169 else if (context == 1) {
171 for (int j = 0; j < optnames.length; j++) {
172 if (args[i].equals("all") ||
173 (args[i].equals(optnames[j]))) {
177 if (args[i].equals("-" + optnames[j])) {
183 extraopts.addElement(args[i]);
184 } else if (context == 2) {
189 for (int j = 0; j < optnames.length; j++) {
190 if (args[i].equals("-" + optnames[j])) {
196 extras.addElement(args[i]);
201 // grab infile and lose extra args
203 while (infile == null && i < extras.size()) {
204 String fn = (String) extras.elementAt(i);
206 if (fn.charAt(0) != '-')
209 extras.removeElementAt(i);