+2003-05-31 Jackson Harper <jackson@latitudegeo.com>
+
+ * CustomAttr.cs: New file - Custom attributes
+ * InstrTable.cs: Add stelem.r4 and stelem.r8 instructions. Add
+ . tail to unaligned modifier.
+ * LdtokenInstr.cs: Add type tokens.
+ * MethodDef.cs: Fix IsVararg, add method to add custom attributes,
+ emitting custom attributes when writing code, allow for Ellipsises
+ in param lists, add coma between args in signatures.
+ * ParamDef.cs: Add the Ellipsis pseudo param
+ * PrimitiveTypeRef.cs: System.String and System.Object can be
+ referenced without an [mscorlib] assembly prefix.
+ * TypeDef.cs: Add Custom attributes.
+
2003-05-25 Jackson Harper <jackson@latitudegeo.com>
* CodeGen.cs: Add method to resolve global vararg methods.
--- /dev/null
+//
+// Mono.ILASM.CustomAttr
+//
+// Author(s):
+// Jackson Harper (Jackson@LatitudeGeo.com)
+//
+// (C) 2003 Jackson Harper, All rights reserved
+//
+
+
+using System;
+
+
+namespace Mono.ILASM {
+
+ public class CustomAttr {
+
+ private IMethodRef method_ref;
+ private byte[] data;
+
+ public CustomAttr (IMethodRef method_ref, byte[] data)
+ {
+ this.method_ref = method_ref;
+ this.data = data;
+ }
+
+ public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
+ {
+ method_ref.Resolve (code_gen);
+
+ elem.AddCustomAttribute (method_ref.PeapiMethod, data);
+ }
+
+ }
+
+}
+
inst_table["stelem.i2"] = new ILToken (Token.INSTR_NONE, Op.stelem_i2);
inst_table["stelem.i4"] = new ILToken (Token.INSTR_NONE, Op.stelem_i4);
inst_table["stelem.i8"] = new ILToken (Token.INSTR_NONE, Op.stelem_i8);
+ inst_table["stelem.r4"] = new ILToken (Token.INSTR_NONE, Op.stelem_r4);
+ inst_table["stelem.r8"] = new ILToken (Token.INSTR_NONE, Op.stelem_r8);
inst_table["stelem.ref"] = new ILToken (Token.INSTR_NONE, Op.stelem_ref);
inst_table["conv.ovf.i1"] = new ILToken (Token.INSTR_NONE, Op.conv_ovf_i1);
inst_table["conv.ovf.u1"] = new ILToken (Token.INSTR_NONE, Op.conv_ovf_u1);
inst_table["ldc.i4.s"] = new ILToken (Token.INSTR_I, IntOp.ldc_i4_s);
inst_table["ldc.i4"] = new ILToken (Token.INSTR_I, IntOp.ldc_i4);
- inst_table["unaligned"] = new ILToken (Token.INSTR_I, IntOp.unaligned);
+ inst_table["unaligned."] = new ILToken (Token.INSTR_I, IntOp.unaligned);
//
// Type operations
private IFieldRef field_ref;
private IMethodRef method_ref;
+ private ITypeRef type_ref;
public LdtokenInstr (IFieldRef field_ref)
{
this.method_ref = method_ref;
}
+ public LdtokenInstr (ITypeRef type_ref)
+ {
+ this.type_ref = type_ref;
+ }
+
public void Emit (CodeGen code_gen, PEAPI.CILInstructions cil)
{
if (field_ref != null) {
method_ref.Resolve (code_gen);
cil.MethInst (PEAPI.MethodOp.ldtoken,
method_ref.PeapiMethod);
+ } else if (type_ref != null) {
+ type_ref.Resolve (code_gen);
+ cil.TypeInst (PEAPI.TypeOp.ldtoken,
+ type_ref.PeapiType);
}
}
private ArrayList param_list;
private Hashtable named_param_table;
private ArrayList inst_list;
+ private ArrayList customattr_list;
private Hashtable label_table;
private PEAPI.MethodDef methoddef;
private bool entry_point;
this.param_list = param_list;
inst_list = new ArrayList ();
+ customattr_list = new ArrayList ();
label_table = new Hashtable ();
local_list = new ArrayList ();
named_local_table = new Hashtable ();
}
public bool IsVararg {
- get { return (call_conv & PEAPI.CallConv.Vararg) == 0; }
+ get { return (call_conv & PEAPI.CallConv.Vararg) != 0; }
}
public void AddLocals (ArrayList local_list)
this.max_stack = max_stack;
}
+ public void AddCustomAttr (CustomAttr customattr)
+ {
+ customattr_list.Add (customattr);
+ }
+
public PEAPI.MethodDef Resolve (CodeGen code_gen)
{
if (is_resolved)
PEAPI.Param[] param_array;
if (param_list != null) {
- param_array = new PEAPI.Param[param_list.Count];
+ int param_count = param_list.Count;
+ //if (IsVararg)
+ // param_count--;
+ param_array = new PEAPI.Param[param_count];
int count = 0;
ret_type.Resolve (code_gen);
foreach (ParamDef paramdef in param_list) {
+ if (paramdef == ParamDef.Ellipsis)
+ break;
paramdef.Define (code_gen);
param_array[count++] = paramdef.PeapiParam;
}
PEAPI.Param[] param_array;
if (param_list != null) {
- param_array = new PEAPI.Param[param_list.Count];
+ int param_count = param_list.Count;
+ if (IsVararg)
+ param_count--;
+ param_array = new PEAPI.Param[param_count];
int count = 0;
ret_type.Resolve (code_gen);
foreach (ParamDef paramdef in param_list) {
+ if (paramdef == ParamDef.Ellipsis)
+ break;
paramdef.Define (code_gen);
param_array[count++] = paramdef.PeapiParam;
}
max_stack = 8;
methoddef.SetMaxStack (max_stack);
+ /// Add the custrom attributes to this method
+ foreach (CustomAttr customattr in customattr_list)
+ customattr.AddTo (code_gen, methoddef);
+
if (inst_list.Count < 1)
return;
if (param_list != null) {
bool first = true;
foreach (ParamDef paramdef in param_list) {
+ if (ParamDef.Ellipsis == paramdef)
+ break;
if (!first)
builder.Append (',');
builder.Append (paramdef.TypeName);
+ first = false;
}
}
builder.Append (')');
if (!first)
builder.Append (',');
builder.Append (param.FullName);
+ first = false;
}
}
builder.Append (')');
-
return builder.ToString ();
}
private bool is_defined;
private PEAPI.Param peapi_param;
+ public static readonly ParamDef Ellipsis = new ParamDef (new PEAPI.ParamAttr (), "ELLIPSIS", null);
+
public ParamDef (PEAPI.ParamAttr attr, string name,
ITypeRef typeref) {
this.attr = attr;
}
+ /// <summary>
+ /// Primitive types can be created like this System.String instead
+ /// of like a normal type that would be [mscorlib]System.String This
+ /// method returns a proper primitive type if the supplied name is
+ /// the name of a primitive type.
+ /// </summary>
+ public static PrimitiveTypeRef GetPrimitiveType (string full_name)
+ {
+ switch (full_name) {
+ case "System.String":
+ return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
+ case "System.Object":
+ return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
+ default:
+ return null;
+ }
+ }
+
public IClassRef AsClassRef (CodeGen code_gen)
{
PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
private Hashtable field_table;
private Hashtable method_table;
private ArrayList data_list;
+ private ArrayList customattr_list;
private TypeDef outer;
private int size;
method_table.Add (methoddef.Signature, methoddef);
}
+ public void AddCustomAttribute (CustomAttr customattr)
+ {
+ if (customattr_list == null)
+ customattr_list = new ArrayList ();
+
+ customattr_list.Add (customattr);
+ }
+
public void Define (CodeGen code_gen)
{
if (is_defined)
foreach (MethodDef methoddef in method_table.Values) {
methoddef.Define (code_gen, classdef);
}
+
+ if (customattr_list != null) {
+ foreach (CustomAttr customattr in customattr_list)
+ customattr.AddTo (code_gen, classdef);
+ }
}
public PEAPI.Method ResolveMethod (string signature, CodeGen code_gen)