* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / bmcs / gen-il.cs
1 // gen-il.cs: Generates MSIL code from the CIR.Tree
2 //
3 // Author: Miguel de Icaza (miguel@ximian.com)
4 //
5 // Licensed under the terms of the GNU GPL
6 //
7 // (C) 2001 Ximian, Inc. (http://www.ximian.com)
8 //
9
10 using System;
11 using System.IO;
12 using System.Collections;
13 using CIR;
14
15 namespace MSIL {
16
17         public class Generator : CIR.ITreeDump {
18                 StreamWriter o;
19                 int indent = 0;
20                 
21                 void output (string s)
22                 {
23                         Console.Write (s);
24                         o.Write (s);
25                 }
26
27                 void space ()
28                 {
29                         output (new String (' ', indent * 2));
30                 }
31
32                 void ioutput (string s)
33                 {
34                         space ();
35                         output (s);
36                 }
37
38                 void ioutputl (string s)
39                 {
40                         ioutput (s + "\n");
41                 }
42
43                 string ClassAttributes (Class c)
44                 {
45                         // FIXME
46                         return "";
47                 }
48
49                 string ILName (string name)
50                 {
51                         return name;
52                 }
53
54                 string ClassExtends (Class c)
55                 {
56                         return "";
57                 }
58                 
59                 void GenerateFromClass (Class c)
60                 {
61                         ioutputl (".class " + ClassAttributes (c) + " " + ILName (c.Name));
62                         ioutputl (ClassExtends (c));
63                         ioutputl ("{");
64                         indent++;
65
66                         
67
68                         indent--;
69                         ioutputl ("}");
70                 }
71                 
72                 void GenerateFromTypes (TypeContainer types)
73                 {
74                         if (types.Types == null)
75                                 return;
76                         
77                         foreach (DictionaryEntry de in types.Types){
78                                 TypeContainer type = (TypeContainer) de.Value;
79                                 
80                                 if (type is Class)
81                                         GenerateFromClass ((Class) type);
82                         }
83                         
84                 }
85                 
86                 public int GenerateFromTree (Tree tree, StreamWriter os)
87                 {
88                         this.o = os;
89
90                         ioutputl (".assembly test.exe { }");
91                         GenerateFromTypes (tree.Types);
92                         return 0;
93                 }
94
95                 public void ParseOptions (string options)
96                 {
97                 }
98                 
99         }
100 }