1 /*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // MAIN.CPP - Entry point for the Architecture Description Language Compiler
26 #include "adlc.hpp"
27
28 //------------------------------Prototypes-------------------------------------
29 static void usage(ArchDesc& AD); // Print usage message and exit
30 static char *strip_ext(char *fname); // Strip off name extension
31 static char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
32 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
33 static int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
34
35 ArchDesc* globalAD = NULL; // global reference to Architecture Description object
36
37 //------------------------------main-------------------------------------------
38 int main(int argc, char *argv[])
39 {
40 ArchDesc AD; // Architecture Description object
41 globalAD = &AD;
42
43 // ResourceMark mark;
44 ADLParser *ADL_Parse; // ADL Parser object to parse AD file
45
46 // Check for proper arguments
47 if( argc == 1 ) usage(AD); // No arguments? Then print usage
48
49 // Read command line arguments and file names
50 for( int i = 1; i < argc; i++ ) { // For all arguments
51 register char *s = argv[i]; // Get option/filename
52
53 if( *s++ == '-' ) { // It's a flag? (not a filename)
54 if( !*s ) { // Stand-alone `-' means stdin
55 //********** INSERT CODE HERE **********
56 } else while (*s != '\0') { // While have flags on option
176 // Verify that the results of the parse are consistent
177 AD.verify();
178
179 // Prepare to generate the result files:
180 AD.generateMatchLists();
181 AD.identify_unique_operands();
182 AD.identify_cisc_spill_instructions();
183 AD.identify_short_branches();
184 // Make sure every file starts with a copyright:
185 AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp); // .hpp
186 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp); // .cpp
187 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp); // .cpp
188 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp); // .cpp
189 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp); // .cpp
190 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp); // .cpp
191 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp); // .cpp
192 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp); // .cpp
193 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp); // .cpp
194 AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp); // .hpp
195 AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp); // .cpp
196 // Make sure each .cpp file starts with include lines:
197 // files declaring and defining generators for Mach* Objects (hpp,cpp)
198 AD.machineDependentIncludes(AD._CPP_file); // .cpp
199 AD.machineDependentIncludes(AD._CPP_CLONE_file); // .cpp
200 AD.machineDependentIncludes(AD._CPP_EXPAND_file); // .cpp
201 AD.machineDependentIncludes(AD._CPP_FORMAT_file); // .cpp
202 AD.machineDependentIncludes(AD._CPP_GEN_file); // .cpp
203 AD.machineDependentIncludes(AD._CPP_MISC_file); // .cpp
204 AD.machineDependentIncludes(AD._CPP_PEEPHOLE_file); // .cpp
205 AD.machineDependentIncludes(AD._CPP_PIPELINE_file); // .cpp
206 // Generate the result files:
207 // enumerations, class definitions, object generators, and the DFA
208 // file containing enumeration of machine operands & instructions (hpp)
209 AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp
210 AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp
211 AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp
212 AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file
213 AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file
214 AD.declareRegSizes(AD._HPP_file._fp); // .hpp
215 AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp
216 // output definition of class "State"
217 AD.defineStateClass(AD._HPP_file._fp); // .hpp
218 // file declaring the Mach* classes derived from MachOper and MachNode
219 AD.declareClasses(AD._HPP_file._fp);
220 // declare and define maps: in the .hpp and .cpp files respectively
221 AD.addSourceBlocks(AD._CPP_file._fp); // .cpp
222 AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp
223 AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
224 AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
225 // build CISC_spilling oracle and MachNode::cisc_spill() methods
227 // define methods for machine dependent State, MachOper, and MachNode classes
228 AD.defineClasses(AD._CPP_file._fp);
229 AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
230 AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
231 // define methods for machine dependent instruction matching
232 AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp
233 // define methods for machine dependent frame management
234 AD.buildFrameMethods(AD._CPP_file._fp); // .cpp
235
236 // do this last:
237 AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp
238 AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp
239 AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp
240 AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp
241 AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp
242 AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp
243 AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp
244 AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp
245
246 // define the finite automata that selects lowest cost production
247 AD.machineDependentIncludes(AD._DFA_file); // .cpp
248 AD.buildDFA(AD._DFA_file._fp);
249
250 AD.close_files(0); // Close all input/output files
251
252 // Final printout and statistics
253 // cout << program;
254
255 if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info
256 // Timer t_stop;
257 // Timer t_total = t_stop - t_start; // Total running time
258 // cerr << "\n---Architecture Description Totals---\n";
259 // cerr << ", Total lines: " << TotalLines;
260 // float l = TotalLines;
261 // cerr << "\nTotal Compilation Time: " << t_total << "\n";
262 // float ft = (float)t_total;
263 // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
264 }
265 return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
266 }
267
268 //------------------------------usage------------------------------------------
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // MAIN.CPP - Entry point for the Architecture Description Language Compiler
26 #include "adlc.hpp"
27
28 //------------------------------Prototypes-------------------------------------
29 static void usage(ArchDesc& AD); // Print usage message and exit
30 static char *strip_ext(char *fname); // Strip off name extension
31 static char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
32 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
33 static int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
34
35 ArchDesc* globalAD = NULL; // global reference to Architecture Description object
36
37 const char* get_basename(const char* filename) {
38 const char *basename = filename;
39 const char *cp;
40 for (cp = basename; *cp; cp++) {
41 if (*cp == '/') {
42 basename = cp+1;
43 }
44 }
45 return basename;
46 }
47
48 //------------------------------main-------------------------------------------
49 int main(int argc, char *argv[])
50 {
51 ArchDesc AD; // Architecture Description object
52 globalAD = &AD;
53
54 // ResourceMark mark;
55 ADLParser *ADL_Parse; // ADL Parser object to parse AD file
56
57 // Check for proper arguments
58 if( argc == 1 ) usage(AD); // No arguments? Then print usage
59
60 // Read command line arguments and file names
61 for( int i = 1; i < argc; i++ ) { // For all arguments
62 register char *s = argv[i]; // Get option/filename
63
64 if( *s++ == '-' ) { // It's a flag? (not a filename)
65 if( !*s ) { // Stand-alone `-' means stdin
66 //********** INSERT CODE HERE **********
67 } else while (*s != '\0') { // While have flags on option
187 // Verify that the results of the parse are consistent
188 AD.verify();
189
190 // Prepare to generate the result files:
191 AD.generateMatchLists();
192 AD.identify_unique_operands();
193 AD.identify_cisc_spill_instructions();
194 AD.identify_short_branches();
195 // Make sure every file starts with a copyright:
196 AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp); // .hpp
197 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp); // .cpp
198 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp); // .cpp
199 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp); // .cpp
200 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp); // .cpp
201 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp); // .cpp
202 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp); // .cpp
203 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp); // .cpp
204 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp); // .cpp
205 AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp); // .hpp
206 AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp); // .cpp
207 // Add include guards for all .hpp files
208 AD.addIncludeGuardStart(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
209 AD.addIncludeGuardStart(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
210 // Add includes
211 AD.addInclude(AD._CPP_file, "precompiled.hpp");
212 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._VM_file._name));
213 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._HPP_file._name));
214 AD.addInclude(AD._CPP_file, "memory/allocation.inline.hpp");
215 AD.addInclude(AD._CPP_file, "asm/assembler.hpp");
216 AD.addInclude(AD._CPP_file, "code/vmreg.hpp");
217 AD.addInclude(AD._CPP_file, "gc_interface/collectedHeap.inline.hpp");
218 AD.addInclude(AD._CPP_file, "oops/compiledICHolderOop.hpp");
219 AD.addInclude(AD._CPP_file, "oops/markOop.hpp");
220 AD.addInclude(AD._CPP_file, "oops/methodOop.hpp");
221 AD.addInclude(AD._CPP_file, "oops/oop.inline.hpp");
222 AD.addInclude(AD._CPP_file, "oops/oop.inline2.hpp");
223 AD.addInclude(AD._CPP_file, "opto/cfgnode.hpp");
224 AD.addInclude(AD._CPP_file, "opto/locknode.hpp");
225 AD.addInclude(AD._CPP_file, "opto/opcodes.hpp");
226 AD.addInclude(AD._CPP_file, "opto/regalloc.hpp");
227 AD.addInclude(AD._CPP_file, "opto/regmask.hpp");
228 AD.addInclude(AD._CPP_file, "opto/runtime.hpp");
229 AD.addInclude(AD._CPP_file, "runtime/biasedLocking.hpp");
230 AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp");
231 AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp");
232 AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp");
233 #ifdef TARGET_ARCH_x86
234 AD.addInclude(AD._CPP_file, "assembler_x86.inline.hpp");
235 AD.addInclude(AD._CPP_file, "nativeInst_x86.hpp");
236 AD.addInclude(AD._CPP_file, "vmreg_x86.inline.hpp");
237 #endif
238 #ifdef TARGET_ARCH_sparc
239 AD.addInclude(AD._CPP_file, "assembler_sparc.inline.hpp");
240 AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp");
241 AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp");
242 #endif
243 AD.addInclude(AD._HPP_file, "memory/allocation.hpp");
244 AD.addInclude(AD._HPP_file, "opto/machnode.hpp");
245 AD.addInclude(AD._HPP_file, "opto/node.hpp");
246 AD.addInclude(AD._HPP_file, "opto/regalloc.hpp");
247 AD.addInclude(AD._HPP_file, "opto/subnode.hpp");
248 AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp");
249 AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name));
250 AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp");
251 AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name));
252 AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp");
253 AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name));
254 AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp");
255 AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name));
256 AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp");
257 AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp");
258 AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp");
259 AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name));
260 AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp");
261 AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name));
262 AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp");
263 AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name));
264 AD.addInclude(AD._DFA_file, "precompiled.hpp");
265 AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name));
266 AD.addInclude(AD._DFA_file, "opto/matcher.hpp");
267 AD.addInclude(AD._DFA_file, "opto/opcodes.hpp");
268 // Make sure each .cpp file starts with include lines:
269 // files declaring and defining generators for Mach* Objects (hpp,cpp)
270 // Generate the result files:
271 // enumerations, class definitions, object generators, and the DFA
272 // file containing enumeration of machine operands & instructions (hpp)
273 AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp
274 AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp
275 AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp
276 AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file
277 AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file
278 AD.declareRegSizes(AD._HPP_file._fp); // .hpp
279 AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp
280 // output definition of class "State"
281 AD.defineStateClass(AD._HPP_file._fp); // .hpp
282 // file declaring the Mach* classes derived from MachOper and MachNode
283 AD.declareClasses(AD._HPP_file._fp);
284 // declare and define maps: in the .hpp and .cpp files respectively
285 AD.addSourceBlocks(AD._CPP_file._fp); // .cpp
286 AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp
287 AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
288 AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
289 // build CISC_spilling oracle and MachNode::cisc_spill() methods
291 // define methods for machine dependent State, MachOper, and MachNode classes
292 AD.defineClasses(AD._CPP_file._fp);
293 AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
294 AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
295 // define methods for machine dependent instruction matching
296 AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp
297 // define methods for machine dependent frame management
298 AD.buildFrameMethods(AD._CPP_file._fp); // .cpp
299
300 // do this last:
301 AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp
302 AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp
303 AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp
304 AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp
305 AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp
306 AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp
307 AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp
308 AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp
309
310 // define the finite automata that selects lowest cost production
311 AD.buildDFA(AD._DFA_file._fp);
312 // Add include guards for all .hpp files
313 AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
314 AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
315
316 AD.close_files(0); // Close all input/output files
317
318 // Final printout and statistics
319 // cout << program;
320
321 if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info
322 // Timer t_stop;
323 // Timer t_total = t_stop - t_start; // Total running time
324 // cerr << "\n---Architecture Description Totals---\n";
325 // cerr << ", Total lines: " << TotalLines;
326 // float l = TotalLines;
327 // cerr << "\nTotal Compilation Time: " << t_total << "\n";
328 // float ft = (float)t_total;
329 // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
330 }
331 return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
332 }
333
334 //------------------------------usage------------------------------------------
|