package MCC;
import java.util.Vector;
import java.util.StringTokenizer;
/**
* A generic command-line interface for 6.035 compilers. This class
* provides command-line parsing for student projects. It recognizes
* the required -target, -debug, -opt, and
* -o switches, and generates a name for input and output
* files.
*
* @author le01, 6.035 Staff (6.035-staff@mit.edu)
* @version $Id: CLI.java,v 1.2 2004/04/15 05:41:46 bdemsky Exp $
*/
public class CLI {
/**
* Target value indicating that the compiler should produce its
* default output.
*/
public static final int DEFAULT = 0;
/**
* Target value indicating that the compiler should scan the input
* and stop.
*/
public static final int SCAN = 1;
/**
* Target value indicating that the compiler should scan and parse
* its input, and stop.
*/
public static final int PARSE = 2;
/**
* Target value indicating that the compiler should produce a
* high-level intermediate representation from its input, and stop.
* This is not one of the segment targets for Fall 2000, but you
* may wish to use it for your own purposes.
*/
public static final int INTER = 3;
/**
* Target value indicating that the compiler should produce a
* low-level intermediate representation from its input, and stop.
*/
public static final int LOWIR = 4;
/**
* Target value indicating that the compiler should produce
* assembly from its input.
*/
public static final int ASSEMBLY = 5;
/**
* Array indicating which optimizations should be performed. If
* a particular element is true, it indicates that the optimization
* named in the optnames[] parameter to parse with the same index
* should be performed.
*/
public boolean opts[];
/**
* Vector of String containing the command-line arguments which could
* not otherwise be parsed.
*/
public Vector extras;
/**
* Vector of String containing the optimizations which could not be
* parsed. It is okay to complain about anything in this list, even
* without the -debug flag.
*/
public Vector extraopts;
/**
* Name of the file to put the output in.
*/
public String outfile;
/**
* Name of the file to get input from. This is null if the user didn't
* provide a file name.
*/
public String infile;
/**
* The target stage. This should be one of the integer constants
* defined elsewhere in this package.
*/
public int target;
/**
* The debug flag. This is true if -debug was passed on
* the command line, requesting debugging output.
*/
public boolean debug;
/**
* Native MIPS architecture is specified by "-native". The default
* is SPIM.
*/
public boolean fNative;
/**
* Runs IRVis on final node tree.
*/
public boolean fVis;
public String visClass;
public String visMethod;
/**
* Dumps the before and after Node structure to two files that can be diffed.
*/
public boolean fDiff;
public String diffFile;
/**
* Maximum optimization iterations.
*/
public int numIterations = 5;
/**
* Verbose output
*/
public int verbose;
/**
* Public constructor. Sets up default values for all of the
* result fields. Specifically, sets the input and output files
* to null, the target to DEFAULT, and the extras and extraopts
* arrays to new empty Vectors.
*/
public CLI() {
outfile = null;
infile = null;
target = DEFAULT;
extras = new Vector();
extraopts = new Vector();
fNative = false;
fVis = false;
verbose = 0;
visClass = "";
visMethod = "";
fDiff = false;
diffFile = "";
}
/**
* Parse the command-line arguments. Sets all of the result fields
* accordingly.
*