main.cpp revision 1879
3909N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 3551N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3551N/A * This code is free software; you can redistribute it and/or modify it 3551N/A * under the terms of the GNU General Public License version 2 only, as 3551N/A * published by the Free Software Foundation. 3551N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3551N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3551N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3551N/A * version 2 for more details (a copy is included in the LICENSE file that 3551N/A * You should have received a copy of the GNU General Public License version 3551N/A * 2 along with this work; if not, write to the Free Software Foundation, 3551N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3551N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1045N/A// MAIN.CPP - Entry point for the Architecture Description Language Compiler 1045N/A//------------------------------Prototypes------------------------------------- 1045N/A//------------------------------main------------------------------------------- 1045N/A // Check for proper arguments 1045N/A // Read command line arguments and file names 1045N/A for(
int i =
1; i <
argc; i++ ) {
// For all arguments 1045N/A if( *s++ ==
'-' ) {
// It's a flag? (not a filename) 1045N/A if( !*s ) {
// Stand-alone `-' means stdin 1045N/A //********** INSERT CODE HERE ********** 1045N/A }
else while (*s !=
'\0') {
// While have flags on option 1045N/A switch (*s++) {
// Handle flag 1045N/A case 'g':
// Debug ad location flag 1045N/A case 'o':
// No Output Flag 1045N/A case 'q':
// Quiet Mode Flag 1045N/A case 'w':
// Disable Warnings Flag 1045N/A case 'T':
// Option to make DFA as many subroutine calls. 1045N/A case 'c': {
// Set C++ Output file name 1045N/A case 'h':
// Set C++ Output file name 1045N/A case 'v':
// Set C++ Output file name 1045N/A case 'a':
// Set C++ Output file name 1045N/A case '#':
// Special internal debug flag 1045N/A case 's':
// Output which instructions are cisc-spillable 1045N/A case 'D':
// Flag Definition 1045N/A case 'U':
// Flag Un-Definition 1045N/A }
// End of switch on options... 1045N/A }
// End of while have options... 1045N/A }
else {
// Not an option; must be a filename 1045N/A // // Files for storage, based on input file name 1045N/A }
// End of files vs options... 1045N/A }
// End of while have command line arguments 1045N/A // Open files used to store the matcher and its components 1045N/A // Build the File Buffer, Parse the input, & Generate Code 1045N/A // Get pointer to legal text at the beginning of AD file. 1045N/A // It will be used in generated ad files. 1045N/A // Verify that the results of the parse are consistent 1045N/A // Prepare to generate the result files: 1045N/A // Make sure every file starts with a copyright: 1045N/A // Add include guards for all .hpp files 1045N/A // Make sure each .cpp file starts with include lines: 1045N/A // files declaring and defining generators for Mach* Objects (hpp,cpp) 1045N/A // Generate the result files: 1045N/A // enumerations, class definitions, object generators, and the DFA 1045N/A // file containing enumeration of machine operands & instructions (hpp) 1045N/A // output definition of class "State" 1045N/A // file declaring the Mach* classes derived from MachOper and MachNode 1045N/A // declare and define maps: in the .hpp and .cpp files respectively 1045N/A // build CISC_spilling oracle and MachNode::cisc_spill() methods 1045N/A // define methods for machine dependent State, MachOper, and MachNode classes 1045N/A // define methods for machine dependent instruction matching 1045N/A // define methods for machine dependent frame management 1045N/A // define the finite automata that selects lowest cost production 1045N/A // Add include guards for all .hpp files 1045N/A // Final printout and statistics 1045N/A // Timer t_total = t_stop - t_start; // Total running time 1045N/A // cerr << "\n---Architecture Description Totals---\n"; 1045N/A // cerr << ", Total lines: " << TotalLines; 1045N/A // cerr << "\nTotal Compilation Time: " << t_total << "\n"; 1045N/A // float ft = (float)t_total; 1045N/A//------------------------------usage------------------------------------------ 1045N/A printf(
"Architecture Description Language Compiler\n\n");
1045N/A printf(
"Usage: adl [-doqw] [-Dflag[=def]] [-Uflag] [-cFILENAME] [-hFILENAME] [-aDFAFILE] ADLFILE\n");
1045N/A printf(
" o no output produced, syntax and semantic checking only\n");
1045N/A printf(
" q quiet mode, supresses all non-essential messages\n");
1045N/A//------------------------------open_file------------------------------------ 1045N/A//------------------------------open_files------------------------------------- 1045N/A {
printf(
"ERROR: No ADL input file specified\n");
return 0; }
1045N/A//------------------------------close_file------------------------------------ 1045N/A//------------------------------close_files------------------------------------ 1045N/A printf(
"%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
1045N/A//------------------------------strip_ext-------------------------------------- 1045N/A if (*
ep ==
'.') *
ep =
'\0';
// truncate string at '.' 1045N/A//------------------------------strip_path_and_ext------------------------------ 1045N/A if (*
ep ==
'.') *
ep =
'\0';
// truncate string at '.' 1045N/A//------------------------------base_plus_suffix------------------------------- 1045N/A//------------------------------prefix_plus_base_plus_suffix------------------- 1045N/A//------------------------------get_legal_text--------------------------------- 1045N/A// Get pointer to legal text at the beginning of AD file. 1045N/A// This code assumes that a legal text starts at the beginning of .ad files, 1045N/A// is commented by "//" at each line and ends with empty line. 1045N/A// VS2005 has its own definition, identical to this one.