* MethodDef.cs: Accept and emit instructions.
authorJackson Harper <jackson@novell.com>
Thu, 1 May 2003 05:09:15 +0000 (05:09 -0000)
committerJackson Harper <jackson@novell.com>
Thu, 1 May 2003 05:09:15 +0000 (05:09 -0000)
* CodeGen.cs: Fix typo
* IInstr.cs: New file - Interface for instructions that are added to methods
* IntInstr.cs: New file - Instruction that takes a single int
param
* LdstrInstr.cs: New file - ldstr instruction (the only
instruction that takes a string parameter)

svn path=/trunk/mcs/; revision=14173

mcs/ilasm/codegen/ChangeLog
mcs/ilasm/codegen/CodeGen.cs
mcs/ilasm/codegen/IInstr.cs [new file with mode: 0644]
mcs/ilasm/codegen/IntInstr.cs [new file with mode: 0644]
mcs/ilasm/codegen/LdstrInstr.cs [new file with mode: 0644]
mcs/ilasm/codegen/MethodDef.cs

index 3f797df2f49664c0942843fbdee927b44077b08f..4df9a213a10250233f67ea2344729460bfd1d667 100644 (file)
@@ -1,3 +1,13 @@
+2003-04-30 Jackson Harper <jackson@latitudegeo.com>
+
+       * MethodDef.cs: Accept and emit instructions.
+       * CodeGen.cs: Fix typo
+       * IInstr.cs: New file - Interface for instructions that are added to methods
+       * IntInstr.cs: New file - Instruction that takes a single int
+       param
+       * LdstrInstr.cs: New file - ldstr instruction (the only
+       instruction that takes a string parameter)
+               
 2003-04-28 Jackson Harper <jackson@latitudegeo.com>
 
        * InstrTable.cs: Much simpler system. All tokens go into one
index 5038ce186523e2029f36b77623a5aa1e54eb7088..50882ee58ca97813302723c610c36415424aa2c4 100644 (file)
@@ -56,7 +56,7 @@ namespace Mono.ILASM {
                         get { return current_typedef; }\r
                 }\r
 \r
-                public MethodDef CurrentMethoDef {\r
+                public MethodDef CurrentMethodDef {\r
                         get { return current_methoddef; }\r
                 }\r
 \r
diff --git a/mcs/ilasm/codegen/IInstr.cs b/mcs/ilasm/codegen/IInstr.cs
new file mode 100644 (file)
index 0000000..0c87310
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// Mono.ILASM.IInstr
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+namespace Mono.ILASM {
+
+        public interface IInstr {
+
+                /// <summary>
+                ///  Add this instruction to the supplied codebuffer
+                /// </summary>
+                void Emit (CodeGen code_gen, PEAPI.CILInstructions cil);
+        }
+
+}
+
diff --git a/mcs/ilasm/codegen/IntInstr.cs b/mcs/ilasm/codegen/IntInstr.cs
new file mode 100644 (file)
index 0000000..f9aadbc
--- /dev/null
@@ -0,0 +1,34 @@
+//
+// Mono.ILASM.IntInstr
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+namespace Mono.ILASM {
+
+        public class IntInstr : IInstr {
+
+                private PEAPI.IntOp op;
+                private int operand;
+
+                public IntInstr (PEAPI.IntOp op, int operand)
+                {
+                        this.op = op;
+                        this.operand = operand;
+                }
+
+                public void Emit (CodeGen code_gen, PEAPI.CILInstructions cil)
+                {
+                        cil.IntInst (op, operand);
+                }
+
+        }
+
+}
+
diff --git a/mcs/ilasm/codegen/LdstrInstr.cs b/mcs/ilasm/codegen/LdstrInstr.cs
new file mode 100644 (file)
index 0000000..191dad2
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// Mono.ILASM.LdstrInstr
+//
+// Author(s):
+//  Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+namespace Mono.ILASM {
+
+        public class LdstrInstr : IInstr {
+
+                private string operand;
+
+                public LdstrInstr (string operand)
+                {
+                        this.operand = operand;
+                }
+
+                public void Emit (CodeGen code_gen, PEAPI.CILInstructions cil)
+                {
+                        cil.ldstr (operand);
+                }
+
+        }
+
+}
+
index 100c32c9092501debe802ee114e0f5780577fddc..41f695b0d731264fd25e1036f5aa58d279023251 100644 (file)
@@ -23,6 +23,7 @@ namespace Mono.ILASM {
                 private string signature;
                 private ITypeRef ret_type;
                 private ArrayList param_list;
+                private ArrayList inst_list;
                 private PEAPI.MethodDef methoddef;
                 private bool is_defined;
 
@@ -35,6 +36,7 @@ namespace Mono.ILASM {
                         this.ret_type = ret_type;
                         this.param_list = param_list;
 
+                        inst_list = new ArrayList ();
                         is_defined = false;
                         CreateSignature ();
                 }
@@ -93,9 +95,20 @@ namespace Mono.ILASM {
                         methoddef = classdef.AddMethod (meth_attr, impl_attr,
                                         name, ret_type.PeapiType, param_array);
 
+                        if (inst_list.Count > 0) {
+                                PEAPI.CILInstructions cil = methoddef.CreateCodeBuffer ();
+                                foreach (IInstr instr in inst_list)
+                                        instr.Emit (code_gen, cil);
+                        }
+
                         is_defined = true;
                 }
 
+                public void AddInstr (IInstr instr)
+                {
+                        inst_list.Add (instr);
+                }
+
                 private void CreateSignature ()
                 {
                         StringBuilder builder = new StringBuilder ();