DEADSOFTWARE

Mirror gpcp-32255
[gpcp-linux.git] / gpcp / csharp / MsilAsm.cs
1 // (* ========================================================= *)
2 // (** Interface to the ILASM Byte-code assembler. *)
3 // (* K John Gough, 10th June 1999 *)
4 // (* Modifications: *)
5 // (* Version for GPCP V0.3 April 2000 (kjg) *)
6 // (* ========================================================= *)
7 // (* The real code is in MsilAsm.cs *)
8 // (* ========================================================= *)
9 //
10 //MODULE MsilAsm;
11 //
12 // PROCEDURE Init*(); BEGIN END Init;
13 //
14 // PROCEDURE Assemble*(IN fil, opt : ARRAY OF CHAR; main : BOOLEAN);
15 // BEGIN END Assemble;
16 //
17 //END MsilAsm.
18 //
19 //
20 // NOTE: this needs (as at 13-Jun-2000) to be compiled using
21 //
22 // $ csc /t:library /r:System.Diagnostics.dll /r:RTS.dll MsilAsm.cs
23 //
24 // NOTE: for Beta2 this finds System.Diagnostics in mscorlib.dll
25 //
26 // $ csc /t:library /r:RTS.dll MsilAsm.cs
27 //
28 #if !BETA1
29 #define BETA2
30 #endif
32 using System.Diagnostics;
34 namespace MsilAsm {
36 public class MsilAsm {
38 private static Process asm = null;
41 public static string GetDotNetRuntimeInstallDirectory()
42 {
43 // Get the path to mscorlib.dll
44 string s = typeof(object).Module.FullyQualifiedName;
46 // Remove the file part to get the directory
47 return System.IO.Directory.GetParent(s).ToString() + "\\";
48 }
50 public static void Init() {
51 if (asm == null) {
52 asm = new Process();
53 asm.StartInfo.FileName = GetDotNetRuntimeInstallDirectory() + "ilasm";
54 #if BETA1
55 asm.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
56 #else //BETA2
57 asm.StartInfo.CreateNoWindow = true;
58 asm.StartInfo.UseShellExecute = false;
59 #endif
60 }
61 }
63 public static void Assemble(char[] fil, char[] opt, bool hasMain) {
64 int retCode;
65 System.String optNm;
66 System.String suffx;
67 System.String fName = CP_rts.mkStr(fil);
68 if (hasMain) {
69 optNm ="/exe ";
70 suffx = ".exe";
71 } else {
72 optNm = "/dll ";
73 suffx = ".dll";
74 }
75 optNm = optNm + CP_rts.mkStr(opt) + ' ';
76 asm.StartInfo.Arguments = optNm + "/nologo /quiet " + fName + ".il";
77 asm.Start();
78 asm.WaitForExit();
79 retCode = asm.ExitCode;
80 if (retCode != 0)
81 System.Console.WriteLine("#gpcp: ilasm FAILED " + retCode);
82 else
83 System.Console.WriteLine("#gpcp: created " + fName + suffx);
84 }
86 public static void DoAsm(char[] fil, char[] opt,
87 bool hasMain,
88 bool verbose,
89 ref int rslt) {
90 System.String optNm;
91 System.String suffx;
92 System.String fName = CP_rts.mkStr(fil);
93 if (hasMain) {
94 optNm ="/exe ";
95 suffx = ".exe";
96 } else {
97 optNm = "/dll ";
98 suffx = ".dll";
99 }
100 optNm = optNm + CP_rts.mkStr(opt) + ' ';
101 if (verbose) {
102 System.Console.WriteLine("#gpcp: Calling " + asm.StartInfo.FileName);
103 #if BETA2
104 asm.StartInfo.CreateNoWindow = false;
105 #endif
106 asm.StartInfo.Arguments = optNm + "/nologo " + fName + ".il";
107 } else {
108 #if BETA2
109 asm.StartInfo.CreateNoWindow = true;
110 #endif
111 asm.StartInfo.Arguments = optNm + "/nologo /quiet " + fName + ".il";
113 asm.Start();
114 asm.WaitForExit();
115 rslt = asm.ExitCode;
116 if (rslt == 0)
117 System.Console.WriteLine("#gpcp: Created " + fName + suffx);
121 public static void Assemble(char[] fil, bool hasMain) {
122 char[] opt = {'/', 'd', 'e', 'b', 'u', 'g', '\0' };
123 Assemble(fil, opt, hasMain);