Mercurial > hg > graal-compiler
annotate src/share/vm/adlc/main.cpp @ 4316:b4b16e4e043f
Fix eager resolving for class constants
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Mon, 23 Jan 2012 14:35:29 +0100 |
parents | 1d1603768966 |
children | 8c92982cbbc4 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2401
diff
changeset
|
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
603
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
603
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
603
diff
changeset
|
21 * questions. |
0 | 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 | |
1972 | 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 | |
0 | 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 | |
68 switch (*s++) { // Handle flag | |
69 case 'd': // Debug flag | |
70 AD._dfa_debug += 1; // Set Debug Flag | |
71 break; | |
72 case 'g': // Debug ad location flag | |
73 AD._adlocation_debug += 1; // Set Debug ad location Flag | |
74 break; | |
75 case 'o': // No Output Flag | |
76 AD._no_output ^= 1; // Toggle no_output flag | |
77 break; | |
78 case 'q': // Quiet Mode Flag | |
79 AD._quiet_mode ^= 1; // Toggle quiet_mode flag | |
80 break; | |
81 case 'w': // Disable Warnings Flag | |
82 AD._disable_warnings ^= 1; // Toggle disable_warnings flag | |
83 break; | |
84 case 'T': // Option to make DFA as many subroutine calls. | |
85 AD._dfa_small += 1; // Set Mode Flag | |
86 break; | |
87 case 'c': { // Set C++ Output file name | |
88 AD._CPP_file._name = s; | |
89 const char *base = strip_ext(strdup(s)); | |
90 AD._CPP_CLONE_file._name = base_plus_suffix(base,"_clone.cpp"); | |
91 AD._CPP_EXPAND_file._name = base_plus_suffix(base,"_expand.cpp"); | |
92 AD._CPP_FORMAT_file._name = base_plus_suffix(base,"_format.cpp"); | |
93 AD._CPP_GEN_file._name = base_plus_suffix(base,"_gen.cpp"); | |
94 AD._CPP_MISC_file._name = base_plus_suffix(base,"_misc.cpp"); | |
95 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(base,"_peephole.cpp"); | |
96 AD._CPP_PIPELINE_file._name = base_plus_suffix(base,"_pipeline.cpp"); | |
97 s += strlen(s); | |
98 break; | |
99 } | |
100 case 'h': // Set C++ Output file name | |
101 AD._HPP_file._name = s; s += strlen(s); | |
102 break; | |
103 case 'v': // Set C++ Output file name | |
104 AD._VM_file._name = s; s += strlen(s); | |
105 break; | |
106 case 'a': // Set C++ Output file name | |
107 AD._DFA_file._name = s; | |
108 AD._bug_file._name = s; | |
109 s += strlen(s); | |
110 break; | |
111 case '#': // Special internal debug flag | |
112 AD._adl_debug++; // Increment internal debug level | |
113 break; | |
114 case 's': // Output which instructions are cisc-spillable | |
115 AD._cisc_spill_debug = true; | |
116 break; | |
117 case 'D': // Flag Definition | |
118 { | |
119 char* flag = s; | |
120 s += strlen(s); | |
121 char* def = strchr(flag, '='); | |
122 if (def == NULL) def = (char*)"1"; | |
123 else *def++ = '\0'; | |
124 AD.set_preproc_def(flag, def); | |
125 } | |
126 break; | |
127 case 'U': // Flag Un-Definition | |
128 { | |
129 char* flag = s; | |
130 s += strlen(s); | |
131 AD.set_preproc_def(flag, NULL); | |
132 } | |
133 break; | |
134 default: // Unknown option | |
135 usage(AD); // So print usage and exit | |
136 } // End of switch on options... | |
137 } // End of while have options... | |
138 | |
139 } else { // Not an option; must be a filename | |
140 AD._ADL_file._name = argv[i]; // Set the input filename | |
141 | |
142 // // Files for storage, based on input file name | |
143 const char *base = strip_ext(strdup(argv[i])); | |
144 char *temp = base_plus_suffix("dfa_",base); | |
145 AD._DFA_file._name = base_plus_suffix(temp,".cpp"); | |
146 delete temp; | |
147 temp = base_plus_suffix("ad_",base); | |
148 AD._CPP_file._name = base_plus_suffix(temp,".cpp"); | |
149 AD._CPP_CLONE_file._name = base_plus_suffix(temp,"_clone.cpp"); | |
150 AD._CPP_EXPAND_file._name = base_plus_suffix(temp,"_expand.cpp"); | |
151 AD._CPP_FORMAT_file._name = base_plus_suffix(temp,"_format.cpp"); | |
152 AD._CPP_GEN_file._name = base_plus_suffix(temp,"_gen.cpp"); | |
153 AD._CPP_MISC_file._name = base_plus_suffix(temp,"_misc.cpp"); | |
154 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp"); | |
155 AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp"); | |
156 AD._HPP_file._name = base_plus_suffix(temp,".hpp"); | |
157 delete temp; | |
158 temp = base_plus_suffix("adGlobals_",base); | |
159 AD._VM_file._name = base_plus_suffix(temp,".hpp"); | |
160 delete temp; | |
161 temp = base_plus_suffix("bugs_",base); | |
162 AD._bug_file._name = base_plus_suffix(temp,".out"); | |
163 delete temp; | |
164 } // End of files vs options... | |
165 } // End of while have command line arguments | |
166 | |
167 // Open files used to store the matcher and its components | |
168 if (AD.open_files() == 0) return 1; // Open all input/output files | |
169 | |
170 // Build the File Buffer, Parse the input, & Generate Code | |
171 FileBuff ADL_Buf(&AD._ADL_file, AD); // Create a file buffer for input file | |
172 | |
173 // Get pointer to legal text at the beginning of AD file. | |
174 // It will be used in generated ad files. | |
175 char* legal_text; | |
176 int legal_sz = get_legal_text(ADL_Buf, &legal_text); | |
177 | |
178 ADL_Parse = new ADLParser(ADL_Buf, AD); // Create a parser to parse the buffer | |
179 ADL_Parse->parse(); // Parse buffer & build description lists | |
180 | |
181 if( AD._dfa_debug >= 1 ) { // For higher debug settings, print dump | |
182 AD.dump(); | |
183 } | |
184 | |
185 delete ADL_Parse; // Delete parser | |
186 | |
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 | |
1972 | 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 | |
2401
7e88bdae86ec
7029017: Additional architecture support for c2 compiler
roland
parents:
1972
diff
changeset
|
243 #ifdef TARGET_ARCH_arm |
7e88bdae86ec
7029017: Additional architecture support for c2 compiler
roland
parents:
1972
diff
changeset
|
244 AD.addInclude(AD._CPP_file, "assembler_arm.inline.hpp"); |
7e88bdae86ec
7029017: Additional architecture support for c2 compiler
roland
parents:
1972
diff
changeset
|
245 AD.addInclude(AD._CPP_file, "nativeInst_arm.hpp"); |
7e88bdae86ec
7029017: Additional architecture support for c2 compiler
roland
parents:
1972
diff
changeset
|
246 AD.addInclude(AD._CPP_file, "vmreg_arm.inline.hpp"); |
7e88bdae86ec
7029017: Additional architecture support for c2 compiler
roland
parents:
1972
diff
changeset
|
247 #endif |
1972 | 248 AD.addInclude(AD._HPP_file, "memory/allocation.hpp"); |
249 AD.addInclude(AD._HPP_file, "opto/machnode.hpp"); | |
250 AD.addInclude(AD._HPP_file, "opto/node.hpp"); | |
251 AD.addInclude(AD._HPP_file, "opto/regalloc.hpp"); | |
252 AD.addInclude(AD._HPP_file, "opto/subnode.hpp"); | |
253 AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp"); | |
254 AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name)); | |
255 AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp"); | |
256 AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name)); | |
257 AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp"); | |
258 AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name)); | |
259 AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp"); | |
260 AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name)); | |
261 AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp"); | |
262 AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp"); | |
263 AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp"); | |
264 AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name)); | |
265 AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp"); | |
266 AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name)); | |
267 AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp"); | |
268 AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name)); | |
269 AD.addInclude(AD._DFA_file, "precompiled.hpp"); | |
270 AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name)); | |
271 AD.addInclude(AD._DFA_file, "opto/matcher.hpp"); | |
272 AD.addInclude(AD._DFA_file, "opto/opcodes.hpp"); | |
0 | 273 // Make sure each .cpp file starts with include lines: |
274 // files declaring and defining generators for Mach* Objects (hpp,cpp) | |
275 // Generate the result files: | |
276 // enumerations, class definitions, object generators, and the DFA | |
277 // file containing enumeration of machine operands & instructions (hpp) | |
278 AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp | |
279 AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp | |
280 AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp | |
281 AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file | |
282 AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file | |
283 AD.declareRegSizes(AD._HPP_file._fp); // .hpp | |
284 AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp | |
285 // output definition of class "State" | |
286 AD.defineStateClass(AD._HPP_file._fp); // .hpp | |
287 // file declaring the Mach* classes derived from MachOper and MachNode | |
288 AD.declareClasses(AD._HPP_file._fp); | |
289 // declare and define maps: in the .hpp and .cpp files respectively | |
290 AD.addSourceBlocks(AD._CPP_file._fp); // .cpp | |
291 AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp | |
292 AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp); | |
293 AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp); | |
294 // build CISC_spilling oracle and MachNode::cisc_spill() methods | |
295 AD.build_cisc_spill_instructions(AD._HPP_file._fp, AD._CPP_file._fp); | |
296 // define methods for machine dependent State, MachOper, and MachNode classes | |
297 AD.defineClasses(AD._CPP_file._fp); | |
298 AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp | |
299 AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp | |
300 // define methods for machine dependent instruction matching | |
301 AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp | |
302 // define methods for machine dependent frame management | |
303 AD.buildFrameMethods(AD._CPP_file._fp); // .cpp | |
304 | |
305 // do this last: | |
306 AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp | |
307 AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp | |
308 AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp | |
309 AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp | |
310 AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp | |
311 AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp | |
312 AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp | |
313 AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp | |
314 | |
315 // define the finite automata that selects lowest cost production | |
316 AD.buildDFA(AD._DFA_file._fp); | |
1972 | 317 // Add include guards for all .hpp files |
318 AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp | |
319 AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp | |
0 | 320 |
321 AD.close_files(0); // Close all input/output files | |
322 | |
323 // Final printout and statistics | |
324 // cout << program; | |
325 | |
326 if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info | |
327 // Timer t_stop; | |
328 // Timer t_total = t_stop - t_start; // Total running time | |
329 // cerr << "\n---Architecture Description Totals---\n"; | |
330 // cerr << ", Total lines: " << TotalLines; | |
331 // float l = TotalLines; | |
332 // cerr << "\nTotal Compilation Time: " << t_total << "\n"; | |
333 // float ft = (float)t_total; | |
334 // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft); | |
335 } | |
336 return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!! | |
337 } | |
338 | |
339 //------------------------------usage------------------------------------------ | |
340 static void usage(ArchDesc& AD) | |
341 { | |
342 printf("Architecture Description Language Compiler\n\n"); | |
343 printf("Usage: adl [-doqw] [-Dflag[=def]] [-Uflag] [-cFILENAME] [-hFILENAME] [-aDFAFILE] ADLFILE\n"); | |
344 printf(" d produce DFA debugging info\n"); | |
345 printf(" o no output produced, syntax and semantic checking only\n"); | |
346 printf(" q quiet mode, supresses all non-essential messages\n"); | |
347 printf(" w suppress warning messages\n"); | |
348 printf(" c specify CPP file name (default: %s)\n", AD._CPP_file._name); | |
349 printf(" h specify HPP file name (default: %s)\n", AD._HPP_file._name); | |
350 printf(" a specify DFA output file name\n"); | |
351 printf("\n"); | |
352 } | |
353 | |
354 //------------------------------open_file------------------------------------ | |
355 int ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action) | |
356 { | |
357 if (required && | |
358 (ADF._fp = fopen(ADF._name, action)) == NULL) { | |
359 printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name); | |
360 close_files(1); | |
361 return 0; | |
362 } | |
363 return 1; | |
364 } | |
365 | |
366 //------------------------------open_files------------------------------------- | |
367 int ArchDesc::open_files(void) | |
368 { | |
369 if (_ADL_file._name == NULL) | |
370 { printf("ERROR: No ADL input file specified\n"); return 0; } | |
371 | |
372 if (!open_file(true , _ADL_file, "r")) { return 0; } | |
373 if (!open_file(!_no_output, _DFA_file, "w")) { return 0; } | |
374 if (!open_file(!_no_output, _HPP_file, "w")) { return 0; } | |
375 if (!open_file(!_no_output, _CPP_file, "w")) { return 0; } | |
376 if (!open_file(!_no_output, _CPP_CLONE_file, "w")) { return 0; } | |
377 if (!open_file(!_no_output, _CPP_EXPAND_file, "w")) { return 0; } | |
378 if (!open_file(!_no_output, _CPP_FORMAT_file, "w")) { return 0; } | |
379 if (!open_file(!_no_output, _CPP_GEN_file, "w")) { return 0; } | |
380 if (!open_file(!_no_output, _CPP_MISC_file, "w")) { return 0; } | |
381 if (!open_file(!_no_output, _CPP_PEEPHOLE_file, "w")) { return 0; } | |
382 if (!open_file(!_no_output, _CPP_PIPELINE_file, "w")) { return 0; } | |
383 if (!open_file(!_no_output, _VM_file , "w")) { return 0; } | |
384 if (!open_file(_dfa_debug != 0, _bug_file, "w")) { return 0; } | |
385 | |
386 return 1; | |
387 } | |
388 | |
389 //------------------------------close_file------------------------------------ | |
390 void ArchDesc::close_file(int delete_out, ADLFILE& ADF) | |
391 { | |
392 if (ADF._fp) { | |
393 fclose(ADF._fp); | |
394 if (delete_out) remove(ADF._name); | |
395 } | |
396 } | |
397 | |
398 //------------------------------close_files------------------------------------ | |
399 void ArchDesc::close_files(int delete_out) | |
400 { | |
401 if (_ADL_file._fp) fclose(_ADL_file._fp); | |
402 | |
403 close_file(delete_out, _CPP_file); | |
404 close_file(delete_out, _CPP_CLONE_file); | |
405 close_file(delete_out, _CPP_EXPAND_file); | |
406 close_file(delete_out, _CPP_FORMAT_file); | |
407 close_file(delete_out, _CPP_GEN_file); | |
408 close_file(delete_out, _CPP_MISC_file); | |
409 close_file(delete_out, _CPP_PEEPHOLE_file); | |
410 close_file(delete_out, _CPP_PIPELINE_file); | |
411 close_file(delete_out, _HPP_file); | |
412 close_file(delete_out, _DFA_file); | |
413 close_file(delete_out, _bug_file); | |
414 | |
415 if (!_quiet_mode) { | |
416 printf("\n"); | |
417 if (_no_output || delete_out) { | |
418 if (_ADL_file._name) printf("%s: ", _ADL_file._name); | |
419 printf("No output produced"); | |
420 } | |
421 else { | |
422 if (_ADL_file._name) printf("%s --> ", _ADL_file._name); | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
0
diff
changeset
|
423 printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s", |
0 | 424 _CPP_file._name, |
425 _CPP_CLONE_file._name, | |
426 _CPP_EXPAND_file._name, | |
427 _CPP_FORMAT_file._name, | |
428 _CPP_GEN_file._name, | |
429 _CPP_MISC_file._name, | |
430 _CPP_PEEPHOLE_file._name, | |
431 _CPP_PIPELINE_file._name, | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
0
diff
changeset
|
432 _HPP_file._name, |
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
0
diff
changeset
|
433 _DFA_file._name); |
0 | 434 } |
435 printf("\n"); | |
436 } | |
437 } | |
438 | |
439 //------------------------------strip_ext-------------------------------------- | |
440 static char *strip_ext(char *fname) | |
441 { | |
442 char *ep; | |
443 | |
444 if (fname) { | |
445 ep = fname + strlen(fname) - 1; // start at last character and look for '.' | |
446 while (ep >= fname && *ep != '.') --ep; | |
447 if (*ep == '.') *ep = '\0'; // truncate string at '.' | |
448 } | |
449 return fname; | |
450 } | |
451 | |
452 //------------------------------strip_path_and_ext------------------------------ | |
453 static char *strip_path_and_ext(char *fname) | |
454 { | |
455 char *ep; | |
456 char *sp; | |
457 | |
458 if (fname) { | |
459 for (sp = fname; *sp; sp++) | |
460 if (*sp == '/') fname = sp+1; | |
461 ep = fname; // start at first character and look for '.' | |
462 while (ep <= (fname + strlen(fname) - 1) && *ep != '.') ep++; | |
463 if (*ep == '.') *ep = '\0'; // truncate string at '.' | |
464 } | |
465 return fname; | |
466 } | |
467 | |
468 //------------------------------base_plus_suffix------------------------------- | |
469 // New concatenated string | |
470 static char *base_plus_suffix(const char* base, const char *suffix) | |
471 { | |
472 int len = (int)strlen(base) + (int)strlen(suffix) + 1; | |
473 | |
474 char* fname = new char[len]; | |
475 sprintf(fname,"%s%s",base,suffix); | |
476 return fname; | |
477 } | |
478 | |
479 | |
480 //------------------------------prefix_plus_base_plus_suffix------------------- | |
481 // New concatenated string | |
482 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix) | |
483 { | |
484 int len = (int)strlen(prefix) + (int)strlen(base) + (int)strlen(suffix) + 1; | |
485 | |
486 char* fname = new char[len]; | |
487 sprintf(fname,"%s%s%s",prefix,base,suffix); | |
488 return fname; | |
489 } | |
490 | |
491 //------------------------------get_legal_text--------------------------------- | |
492 // Get pointer to legal text at the beginning of AD file. | |
493 // This code assumes that a legal text starts at the beginning of .ad files, | |
494 // is commented by "//" at each line and ends with empty line. | |
495 // | |
496 int get_legal_text(FileBuff &fbuf, char **legal_text) | |
497 { | |
498 char* legal_start = fbuf.get_line(); | |
499 assert(legal_start[0] == '/' && legal_start[1] == '/', "Incorrect header of AD file"); | |
500 char* legal_end = fbuf.get_line(); | |
501 assert(strncmp(legal_end, "// Copyright", 12) == 0, "Incorrect header of AD file"); | |
502 while(legal_end[0] == '/' && legal_end[1] == '/') { | |
503 legal_end = fbuf.get_line(); | |
504 } | |
505 *legal_text = legal_start; | |
603
dbbe28fc66b5
6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents:
0
diff
changeset
|
506 return (int) (legal_end - legal_start); |
0 | 507 } |
508 | |
509 // VS2005 has its own definition, identical to this one. | |
510 #if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400 | |
511 void *operator new( size_t size, int, const char *, int ) { | |
512 return ::operator new( size ); | |
513 } | |
514 #endif |