src/share/vm/adlc/main.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial