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