main.cpp revision 4033
1505N/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 * 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 * 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 * 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// MAIN.CPP - Entry point for the Architecture Description Language Compiler 0N/A//------------------------------Prototypes------------------------------------- 0N/A//------------------------------main------------------------------------------- 0N/A // ResourceMark mark; 0N/A // Check for proper arguments 0N/A // Read command line arguments and file names 0N/A for(
int i =
1; i <
argc; i++ ) {
// For all arguments 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 105N/A switch (*s++) {
// Handle flag 105N/A case 'd':
// Debug flag 105N/A case 'g':
// Debug ad location flag 0N/A case 'o':
// No Output Flag 0N/A case 'q':
// Quiet Mode Flag 0N/A case 'w':
// Disable Warnings Flag 0N/A case 'T':
// Option to make DFA as many subroutine calls. 0N/A case 'c': {
// Set C++ Output file name 0N/A case 'h':
// Set C++ Output file name 0N/A case 'v':
// Set C++ Output file name 0N/A case 'a':
// Set C++ Output file name 0N/A case '#':
// Special internal debug flag 0N/A case 's':
// Output which instructions are cisc-spillable 0N/A case 'D':
// Flag Definition 0N/A case 'U':
// Flag Un-Definition 0N/A default:
// Unknown option 0N/A }
// End of switch on options... 0N/A }
// End of while have options... 0N/A }
else {
// Not an option; must be a filename 0N/A // // Files for storage, based on input file name 0N/A }
// End of files vs options... 0N/A }
// End of while have command line arguments 29N/A // Open files used to store the matcher and its components 0N/A // Build the File Buffer, Parse the input, & Generate Code 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 // Verify that the results of the parse are consistent 0N/A // Prepare to generate the result files: 0N/A // Make sure every file starts with a copyright: 0N/A // Add include guards for all .hpp files 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 // output definition of class "State" 0N/A // file declaring the Mach* classes derived from MachOper and MachNode 0N/A // declare and define maps: in the .hpp and .cpp files respectively 0N/A // build CISC_spilling oracle and MachNode::cisc_spill() methods 0N/A // define methods for machine dependent State, MachOper, and MachNode classes 0N/A // define methods for machine dependent instruction matching 0N/A // define methods for machine dependent frame management 0N/A // define the finite automata that selects lowest cost production 0N/A // Add include guards for all .hpp files 0N/A // Final printout and statistics 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//------------------------------usage------------------------------------------ 0N/A printf(
"Architecture Description Language Compiler\n\n");
0N/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(
" 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(
" T make DFA as many subroutine calls\n");
0N/A printf(
" s output which instructions are cisc-spillable\n");
0N/A printf(
" v specify adGlobals output file name\n");
0N/A//------------------------------open_file------------------------------------ 0N/A//------------------------------open_files------------------------------------- 0N/A {
printf(
"ERROR: No ADL input file specified\n");
return 0; }
0N/A//------------------------------close_file------------------------------------ 0N/A//------------------------------close_files------------------------------------ 0N/A printf(
"%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
0N/A//------------------------------strip_ext-------------------------------------- 0N/A if (*
ep ==
'.') *
ep =
'\0';
// truncate string at '.' 0N/A//------------------------------base_plus_suffix------------------------------- 0N/A// New concatenated string 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, 605N/A// is commented by "//" at each line and ends with empty line. 0N/A// VS2005 has its own definition, identical to this one.