**** Merged from MCS ****
[mono-project.git] / mcs / mcs / gen-il.cs
blob2dfeecc974c1e684326577139ef0c7504f360254
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 //
10 using System;
11 using System.IO;
12 using System.Collections;
13 using CIR;
15 namespace MSIL {
17 public class Generator : CIR.ITreeDump {
18 StreamWriter o;
19 int indent = 0;
21 void output (string s)
23 Console.Write (s);
24 o.Write (s);
27 void space ()
29 output (new String (' ', indent * 2));
32 void ioutput (string s)
34 space ();
35 output (s);
38 void ioutputl (string s)
40 ioutput (s + "\n");
43 string ClassAttributes (Class c)
45 // FIXME
46 return "";
49 string ILName (string name)
51 return name;
54 string ClassExtends (Class c)
56 return "";
59 void GenerateFromClass (Class c)
61 ioutputl (".class " + ClassAttributes (c) + " " + ILName (c.Name));
62 ioutputl (ClassExtends (c));
63 ioutputl ("{");
64 indent++;
68 indent--;
69 ioutputl ("}");
72 void GenerateFromTypes (TypeContainer types)
74 if (types.Types == null)
75 return;
77 foreach (DictionaryEntry de in types.Types){
78 TypeContainer type = (TypeContainer) de.Value;
80 if (type is Class)
81 GenerateFromClass ((Class) type);
86 public int GenerateFromTree (Tree tree, StreamWriter os)
88 this.o = os;
90 ioutputl (".assembly test.exe { }");
91 GenerateFromTypes (tree.Types);
92 return 0;
95 public void ParseOptions (string options)