Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
1 /*
2 * Copyright (c) 1997, 2013, 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 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 // MAIN.CPP - Entry point for the Architecture Description Language Compiler
32 #include "adlc.hpp"
34 //------------------------------Prototypes-------------------------------------
35 static void usage(ArchDesc& AD); // Print usage message and exit
36 static char *strip_ext(char *fname); // Strip off name extension
37 static char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
38 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
39 static int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
41 ArchDesc* globalAD = NULL; // global reference to Architecture Description object
43 const char* get_basename(const char* filename) {
44 const char *basename = filename;
45 const char *cp;
46 for (cp = basename; *cp; cp++) {
47 if (*cp == '/') {
48 basename = cp+1;
49 }
50 }
51 return basename;
52 }
54 //------------------------------main-------------------------------------------
55 int main(int argc, char *argv[])
56 {
57 ArchDesc AD; // Architecture Description object
58 globalAD = &AD;
60 // ResourceMark mark;
61 ADLParser *ADL_Parse; // ADL Parser object to parse AD file
63 // Check for proper arguments
64 if( argc == 1 ) usage(AD); // No arguments? Then print usage
66 // Read command line arguments and file names
67 for( int i = 1; i < argc; i++ ) { // For all arguments
68 register char *s = argv[i]; // Get option/filename
70 if( *s++ == '-' ) { // It's a flag? (not a filename)
71 if( !*s ) { // Stand-alone `-' means stdin
72 //********** INSERT CODE HERE **********
73 } else while (*s != '\0') { // While have flags on option
74 switch (*s++) { // Handle flag
75 case 'd': // Debug flag
76 AD._dfa_debug += 1; // Set Debug Flag
77 break;
78 case 'g': // Debug ad location flag
79 AD._adlocation_debug += 1; // Set Debug ad location Flag
80 break;
81 case 'o': // No Output Flag
82 AD._no_output ^= 1; // Toggle no_output flag
83 break;
84 case 'q': // Quiet Mode Flag
85 AD._quiet_mode ^= 1; // Toggle quiet_mode flag
86 break;
87 case 'w': // Disable Warnings Flag
88 AD._disable_warnings ^= 1; // Toggle disable_warnings flag
89 break;
90 case 'T': // Option to make DFA as many subroutine calls.
91 AD._dfa_small += 1; // Set Mode Flag
92 break;
93 case 'c': { // Set C++ Output file name
94 AD._CPP_file._name = s;
95 const char *base = strip_ext(strdup(s));
96 AD._CPP_CLONE_file._name = base_plus_suffix(base,"_clone.cpp");
97 AD._CPP_EXPAND_file._name = base_plus_suffix(base,"_expand.cpp");
98 AD._CPP_FORMAT_file._name = base_plus_suffix(base,"_format.cpp");
99 AD._CPP_GEN_file._name = base_plus_suffix(base,"_gen.cpp");
100 AD._CPP_MISC_file._name = base_plus_suffix(base,"_misc.cpp");
101 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(base,"_peephole.cpp");
102 AD._CPP_PIPELINE_file._name = base_plus_suffix(base,"_pipeline.cpp");
103 s += strlen(s);
104 break;
105 }
106 case 'h': // Set C++ Output file name
107 AD._HPP_file._name = s; s += strlen(s);
108 break;
109 case 'v': // Set C++ Output file name
110 AD._VM_file._name = s; s += strlen(s);
111 break;
112 case 'a': // Set C++ Output file name
113 AD._DFA_file._name = s;
114 AD._bug_file._name = s;
115 s += strlen(s);
116 break;
117 case '#': // Special internal debug flag
118 AD._adl_debug++; // Increment internal debug level
119 break;
120 case 's': // Output which instructions are cisc-spillable
121 AD._cisc_spill_debug = true;
122 break;
123 case 'D': // Flag Definition
124 {
125 char* flag = s;
126 s += strlen(s);
127 char* def = strchr(flag, '=');
128 if (def == NULL) def = (char*)"1";
129 else *def++ = '\0';
130 AD.set_preproc_def(flag, def);
131 }
132 break;
133 case 'U': // Flag Un-Definition
134 {
135 char* flag = s;
136 s += strlen(s);
137 AD.set_preproc_def(flag, NULL);
138 }
139 break;
140 default: // Unknown option
141 usage(AD); // So print usage and exit
142 } // End of switch on options...
143 } // End of while have options...
145 } else { // Not an option; must be a filename
146 AD._ADL_file._name = argv[i]; // Set the input filename
148 // // Files for storage, based on input file name
149 const char *base = strip_ext(strdup(argv[i]));
150 char *temp = base_plus_suffix("dfa_",base);
151 AD._DFA_file._name = base_plus_suffix(temp,".cpp");
152 delete temp;
153 temp = base_plus_suffix("ad_",base);
154 AD._CPP_file._name = base_plus_suffix(temp,".cpp");
155 AD._CPP_CLONE_file._name = base_plus_suffix(temp,"_clone.cpp");
156 AD._CPP_EXPAND_file._name = base_plus_suffix(temp,"_expand.cpp");
157 AD._CPP_FORMAT_file._name = base_plus_suffix(temp,"_format.cpp");
158 AD._CPP_GEN_file._name = base_plus_suffix(temp,"_gen.cpp");
159 AD._CPP_MISC_file._name = base_plus_suffix(temp,"_misc.cpp");
160 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp");
161 AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp");
162 AD._HPP_file._name = base_plus_suffix(temp,".hpp");
163 delete temp;
164 temp = base_plus_suffix("adGlobals_",base);
165 AD._VM_file._name = base_plus_suffix(temp,".hpp");
166 delete temp;
167 temp = base_plus_suffix("bugs_",base);
168 AD._bug_file._name = base_plus_suffix(temp,".out");
169 delete temp;
170 } // End of files vs options...
171 } // End of while have command line arguments
173 // Open files used to store the matcher and its components
174 if (AD.open_files() == 0) return 1; // Open all input/output files
176 // Build the File Buffer, Parse the input, & Generate Code
177 FileBuff ADL_Buf(&AD._ADL_file, AD); // Create a file buffer for input file
179 // Get pointer to legal text at the beginning of AD file.
180 // It will be used in generated ad files.
181 char* legal_text;
182 int legal_sz = get_legal_text(ADL_Buf, &legal_text);
184 ADL_Parse = new ADLParser(ADL_Buf, AD); // Create a parser to parse the buffer
185 ADL_Parse->parse(); // Parse buffer & build description lists
187 if( AD._dfa_debug >= 1 ) { // For higher debug settings, print dump
188 AD.dump();
189 }
191 delete ADL_Parse; // Delete parser
193 // Verify that the results of the parse are consistent
194 AD.verify();
196 // Prepare to generate the result files:
197 AD.generateMatchLists();
198 AD.identify_unique_operands();
199 AD.identify_cisc_spill_instructions();
200 AD.identify_short_branches();
201 // Make sure every file starts with a copyright:
202 AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp); // .hpp
203 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp); // .cpp
204 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp); // .cpp
205 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp); // .cpp
206 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp); // .cpp
207 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp); // .cpp
208 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp); // .cpp
209 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp); // .cpp
210 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp); // .cpp
211 AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp); // .hpp
212 AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp); // .cpp
213 // Add include guards for all .hpp files
214 AD.addIncludeGuardStart(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
215 AD.addIncludeGuardStart(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
216 // Add includes
217 AD.addInclude(AD._CPP_file, "precompiled.hpp");
218 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._VM_file._name));
219 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._HPP_file._name));
220 AD.addInclude(AD._CPP_file, "memory/allocation.inline.hpp");
221 AD.addInclude(AD._CPP_file, "asm/macroAssembler.inline.hpp");
222 AD.addInclude(AD._CPP_file, "code/compiledIC.hpp");
223 AD.addInclude(AD._CPP_file, "code/vmreg.hpp");
224 AD.addInclude(AD._CPP_file, "gc_interface/collectedHeap.inline.hpp");
225 AD.addInclude(AD._CPP_file, "oops/compiledICHolder.hpp");
226 AD.addInclude(AD._CPP_file, "oops/markOop.hpp");
227 AD.addInclude(AD._CPP_file, "oops/method.hpp");
228 AD.addInclude(AD._CPP_file, "oops/oop.inline.hpp");
229 AD.addInclude(AD._CPP_file, "oops/oop.inline2.hpp");
230 AD.addInclude(AD._CPP_file, "opto/cfgnode.hpp");
231 AD.addInclude(AD._CPP_file, "opto/locknode.hpp");
232 AD.addInclude(AD._CPP_file, "opto/opcodes.hpp");
233 AD.addInclude(AD._CPP_file, "opto/regalloc.hpp");
234 AD.addInclude(AD._CPP_file, "opto/regmask.hpp");
235 AD.addInclude(AD._CPP_file, "opto/runtime.hpp");
236 AD.addInclude(AD._CPP_file, "runtime/biasedLocking.hpp");
237 AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp");
238 AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp");
239 AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp");
240 #ifdef TARGET_ARCH_x86
241 AD.addInclude(AD._CPP_file, "nativeInst_x86.hpp");
242 AD.addInclude(AD._CPP_file, "vmreg_x86.inline.hpp");
243 #endif
244 #ifdef TARGET_ARCH_mips
245 AD.addInclude(AD._CPP_file, "nativeInst_mips.hpp");
246 AD.addInclude(AD._CPP_file, "vmreg_mips.inline.hpp");
247 #endif
248 #ifdef TARGET_ARCH_sparc
249 AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp");
250 AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp");
251 #endif
252 #ifdef TARGET_ARCH_arm
253 AD.addInclude(AD._CPP_file, "nativeInst_arm.hpp");
254 AD.addInclude(AD._CPP_file, "vmreg_arm.inline.hpp");
255 #endif
256 #ifdef TARGET_ARCH_ppc
257 AD.addInclude(AD._CPP_file, "assembler_ppc.inline.hpp");
258 AD.addInclude(AD._CPP_file, "nativeInst_ppc.hpp");
259 AD.addInclude(AD._CPP_file, "vmreg_ppc.inline.hpp");
260 #endif
261 AD.addInclude(AD._HPP_file, "memory/allocation.hpp");
262 AD.addInclude(AD._HPP_file, "opto/machnode.hpp");
263 AD.addInclude(AD._HPP_file, "opto/node.hpp");
264 AD.addInclude(AD._HPP_file, "opto/regalloc.hpp");
265 AD.addInclude(AD._HPP_file, "opto/subnode.hpp");
266 AD.addInclude(AD._HPP_file, "opto/vectornode.hpp");
267 AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp");
268 AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name));
269 AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp");
270 AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name));
271 AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp");
272 AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name));
273 AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp");
274 AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name));
275 AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp");
276 AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp");
277 AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp");
278 AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name));
279 AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp");
280 AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name));
281 AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp");
282 AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name));
283 AD.addInclude(AD._DFA_file, "precompiled.hpp");
284 AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name));
285 AD.addInclude(AD._DFA_file, "opto/cfgnode.hpp"); // Use PROB_MAX in predicate.
286 AD.addInclude(AD._DFA_file, "opto/matcher.hpp");
287 AD.addInclude(AD._DFA_file, "opto/opcodes.hpp");
288 // Make sure each .cpp file starts with include lines:
289 // files declaring and defining generators for Mach* Objects (hpp,cpp)
290 // Generate the result files:
291 // enumerations, class definitions, object generators, and the DFA
292 // file containing enumeration of machine operands & instructions (hpp)
293 AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp
294 AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp
295 AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp
296 AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file
297 AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file
298 AD.declareRegSizes(AD._HPP_file._fp); // .hpp
299 AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp
300 // output definition of class "State"
301 AD.defineStateClass(AD._HPP_file._fp); // .hpp
302 // file declaring the Mach* classes derived from MachOper and MachNode
303 AD.declareClasses(AD._HPP_file._fp);
304 // declare and define maps: in the .hpp and .cpp files respectively
305 AD.addSourceBlocks(AD._CPP_file._fp); // .cpp
306 AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp
307 AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
308 AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
309 // build CISC_spilling oracle and MachNode::cisc_spill() methods
310 AD.build_cisc_spill_instructions(AD._HPP_file._fp, AD._CPP_file._fp);
311 // define methods for machine dependent State, MachOper, and MachNode classes
312 AD.defineClasses(AD._CPP_file._fp);
313 AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
314 AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
315 // define methods for machine dependent instruction matching
316 AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp
317 // define methods for machine dependent frame management
318 AD.buildFrameMethods(AD._CPP_file._fp); // .cpp
319 AD.generate_needs_clone_jvms(AD._CPP_file._fp);
321 // do this last:
322 AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp
323 AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp
324 AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp
325 AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp
326 AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp
327 AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp
328 AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp
329 AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp
331 // define the finite automata that selects lowest cost production
332 AD.buildDFA(AD._DFA_file._fp);
333 // Add include guards for all .hpp files
334 AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
335 AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
337 AD.close_files(0); // Close all input/output files
339 // Final printout and statistics
340 // cout << program;
342 if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info
343 // Timer t_stop;
344 // Timer t_total = t_stop - t_start; // Total running time
345 // cerr << "\n---Architecture Description Totals---\n";
346 // cerr << ", Total lines: " << TotalLines;
347 // float l = TotalLines;
348 // cerr << "\nTotal Compilation Time: " << t_total << "\n";
349 // float ft = (float)t_total;
350 // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
351 }
352 return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
353 }
355 //------------------------------usage------------------------------------------
356 static void usage(ArchDesc& AD)
357 {
358 printf("Architecture Description Language Compiler\n\n");
359 printf("Usage: adlc [-doqwTs] [-#]* [-D<FLAG>[=<DEF>]] [-U<FLAG>] [-c<CPP_FILE_NAME>] [-h<HPP_FILE_NAME>] [-a<DFA_FILE_NAME>] [-v<GLOBALS_FILE_NAME>] <ADL_FILE_NAME>\n");
360 printf(" d produce DFA debugging info\n");
361 printf(" o no output produced, syntax and semantic checking only\n");
362 printf(" q quiet mode, supresses all non-essential messages\n");
363 printf(" w suppress warning messages\n");
364 printf(" T make DFA as many subroutine calls\n");
365 printf(" s output which instructions are cisc-spillable\n");
366 printf(" D define preprocessor symbol\n");
367 printf(" U undefine preprocessor symbol\n");
368 printf(" c specify CPP file name (default: %s)\n", AD._CPP_file._name);
369 printf(" h specify HPP file name (default: %s)\n", AD._HPP_file._name);
370 printf(" a specify DFA output file name\n");
371 printf(" v specify adGlobals output file name\n");
372 printf(" # increment ADL debug level\n");
373 printf("\n");
374 }
376 //------------------------------open_file------------------------------------
377 int ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action)
378 {
379 if (required &&
380 (ADF._fp = fopen(ADF._name, action)) == NULL) {
381 printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name);
382 close_files(1);
383 return 0;
384 }
385 return 1;
386 }
388 //------------------------------open_files-------------------------------------
389 int ArchDesc::open_files(void)
390 {
391 if (_ADL_file._name == NULL)
392 { printf("ERROR: No ADL input file specified\n"); return 0; }
394 if (!open_file(true , _ADL_file, "r")) { return 0; }
395 if (!open_file(!_no_output, _DFA_file, "w")) { return 0; }
396 if (!open_file(!_no_output, _HPP_file, "w")) { return 0; }
397 if (!open_file(!_no_output, _CPP_file, "w")) { return 0; }
398 if (!open_file(!_no_output, _CPP_CLONE_file, "w")) { return 0; }
399 if (!open_file(!_no_output, _CPP_EXPAND_file, "w")) { return 0; }
400 if (!open_file(!_no_output, _CPP_FORMAT_file, "w")) { return 0; }
401 if (!open_file(!_no_output, _CPP_GEN_file, "w")) { return 0; }
402 if (!open_file(!_no_output, _CPP_MISC_file, "w")) { return 0; }
403 if (!open_file(!_no_output, _CPP_PEEPHOLE_file, "w")) { return 0; }
404 if (!open_file(!_no_output, _CPP_PIPELINE_file, "w")) { return 0; }
405 if (!open_file(!_no_output, _VM_file , "w")) { return 0; }
406 if (!open_file(_dfa_debug != 0, _bug_file, "w")) { return 0; }
408 return 1;
409 }
411 //------------------------------close_file------------------------------------
412 void ArchDesc::close_file(int delete_out, ADLFILE& ADF)
413 {
414 if (ADF._fp) {
415 fclose(ADF._fp);
416 if (delete_out) remove(ADF._name);
417 }
418 }
420 //------------------------------close_files------------------------------------
421 void ArchDesc::close_files(int delete_out)
422 {
423 if (_ADL_file._fp) fclose(_ADL_file._fp);
425 close_file(delete_out, _CPP_file);
426 close_file(delete_out, _CPP_CLONE_file);
427 close_file(delete_out, _CPP_EXPAND_file);
428 close_file(delete_out, _CPP_FORMAT_file);
429 close_file(delete_out, _CPP_GEN_file);
430 close_file(delete_out, _CPP_MISC_file);
431 close_file(delete_out, _CPP_PEEPHOLE_file);
432 close_file(delete_out, _CPP_PIPELINE_file);
433 close_file(delete_out, _HPP_file);
434 close_file(delete_out, _DFA_file);
435 close_file(delete_out, _bug_file);
437 if (!_quiet_mode) {
438 printf("\n");
439 if (_no_output || delete_out) {
440 if (_ADL_file._name) printf("%s: ", _ADL_file._name);
441 printf("No output produced");
442 }
443 else {
444 if (_ADL_file._name) printf("%s --> ", _ADL_file._name);
445 printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
446 _CPP_file._name,
447 _CPP_CLONE_file._name,
448 _CPP_EXPAND_file._name,
449 _CPP_FORMAT_file._name,
450 _CPP_GEN_file._name,
451 _CPP_MISC_file._name,
452 _CPP_PEEPHOLE_file._name,
453 _CPP_PIPELINE_file._name,
454 _HPP_file._name,
455 _DFA_file._name);
456 }
457 printf("\n");
458 }
459 }
461 //------------------------------strip_ext--------------------------------------
462 static char *strip_ext(char *fname)
463 {
464 char *ep;
466 if (fname) {
467 ep = fname + strlen(fname) - 1; // start at last character and look for '.'
468 while (ep >= fname && *ep != '.') --ep;
469 if (*ep == '.') *ep = '\0'; // truncate string at '.'
470 }
471 return fname;
472 }
474 //------------------------------base_plus_suffix-------------------------------
475 // New concatenated string
476 static char *base_plus_suffix(const char* base, const char *suffix)
477 {
478 int len = (int)strlen(base) + (int)strlen(suffix) + 1;
480 char* fname = new char[len];
481 sprintf(fname,"%s%s",base,suffix);
482 return fname;
483 }
485 //------------------------------get_legal_text---------------------------------
486 // Get pointer to legal text at the beginning of AD file.
487 // This code assumes that a legal text starts at the beginning of .ad files,
488 // is commented by "//" at each line and ends with empty line.
489 //
490 int get_legal_text(FileBuff &fbuf, char **legal_text)
491 {
492 char* legal_start = fbuf.get_line();
493 assert(legal_start[0] == '/' && legal_start[1] == '/', "Incorrect header of AD file");
494 char* legal_end = fbuf.get_line();
495 assert(strncmp(legal_end, "// Copyright", 12) == 0, "Incorrect header of AD file");
496 while(legal_end[0] == '/' && legal_end[1] == '/') {
497 legal_end = fbuf.get_line();
498 }
499 *legal_text = legal_start;
500 return (int) (legal_end - legal_start);
501 }
503 // VS2005 has its own definition, identical to this one.
504 #if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400
505 void *operator new( size_t size, int, const char *, int ) throw() {
506 return ::operator new( size );
507 }
508 #endif