1 /* $Id: Options.java 203 2010-10-11 08:59:47Z dchokshi $ */
5 * This class handles the command line options. It checks if an option is
6 * valid, and if so, it calls the appropriate method in the UserInterface,
7 * that reflects the global setting of DOL.
12 * Parse the command-line arguments, creating models as specified. Then
13 * execute each model that contains a manager.
16 * The command-line arguments.
17 * @exception IllegalArgumentException
18 * MyException If such and such occurs
19 * @throws IllegalArgumentException
20 * if an illegal argument is found on the command line.
22 public Options(String args[]) throws IllegalArgumentException, NumberFormatException {
23 _ui = UserInterface.getInstance();
30 * Parse the command-line arguments.
32 * @param args The arguments to be parsed
34 * @throws IllegalArgumentException
35 * if an illegal argument is found on the command line.
37 protected void _parseArgs(String args[]) throws IllegalArgumentException,
38 NumberFormatException {
40 for(int i = 0; i < args.length; i++ ) {
42 if(_parseArg(arg) == false ) {
43 if(arg.startsWith("-") && i < args.length - 1 ) {
44 if(arg.equals("--platform") || arg.equals("-p") ) {
45 _ui.setPlatformFileName(args[++i]);
46 } else if(arg.equals("--processnetwork") || arg.equals("-P") ) {
47 _ui.setNetworkFileName(args[++i]);
48 } else if(arg.equals("--mapping") || arg.equals("-m") ) {
49 _ui.setMappingFileName(args[++i]);
50 } else if(arg.equals("--scheduler") || arg.equals("-s") ) {
51 _ui.setSchedulerFileName(args[++i]);
52 } else if(arg.equals("--systemC") || arg.equals("-C") ) {
53 _ui.setCodeDirectoryName(args[++i]);
55 } else if(arg.equals("--HdS") || arg.equals("-H") ) {
56 _ui.setHdsCodeDirectoryName(args[++i]);
58 } else if(arg.startsWith("--rtems") || arg.startsWith("-R") ) {
60 bsp = bsp.replaceAll("--rtems" , "");
61 bsp = bsp.replaceAll("-R", "");
63 _ui.setRtemsBSP("pc386");
64 } else if (bsp.equals("pc386") || bsp.equals("mparm")) {
67 throw new IllegalArgumentException(
68 "Board support package \"" + bsp
69 + "\" not supported by code generation.");
71 _ui.setRtemsCodeDirectoryName(args[++i]);
73 } else if(arg.equals("--PaF") || arg.equals("-PF") ) {
74 _ui.setPipeAndFilterCodeDirectoryName(args[++i]);
75 _ui.setPipeAndFilterFlag();
76 } else if(arg.equals("--protothread") || arg.equals("-PT") ) {
77 _ui.setProtothreadCodeDirectoryName(args[++i]);
78 _ui.setProtothreadFlag();
79 } else if(arg.equals("--dotty") || arg.equals("-D")) {
80 _ui.setDottyFileName(args[++i]);
81 } else if(arg.equals("--profiling") || arg.equals("-T")) {
82 _ui.setTraceName(args[++i]);
83 _ui.setProfilingFlag();
84 } else if (arg.equals("--vsplog") || arg.equals("-L")) {
85 _ui.setVspLogFileName(args[++i]);
87 } else if (arg.equals("--workload") || arg.equals("-W")) {
88 _ui.setWorkloadFileName(args[++i]);
89 _ui.setWorkloadFlag();
90 } else if(arg.equals("--xmlGen") || arg.equals("-G")) {
91 _ui.setOutputFileName(args[++i]);
93 } else if(arg.equals("--cbe") || arg.equals("-CBE")) {
94 _ui.setCbeCodeDirectoryName(args[++i]);
96 } else if(arg.equals("--yapi") || arg.equals("-Y")) {
97 _ui.setYapiCodeDirectoryName(args[++i]);
100 throw new IllegalArgumentException("Unrecognized option: " + arg);
103 throw new IllegalArgumentException("Unrecognized option: " + arg);
108 throw new IllegalArgumentException(_usage());
113 * Parse a single commandline argument.
115 * @param arg commandline argument
116 * @return true if the argument is understood, false otherwise
117 * @throws IllegalArgumentExcecption thrown if an illegal argument is
118 * found on the command line.
120 protected boolean _parseArg(String arg) throws IllegalArgumentException {
121 if(arg.equals("--help") || arg.equals("-h") ) {
122 //throw new IllegalArgumentException(_usage());
123 System.out.println(_usage() );
125 } else if(arg.equals("--version") || arg.equals("-V") ) {
126 System.out.println("DOL version 0.0.1\n");
128 } else if(arg.equals("--verbose") || arg.equals("-v") ) {
129 _ui.setVerboseFlag();
130 } else if(arg.equals("--check") || arg.equals("-c")) {
132 } else if(arg.equals("--debug")) {
134 } else if(arg.equals("")) { // Ignore blank argument.
135 } else { // Argument not recognized.
142 * Return a string summarizing the command-line arguments.
144 * @return A usage string.
146 protected String _usage() {
147 String result = "Usage: " + _commandTemplate + "\n\n"
151 for(i = 0; i < _commandOptions.length; i++) {
152 result += " " + _commandOptions[i][0] + "\tabbr["
153 + _commandOptions[i][1] + " " + _commandOptions[i][2]
156 result += "\nBoolean flags:\n";
157 for(i = 0; i < _commandFlags.length; i++) {
158 result += " " + _commandFlags[i][0] + "\tabbr["
159 + _commandFlags[i][1] + "]\n";
165 * The command-line options that are either present or not. Give the full
166 * name preceded with '--' and abbreviated version.
168 protected String _commandFlags[][] = {
169 { "--check ", "-c" },
170 { "--flatten ", "-F" },
172 { "--version ", "-V" },
173 { "--verbose ", "-v" },
174 { "--debug ", "none" },
178 * The command-line options that take arguments.
180 protected String _commandOptions[][] = {
181 { "--platform ", "-p ", "<FileName>" },
182 { "--processnetwork", "-P ", "<FileName>" },
183 { "--mapping ", "-m ", "<FileName>" },
184 { "--scheduler ", "-s ", "<FileName>" },
185 { "--dotty ", "-D ", "<FileName>" },
186 { "--xmlGen ", "-G", "<FileName>" },
187 { "--systemC ", "-C ", "<DirectoryName>" },
188 { "--HdS ", "-H ", "<DirectoryName>" },
189 { "--PaF ", "-PF", "<DirectoryName>" },
190 { "--rtems ", "-R", "<DirectoryName>" },
191 { "--protothread ", "-PT", "<DirectoryName>" },
192 { "--profiling ", "-T", "<trace FileName>" },
193 { "--vsplog ", "-L", "<log FileName>" },
194 { "--cbe ", "-CBE", "<DirectoryName>" },
195 { "--yapi ", "-Y", "<DirectoryName>" }
199 * The form of the command line.
201 protected String _commandTemplate = "dol [ options ]";
204 * The UserInterface object.
206 protected UserInterface _ui = null;