src/share/vm/adlc/main.cpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/adlc/main.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,498 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// MAIN.CPP - Entry point for the Architecture Description Language Compiler
    1.29 +#include "adlc.hpp"
    1.30 +
    1.31 +//------------------------------Prototypes-------------------------------------
    1.32 +static void  usage(ArchDesc& AD);          // Print usage message and exit
    1.33 +static char *strip_ext(char *fname);       // Strip off name extension
    1.34 +static char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
    1.35 +static char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
    1.36 +static int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
    1.37 +
    1.38 +ArchDesc* globalAD = NULL;      // global reference to Architecture Description object
    1.39 +
    1.40 +const char* get_basename(const char* filename) {
    1.41 +  const char *basename = filename;
    1.42 +  const char *cp;
    1.43 +  for (cp = basename; *cp; cp++) {
    1.44 +    if (*cp == '/') {
    1.45 +      basename = cp+1;
    1.46 +    }
    1.47 +  }
    1.48 +  return basename;
    1.49 +}
    1.50 +
    1.51 +//------------------------------main-------------------------------------------
    1.52 +int main(int argc, char *argv[])
    1.53 +{
    1.54 +  ArchDesc      AD;             // Architecture Description object
    1.55 +  globalAD = &AD;
    1.56 +
    1.57 +  // ResourceMark  mark;
    1.58 +  ADLParser    *ADL_Parse;      // ADL Parser object to parse AD file
    1.59 +
    1.60 +  // Check for proper arguments
    1.61 +  if( argc == 1 ) usage(AD);    // No arguments?  Then print usage
    1.62 +
    1.63 +  // Read command line arguments and file names
    1.64 +  for( int i = 1; i < argc; i++ ) { // For all arguments
    1.65 +    register char *s = argv[i]; // Get option/filename
    1.66 +
    1.67 +    if( *s++ == '-' ) {         // It's a flag? (not a filename)
    1.68 +      if( !*s ) {               // Stand-alone `-' means stdin
    1.69 +        //********** INSERT CODE HERE **********
    1.70 +      } else while (*s != '\0') { // While have flags on option
    1.71 +        switch (*s++) {         // Handle flag
    1.72 +        case 'd':               // Debug flag
    1.73 +          AD._dfa_debug += 1;   // Set Debug Flag
    1.74 +          break;
    1.75 +        case 'g':               // Debug ad location flag
    1.76 +          AD._adlocation_debug += 1;       // Set Debug ad location Flag
    1.77 +          break;
    1.78 +        case 'o':               // No Output Flag
    1.79 +          AD._no_output ^= 1;   // Toggle no_output flag
    1.80 +          break;
    1.81 +        case 'q':               // Quiet Mode Flag
    1.82 +          AD._quiet_mode ^= 1;  // Toggle quiet_mode flag
    1.83 +          break;
    1.84 +        case 'w':               // Disable Warnings Flag
    1.85 +          AD._disable_warnings ^= 1; // Toggle disable_warnings flag
    1.86 +          break;
    1.87 +        case 'T':               // Option to make DFA as many subroutine calls.
    1.88 +          AD._dfa_small += 1;   // Set Mode Flag
    1.89 +          break;
    1.90 +        case 'c': {             // Set C++ Output file name
    1.91 +          AD._CPP_file._name = s;
    1.92 +          const char *base = strip_ext(strdup(s));
    1.93 +          AD._CPP_CLONE_file._name    = base_plus_suffix(base,"_clone.cpp");
    1.94 +          AD._CPP_EXPAND_file._name   = base_plus_suffix(base,"_expand.cpp");
    1.95 +          AD._CPP_FORMAT_file._name   = base_plus_suffix(base,"_format.cpp");
    1.96 +          AD._CPP_GEN_file._name      = base_plus_suffix(base,"_gen.cpp");
    1.97 +          AD._CPP_MISC_file._name     = base_plus_suffix(base,"_misc.cpp");
    1.98 +          AD._CPP_PEEPHOLE_file._name = base_plus_suffix(base,"_peephole.cpp");
    1.99 +          AD._CPP_PIPELINE_file._name = base_plus_suffix(base,"_pipeline.cpp");
   1.100 +          s += strlen(s);
   1.101 +          break;
   1.102 +        }
   1.103 +        case 'h':               // Set C++ Output file name
   1.104 +          AD._HPP_file._name = s; s += strlen(s);
   1.105 +          break;
   1.106 +        case 'v':               // Set C++ Output file name
   1.107 +          AD._VM_file._name = s; s += strlen(s);
   1.108 +          break;
   1.109 +        case 'a':               // Set C++ Output file name
   1.110 +          AD._DFA_file._name = s;
   1.111 +          AD._bug_file._name = s;
   1.112 +          s += strlen(s);
   1.113 +          break;
   1.114 +        case '#':               // Special internal debug flag
   1.115 +          AD._adl_debug++;      // Increment internal debug level
   1.116 +          break;
   1.117 +        case 's':               // Output which instructions are cisc-spillable
   1.118 +          AD._cisc_spill_debug = true;
   1.119 +          break;
   1.120 +        case 'D':               // Flag Definition
   1.121 +          {
   1.122 +            char* flag = s;
   1.123 +            s += strlen(s);
   1.124 +            char* def = strchr(flag, '=');
   1.125 +            if (def == NULL)  def = (char*)"1";
   1.126 +            else              *def++ = '\0';
   1.127 +            AD.set_preproc_def(flag, def);
   1.128 +          }
   1.129 +          break;
   1.130 +        case 'U':               // Flag Un-Definition
   1.131 +          {
   1.132 +            char* flag = s;
   1.133 +            s += strlen(s);
   1.134 +            AD.set_preproc_def(flag, NULL);
   1.135 +          }
   1.136 +          break;
   1.137 +        default:                // Unknown option
   1.138 +          usage(AD);            // So print usage and exit
   1.139 +        }                       // End of switch on options...
   1.140 +      }                         // End of while have options...
   1.141 +
   1.142 +    } else {                    // Not an option; must be a filename
   1.143 +      AD._ADL_file._name = argv[i]; // Set the input filename
   1.144 +
   1.145 +      // // Files for storage, based on input file name
   1.146 +      const char *base = strip_ext(strdup(argv[i]));
   1.147 +      char       *temp = base_plus_suffix("dfa_",base);
   1.148 +      AD._DFA_file._name = base_plus_suffix(temp,".cpp");
   1.149 +      delete temp;
   1.150 +      temp = base_plus_suffix("ad_",base);
   1.151 +      AD._CPP_file._name          = base_plus_suffix(temp,".cpp");
   1.152 +      AD._CPP_CLONE_file._name    = base_plus_suffix(temp,"_clone.cpp");
   1.153 +      AD._CPP_EXPAND_file._name   = base_plus_suffix(temp,"_expand.cpp");
   1.154 +      AD._CPP_FORMAT_file._name   = base_plus_suffix(temp,"_format.cpp");
   1.155 +      AD._CPP_GEN_file._name      = base_plus_suffix(temp,"_gen.cpp");
   1.156 +      AD._CPP_MISC_file._name     = base_plus_suffix(temp,"_misc.cpp");
   1.157 +      AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp");
   1.158 +      AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp");
   1.159 +      AD._HPP_file._name = base_plus_suffix(temp,".hpp");
   1.160 +      delete temp;
   1.161 +      temp = base_plus_suffix("adGlobals_",base);
   1.162 +      AD._VM_file._name = base_plus_suffix(temp,".hpp");
   1.163 +      delete temp;
   1.164 +      temp = base_plus_suffix("bugs_",base);
   1.165 +      AD._bug_file._name = base_plus_suffix(temp,".out");
   1.166 +      delete temp;
   1.167 +    }                           // End of files vs options...
   1.168 +  }                             // End of while have command line arguments
   1.169 +
   1.170 +  // Open files used to store the matcher and its components
   1.171 +  if (AD.open_files() == 0) return 1; // Open all input/output files
   1.172 +
   1.173 +  // Build the File Buffer, Parse the input, & Generate Code
   1.174 +  FileBuff  ADL_Buf(&AD._ADL_file, AD); // Create a file buffer for input file
   1.175 +
   1.176 +  // Get pointer to legal text at the beginning of AD file.
   1.177 +  // It will be used in generated ad files.
   1.178 +  char* legal_text;
   1.179 +  int legal_sz = get_legal_text(ADL_Buf, &legal_text);
   1.180 +
   1.181 +  ADL_Parse = new ADLParser(ADL_Buf, AD); // Create a parser to parse the buffer
   1.182 +  ADL_Parse->parse();           // Parse buffer & build description lists
   1.183 +
   1.184 +  if( AD._dfa_debug >= 1 ) {    // For higher debug settings, print dump
   1.185 +    AD.dump();
   1.186 +  }
   1.187 +
   1.188 +  delete ADL_Parse;             // Delete parser
   1.189 +
   1.190 +  // Verify that the results of the parse are consistent
   1.191 +  AD.verify();
   1.192 +
   1.193 +  // Prepare to generate the result files:
   1.194 +  AD.generateMatchLists();
   1.195 +  AD.identify_unique_operands();
   1.196 +  AD.identify_cisc_spill_instructions();
   1.197 +  AD.identify_short_branches();
   1.198 +  // Make sure every file starts with a copyright:
   1.199 +  AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp);           // .hpp
   1.200 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp);           // .cpp
   1.201 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp);     // .cpp
   1.202 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp);    // .cpp
   1.203 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp);    // .cpp
   1.204 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp);       // .cpp
   1.205 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp);      // .cpp
   1.206 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp);  // .cpp
   1.207 +  AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp);  // .cpp
   1.208 +  AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp);            // .hpp
   1.209 +  AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp);           // .cpp
   1.210 +  // Add include guards for all .hpp files
   1.211 +  AD.addIncludeGuardStart(AD._HPP_file, "GENERATED_ADFILES_AD_HPP");        // .hpp
   1.212 +  AD.addIncludeGuardStart(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP");  // .hpp
   1.213 +  // Add includes
   1.214 +  AD.addInclude(AD._CPP_file, "precompiled.hpp");
   1.215 +  AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._VM_file._name));
   1.216 +  AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._HPP_file._name));
   1.217 +  AD.addInclude(AD._CPP_file, "memory/allocation.inline.hpp");
   1.218 +  AD.addInclude(AD._CPP_file, "asm/macroAssembler.inline.hpp");
   1.219 +  AD.addInclude(AD._CPP_file, "code/compiledIC.hpp");
   1.220 +  AD.addInclude(AD._CPP_file, "code/vmreg.hpp");
   1.221 +  AD.addInclude(AD._CPP_file, "gc_interface/collectedHeap.inline.hpp");
   1.222 +  AD.addInclude(AD._CPP_file, "oops/compiledICHolder.hpp");
   1.223 +  AD.addInclude(AD._CPP_file, "oops/markOop.hpp");
   1.224 +  AD.addInclude(AD._CPP_file, "oops/method.hpp");
   1.225 +  AD.addInclude(AD._CPP_file, "oops/oop.inline.hpp");
   1.226 +  AD.addInclude(AD._CPP_file, "oops/oop.inline2.hpp");
   1.227 +  AD.addInclude(AD._CPP_file, "opto/cfgnode.hpp");
   1.228 +  AD.addInclude(AD._CPP_file, "opto/locknode.hpp");
   1.229 +  AD.addInclude(AD._CPP_file, "opto/opcodes.hpp");
   1.230 +  AD.addInclude(AD._CPP_file, "opto/regalloc.hpp");
   1.231 +  AD.addInclude(AD._CPP_file, "opto/regmask.hpp");
   1.232 +  AD.addInclude(AD._CPP_file, "opto/runtime.hpp");
   1.233 +  AD.addInclude(AD._CPP_file, "runtime/biasedLocking.hpp");
   1.234 +  AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp");
   1.235 +  AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp");
   1.236 +  AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp");
   1.237 +#ifdef TARGET_ARCH_x86
   1.238 +  AD.addInclude(AD._CPP_file, "nativeInst_x86.hpp");
   1.239 +  AD.addInclude(AD._CPP_file, "vmreg_x86.inline.hpp");
   1.240 +#endif
   1.241 +#ifdef TARGET_ARCH_sparc
   1.242 +  AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp");
   1.243 +  AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp");
   1.244 +#endif
   1.245 +#ifdef TARGET_ARCH_arm
   1.246 +  AD.addInclude(AD._CPP_file, "nativeInst_arm.hpp");
   1.247 +  AD.addInclude(AD._CPP_file, "vmreg_arm.inline.hpp");
   1.248 +#endif
   1.249 +#ifdef TARGET_ARCH_ppc
   1.250 +  AD.addInclude(AD._CPP_file, "assembler_ppc.inline.hpp");
   1.251 +  AD.addInclude(AD._CPP_file, "nativeInst_ppc.hpp");
   1.252 +  AD.addInclude(AD._CPP_file, "vmreg_ppc.inline.hpp");
   1.253 +#endif
   1.254 +  AD.addInclude(AD._HPP_file, "memory/allocation.hpp");
   1.255 +  AD.addInclude(AD._HPP_file, "opto/machnode.hpp");
   1.256 +  AD.addInclude(AD._HPP_file, "opto/node.hpp");
   1.257 +  AD.addInclude(AD._HPP_file, "opto/regalloc.hpp");
   1.258 +  AD.addInclude(AD._HPP_file, "opto/subnode.hpp");
   1.259 +  AD.addInclude(AD._HPP_file, "opto/vectornode.hpp");
   1.260 +  AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp");
   1.261 +  AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name));
   1.262 +  AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp");
   1.263 +  AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name));
   1.264 +  AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp");
   1.265 +  AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name));
   1.266 +  AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp");
   1.267 +  AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name));
   1.268 +  AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp");
   1.269 +  AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp");
   1.270 +  AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp");
   1.271 +  AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name));
   1.272 +  AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp");
   1.273 +  AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name));
   1.274 +  AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp");
   1.275 +  AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name));
   1.276 +  AD.addInclude(AD._DFA_file, "precompiled.hpp");
   1.277 +  AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name));
   1.278 +  AD.addInclude(AD._DFA_file, "opto/cfgnode.hpp");  // Use PROB_MAX in predicate.
   1.279 +  AD.addInclude(AD._DFA_file, "opto/matcher.hpp");
   1.280 +  AD.addInclude(AD._DFA_file, "opto/opcodes.hpp");
   1.281 +  // Make sure each .cpp file starts with include lines:
   1.282 +  // files declaring and defining generators for Mach* Objects (hpp,cpp)
   1.283 +  // Generate the result files:
   1.284 +  // enumerations, class definitions, object generators, and the DFA
   1.285 +  // file containing enumeration of machine operands & instructions (hpp)
   1.286 +  AD.addPreHeaderBlocks(AD._HPP_file._fp);        // .hpp
   1.287 +  AD.buildMachOperEnum(AD._HPP_file._fp);         // .hpp
   1.288 +  AD.buildMachOpcodesEnum(AD._HPP_file._fp);      // .hpp
   1.289 +  AD.buildMachRegisterNumbers(AD._VM_file._fp);   // VM file
   1.290 +  AD.buildMachRegisterEncodes(AD._HPP_file._fp);  // .hpp file
   1.291 +  AD.declareRegSizes(AD._HPP_file._fp);           // .hpp
   1.292 +  AD.build_pipeline_enums(AD._HPP_file._fp);      // .hpp
   1.293 +  // output definition of class "State"
   1.294 +  AD.defineStateClass(AD._HPP_file._fp);          // .hpp
   1.295 +  // file declaring the Mach* classes derived from MachOper and MachNode
   1.296 +  AD.declareClasses(AD._HPP_file._fp);
   1.297 +  // declare and define maps: in the .hpp and .cpp files respectively
   1.298 +  AD.addSourceBlocks(AD._CPP_file._fp);           // .cpp
   1.299 +  AD.addHeaderBlocks(AD._HPP_file._fp);           // .hpp
   1.300 +  AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
   1.301 +  AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
   1.302 +  // build CISC_spilling oracle and MachNode::cisc_spill() methods
   1.303 +  AD.build_cisc_spill_instructions(AD._HPP_file._fp, AD._CPP_file._fp);
   1.304 +  // define methods for machine dependent State, MachOper, and MachNode classes
   1.305 +  AD.defineClasses(AD._CPP_file._fp);
   1.306 +  AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
   1.307 +  AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
   1.308 +  // define methods for machine dependent instruction matching
   1.309 +  AD.buildInstructMatchCheck(AD._CPP_file._fp);  // .cpp
   1.310 +  // define methods for machine dependent frame management
   1.311 +  AD.buildFrameMethods(AD._CPP_file._fp);         // .cpp
   1.312 +  AD.generate_needs_clone_jvms(AD._CPP_file._fp);
   1.313 +
   1.314 +  // do this last:
   1.315 +  AD.addPreprocessorChecks(AD._CPP_file._fp);     // .cpp
   1.316 +  AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp);     // .cpp
   1.317 +  AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp);    // .cpp
   1.318 +  AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp);    // .cpp
   1.319 +  AD.addPreprocessorChecks(AD._CPP_GEN_file._fp);       // .cpp
   1.320 +  AD.addPreprocessorChecks(AD._CPP_MISC_file._fp);      // .cpp
   1.321 +  AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp);  // .cpp
   1.322 +  AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp);  // .cpp
   1.323 +
   1.324 +  // define the finite automata that selects lowest cost production
   1.325 +  AD.buildDFA(AD._DFA_file._fp);
   1.326 +  // Add include guards for all .hpp files
   1.327 +  AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP");        // .hpp
   1.328 +  AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP");  // .hpp
   1.329 +
   1.330 +  AD.close_files(0);               // Close all input/output files
   1.331 +
   1.332 +  // Final printout and statistics
   1.333 +  // cout << program;
   1.334 +
   1.335 +  if( AD._dfa_debug & 2 ) {    // For higher debug settings, print timing info
   1.336 +    //    Timer t_stop;
   1.337 +    //    Timer t_total = t_stop - t_start; // Total running time
   1.338 +    //    cerr << "\n---Architecture Description Totals---\n";
   1.339 +    //    cerr << ", Total lines: " << TotalLines;
   1.340 +    //    float l = TotalLines;
   1.341 +    //    cerr << "\nTotal Compilation Time: " << t_total << "\n";
   1.342 +    //    float ft = (float)t_total;
   1.343 +    //    if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
   1.344 +  }
   1.345 +  return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
   1.346 +}
   1.347 +
   1.348 +//------------------------------usage------------------------------------------
   1.349 +static void usage(ArchDesc& AD)
   1.350 +{
   1.351 +  printf("Architecture Description Language Compiler\n\n");
   1.352 +  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");
   1.353 +  printf(" d  produce DFA debugging info\n");
   1.354 +  printf(" o  no output produced, syntax and semantic checking only\n");
   1.355 +  printf(" q  quiet mode, supresses all non-essential messages\n");
   1.356 +  printf(" w  suppress warning messages\n");
   1.357 +  printf(" T  make DFA as many subroutine calls\n");
   1.358 +  printf(" s  output which instructions are cisc-spillable\n");
   1.359 +  printf(" D  define preprocessor symbol\n");
   1.360 +  printf(" U  undefine preprocessor symbol\n");
   1.361 +  printf(" c  specify CPP file name (default: %s)\n", AD._CPP_file._name);
   1.362 +  printf(" h  specify HPP file name (default: %s)\n", AD._HPP_file._name);
   1.363 +  printf(" a  specify DFA output file name\n");
   1.364 +  printf(" v  specify adGlobals output file name\n");
   1.365 +  printf(" #  increment ADL debug level\n");
   1.366 +  printf("\n");
   1.367 +}
   1.368 +
   1.369 +//------------------------------open_file------------------------------------
   1.370 +int ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action)
   1.371 +{
   1.372 +  if (required &&
   1.373 +      (ADF._fp = fopen(ADF._name, action)) == NULL) {
   1.374 +    printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name);
   1.375 +    close_files(1);
   1.376 +    return 0;
   1.377 +  }
   1.378 +  return 1;
   1.379 +}
   1.380 +
   1.381 +//------------------------------open_files-------------------------------------
   1.382 +int ArchDesc::open_files(void)
   1.383 +{
   1.384 +  if (_ADL_file._name == NULL)
   1.385 +  { printf("ERROR: No ADL input file specified\n"); return 0; }
   1.386 +
   1.387 +  if (!open_file(true       , _ADL_file, "r"))          { return 0; }
   1.388 +  if (!open_file(!_no_output, _DFA_file, "w"))          { return 0; }
   1.389 +  if (!open_file(!_no_output, _HPP_file, "w"))          { return 0; }
   1.390 +  if (!open_file(!_no_output, _CPP_file, "w"))          { return 0; }
   1.391 +  if (!open_file(!_no_output, _CPP_CLONE_file, "w"))    { return 0; }
   1.392 +  if (!open_file(!_no_output, _CPP_EXPAND_file, "w"))   { return 0; }
   1.393 +  if (!open_file(!_no_output, _CPP_FORMAT_file, "w"))   { return 0; }
   1.394 +  if (!open_file(!_no_output, _CPP_GEN_file, "w"))      { return 0; }
   1.395 +  if (!open_file(!_no_output, _CPP_MISC_file, "w"))     { return 0; }
   1.396 +  if (!open_file(!_no_output, _CPP_PEEPHOLE_file, "w")) { return 0; }
   1.397 +  if (!open_file(!_no_output, _CPP_PIPELINE_file, "w")) { return 0; }
   1.398 +  if (!open_file(!_no_output, _VM_file , "w"))          { return 0; }
   1.399 +  if (!open_file(_dfa_debug != 0, _bug_file, "w"))    { return 0; }
   1.400 +
   1.401 +  return 1;
   1.402 +}
   1.403 +
   1.404 +//------------------------------close_file------------------------------------
   1.405 +void ArchDesc::close_file(int delete_out, ADLFILE& ADF)
   1.406 +{
   1.407 +  if (ADF._fp) {
   1.408 +    fclose(ADF._fp);
   1.409 +    if (delete_out) remove(ADF._name);
   1.410 +  }
   1.411 +}
   1.412 +
   1.413 +//------------------------------close_files------------------------------------
   1.414 +void ArchDesc::close_files(int delete_out)
   1.415 +{
   1.416 +  if (_ADL_file._fp) fclose(_ADL_file._fp);
   1.417 +
   1.418 +  close_file(delete_out, _CPP_file);
   1.419 +  close_file(delete_out, _CPP_CLONE_file);
   1.420 +  close_file(delete_out, _CPP_EXPAND_file);
   1.421 +  close_file(delete_out, _CPP_FORMAT_file);
   1.422 +  close_file(delete_out, _CPP_GEN_file);
   1.423 +  close_file(delete_out, _CPP_MISC_file);
   1.424 +  close_file(delete_out, _CPP_PEEPHOLE_file);
   1.425 +  close_file(delete_out, _CPP_PIPELINE_file);
   1.426 +  close_file(delete_out, _HPP_file);
   1.427 +  close_file(delete_out, _DFA_file);
   1.428 +  close_file(delete_out, _bug_file);
   1.429 +
   1.430 +  if (!_quiet_mode) {
   1.431 +    printf("\n");
   1.432 +    if (_no_output || delete_out) {
   1.433 +      if (_ADL_file._name) printf("%s: ", _ADL_file._name);
   1.434 +      printf("No output produced");
   1.435 +    }
   1.436 +    else {
   1.437 +      if (_ADL_file._name) printf("%s --> ", _ADL_file._name);
   1.438 +      printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
   1.439 +             _CPP_file._name,
   1.440 +             _CPP_CLONE_file._name,
   1.441 +             _CPP_EXPAND_file._name,
   1.442 +             _CPP_FORMAT_file._name,
   1.443 +             _CPP_GEN_file._name,
   1.444 +             _CPP_MISC_file._name,
   1.445 +             _CPP_PEEPHOLE_file._name,
   1.446 +             _CPP_PIPELINE_file._name,
   1.447 +             _HPP_file._name,
   1.448 +             _DFA_file._name);
   1.449 +    }
   1.450 +    printf("\n");
   1.451 +  }
   1.452 +}
   1.453 +
   1.454 +//------------------------------strip_ext--------------------------------------
   1.455 +static char *strip_ext(char *fname)
   1.456 +{
   1.457 +  char *ep;
   1.458 +
   1.459 +  if (fname) {
   1.460 +    ep = fname + strlen(fname) - 1; // start at last character and look for '.'
   1.461 +    while (ep >= fname && *ep != '.') --ep;
   1.462 +    if (*ep == '.')     *ep = '\0'; // truncate string at '.'
   1.463 +  }
   1.464 +  return fname;
   1.465 +}
   1.466 +
   1.467 +//------------------------------base_plus_suffix-------------------------------
   1.468 +// New concatenated string
   1.469 +static char *base_plus_suffix(const char* base, const char *suffix)
   1.470 +{
   1.471 +  int len = (int)strlen(base) + (int)strlen(suffix) + 1;
   1.472 +
   1.473 +  char* fname = new char[len];
   1.474 +  sprintf(fname,"%s%s",base,suffix);
   1.475 +  return fname;
   1.476 +}
   1.477 +
   1.478 +//------------------------------get_legal_text---------------------------------
   1.479 +// Get pointer to legal text at the beginning of AD file.
   1.480 +// This code assumes that a legal text starts at the beginning of .ad files,
   1.481 +// is commented by "//" at each line and ends with empty line.
   1.482 +//
   1.483 +int get_legal_text(FileBuff &fbuf, char **legal_text)
   1.484 +{
   1.485 +  char* legal_start = fbuf.get_line();
   1.486 +  assert(legal_start[0] == '/' && legal_start[1] == '/', "Incorrect header of AD file");
   1.487 +  char* legal_end = fbuf.get_line();
   1.488 +  assert(strncmp(legal_end, "// Copyright", 12) == 0, "Incorrect header of AD file");
   1.489 +  while(legal_end[0] == '/' && legal_end[1] == '/') {
   1.490 +    legal_end = fbuf.get_line();
   1.491 +  }
   1.492 +  *legal_text = legal_start;
   1.493 +  return (int) (legal_end - legal_start);
   1.494 +}
   1.495 +
   1.496 +// VS2005 has its own definition, identical to this one.
   1.497 +#if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400
   1.498 +void *operator new( size_t size, int, const char *, int ) throw() {
   1.499 +  return ::operator new( size );
   1.500 +}
   1.501 +#endif

mercurial