src/share/vm/adlc/main.cpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6499
ad3b94907eed
child 6876
710a3c8b516e
child 9846
9003f35baaa0
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

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

mercurial