annotate src/share/vm/adlc/main.cpp @ 2401:7e88bdae86ec

7029017: Additional architecture support for c2 compiler Summary: Enables cross building of a c2 VM. Support masking of shift counts when the processor architecture mandates it. Reviewed-by: kvn, never
author roland
date Fri, 25 Mar 2011 09:35:39 +0100
parents f95d63e2154a
children 1d1603768966
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // MAIN.CPP - Entry point for the Architecture Description Language Compiler
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "adlc.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //------------------------------Prototypes-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
29 static void usage(ArchDesc& AD); // Print usage message and exit
a61af66fc99e Initial load
duke
parents:
diff changeset
30 static char *strip_ext(char *fname); // Strip off name extension
a61af66fc99e Initial load
duke
parents:
diff changeset
31 static char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
a61af66fc99e Initial load
duke
parents:
diff changeset
32 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
a61af66fc99e Initial load
duke
parents:
diff changeset
33 static int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 ArchDesc* globalAD = NULL; // global reference to Architecture Description object
a61af66fc99e Initial load
duke
parents:
diff changeset
36
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 const char* get_basename(const char* filename) {
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 const char *basename = filename;
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 const char *cp;
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
40 for (cp = basename; *cp; cp++) {
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
41 if (*cp == '/') {
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
42 basename = cp+1;
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
43 }
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
44 }
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
45 return basename;
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
46 }
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
47
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48 //------------------------------main-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
49 int main(int argc, char *argv[])
a61af66fc99e Initial load
duke
parents:
diff changeset
50 {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 ArchDesc AD; // Architecture Description object
a61af66fc99e Initial load
duke
parents:
diff changeset
52 globalAD = &AD;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // ResourceMark mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 ADLParser *ADL_Parse; // ADL Parser object to parse AD file
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Check for proper arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if( argc == 1 ) usage(AD); // No arguments? Then print usage
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Read command line arguments and file names
a61af66fc99e Initial load
duke
parents:
diff changeset
61 for( int i = 1; i < argc; i++ ) { // For all arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
62 register char *s = argv[i]; // Get option/filename
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if( *s++ == '-' ) { // It's a flag? (not a filename)
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if( !*s ) { // Stand-alone `-' means stdin
a61af66fc99e Initial load
duke
parents:
diff changeset
66 //********** INSERT CODE HERE **********
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else while (*s != '\0') { // While have flags on option
a61af66fc99e Initial load
duke
parents:
diff changeset
68 switch (*s++) { // Handle flag
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case 'd': // Debug flag
a61af66fc99e Initial load
duke
parents:
diff changeset
70 AD._dfa_debug += 1; // Set Debug Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
71 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 case 'g': // Debug ad location flag
a61af66fc99e Initial load
duke
parents:
diff changeset
73 AD._adlocation_debug += 1; // Set Debug ad location Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
74 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case 'o': // No Output Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
76 AD._no_output ^= 1; // Toggle no_output flag
a61af66fc99e Initial load
duke
parents:
diff changeset
77 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case 'q': // Quiet Mode Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
79 AD._quiet_mode ^= 1; // Toggle quiet_mode flag
a61af66fc99e Initial load
duke
parents:
diff changeset
80 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 case 'w': // Disable Warnings Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
82 AD._disable_warnings ^= 1; // Toggle disable_warnings flag
a61af66fc99e Initial load
duke
parents:
diff changeset
83 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 case 'T': // Option to make DFA as many subroutine calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 AD._dfa_small += 1; // Set Mode Flag
a61af66fc99e Initial load
duke
parents:
diff changeset
86 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case 'c': { // Set C++ Output file name
a61af66fc99e Initial load
duke
parents:
diff changeset
88 AD._CPP_file._name = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 const char *base = strip_ext(strdup(s));
a61af66fc99e Initial load
duke
parents:
diff changeset
90 AD._CPP_CLONE_file._name = base_plus_suffix(base,"_clone.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 AD._CPP_EXPAND_file._name = base_plus_suffix(base,"_expand.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 AD._CPP_FORMAT_file._name = base_plus_suffix(base,"_format.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 AD._CPP_GEN_file._name = base_plus_suffix(base,"_gen.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 AD._CPP_MISC_file._name = base_plus_suffix(base,"_misc.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(base,"_peephole.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 AD._CPP_PIPELINE_file._name = base_plus_suffix(base,"_pipeline.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 case 'h': // Set C++ Output file name
a61af66fc99e Initial load
duke
parents:
diff changeset
101 AD._HPP_file._name = s; s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 case 'v': // Set C++ Output file name
a61af66fc99e Initial load
duke
parents:
diff changeset
104 AD._VM_file._name = s; s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 case 'a': // Set C++ Output file name
a61af66fc99e Initial load
duke
parents:
diff changeset
107 AD._DFA_file._name = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 AD._bug_file._name = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 case '#': // Special internal debug flag
a61af66fc99e Initial load
duke
parents:
diff changeset
112 AD._adl_debug++; // Increment internal debug level
a61af66fc99e Initial load
duke
parents:
diff changeset
113 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case 's': // Output which instructions are cisc-spillable
a61af66fc99e Initial load
duke
parents:
diff changeset
115 AD._cisc_spill_debug = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case 'D': // Flag Definition
a61af66fc99e Initial load
duke
parents:
diff changeset
118 {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 char* flag = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 char* def = strchr(flag, '=');
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (def == NULL) def = (char*)"1";
a61af66fc99e Initial load
duke
parents:
diff changeset
123 else *def++ = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
124 AD.set_preproc_def(flag, def);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 case 'U': // Flag Un-Definition
a61af66fc99e Initial load
duke
parents:
diff changeset
128 {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 char* flag = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 s += strlen(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 AD.set_preproc_def(flag, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 default: // Unknown option
a61af66fc99e Initial load
duke
parents:
diff changeset
135 usage(AD); // So print usage and exit
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } // End of switch on options...
a61af66fc99e Initial load
duke
parents:
diff changeset
137 } // End of while have options...
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 } else { // Not an option; must be a filename
a61af66fc99e Initial load
duke
parents:
diff changeset
140 AD._ADL_file._name = argv[i]; // Set the input filename
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // // Files for storage, based on input file name
a61af66fc99e Initial load
duke
parents:
diff changeset
143 const char *base = strip_ext(strdup(argv[i]));
a61af66fc99e Initial load
duke
parents:
diff changeset
144 char *temp = base_plus_suffix("dfa_",base);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 AD._DFA_file._name = base_plus_suffix(temp,".cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 delete temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 temp = base_plus_suffix("ad_",base);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 AD._CPP_file._name = base_plus_suffix(temp,".cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 AD._CPP_CLONE_file._name = base_plus_suffix(temp,"_clone.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
150 AD._CPP_EXPAND_file._name = base_plus_suffix(temp,"_expand.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
151 AD._CPP_FORMAT_file._name = base_plus_suffix(temp,"_format.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 AD._CPP_GEN_file._name = base_plus_suffix(temp,"_gen.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 AD._CPP_MISC_file._name = base_plus_suffix(temp,"_misc.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 AD._HPP_file._name = base_plus_suffix(temp,".hpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 delete temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 temp = base_plus_suffix("adGlobals_",base);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 AD._VM_file._name = base_plus_suffix(temp,".hpp");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 delete temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 temp = base_plus_suffix("bugs_",base);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 AD._bug_file._name = base_plus_suffix(temp,".out");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 delete temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 } // End of files vs options...
a61af66fc99e Initial load
duke
parents:
diff changeset
165 } // End of while have command line arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Open files used to store the matcher and its components
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (AD.open_files() == 0) return 1; // Open all input/output files
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Build the File Buffer, Parse the input, & Generate Code
a61af66fc99e Initial load
duke
parents:
diff changeset
171 FileBuff ADL_Buf(&AD._ADL_file, AD); // Create a file buffer for input file
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Get pointer to legal text at the beginning of AD file.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // It will be used in generated ad files.
a61af66fc99e Initial load
duke
parents:
diff changeset
175 char* legal_text;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int legal_sz = get_legal_text(ADL_Buf, &legal_text);
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 ADL_Parse = new ADLParser(ADL_Buf, AD); // Create a parser to parse the buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
179 ADL_Parse->parse(); // Parse buffer & build description lists
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if( AD._dfa_debug >= 1 ) { // For higher debug settings, print dump
a61af66fc99e Initial load
duke
parents:
diff changeset
182 AD.dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 delete ADL_Parse; // Delete parser
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Verify that the results of the parse are consistent
a61af66fc99e Initial load
duke
parents:
diff changeset
188 AD.verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Prepare to generate the result files:
a61af66fc99e Initial load
duke
parents:
diff changeset
191 AD.generateMatchLists();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 AD.identify_unique_operands();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 AD.identify_cisc_spill_instructions();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 AD.identify_short_branches();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Make sure every file starts with a copyright:
a61af66fc99e Initial load
duke
parents:
diff changeset
196 AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
197 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
198 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
199 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
200 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
201 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
202 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
203 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
204 AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
205 AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
206 AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp); // .cpp
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
207 // Add include guards for all .hpp files
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
208 AD.addIncludeGuardStart(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
209 AD.addIncludeGuardStart(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
210 // Add includes
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
211 AD.addInclude(AD._CPP_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
212 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._VM_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
213 AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
214 AD.addInclude(AD._CPP_file, "memory/allocation.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
215 AD.addInclude(AD._CPP_file, "asm/assembler.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
216 AD.addInclude(AD._CPP_file, "code/vmreg.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
217 AD.addInclude(AD._CPP_file, "gc_interface/collectedHeap.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
218 AD.addInclude(AD._CPP_file, "oops/compiledICHolderOop.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
219 AD.addInclude(AD._CPP_file, "oops/markOop.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
220 AD.addInclude(AD._CPP_file, "oops/methodOop.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
221 AD.addInclude(AD._CPP_file, "oops/oop.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
222 AD.addInclude(AD._CPP_file, "oops/oop.inline2.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
223 AD.addInclude(AD._CPP_file, "opto/cfgnode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
224 AD.addInclude(AD._CPP_file, "opto/locknode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
225 AD.addInclude(AD._CPP_file, "opto/opcodes.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
226 AD.addInclude(AD._CPP_file, "opto/regalloc.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
227 AD.addInclude(AD._CPP_file, "opto/regmask.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
228 AD.addInclude(AD._CPP_file, "opto/runtime.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
229 AD.addInclude(AD._CPP_file, "runtime/biasedLocking.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
230 AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
231 AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
232 AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
233 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
234 AD.addInclude(AD._CPP_file, "assembler_x86.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
235 AD.addInclude(AD._CPP_file, "nativeInst_x86.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
236 AD.addInclude(AD._CPP_file, "vmreg_x86.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
237 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
238 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
239 AD.addInclude(AD._CPP_file, "assembler_sparc.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
240 AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
241 AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
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
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
248 AD.addInclude(AD._HPP_file, "memory/allocation.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
249 AD.addInclude(AD._HPP_file, "opto/machnode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
250 AD.addInclude(AD._HPP_file, "opto/node.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
251 AD.addInclude(AD._HPP_file, "opto/regalloc.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
252 AD.addInclude(AD._HPP_file, "opto/subnode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
253 AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
254 AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
255 AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
256 AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
257 AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
258 AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
259 AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
260 AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
261 AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
262 AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
263 AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
264 AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
265 AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
266 AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
267 AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
268 AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
269 AD.addInclude(AD._DFA_file, "precompiled.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
270 AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name));
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
271 AD.addInclude(AD._DFA_file, "opto/matcher.hpp");
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
272 AD.addInclude(AD._DFA_file, "opto/opcodes.hpp");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // Make sure each .cpp file starts with include lines:
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // files declaring and defining generators for Mach* Objects (hpp,cpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Generate the result files:
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // enumerations, class definitions, object generators, and the DFA
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // file containing enumeration of machine operands & instructions (hpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
278 AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
279 AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
280 AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
281 AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file
a61af66fc99e Initial load
duke
parents:
diff changeset
282 AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file
a61af66fc99e Initial load
duke
parents:
diff changeset
283 AD.declareRegSizes(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
284 AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // output definition of class "State"
a61af66fc99e Initial load
duke
parents:
diff changeset
286 AD.defineStateClass(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // file declaring the Mach* classes derived from MachOper and MachNode
a61af66fc99e Initial load
duke
parents:
diff changeset
288 AD.declareClasses(AD._HPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // declare and define maps: in the .hpp and .cpp files respectively
a61af66fc99e Initial load
duke
parents:
diff changeset
290 AD.addSourceBlocks(AD._CPP_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
291 AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp
a61af66fc99e Initial load
duke
parents:
diff changeset
292 AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // build CISC_spilling oracle and MachNode::cisc_spill() methods
a61af66fc99e Initial load
duke
parents:
diff changeset
295 AD.build_cisc_spill_instructions(AD._HPP_file._fp, AD._CPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // define methods for machine dependent State, MachOper, and MachNode classes
a61af66fc99e Initial load
duke
parents:
diff changeset
297 AD.defineClasses(AD._CPP_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
299 AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // define methods for machine dependent instruction matching
a61af66fc99e Initial load
duke
parents:
diff changeset
301 AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // define methods for machine dependent frame management
a61af66fc99e Initial load
duke
parents:
diff changeset
303 AD.buildFrameMethods(AD._CPP_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // do this last:
a61af66fc99e Initial load
duke
parents:
diff changeset
306 AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
307 AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
308 AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
309 AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
310 AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
311 AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
312 AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
313 AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // define the finite automata that selects lowest cost production
a61af66fc99e Initial load
duke
parents:
diff changeset
316 AD.buildDFA(AD._DFA_file._fp);
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
317 // Add include guards for all .hpp files
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
318 AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
319 AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
0
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 AD.close_files(0); // Close all input/output files
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Final printout and statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // cout << program;
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Timer t_stop;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // Timer t_total = t_stop - t_start; // Total running time
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // cerr << "\n---Architecture Description Totals---\n";
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // cerr << ", Total lines: " << TotalLines;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // float l = TotalLines;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // cerr << "\nTotal Compilation Time: " << t_total << "\n";
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // float ft = (float)t_total;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 //------------------------------usage------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
340 static void usage(ArchDesc& AD)
a61af66fc99e Initial load
duke
parents:
diff changeset
341 {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 printf("Architecture Description Language Compiler\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 printf("Usage: adl [-doqw] [-Dflag[=def]] [-Uflag] [-cFILENAME] [-hFILENAME] [-aDFAFILE] ADLFILE\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
344 printf(" d produce DFA debugging info\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
345 printf(" o no output produced, syntax and semantic checking only\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
346 printf(" q quiet mode, supresses all non-essential messages\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
347 printf(" w suppress warning messages\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
348 printf(" c specify CPP file name (default: %s)\n", AD._CPP_file._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 printf(" h specify HPP file name (default: %s)\n", AD._HPP_file._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 printf(" a specify DFA output file name\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
351 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354 //------------------------------open_file------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
355 int ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action)
a61af66fc99e Initial load
duke
parents:
diff changeset
356 {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (required &&
a61af66fc99e Initial load
duke
parents:
diff changeset
358 (ADF._fp = fopen(ADF._name, action)) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 close_files(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 //------------------------------open_files-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
367 int ArchDesc::open_files(void)
a61af66fc99e Initial load
duke
parents:
diff changeset
368 {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if (_ADL_file._name == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
370 { printf("ERROR: No ADL input file specified\n"); return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 if (!open_file(true , _ADL_file, "r")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (!open_file(!_no_output, _DFA_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if (!open_file(!_no_output, _HPP_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (!open_file(!_no_output, _CPP_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if (!open_file(!_no_output, _CPP_CLONE_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
377 if (!open_file(!_no_output, _CPP_EXPAND_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (!open_file(!_no_output, _CPP_FORMAT_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (!open_file(!_no_output, _CPP_GEN_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (!open_file(!_no_output, _CPP_MISC_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (!open_file(!_no_output, _CPP_PEEPHOLE_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
382 if (!open_file(!_no_output, _CPP_PIPELINE_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (!open_file(!_no_output, _VM_file , "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 if (!open_file(_dfa_debug != 0, _bug_file, "w")) { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 //------------------------------close_file------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
390 void ArchDesc::close_file(int delete_out, ADLFILE& ADF)
a61af66fc99e Initial load
duke
parents:
diff changeset
391 {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (ADF._fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 fclose(ADF._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 if (delete_out) remove(ADF._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 //------------------------------close_files------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
399 void ArchDesc::close_files(int delete_out)
a61af66fc99e Initial load
duke
parents:
diff changeset
400 {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (_ADL_file._fp) fclose(_ADL_file._fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 close_file(delete_out, _CPP_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 close_file(delete_out, _CPP_CLONE_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 close_file(delete_out, _CPP_EXPAND_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 close_file(delete_out, _CPP_FORMAT_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 close_file(delete_out, _CPP_GEN_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 close_file(delete_out, _CPP_MISC_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 close_file(delete_out, _CPP_PEEPHOLE_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
410 close_file(delete_out, _CPP_PIPELINE_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 close_file(delete_out, _HPP_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
412 close_file(delete_out, _DFA_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 close_file(delete_out, _bug_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 if (!_quiet_mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
417 if (_no_output || delete_out) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (_ADL_file._name) printf("%s: ", _ADL_file._name);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 printf("No output produced");
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
424 _CPP_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
425 _CPP_CLONE_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
426 _CPP_EXPAND_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
427 _CPP_FORMAT_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
428 _CPP_GEN_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
429 _CPP_MISC_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
430 _CPP_PEEPHOLE_file._name,
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 //------------------------------strip_ext--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
440 static char *strip_ext(char *fname)
a61af66fc99e Initial load
duke
parents:
diff changeset
441 {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 char *ep;
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if (fname) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 ep = fname + strlen(fname) - 1; // start at last character and look for '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
446 while (ep >= fname && *ep != '.') --ep;
a61af66fc99e Initial load
duke
parents:
diff changeset
447 if (*ep == '.') *ep = '\0'; // truncate string at '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 return fname;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 //------------------------------strip_path_and_ext------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
453 static char *strip_path_and_ext(char *fname)
a61af66fc99e Initial load
duke
parents:
diff changeset
454 {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 char *ep;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 char *sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (fname) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 for (sp = fname; *sp; sp++)
a61af66fc99e Initial load
duke
parents:
diff changeset
460 if (*sp == '/') fname = sp+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 ep = fname; // start at first character and look for '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
462 while (ep <= (fname + strlen(fname) - 1) && *ep != '.') ep++;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 if (*ep == '.') *ep = '\0'; // truncate string at '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 return fname;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 //------------------------------base_plus_suffix-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // New concatenated string
a61af66fc99e Initial load
duke
parents:
diff changeset
470 static char *base_plus_suffix(const char* base, const char *suffix)
a61af66fc99e Initial load
duke
parents:
diff changeset
471 {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 int len = (int)strlen(base) + (int)strlen(suffix) + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 char* fname = new char[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
475 sprintf(fname,"%s%s",base,suffix);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 return fname;
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 //------------------------------prefix_plus_base_plus_suffix-------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // New concatenated string
a61af66fc99e Initial load
duke
parents:
diff changeset
482 static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix)
a61af66fc99e Initial load
duke
parents:
diff changeset
483 {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 int len = (int)strlen(prefix) + (int)strlen(base) + (int)strlen(suffix) + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 char* fname = new char[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
487 sprintf(fname,"%s%s%s",prefix,base,suffix);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return fname;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 //------------------------------get_legal_text---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // Get pointer to legal text at the beginning of AD file.
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // This code assumes that a legal text starts at the beginning of .ad files,
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // is commented by "//" at each line and ends with empty line.
a61af66fc99e Initial load
duke
parents:
diff changeset
495 //
a61af66fc99e Initial load
duke
parents:
diff changeset
496 int get_legal_text(FileBuff &fbuf, char **legal_text)
a61af66fc99e Initial load
duke
parents:
diff changeset
497 {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 char* legal_start = fbuf.get_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
499 assert(legal_start[0] == '/' && legal_start[1] == '/', "Incorrect header of AD file");
a61af66fc99e Initial load
duke
parents:
diff changeset
500 char* legal_end = fbuf.get_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 assert(strncmp(legal_end, "// Copyright", 12) == 0, "Incorrect header of AD file");
a61af66fc99e Initial load
duke
parents:
diff changeset
502 while(legal_end[0] == '/' && legal_end[1] == '/') {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 legal_end = fbuf.get_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // VS2005 has its own definition, identical to this one.
a61af66fc99e Initial load
duke
parents:
diff changeset
510 #if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400
a61af66fc99e Initial load
duke
parents:
diff changeset
511 void *operator new( size_t size, int, const char *, int ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 return ::operator new( size );
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 #endif