X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fmain%2FOptions.java;fp=dol%2Fsrc%2Fdol%2Fmain%2FOptions.java;h=b284d90a084f9f823a3d8df18c62cbac111493a7;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/main/Options.java b/dol/src/dol/main/Options.java new file mode 100644 index 0000000..b284d90 --- /dev/null +++ b/dol/src/dol/main/Options.java @@ -0,0 +1,207 @@ +/* $Id: Options.java 203 2010-10-11 08:59:47Z dchokshi $ */ +package dol.main; + +/** + * This class handles the command line options. It checks if an option is + * valid, and if so, it calls the appropriate method in the UserInterface, + * that reflects the global setting of DOL. + */ +public class Options { + + /** + * Parse the command-line arguments, creating models as specified. Then + * execute each model that contains a manager. + * + * @param args + * The command-line arguments. + * @exception IllegalArgumentException + * MyException If such and such occurs + * @throws IllegalArgumentException + * if an illegal argument is found on the command line. + */ + public Options(String args[]) throws IllegalArgumentException, NumberFormatException { + _ui = UserInterface.getInstance(); + if(args != null) { + _parseArgs(args); + } + } + + /** + * Parse the command-line arguments. + * + * @param args The arguments to be parsed + * + * @throws IllegalArgumentException + * if an illegal argument is found on the command line. + */ + protected void _parseArgs(String args[]) throws IllegalArgumentException, + NumberFormatException { + if(args.length > 0) { + for(int i = 0; i < args.length; i++ ) { + String arg = args[i]; + if(_parseArg(arg) == false ) { + if(arg.startsWith("-") && i < args.length - 1 ) { + if(arg.equals("--platform") || arg.equals("-p") ) { + _ui.setPlatformFileName(args[++i]); + } else if(arg.equals("--processnetwork") || arg.equals("-P") ) { + _ui.setNetworkFileName(args[++i]); + } else if(arg.equals("--mapping") || arg.equals("-m") ) { + _ui.setMappingFileName(args[++i]); + } else if(arg.equals("--scheduler") || arg.equals("-s") ) { + _ui.setSchedulerFileName(args[++i]); + } else if(arg.equals("--systemC") || arg.equals("-C") ) { + _ui.setCodeDirectoryName(args[++i]); + _ui.setSystemCFlag(); + } else if(arg.equals("--HdS") || arg.equals("-H") ) { + _ui.setHdsCodeDirectoryName(args[++i]); + _ui.setHdsFlag(); + } else if(arg.startsWith("--rtems") || arg.startsWith("-R") ) { + String bsp = arg; + bsp = bsp.replaceAll("--rtems" , ""); + bsp = bsp.replaceAll("-R", ""); + if (bsp.equals("")) { + _ui.setRtemsBSP("pc386"); + } else if (bsp.equals("pc386") || bsp.equals("mparm")) { + _ui.setRtemsBSP(bsp); + } else { + throw new IllegalArgumentException( + "Board support package \"" + bsp + + "\" not supported by code generation."); + } + _ui.setRtemsCodeDirectoryName(args[++i]); + _ui.setRtemsFlag(); + } else if(arg.equals("--PaF") || arg.equals("-PF") ) { + _ui.setPipeAndFilterCodeDirectoryName(args[++i]); + _ui.setPipeAndFilterFlag(); + } else if(arg.equals("--protothread") || arg.equals("-PT") ) { + _ui.setProtothreadCodeDirectoryName(args[++i]); + _ui.setProtothreadFlag(); + } else if(arg.equals("--dotty") || arg.equals("-D")) { + _ui.setDottyFileName(args[++i]); + } else if(arg.equals("--profiling") || arg.equals("-T")) { + _ui.setTraceName(args[++i]); + _ui.setProfilingFlag(); + } else if (arg.equals("--vsplog") || arg.equals("-L")) { + _ui.setVspLogFileName(args[++i]); + _ui.setVspLogFlag(); + } else if (arg.equals("--workload") || arg.equals("-W")) { + _ui.setWorkloadFileName(args[++i]); + _ui.setWorkloadFlag(); + } else if(arg.equals("--xmlGen") || arg.equals("-G")) { + _ui.setOutputFileName(args[++i]); + _ui.setXmlGenFlag(); + } else if(arg.equals("--cbe") || arg.equals("-CBE")) { + _ui.setCbeCodeDirectoryName(args[++i]); + _ui.setCbeFlag(); + } else if(arg.equals("--yapi") || arg.equals("-Y")) { + _ui.setYapiCodeDirectoryName(args[++i]); + _ui.setYapiFlag(); + } else { + throw new IllegalArgumentException("Unrecognized option: " + arg); + } + } else { + throw new IllegalArgumentException("Unrecognized option: " + arg); + } + } + } + } else { + throw new IllegalArgumentException(_usage()); + } + } + + /** + * Parse a single commandline argument. + * + * @param arg commandline argument + * @return true if the argument is understood, false otherwise + * @throws IllegalArgumentExcecption thrown if an illegal argument is + * found on the command line. + */ + protected boolean _parseArg(String arg) throws IllegalArgumentException { + if(arg.equals("--help") || arg.equals("-h") ) { + //throw new IllegalArgumentException(_usage()); + System.out.println(_usage() ); + System.exit(0); + } else if(arg.equals("--version") || arg.equals("-V") ) { + System.out.println("DOL version 0.0.1\n"); + System.exit(0); + } else if(arg.equals("--verbose") || arg.equals("-v") ) { + _ui.setVerboseFlag(); + } else if(arg.equals("--check") || arg.equals("-c")) { + _ui.setCheckFlag(); + } else if(arg.equals("--debug")) { + _ui.setDebugFlag(); + } else if(arg.equals("")) { // Ignore blank argument. + } else { // Argument not recognized. + return false; + } + return true; + } + + /** + * Return a string summarizing the command-line arguments. + * + * @return A usage string. + */ + protected String _usage() { + String result = "Usage: " + _commandTemplate + "\n\n" + + "Options:\n"; + + int i; + for(i = 0; i < _commandOptions.length; i++) { + result += " " + _commandOptions[i][0] + "\tabbr[" + + _commandOptions[i][1] + " " + _commandOptions[i][2] + + "]\n"; + } + result += "\nBoolean flags:\n"; + for(i = 0; i < _commandFlags.length; i++) { + result += " " + _commandFlags[i][0] + "\tabbr[" + + _commandFlags[i][1] + "]\n"; + } + return result; + } + + /** + * The command-line options that are either present or not. Give the full + * name preceded with '--' and abbreviated version. + */ + protected String _commandFlags[][] = { + { "--check ", "-c" }, + { "--flatten ", "-F" }, + { "--help ", "-h" }, + { "--version ", "-V" }, + { "--verbose ", "-v" }, + { "--debug ", "none" }, + }; + + /** + * The command-line options that take arguments. + */ + protected String _commandOptions[][] = { + { "--platform ", "-p ", "" }, + { "--processnetwork", "-P ", "" }, + { "--mapping ", "-m ", "" }, + { "--scheduler ", "-s ", "" }, + { "--dotty ", "-D ", "" }, + { "--xmlGen ", "-G", "" }, + { "--systemC ", "-C ", "" }, + { "--HdS ", "-H ", "" }, + { "--PaF ", "-PF", "" }, + { "--rtems ", "-R", "" }, + { "--protothread ", "-PT", "" }, + { "--profiling ", "-T", "" }, + { "--vsplog ", "-L", "" }, + { "--cbe ", "-CBE", "" }, + { "--yapi ", "-Y", "" } + }; + + /** + * The form of the command line. + */ + protected String _commandTemplate = "dol [ options ]"; + + /** + * The UserInterface object. + */ + protected UserInterface _ui = null; +}