1 ///////////////////////////////////////////////////////////////////////////////
4 // // // ////// ///// ///////
5 // //////// // // // // //
10 // Allen Leung (leunga@cs.nyu.edu)
11 ///////////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 static const char * HELP_MESSAGE =
26 "%s version %s.%s, last updated on %s\n"
27 "usage: %s [options] <files>\n"
28 "options: [-automake]\n"
29 " [-d -debug] [-G -GNU] [-html] [-I<path>]\n"
30 " [-l -no_line_directives] [-M -make_depends]\n"
31 " [-n -no_codegen] [-N -non_linear]\n"
32 " [-o<outfile>] [-O#]\n"
33 " [-Ofast_string_match] [-Oadaptive_matching]\n"
34 " [-Oinline_casts] [-Otagged_pointer] [-Orewriting]\n"
35 " [-r -report] [-s -strict] [-S -save_space]\n"
36 " [-t -stdout] [-v#] [-V# -vector#] [-vcg]\n"
37 " [-new_list_format]\n"
38 " [-use_global_pools]\n"
42 ///////////////////////////////////////////////////////////////////////////////
44 // The global options data structure.
46 ///////////////////////////////////////////////////////////////////////////////
48 static Bool print_memory_usage = false;
50 ///////////////////////////////////////////////////////////////////////////////
52 // Routine to process command line arguments
54 ///////////////////////////////////////////////////////////////////////////////
55 void PropOptions::process_command_line_arguments
56 (int argc, const char * argv[])
60 for (argc--, argv++; argc > 0; argc--, argv++)
62 /-automake/: { automake = true; }
63 | /-(d|debug)/: { debug = true; }
64 | /-(n|no_codegen)/: { emit_code = false; }
65 | /-(l|no_line_directives)/: { line_directives = false; }
66 | /-(G|GNU)/: { GNU_style_message = true; }
67 | /-html/: { generate_html = true; }
68 | /-(r|report)/: { generate_report = true; }
69 | /-(s|strict)/: { strict_checking = true; }
70 | /-(t|stdout)/: { to_stdout = true; }
71 | /-trace/: { trace = true; }
72 | /-I.*/: { char c[2]; c[0] = FILE_SEPARATOR; c[1] = '\0';
73 strcat(search_paths,c);
74 strcat(search_paths,argv[0]+2);
76 | /-o.+/: { strcpy(output_file_name,argv[0]+2); }
77 | /-o/: { if (argc > 1)
79 strcpy(output_file_name,argv[0]);
82 | /-O[0-9]+/: { int opt = atol(argv[0]+2);
83 optimization_level = opt <= 0 ? 1 : opt;
84 fast_string_match = optimization_level & 1;
85 adaptive_matching = optimization_level & 2;
86 inline_casts = optimization_level & 4;
87 tagged_pointer = optimization_level & 8;
88 optimize_rewrite = optimization_level & 16;
90 | /-Ofast_string_match/: { fast_string_match = true; }
91 | /-Oadaptive_matching/: { adaptive_matching = true; }
92 | /-Oinline_casts/: { inline_casts = true; }
93 | /-Otagged_pointer/: { tagged_pointer = true; }
94 | /-Orewriting/: { optimize_rewrite = true; }
95 | /-(N|non_linear)/: { nonlinear_patterns = true; }
96 | /-(S|save_space)/: { save_space = true; }
97 | /-V[0-9]+/: { max_vector_len = atol(argv[0]+2); }
98 | /-v[0-9]*/: { verbosity = atol(argv[0]+2);
99 if (verbosity <= 0) verbosity = 1;
101 | /-vcg/: { visualization = true; }
102 | /-(M|make_depends)/: { gen_dependences = true; }
103 | /-(n|no_codegen)/: { emit_code = false; }
104 | /-new_list_format/: { new_list_format = true; }
105 | /-(h|help)/: { help = true; }
106 | /-use_global_pools/: { MEM::use_global_pools(); }
107 | /-memory_usage/: { print_memory_usage = true; }
109 { error("%s: unknown option %s\n",prog_name, argv[0]); help = true; }
110 | _: { input_files[file_count++] = argv[0]; }
112 if (argv[0][0] == '-') input_options[option_count++] = argv[0];
114 input_file_name = input_files[0];
116 ////////////////////////////////////////////////////////////////////////////
117 // Print help message
118 ////////////////////////////////////////////////////////////////////////////
119 if (help || file_count == 0)
120 { error(HELP_MESSAGE,prog_name,VERSION,PATCH_LEVEL,LAST_UPDATED,prog_name);
125 ///////////////////////////////////////////////////////////////////////////////
127 // Run a program recursively.
129 ///////////////////////////////////////////////////////////////////////////////
130 static int run_prog(const char * prog, int argc, const char * argv[])
131 { char command[4096];
132 strcpy(command,prog);
133 for (int i = 0; i < argc; i++)
134 { strcat(command," ");
135 strcat(command,argv[i]);
137 int stat = system(command);
138 if (stat) error("Error in command: %s\n", command);
142 ///////////////////////////////////////////////////////////////////////////////
146 ///////////////////////////////////////////////////////////////////////////////
147 int main(int argc, const char * argv [])
148 { extern int process_input(PropOptions&);
150 options.process_command_line_arguments(argc, argv);
151 options.compute_output_file_name();
154 if (options.file_count == 1)
155 { stat = process_input(options);
156 if (print_memory_usage)
157 { msg("[global pool size = %i local pool size = %i string pool size = %i]\n",
158 global_pool.bytes_used(), mem_pool.bytes_used(), str_pool.bytes_used());
161 { for (int i = 0; i < options.file_count; i++)
162 { options.input_options[options.option_count] = options.input_files[i];
163 stat = run_prog(options.prog_name,
164 options.option_count+1,
165 options.input_options);