0N/A/*
3845N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/A// MAIN.CPP - Entry point for the Architecture Description Language Compiler
0N/A#include "adlc.hpp"
0N/A
0N/A//------------------------------Prototypes-------------------------------------
0N/Astatic void usage(ArchDesc& AD); // Print usage message and exit
0N/Astatic char *strip_ext(char *fname); // Strip off name extension
0N/Astatic char *base_plus_suffix(const char* base, const char *suffix);// New concatenated string
0N/Astatic char *prefix_plus_base_plus_suffix(const char* prefix, const char* base, const char *suffix);// New concatenated string
0N/Astatic int get_legal_text(FileBuff &fbuf, char **legal_text); // Get pointer to legal text
0N/A
0N/AArchDesc* globalAD = NULL; // global reference to Architecture Description object
0N/A
1879N/Aconst char* get_basename(const char* filename) {
1879N/A const char *basename = filename;
1879N/A const char *cp;
1879N/A for (cp = basename; *cp; cp++) {
1879N/A if (*cp == '/') {
1879N/A basename = cp+1;
1879N/A }
1879N/A }
1879N/A return basename;
1879N/A}
1879N/A
0N/A//------------------------------main-------------------------------------------
0N/Aint main(int argc, char *argv[])
0N/A{
0N/A ArchDesc AD; // Architecture Description object
0N/A globalAD = &AD;
0N/A
0N/A // ResourceMark mark;
0N/A ADLParser *ADL_Parse; // ADL Parser object to parse AD file
0N/A
0N/A // Check for proper arguments
0N/A if( argc == 1 ) usage(AD); // No arguments? Then print usage
0N/A
0N/A // Read command line arguments and file names
0N/A for( int i = 1; i < argc; i++ ) { // For all arguments
0N/A register char *s = argv[i]; // Get option/filename
0N/A
0N/A if( *s++ == '-' ) { // It's a flag? (not a filename)
0N/A if( !*s ) { // Stand-alone `-' means stdin
0N/A //********** INSERT CODE HERE **********
0N/A } else while (*s != '\0') { // While have flags on option
0N/A switch (*s++) { // Handle flag
0N/A case 'd': // Debug flag
0N/A AD._dfa_debug += 1; // Set Debug Flag
0N/A break;
0N/A case 'g': // Debug ad location flag
0N/A AD._adlocation_debug += 1; // Set Debug ad location Flag
0N/A break;
0N/A case 'o': // No Output Flag
0N/A AD._no_output ^= 1; // Toggle no_output flag
0N/A break;
0N/A case 'q': // Quiet Mode Flag
0N/A AD._quiet_mode ^= 1; // Toggle quiet_mode flag
0N/A break;
0N/A case 'w': // Disable Warnings Flag
0N/A AD._disable_warnings ^= 1; // Toggle disable_warnings flag
0N/A break;
0N/A case 'T': // Option to make DFA as many subroutine calls.
0N/A AD._dfa_small += 1; // Set Mode Flag
0N/A break;
0N/A case 'c': { // Set C++ Output file name
0N/A AD._CPP_file._name = s;
0N/A const char *base = strip_ext(strdup(s));
0N/A AD._CPP_CLONE_file._name = base_plus_suffix(base,"_clone.cpp");
0N/A AD._CPP_EXPAND_file._name = base_plus_suffix(base,"_expand.cpp");
0N/A AD._CPP_FORMAT_file._name = base_plus_suffix(base,"_format.cpp");
0N/A AD._CPP_GEN_file._name = base_plus_suffix(base,"_gen.cpp");
0N/A AD._CPP_MISC_file._name = base_plus_suffix(base,"_misc.cpp");
0N/A AD._CPP_PEEPHOLE_file._name = base_plus_suffix(base,"_peephole.cpp");
0N/A AD._CPP_PIPELINE_file._name = base_plus_suffix(base,"_pipeline.cpp");
0N/A s += strlen(s);
0N/A break;
0N/A }
0N/A case 'h': // Set C++ Output file name
0N/A AD._HPP_file._name = s; s += strlen(s);
0N/A break;
0N/A case 'v': // Set C++ Output file name
0N/A AD._VM_file._name = s; s += strlen(s);
0N/A break;
0N/A case 'a': // Set C++ Output file name
0N/A AD._DFA_file._name = s;
0N/A AD._bug_file._name = s;
0N/A s += strlen(s);
0N/A break;
0N/A case '#': // Special internal debug flag
0N/A AD._adl_debug++; // Increment internal debug level
0N/A break;
0N/A case 's': // Output which instructions are cisc-spillable
0N/A AD._cisc_spill_debug = true;
0N/A break;
0N/A case 'D': // Flag Definition
0N/A {
0N/A char* flag = s;
0N/A s += strlen(s);
0N/A char* def = strchr(flag, '=');
0N/A if (def == NULL) def = (char*)"1";
0N/A else *def++ = '\0';
0N/A AD.set_preproc_def(flag, def);
0N/A }
0N/A break;
0N/A case 'U': // Flag Un-Definition
0N/A {
0N/A char* flag = s;
0N/A s += strlen(s);
0N/A AD.set_preproc_def(flag, NULL);
0N/A }
0N/A break;
0N/A default: // Unknown option
0N/A usage(AD); // So print usage and exit
0N/A } // End of switch on options...
0N/A } // End of while have options...
0N/A
0N/A } else { // Not an option; must be a filename
0N/A AD._ADL_file._name = argv[i]; // Set the input filename
0N/A
0N/A // // Files for storage, based on input file name
0N/A const char *base = strip_ext(strdup(argv[i]));
0N/A char *temp = base_plus_suffix("dfa_",base);
0N/A AD._DFA_file._name = base_plus_suffix(temp,".cpp");
0N/A delete temp;
0N/A temp = base_plus_suffix("ad_",base);
0N/A AD._CPP_file._name = base_plus_suffix(temp,".cpp");
0N/A AD._CPP_CLONE_file._name = base_plus_suffix(temp,"_clone.cpp");
0N/A AD._CPP_EXPAND_file._name = base_plus_suffix(temp,"_expand.cpp");
0N/A AD._CPP_FORMAT_file._name = base_plus_suffix(temp,"_format.cpp");
0N/A AD._CPP_GEN_file._name = base_plus_suffix(temp,"_gen.cpp");
0N/A AD._CPP_MISC_file._name = base_plus_suffix(temp,"_misc.cpp");
0N/A AD._CPP_PEEPHOLE_file._name = base_plus_suffix(temp,"_peephole.cpp");
0N/A AD._CPP_PIPELINE_file._name = base_plus_suffix(temp,"_pipeline.cpp");
0N/A AD._HPP_file._name = base_plus_suffix(temp,".hpp");
0N/A delete temp;
0N/A temp = base_plus_suffix("adGlobals_",base);
0N/A AD._VM_file._name = base_plus_suffix(temp,".hpp");
0N/A delete temp;
0N/A temp = base_plus_suffix("bugs_",base);
0N/A AD._bug_file._name = base_plus_suffix(temp,".out");
0N/A delete temp;
0N/A } // End of files vs options...
0N/A } // End of while have command line arguments
0N/A
0N/A // Open files used to store the matcher and its components
0N/A if (AD.open_files() == 0) return 1; // Open all input/output files
0N/A
0N/A // Build the File Buffer, Parse the input, & Generate Code
0N/A FileBuff ADL_Buf(&AD._ADL_file, AD); // Create a file buffer for input file
0N/A
0N/A // Get pointer to legal text at the beginning of AD file.
0N/A // It will be used in generated ad files.
0N/A char* legal_text;
0N/A int legal_sz = get_legal_text(ADL_Buf, &legal_text);
0N/A
0N/A ADL_Parse = new ADLParser(ADL_Buf, AD); // Create a parser to parse the buffer
0N/A ADL_Parse->parse(); // Parse buffer & build description lists
0N/A
0N/A if( AD._dfa_debug >= 1 ) { // For higher debug settings, print dump
0N/A AD.dump();
0N/A }
0N/A
0N/A delete ADL_Parse; // Delete parser
0N/A
0N/A // Verify that the results of the parse are consistent
0N/A AD.verify();
0N/A
0N/A // Prepare to generate the result files:
0N/A AD.generateMatchLists();
0N/A AD.identify_unique_operands();
0N/A AD.identify_cisc_spill_instructions();
0N/A AD.identify_short_branches();
0N/A // Make sure every file starts with a copyright:
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._HPP_file._fp); // .hpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_CLONE_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_EXPAND_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_FORMAT_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_GEN_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_MISC_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PEEPHOLE_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._CPP_PIPELINE_file._fp); // .cpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._VM_file._fp); // .hpp
0N/A AD.addSunCopyright(legal_text, legal_sz, AD._DFA_file._fp); // .cpp
1879N/A // Add include guards for all .hpp files
1879N/A AD.addIncludeGuardStart(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
1879N/A AD.addIncludeGuardStart(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
1879N/A // Add includes
1879N/A AD.addInclude(AD._CPP_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._VM_file._name));
1879N/A AD.addInclude(AD._CPP_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_file, "memory/allocation.inline.hpp");
1879N/A AD.addInclude(AD._CPP_file, "asm/assembler.hpp");
1879N/A AD.addInclude(AD._CPP_file, "code/vmreg.hpp");
1879N/A AD.addInclude(AD._CPP_file, "gc_interface/collectedHeap.inline.hpp");
1879N/A AD.addInclude(AD._CPP_file, "oops/compiledICHolderOop.hpp");
1879N/A AD.addInclude(AD._CPP_file, "oops/markOop.hpp");
1879N/A AD.addInclude(AD._CPP_file, "oops/methodOop.hpp");
1879N/A AD.addInclude(AD._CPP_file, "oops/oop.inline.hpp");
1879N/A AD.addInclude(AD._CPP_file, "oops/oop.inline2.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/cfgnode.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/locknode.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/opcodes.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/regalloc.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/regmask.hpp");
1879N/A AD.addInclude(AD._CPP_file, "opto/runtime.hpp");
1879N/A AD.addInclude(AD._CPP_file, "runtime/biasedLocking.hpp");
1879N/A AD.addInclude(AD._CPP_file, "runtime/sharedRuntime.hpp");
1879N/A AD.addInclude(AD._CPP_file, "runtime/stubRoutines.hpp");
1879N/A AD.addInclude(AD._CPP_file, "utilities/growableArray.hpp");
1879N/A#ifdef TARGET_ARCH_x86
1879N/A AD.addInclude(AD._CPP_file, "assembler_x86.inline.hpp");
1879N/A AD.addInclude(AD._CPP_file, "nativeInst_x86.hpp");
1879N/A AD.addInclude(AD._CPP_file, "vmreg_x86.inline.hpp");
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_sparc
1879N/A AD.addInclude(AD._CPP_file, "assembler_sparc.inline.hpp");
1879N/A AD.addInclude(AD._CPP_file, "nativeInst_sparc.hpp");
1879N/A AD.addInclude(AD._CPP_file, "vmreg_sparc.inline.hpp");
1879N/A#endif
2248N/A#ifdef TARGET_ARCH_arm
2248N/A AD.addInclude(AD._CPP_file, "assembler_arm.inline.hpp");
2248N/A AD.addInclude(AD._CPP_file, "nativeInst_arm.hpp");
2248N/A AD.addInclude(AD._CPP_file, "vmreg_arm.inline.hpp");
2248N/A#endif
1879N/A AD.addInclude(AD._HPP_file, "memory/allocation.hpp");
1879N/A AD.addInclude(AD._HPP_file, "opto/machnode.hpp");
1879N/A AD.addInclude(AD._HPP_file, "opto/node.hpp");
1879N/A AD.addInclude(AD._HPP_file, "opto/regalloc.hpp");
1879N/A AD.addInclude(AD._HPP_file, "opto/subnode.hpp");
3845N/A AD.addInclude(AD._HPP_file, "opto/vectornode.hpp");
1879N/A AD.addInclude(AD._CPP_CLONE_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_CLONE_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_EXPAND_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_EXPAND_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_FORMAT_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_FORMAT_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_GEN_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_GEN_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_GEN_file, "opto/cfgnode.hpp");
1879N/A AD.addInclude(AD._CPP_GEN_file, "opto/locknode.hpp");
1879N/A AD.addInclude(AD._CPP_MISC_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_MISC_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_PEEPHOLE_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_PEEPHOLE_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._CPP_PIPELINE_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._CPP_PIPELINE_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._DFA_file, "precompiled.hpp");
1879N/A AD.addInclude(AD._DFA_file, "adfiles", get_basename(AD._HPP_file._name));
1879N/A AD.addInclude(AD._DFA_file, "opto/matcher.hpp");
1879N/A AD.addInclude(AD._DFA_file, "opto/opcodes.hpp");
0N/A // Make sure each .cpp file starts with include lines:
0N/A // files declaring and defining generators for Mach* Objects (hpp,cpp)
0N/A // Generate the result files:
0N/A // enumerations, class definitions, object generators, and the DFA
0N/A // file containing enumeration of machine operands & instructions (hpp)
0N/A AD.addPreHeaderBlocks(AD._HPP_file._fp); // .hpp
0N/A AD.buildMachOperEnum(AD._HPP_file._fp); // .hpp
0N/A AD.buildMachOpcodesEnum(AD._HPP_file._fp); // .hpp
0N/A AD.buildMachRegisterNumbers(AD._VM_file._fp); // VM file
0N/A AD.buildMachRegisterEncodes(AD._HPP_file._fp); // .hpp file
0N/A AD.declareRegSizes(AD._HPP_file._fp); // .hpp
0N/A AD.build_pipeline_enums(AD._HPP_file._fp); // .hpp
0N/A // output definition of class "State"
0N/A AD.defineStateClass(AD._HPP_file._fp); // .hpp
0N/A // file declaring the Mach* classes derived from MachOper and MachNode
0N/A AD.declareClasses(AD._HPP_file._fp);
0N/A // declare and define maps: in the .hpp and .cpp files respectively
0N/A AD.addSourceBlocks(AD._CPP_file._fp); // .cpp
0N/A AD.addHeaderBlocks(AD._HPP_file._fp); // .hpp
0N/A AD.buildReduceMaps(AD._HPP_file._fp, AD._CPP_file._fp);
0N/A AD.buildMustCloneMap(AD._HPP_file._fp, AD._CPP_file._fp);
0N/A // build CISC_spilling oracle and MachNode::cisc_spill() methods
0N/A AD.build_cisc_spill_instructions(AD._HPP_file._fp, AD._CPP_file._fp);
0N/A // define methods for machine dependent State, MachOper, and MachNode classes
0N/A AD.defineClasses(AD._CPP_file._fp);
0N/A AD.buildMachOperGenerator(AD._CPP_GEN_file._fp);// .cpp
0N/A AD.buildMachNodeGenerator(AD._CPP_GEN_file._fp);// .cpp
0N/A // define methods for machine dependent instruction matching
0N/A AD.buildInstructMatchCheck(AD._CPP_file._fp); // .cpp
0N/A // define methods for machine dependent frame management
0N/A AD.buildFrameMethods(AD._CPP_file._fp); // .cpp
0N/A
0N/A // do this last:
0N/A AD.addPreprocessorChecks(AD._CPP_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_CLONE_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_EXPAND_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_FORMAT_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_GEN_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_MISC_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_PEEPHOLE_file._fp); // .cpp
0N/A AD.addPreprocessorChecks(AD._CPP_PIPELINE_file._fp); // .cpp
0N/A
0N/A // define the finite automata that selects lowest cost production
0N/A AD.buildDFA(AD._DFA_file._fp);
1879N/A // Add include guards for all .hpp files
1879N/A AD.addIncludeGuardEnd(AD._HPP_file, "GENERATED_ADFILES_AD_HPP"); // .hpp
1879N/A AD.addIncludeGuardEnd(AD._VM_file, "GENERATED_ADFILES_ADGLOBALS_HPP"); // .hpp
0N/A
0N/A AD.close_files(0); // Close all input/output files
0N/A
0N/A // Final printout and statistics
0N/A // cout << program;
0N/A
0N/A if( AD._dfa_debug & 2 ) { // For higher debug settings, print timing info
0N/A // Timer t_stop;
0N/A // Timer t_total = t_stop - t_start; // Total running time
0N/A // cerr << "\n---Architecture Description Totals---\n";
0N/A // cerr << ", Total lines: " << TotalLines;
0N/A // float l = TotalLines;
0N/A // cerr << "\nTotal Compilation Time: " << t_total << "\n";
0N/A // float ft = (float)t_total;
0N/A // if( ft > 0.0 ) fprintf(stderr,"Lines/sec: %#5.2f\n", l/ft);
0N/A }
0N/A return (AD._syntax_errs + AD._semantic_errs + AD._internal_errs); // Bye Bye!!
0N/A}
0N/A
0N/A//------------------------------usage------------------------------------------
0N/Astatic void usage(ArchDesc& AD)
0N/A{
0N/A printf("Architecture Description Language Compiler\n\n");
4033N/A 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");
0N/A printf(" d produce DFA debugging info\n");
0N/A printf(" o no output produced, syntax and semantic checking only\n");
0N/A printf(" q quiet mode, supresses all non-essential messages\n");
0N/A printf(" w suppress warning messages\n");
4033N/A printf(" T make DFA as many subroutine calls\n");
4033N/A printf(" s output which instructions are cisc-spillable\n");
4033N/A printf(" D define preprocessor symbol\n");
4033N/A printf(" U undefine preprocessor symbol\n");
0N/A printf(" c specify CPP file name (default: %s)\n", AD._CPP_file._name);
0N/A printf(" h specify HPP file name (default: %s)\n", AD._HPP_file._name);
0N/A printf(" a specify DFA output file name\n");
4033N/A printf(" v specify adGlobals output file name\n");
4033N/A printf(" # increment ADL debug level\n");
0N/A printf("\n");
0N/A}
0N/A
0N/A//------------------------------open_file------------------------------------
0N/Aint ArchDesc::open_file(bool required, ADLFILE & ADF, const char *action)
0N/A{
0N/A if (required &&
0N/A (ADF._fp = fopen(ADF._name, action)) == NULL) {
0N/A printf("ERROR: Cannot open file for %s: %s\n", action, ADF._name);
0N/A close_files(1);
0N/A return 0;
0N/A }
0N/A return 1;
0N/A}
0N/A
0N/A//------------------------------open_files-------------------------------------
0N/Aint ArchDesc::open_files(void)
0N/A{
0N/A if (_ADL_file._name == NULL)
0N/A { printf("ERROR: No ADL input file specified\n"); return 0; }
0N/A
0N/A if (!open_file(true , _ADL_file, "r")) { return 0; }
0N/A if (!open_file(!_no_output, _DFA_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _HPP_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_CLONE_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_EXPAND_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_FORMAT_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_GEN_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_MISC_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_PEEPHOLE_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _CPP_PIPELINE_file, "w")) { return 0; }
0N/A if (!open_file(!_no_output, _VM_file , "w")) { return 0; }
0N/A if (!open_file(_dfa_debug != 0, _bug_file, "w")) { return 0; }
0N/A
0N/A return 1;
0N/A}
0N/A
0N/A//------------------------------close_file------------------------------------
0N/Avoid ArchDesc::close_file(int delete_out, ADLFILE& ADF)
0N/A{
0N/A if (ADF._fp) {
0N/A fclose(ADF._fp);
0N/A if (delete_out) remove(ADF._name);
0N/A }
0N/A}
0N/A
0N/A//------------------------------close_files------------------------------------
0N/Avoid ArchDesc::close_files(int delete_out)
0N/A{
0N/A if (_ADL_file._fp) fclose(_ADL_file._fp);
0N/A
0N/A close_file(delete_out, _CPP_file);
0N/A close_file(delete_out, _CPP_CLONE_file);
0N/A close_file(delete_out, _CPP_EXPAND_file);
0N/A close_file(delete_out, _CPP_FORMAT_file);
0N/A close_file(delete_out, _CPP_GEN_file);
0N/A close_file(delete_out, _CPP_MISC_file);
0N/A close_file(delete_out, _CPP_PEEPHOLE_file);
0N/A close_file(delete_out, _CPP_PIPELINE_file);
0N/A close_file(delete_out, _HPP_file);
0N/A close_file(delete_out, _DFA_file);
0N/A close_file(delete_out, _bug_file);
0N/A
0N/A if (!_quiet_mode) {
0N/A printf("\n");
0N/A if (_no_output || delete_out) {
0N/A if (_ADL_file._name) printf("%s: ", _ADL_file._name);
0N/A printf("No output produced");
0N/A }
0N/A else {
0N/A if (_ADL_file._name) printf("%s --> ", _ADL_file._name);
603N/A printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
0N/A _CPP_file._name,
0N/A _CPP_CLONE_file._name,
0N/A _CPP_EXPAND_file._name,
0N/A _CPP_FORMAT_file._name,
0N/A _CPP_GEN_file._name,
0N/A _CPP_MISC_file._name,
0N/A _CPP_PEEPHOLE_file._name,
0N/A _CPP_PIPELINE_file._name,
603N/A _HPP_file._name,
603N/A _DFA_file._name);
0N/A }
0N/A printf("\n");
0N/A }
0N/A}
0N/A
0N/A//------------------------------strip_ext--------------------------------------
0N/Astatic char *strip_ext(char *fname)
0N/A{
0N/A char *ep;
0N/A
0N/A if (fname) {
0N/A ep = fname + strlen(fname) - 1; // start at last character and look for '.'
0N/A while (ep >= fname && *ep != '.') --ep;
0N/A if (*ep == '.') *ep = '\0'; // truncate string at '.'
0N/A }
0N/A return fname;
0N/A}
0N/A
0N/A//------------------------------base_plus_suffix-------------------------------
0N/A// New concatenated string
0N/Astatic char *base_plus_suffix(const char* base, const char *suffix)
0N/A{
0N/A int len = (int)strlen(base) + (int)strlen(suffix) + 1;
0N/A
0N/A char* fname = new char[len];
0N/A sprintf(fname,"%s%s",base,suffix);
0N/A return fname;
0N/A}
0N/A
0N/A//------------------------------get_legal_text---------------------------------
0N/A// Get pointer to legal text at the beginning of AD file.
0N/A// This code assumes that a legal text starts at the beginning of .ad files,
0N/A// is commented by "//" at each line and ends with empty line.
0N/A//
0N/Aint get_legal_text(FileBuff &fbuf, char **legal_text)
0N/A{
0N/A char* legal_start = fbuf.get_line();
0N/A assert(legal_start[0] == '/' && legal_start[1] == '/', "Incorrect header of AD file");
0N/A char* legal_end = fbuf.get_line();
0N/A assert(strncmp(legal_end, "// Copyright", 12) == 0, "Incorrect header of AD file");
0N/A while(legal_end[0] == '/' && legal_end[1] == '/') {
0N/A legal_end = fbuf.get_line();
0N/A }
0N/A *legal_text = legal_start;
603N/A return (int) (legal_end - legal_start);
0N/A}
0N/A
0N/A// VS2005 has its own definition, identical to this one.
0N/A#if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400
0N/Avoid *operator new( size_t size, int, const char *, int ) {
0N/A return ::operator new( size );
0N/A}
0N/A#endif