9e54be7dae5eeec7be72eb9bd7c2593d6ec18c41
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / driver.cs
1 //
2 // driver.cs: Guides the compilation process through the different phases.
3 //
4 // Author: 
5 //      Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
8 //
9
10 namespace Microsoft.JScript.Tmp
11 {
12         using System;
13         using System.IO;
14         using System.Collections;
15         using System.Reflection.Emit;
16         using System.Reflection;
17         using System.Runtime.CompilerServices;
18
19         public class Jsc 
20         {
21                 string filename;
22                 string assemblyName;
23                 ASTList program;
24                 SemanticAnaliser semAnalizer;
25                 CodeGenerator codeGen;
26
27                 public Jsc (string filename)
28                 {
29                         this.filename = filename;
30                         this.assemblyName = Path.GetFileNameWithoutExtension (filename);
31
32                         program = new ASTList ();
33                 }
34
35
36                 public void Run ()
37                 {
38                         this.GetAST (filename);
39                         Console.WriteLine (this.program.ToString ());
40                         // this.SemanticAnalysis ();
41                         this.GenerateCode ();
42
43                         this.codeGen.assemblyBuilder.Save (assemblyName + ".exe");
44                 }
45
46                         
47                 public void GenerateCode ()
48                 {
49                         this.codeGen = new CodeGenerator (assemblyName,
50                                                           AssemblyBuilderAccess.RunAndSave);
51
52                         this.codeGen.EmitJScript0 (this.program);
53                         this.codeGen.EmitJScriptMain ();                        
54                 }
55
56
57                 public void GetAST (string filename)
58                 {
59                         StreamReader reader = new StreamReader (filename);
60                         JScriptLexer lexer = new JScriptLexer (reader);
61                         JScriptParser parser = new JScriptParser (lexer);
62
63                         parser.program (program);
64                 }
65
66
67                 public static void Main (string [] args)
68                 {
69                         try {                   
70                                 Jsc compiler = new Jsc (args [0]);
71
72                                 compiler.Run ();
73                                 Console.WriteLine (compiler.program.ToString ());
74
75                         } catch (IndexOutOfRangeException) {
76                                 Console.WriteLine ("Usage: [mono] mjs.exe filename.js");
77                         }
78                 }
79         }
80 }