home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / compilers / p10 / Main.java < prev    next >
Text File  |  2006-02-16  |  3KB  |  85 lines

  1. // --------------------------------  Main  --------------------------------
  2. //
  3. // Compiler Project 8 - PCAT Compiler Main
  4. //
  5. // This class is never instantiated.  It includes the "main" method
  6. // to exercise components of the PCAT compiler.
  7. //
  8. // Harry Porter -- 01/26/03
  9. //                 02/07/03 -- Modified for Project 4
  10. //                 02/12/03 -- Modified for Project 5
  11. //                 04/09/03 -- Modified for Project 8
  12. //
  13.  
  14. import java.io.*;
  15.  
  16. class Main {
  17.  
  18.     //
  19.     // Static Fields
  20.     //
  21.     static int errorCount = 0;           // How many errors, so far
  22.     static Ast.Body ast = null;          // The Abstract Syntax Tree
  23.     static Parser parser = null;         // The parser
  24.     static Checker checker = null;       // The checker
  25.     static Generator generator = null;   // The IR generator
  26.     static Peephole peephole = null;     // The peephole optimizer
  27.  
  28.  
  29.     //
  30.     // Main ()
  31.     //
  32.     // Create a parser, parse a PCAT source file, and print the AST.
  33.     //
  34.     public static void main (String [] args) {
  35.         try {
  36.  
  37.             // Parse the source...
  38.             System.err.println ("Parsing Source Code...");
  39.             parser = new Parser (args);
  40.             ast = parser.parseProgram ();
  41.  
  42.             // Check the AST...
  43.             System.err.println ("Semantic Error Checking...");
  44.             checker = new Checker ();
  45.             checker.checkAst (ast);
  46.  
  47.             // Print the AST, using printAst...
  48.             // PrintAst.printAst (ast);
  49.  
  50.             // Pretty-print the AST...
  51.             PrettyPrint.prettyPrintAst (ast);
  52.  
  53.             if (errorCount == 0) {
  54.  
  55.                 // Generate the Intermediate Representation (IR)...
  56.                 generator = new Generator ();
  57.                 System.err.println ("Generating Intermediate Code...");
  58.                 generator.generateIR (ast);
  59.  
  60.                 // Perform the peephole optimizations...
  61.                 peephole = new Peephole ();
  62.                 System.err.println ("Performing Peephole Optimizations...");
  63.                 peephole.optimize ();
  64.  
  65.                 // Print out results...
  66.                 IR.printOffsets (ast);
  67.                 IR.printIR ();
  68.  
  69.             }
  70.  
  71.         } catch (LogicError e) {
  72.             e.printStackTrace ();
  73.         } catch (FatalError e) {
  74.             if (e.getMessage () != null) {
  75.                 System.err.println (e.getMessage ());
  76.             }
  77.         }
  78.         if (errorCount > 0) {
  79.             System.err.println (errorCount + " error(s) were detected!");
  80.             System.exit (1);
  81.         }
  82.     }
  83.  
  84. }
  85.