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 / p11 / Main.java < prev    next >
Text File  |  2006-03-01  |  3KB  |  91 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.     static Emit emit = null;             // The target code generator
  28.  
  29.  
  30.     //
  31.     // Main ()
  32.     //
  33.     // Create a parser, parse a PCAT source file, and print the AST.
  34.     //
  35.     public static void main (String [] args) {
  36.         try {
  37.  
  38.             // Parse the source...
  39.             System.err.println ("Parsing Source Code...");
  40.             parser = new Parser (args);
  41.             ast = parser.parseProgram ();
  42.  
  43.             // Check the AST...
  44.             System.err.println ("Semantic Error Checking...");
  45.             checker = new Checker ();
  46.             checker.checkAst (ast);
  47.  
  48.             // Print the AST, using printAst...
  49.             // PrintAst.printAst (ast);
  50.  
  51.             // Pretty-print the AST...
  52.             // PrettyPrint.prettyPrintAst (ast);
  53.  
  54.             if (errorCount == 0) {
  55.  
  56.                 // Generate the Intermediate Representation (IR)...
  57.                 generator = new Generator ();
  58.                 System.err.println ("Generating Intermediate Code...");
  59.                 generator.generateIR (ast);
  60.  
  61.                 // Perform the peephole optimizations...
  62.                 peephole = new Peephole ();
  63.                 System.err.println ("Performing Peephole Optimizations...");
  64.                 peephole.optimize ();
  65.  
  66.                 // Print out results...
  67.                 // IR.printOffsets (ast);
  68.                 // IR.printIR ();
  69.  
  70.                 // Generate the target code...
  71.                 emit = new Emit ();
  72.                 System.err.println ("Producing Target Code...");
  73.                 emit.emitAll ();
  74.  
  75.             }
  76.  
  77.         } catch (LogicError e) {
  78.             e.printStackTrace ();
  79.         } catch (FatalError e) {
  80.             if (e.getMessage () != null) {
  81.                 System.err.println (e.getMessage ());
  82.             }
  83.         }
  84.         if (errorCount > 0) {
  85.             System.err.println (errorCount + " error(s) were detected!");
  86.             System.exit (1);
  87.         }
  88.     }
  89.  
  90. }
  91.