diff --git a/src/IKVM.Reflection/Emit/AssemblyBuilder.cs b/src/IKVM.Reflection/Emit/AssemblyBuilder.cs index 16e913d129..2fa76accbd 100644 --- a/src/IKVM.Reflection/Emit/AssemblyBuilder.cs +++ b/src/IKVM.Reflection/Emit/AssemblyBuilder.cs @@ -750,66 +750,7 @@ internal bool IsWindowsRuntime { get { return (flags & (AssemblyNameFlags)0x200) != 0; } } - } - - sealed class ManifestModule : NonPEModule - { - private readonly AssemblyBuilder assembly; - private readonly Guid guid = Guid.NewGuid(); - - internal ManifestModule(AssemblyBuilder assembly) - : base(assembly.universe) - { - this.assembly = assembly; - } - - public override int MDStreamVersion - { - get { return assembly.mdStreamVersion; } - } - - public override Assembly Assembly - { - get { return assembly; } - } - - internal override Type FindType(TypeName typeName) - { - return null; - } - - internal override Type FindTypeIgnoreCase(TypeName lowerCaseName) - { - return null; - } - - internal override void GetTypesImpl(List list) - { - } - - public override string FullyQualifiedName - { - get { return Path.Combine(assembly.dir, "RefEmit_InMemoryManifestModule"); } - } - - public override string Name - { - get { return ""; } - } - - public override Guid ModuleVersionId - { - get { return guid; } - } - - public override string ScopeName - { - get { return "RefEmit_InMemoryManifestModule"; } - } - protected override Exception NotSupportedException() - { - return new InvalidOperationException(); - } } + } diff --git a/src/IKVM.Reflection/Emit/AssemblyBuilderAccess.cs b/src/IKVM.Reflection/Emit/AssemblyBuilderAccess.cs new file mode 100644 index 0000000000..96ee9d313e --- /dev/null +++ b/src/IKVM.Reflection/Emit/AssemblyBuilderAccess.cs @@ -0,0 +1,36 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum AssemblyBuilderAccess + { + + Save = 2, + ReflectionOnly = 6, + + } + +} diff --git a/src/IKVM.Reflection/Emit/ConstructorBuilder.cs b/src/IKVM.Reflection/Emit/ConstructorBuilder.cs index d21de97032..18cd20f2a3 100644 --- a/src/IKVM.Reflection/Emit/ConstructorBuilder.cs +++ b/src/IKVM.Reflection/Emit/ConstructorBuilder.cs @@ -26,8 +26,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class ConstructorBuilder : ConstructorInfo { + private readonly MethodBuilder methodBuilder; internal ConstructorBuilder(MethodBuilder mb) @@ -137,5 +139,7 @@ internal override MethodInfo GetMethodOnTypeDefinition() { return methodBuilder; } + } + } diff --git a/src/IKVM.Reflection/Emit/CustomAttributeBuilder.cs b/src/IKVM.Reflection/Emit/CustomAttributeBuilder.cs index 31fd670613..2b31e7f506 100644 --- a/src/IKVM.Reflection/Emit/CustomAttributeBuilder.cs +++ b/src/IKVM.Reflection/Emit/CustomAttributeBuilder.cs @@ -736,28 +736,7 @@ internal KnownCA KnownCA return KnownCA.Unknown; } } - } - // These are the pseudo-custom attributes that are recognized by name by the runtime (i.e. the type identity is not considered). - // The corresponding list in the runtime is at https://github.com/dotnet/coreclr/blob/1afe5ce4f45045d724a4e129df4b816655d486fb/src/md/compiler/custattr_emit.cpp#L38 - // Note that we only need to handle a subset of the types, since we don't need the ones that are only used for validation by the runtime. - enum KnownCA - { - Unknown, - DllImportAttribute, - ComImportAttribute, - SerializableAttribute, - NonSerializedAttribute, - MethodImplAttribute, - MarshalAsAttribute, - PreserveSigAttribute, - InAttribute, - OutAttribute, - OptionalAttribute, - StructLayoutAttribute, - FieldOffsetAttribute, - SpecialNameAttribute, - // the following is not part of the runtime known custom attributes, but we handle it here for efficiency and convenience - SuppressUnmanagedCodeSecurityAttribute, } + } diff --git a/src/IKVM.Reflection/Emit/CustomModifiersBuilder.cs b/src/IKVM.Reflection/Emit/CustomModifiersBuilder.cs index 8a173bd85f..c2355515f0 100644 --- a/src/IKVM.Reflection/Emit/CustomModifiersBuilder.cs +++ b/src/IKVM.Reflection/Emit/CustomModifiersBuilder.cs @@ -25,8 +25,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class CustomModifiersBuilder { + private readonly List list = new List(); internal struct Item @@ -69,5 +71,7 @@ public CustomModifiers Create() { return new CustomModifiers(list); } + } + } diff --git a/src/IKVM.Reflection/Emit/EnumBuilder.cs b/src/IKVM.Reflection/Emit/EnumBuilder.cs index 80c3a62fcc..dac5a73b3d 100644 --- a/src/IKVM.Reflection/Emit/EnumBuilder.cs +++ b/src/IKVM.Reflection/Emit/EnumBuilder.cs @@ -23,8 +23,10 @@ Jeroen Frijters */ namespace IKVM.Reflection.Emit { + public sealed class EnumBuilder : TypeInfo { + private readonly TypeBuilder typeBuilder; private readonly FieldBuilder fieldBuilder; @@ -116,5 +118,7 @@ internal override bool IsBaked { get { return typeBuilder.IsBaked; } } + } + } diff --git a/src/IKVM.Reflection/Emit/EventBuilder.cs b/src/IKVM.Reflection/Emit/EventBuilder.cs index 04458233a4..53fd740990 100644 --- a/src/IKVM.Reflection/Emit/EventBuilder.cs +++ b/src/IKVM.Reflection/Emit/EventBuilder.cs @@ -27,8 +27,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class EventBuilder : EventInfo { + private readonly TypeBuilder typeBuilder; private readonly string name; private EventAttributes attributes; @@ -274,5 +276,7 @@ internal override int GetCurrentToken() return lazyPseudoToken; } } + } + } diff --git a/src/IKVM.Reflection/Emit/EventToken.cs b/src/IKVM.Reflection/Emit/EventToken.cs new file mode 100644 index 0000000000..8a113825ca --- /dev/null +++ b/src/IKVM.Reflection/Emit/EventToken.cs @@ -0,0 +1,68 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + public struct EventToken + { + + public static readonly EventToken Empty; + private readonly int token; + + internal EventToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as EventToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(EventToken other) + { + return this == other; + } + + public static bool operator ==(EventToken et1, EventToken et2) + { + return et1.token == et2.token; + } + + public static bool operator !=(EventToken et1, EventToken et2) + { + return et1.token != et2.token; + } + } +} diff --git a/src/IKVM.Reflection/Emit/ExceptionHandler.cs b/src/IKVM.Reflection/Emit/ExceptionHandler.cs index a2ab35077b..b1699d535c 100644 --- a/src/IKVM.Reflection/Emit/ExceptionHandler.cs +++ b/src/IKVM.Reflection/Emit/ExceptionHandler.cs @@ -25,6 +25,7 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public struct ExceptionHandler : IEquatable { @@ -117,5 +118,7 @@ public override int GetHashCode() { return !left.Equals(right); } + } + } diff --git a/src/IKVM.Reflection/Emit/FieldBuilder.cs b/src/IKVM.Reflection/Emit/FieldBuilder.cs index 01a5c6eeb8..5aac92bf06 100644 --- a/src/IKVM.Reflection/Emit/FieldBuilder.cs +++ b/src/IKVM.Reflection/Emit/FieldBuilder.cs @@ -28,8 +28,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class FieldBuilder : FieldInfo { + private readonly TypeBuilder typeBuilder; private readonly string name; private readonly int pseudoToken; @@ -220,5 +222,7 @@ internal override bool IsBaked { get { return typeBuilder.IsBaked; } } + } + } diff --git a/src/IKVM.Reflection/Emit/FieldToken.cs b/src/IKVM.Reflection/Emit/FieldToken.cs new file mode 100644 index 0000000000..2ed7f2f2f0 --- /dev/null +++ b/src/IKVM.Reflection/Emit/FieldToken.cs @@ -0,0 +1,67 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + public struct FieldToken + { + public static readonly FieldToken Empty; + private readonly int token; + + internal FieldToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as FieldToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(FieldToken other) + { + return this == other; + } + + public static bool operator ==(FieldToken ft1, FieldToken ft2) + { + return ft1.token == ft2.token; + } + + public static bool operator !=(FieldToken ft1, FieldToken ft2) + { + return ft1.token != ft2.token; + } + } +} diff --git a/src/IKVM.Reflection/Emit/FlowControl.cs b/src/IKVM.Reflection/Emit/FlowControl.cs new file mode 100644 index 0000000000..0947d99001 --- /dev/null +++ b/src/IKVM.Reflection/Emit/FlowControl.cs @@ -0,0 +1,42 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum FlowControl + { + + Branch = 0, + Break = 1, + Call = 2, + Cond_Branch = 3, + Meta = 4, + Next = 5, + Return = 7, + Throw = 8, + + } + +} diff --git a/src/IKVM.Reflection/Emit/GenericTypeParameterBuilder.cs b/src/IKVM.Reflection/Emit/GenericTypeParameterBuilder.cs index 6f7aa6ce01..83944559c2 100644 --- a/src/IKVM.Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/IKVM.Reflection/Emit/GenericTypeParameterBuilder.cs @@ -28,8 +28,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class GenericTypeParameterBuilder : TypeInfo { + private readonly string name; private readonly TypeBuilder type; private readonly MethodBuilder method; @@ -252,5 +254,7 @@ internal override bool IsBaked { get { return ((MemberInfo)type ?? method).IsBaked; } } + } + } diff --git a/src/IKVM.Reflection/Emit/ILGenerator.cs b/src/IKVM.Reflection/Emit/ILGenerator.cs index c6f02f298a..e9fcfce515 100644 --- a/src/IKVM.Reflection/Emit/ILGenerator.cs +++ b/src/IKVM.Reflection/Emit/ILGenerator.cs @@ -31,75 +31,6 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { - public struct Label - { - // 1-based here, to make sure that an uninitialized Label isn't valid - private readonly int index1; - - internal Label(int index) - { - this.index1 = index + 1; - } - - internal int Index - { - get { return index1 - 1; } - } - - public bool Equals(Label other) - { - return other.index1 == index1; - } - - public override bool Equals(object obj) - { - return this == obj as Label?; - } - - public override int GetHashCode() - { - return index1; - } - - public static bool operator ==(Label arg1, Label arg2) - { - return arg1.index1 == arg2.index1; - } - - public static bool operator !=(Label arg1, Label arg2) - { - return !(arg1 == arg2); - } - } - - public sealed class LocalBuilder : LocalVariableInfo - { - internal string name; - internal int startOffset; - internal int endOffset; - - internal LocalBuilder(Type localType, int index, bool pinned) - : base(index, localType, pinned) - { - } - - internal LocalBuilder(Type localType, int index, bool pinned, CustomModifiers customModifiers) - : base(index, localType, pinned, customModifiers) - { - } - - public void SetLocalSymInfo(string name) - { - this.name = name; - } - - public void SetLocalSymInfo(string name, int startOffset, int endOffset) - { - this.name = name; - this.startOffset = startOffset; - this.endOffset = endOffset; - } - } public sealed class ILGenerator { diff --git a/src/IKVM.Reflection/Emit/KnownCA.cs b/src/IKVM.Reflection/Emit/KnownCA.cs new file mode 100644 index 0000000000..7a877db227 --- /dev/null +++ b/src/IKVM.Reflection/Emit/KnownCA.cs @@ -0,0 +1,48 @@ +/* + Copyright (C) 2008-2013 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +namespace IKVM.Reflection.Emit +{ + // These are the pseudo-custom attributes that are recognized by name by the runtime (i.e. the type identity is not considered). + // The corresponding list in the runtime is at https://github.com/dotnet/coreclr/blob/1afe5ce4f45045d724a4e129df4b816655d486fb/src/md/compiler/custattr_emit.cpp#L38 + // Note that we only need to handle a subset of the types, since we don't need the ones that are only used for validation by the runtime. + enum KnownCA + { + Unknown, + DllImportAttribute, + ComImportAttribute, + SerializableAttribute, + NonSerializedAttribute, + MethodImplAttribute, + MarshalAsAttribute, + PreserveSigAttribute, + InAttribute, + OutAttribute, + OptionalAttribute, + StructLayoutAttribute, + FieldOffsetAttribute, + SpecialNameAttribute, + // the following is not part of the runtime known custom attributes, but we handle it here for efficiency and convenience + SuppressUnmanagedCodeSecurityAttribute, + } +} diff --git a/src/IKVM.Reflection/Emit/Label.cs b/src/IKVM.Reflection/Emit/Label.cs new file mode 100644 index 0000000000..9ac055db3d --- /dev/null +++ b/src/IKVM.Reflection/Emit/Label.cs @@ -0,0 +1,68 @@ +/* + Copyright (C) 2008-2012 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +namespace IKVM.Reflection.Emit +{ + public struct Label + { + + // 1-based here, to make sure that an uninitialized Label isn't valid + private readonly int index1; + + internal Label(int index) + { + this.index1 = index + 1; + } + + internal int Index + { + get { return index1 - 1; } + } + + public bool Equals(Label other) + { + return other.index1 == index1; + } + + public override bool Equals(object obj) + { + return this == obj as Label?; + } + + public override int GetHashCode() + { + return index1; + } + + public static bool operator ==(Label arg1, Label arg2) + { + return arg1.index1 == arg2.index1; + } + + public static bool operator !=(Label arg1, Label arg2) + { + return !(arg1 == arg2); + } + } + +} diff --git a/src/IKVM.Reflection/Emit/LocalBuilder.cs b/src/IKVM.Reflection/Emit/LocalBuilder.cs new file mode 100644 index 0000000000..deebe7111d --- /dev/null +++ b/src/IKVM.Reflection/Emit/LocalBuilder.cs @@ -0,0 +1,58 @@ +/* + Copyright (C) 2008-2012 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +namespace IKVM.Reflection.Emit +{ + + public sealed class LocalBuilder : LocalVariableInfo + { + + internal string name; + internal int startOffset; + internal int endOffset; + + internal LocalBuilder(Type localType, int index, bool pinned) + : base(index, localType, pinned) + { + } + + internal LocalBuilder(Type localType, int index, bool pinned, CustomModifiers customModifiers) + : base(index, localType, pinned, customModifiers) + { + } + + public void SetLocalSymInfo(string name) + { + this.name = name; + } + + public void SetLocalSymInfo(string name, int startOffset, int endOffset) + { + this.name = name; + this.startOffset = startOffset; + this.endOffset = endOffset; + } + + } + +} diff --git a/src/IKVM.Reflection/Emit/ManifestModule.cs b/src/IKVM.Reflection/Emit/ManifestModule.cs new file mode 100644 index 0000000000..7e6e8feab7 --- /dev/null +++ b/src/IKVM.Reflection/Emit/ManifestModule.cs @@ -0,0 +1,94 @@ +/* + Copyright (C) 2008-2013 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +using System; +using System.Collections.Generic; +using System.IO; + +namespace IKVM.Reflection.Emit +{ + + sealed class ManifestModule : NonPEModule + { + + private readonly AssemblyBuilder assembly; + private readonly Guid guid = Guid.NewGuid(); + + internal ManifestModule(AssemblyBuilder assembly) + : base(assembly.universe) + { + this.assembly = assembly; + } + + public override int MDStreamVersion + { + get { return assembly.mdStreamVersion; } + } + + public override Assembly Assembly + { + get { return assembly; } + } + + internal override Type FindType(TypeName typeName) + { + return null; + } + + internal override Type FindTypeIgnoreCase(TypeName lowerCaseName) + { + return null; + } + + internal override void GetTypesImpl(List list) + { + } + + public override string FullyQualifiedName + { + get { return Path.Combine(assembly.dir, "RefEmit_InMemoryManifestModule"); } + } + + public override string Name + { + get { return ""; } + } + + public override Guid ModuleVersionId + { + get { return guid; } + } + + public override string ScopeName + { + get { return "RefEmit_InMemoryManifestModule"; } + } + + protected override Exception NotSupportedException() + { + return new InvalidOperationException(); + } + + } + +} diff --git a/src/IKVM.Reflection/Emit/MethodToken.cs b/src/IKVM.Reflection/Emit/MethodToken.cs new file mode 100644 index 0000000000..08c2c5be33 --- /dev/null +++ b/src/IKVM.Reflection/Emit/MethodToken.cs @@ -0,0 +1,67 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + public struct MethodToken + { + public static readonly MethodToken Empty; + private readonly int token; + + internal MethodToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as MethodToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(MethodToken other) + { + return this == other; + } + + public static bool operator ==(MethodToken mt1, MethodToken mt2) + { + return mt1.token == mt2.token; + } + + public static bool operator !=(MethodToken mt1, MethodToken mt2) + { + return mt1.token != mt2.token; + } + } +} diff --git a/src/IKVM.Reflection/Emit/OpCode.cs b/src/IKVM.Reflection/Emit/OpCode.cs index b5d04aa62b..fe106e5f97 100644 --- a/src/IKVM.Reflection/Emit/OpCode.cs +++ b/src/IKVM.Reflection/Emit/OpCode.cs @@ -23,8 +23,10 @@ Jeroen Frijters */ namespace IKVM.Reflection.Emit { + public struct OpCode { + private const int ValueCount = 1024; private const int OperandTypeCount = 19; private const int FlowControlCount = 9; @@ -32,6 +34,7 @@ public struct OpCode private const int OpCodeTypeCount = 6; private const int StackBehaviourPopCount = 20; private const int StackBehaviourPushCount = 9; + private static readonly StackBehaviour[] pop = { StackBehaviour.Pop0, StackBehaviour.Pop1, @@ -54,6 +57,7 @@ public struct OpCode StackBehaviour.Varpop, StackBehaviour.Popref_popi_pop1 }; + private static readonly StackBehaviour[] push = { StackBehaviour.Push0, StackBehaviour.Push1, @@ -65,6 +69,7 @@ public struct OpCode StackBehaviour.Pushref, StackBehaviour.Varpush }; + private readonly int value; internal OpCode(int value) @@ -108,10 +113,12 @@ public int Size } #if !GENERATOR + public string Name { get { return OpCodes.GetName(this.Value); } } + #endif public OperandType OperandType @@ -145,6 +152,7 @@ public StackBehaviour StackBehaviourPush } #if GENERATOR + static void Main(string[] args) { Debug.Assert(pop.Length == StackBehaviourPopCount); @@ -280,6 +288,9 @@ static int GetStackDiff(System.Reflection.Emit.StackBehaviour sb) } throw new InvalidOperationException(); } + #endif // GENERATOR + } + } diff --git a/src/IKVM.Reflection/Emit/OpCodeType.cs b/src/IKVM.Reflection/Emit/OpCodeType.cs new file mode 100644 index 0000000000..1c8509dd14 --- /dev/null +++ b/src/IKVM.Reflection/Emit/OpCodeType.cs @@ -0,0 +1,40 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum OpCodeType + { + + Annotation = 0, + Macro = 1, + Nternal = 2, + Objmodel = 3, + Prefix = 4, + Primitive = 5, + + } + +} diff --git a/src/IKVM.Reflection/Emit/OpCodes.cs b/src/IKVM.Reflection/Emit/OpCodes.cs index ce3be57459..51a1f86657 100644 --- a/src/IKVM.Reflection/Emit/OpCodes.cs +++ b/src/IKVM.Reflection/Emit/OpCodes.cs @@ -25,8 +25,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public sealed class OpCodes { + public static readonly OpCode Nop = new OpCode(4888); public static readonly OpCode Break = new OpCode(4199116); public static readonly OpCode Ldarg_0 = new OpCode(8492847); @@ -745,5 +747,7 @@ public static bool TakesSingleByteArgument(OpCode inst) return false; } } + } + } diff --git a/src/IKVM.Reflection/Emit/OperandType.cs b/src/IKVM.Reflection/Emit/OperandType.cs new file mode 100644 index 0000000000..08571e59a7 --- /dev/null +++ b/src/IKVM.Reflection/Emit/OperandType.cs @@ -0,0 +1,52 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum OperandType + { + + InlineBrTarget = 0, + InlineField = 1, + InlineI = 2, + InlineI8 = 3, + InlineMethod = 4, + InlineNone = 5, + InlinePhi = 6, + InlineR = 7, + InlineSig = 9, + InlineString = 10, + InlineSwitch = 11, + InlineTok = 12, + InlineType = 13, + InlineVar = 14, + ShortInlineBrTarget = 15, + ShortInlineI = 16, + ShortInlineR = 17, + ShortInlineVar = 18, + + } + +} diff --git a/src/IKVM.Reflection/Emit/PEFileKinds.cs b/src/IKVM.Reflection/Emit/PEFileKinds.cs new file mode 100644 index 0000000000..d01bace56b --- /dev/null +++ b/src/IKVM.Reflection/Emit/PEFileKinds.cs @@ -0,0 +1,37 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum PEFileKinds + { + + Dll = 1, + ConsoleApplication = 2, + WindowApplication = 3, + + } + +} diff --git a/src/IKVM.Reflection/Emit/PackingSize.cs b/src/IKVM.Reflection/Emit/PackingSize.cs new file mode 100644 index 0000000000..f7fcaf6054 --- /dev/null +++ b/src/IKVM.Reflection/Emit/PackingSize.cs @@ -0,0 +1,43 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public enum PackingSize + { + + Unspecified = 0, + Size1 = 1, + Size2 = 2, + Size4 = 4, + Size8 = 8, + Size16 = 16, + Size32 = 32, + Size64 = 64, + Size128 = 128, + + } + +} diff --git a/src/IKVM.Reflection/Emit/RelativeVirtualAddress.cs b/src/IKVM.Reflection/Emit/RelativeVirtualAddress.cs index 83998cc35a..ffe772394f 100644 --- a/src/IKVM.Reflection/Emit/RelativeVirtualAddress.cs +++ b/src/IKVM.Reflection/Emit/RelativeVirtualAddress.cs @@ -24,8 +24,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { + public struct RelativeVirtualAddress { + internal readonly uint initializedDataOffset; internal RelativeVirtualAddress(uint initializedDataOffset) @@ -37,5 +39,7 @@ internal RelativeVirtualAddress(uint initializedDataOffset) { return new RelativeVirtualAddress(rva.initializedDataOffset + (uint)offset); } + } + } diff --git a/src/IKVM.Reflection/Emit/SignatureHelper.cs b/src/IKVM.Reflection/Emit/SignatureHelper.cs index caa1df77aa..efc16aa034 100644 --- a/src/IKVM.Reflection/Emit/SignatureHelper.cs +++ b/src/IKVM.Reflection/Emit/SignatureHelper.cs @@ -315,6 +315,7 @@ public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Typ } } } + } } diff --git a/src/IKVM.Reflection/Emit/SignatureToken.cs b/src/IKVM.Reflection/Emit/SignatureToken.cs new file mode 100644 index 0000000000..98a654533f --- /dev/null +++ b/src/IKVM.Reflection/Emit/SignatureToken.cs @@ -0,0 +1,67 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + public struct SignatureToken + { + public static readonly SignatureToken Empty; + private readonly int token; + + internal SignatureToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as SignatureToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(SignatureToken other) + { + return this == other; + } + + public static bool operator ==(SignatureToken st1, SignatureToken st2) + { + return st1.token == st2.token; + } + + public static bool operator !=(SignatureToken st1, SignatureToken st2) + { + return st1.token != st2.token; + } + } +} diff --git a/src/IKVM.Reflection/Emit/Enums.cs b/src/IKVM.Reflection/Emit/StackBehaviour.cs similarity index 59% rename from src/IKVM.Reflection/Emit/Enums.cs rename to src/IKVM.Reflection/Emit/StackBehaviour.cs index d6fa920050..c49f4d3778 100644 --- a/src/IKVM.Reflection/Emit/Enums.cs +++ b/src/IKVM.Reflection/Emit/StackBehaviour.cs @@ -24,78 +24,10 @@ Jeroen Frijters namespace IKVM.Reflection.Emit { - public enum AssemblyBuilderAccess - { - Save = 2, - ReflectionOnly = 6, - } - public enum OpCodeType + public enum StackBehaviour { - Annotation = 0, - Macro = 1, - Nternal = 2, - Objmodel = 3, - Prefix = 4, - Primitive = 5, - } - - public enum OperandType - { - InlineBrTarget = 0, - InlineField = 1, - InlineI = 2, - InlineI8 = 3, - InlineMethod = 4, - InlineNone = 5, - InlinePhi = 6, - InlineR = 7, - InlineSig = 9, - InlineString = 10, - InlineSwitch = 11, - InlineTok = 12, - InlineType = 13, - InlineVar = 14, - ShortInlineBrTarget = 15, - ShortInlineI = 16, - ShortInlineR = 17, - ShortInlineVar = 18, - } - public enum FlowControl - { - Branch = 0, - Break = 1, - Call = 2, - Cond_Branch = 3, - Meta = 4, - Next = 5, - Return = 7, - Throw = 8, - } - - public enum PackingSize - { - Unspecified = 0, - Size1 = 1, - Size2 = 2, - Size4 = 4, - Size8 = 8, - Size16 = 16, - Size32 = 32, - Size64 = 64, - Size128 = 128, - } - - public enum PEFileKinds - { - Dll = 1, - ConsoleApplication = 2, - WindowApplication = 3, - } - - public enum StackBehaviour - { Pop0 = 0, Pop1 = 1, Pop1_pop1 = 2, @@ -125,5 +57,7 @@ public enum StackBehaviour Varpop = 26, Varpush = 27, Popref_popi_pop1 = 28, + } + } diff --git a/src/IKVM.Reflection/Emit/StringToken.cs b/src/IKVM.Reflection/Emit/StringToken.cs new file mode 100644 index 0000000000..8c36c69907 --- /dev/null +++ b/src/IKVM.Reflection/Emit/StringToken.cs @@ -0,0 +1,70 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public struct StringToken + { + + private readonly int token; + + internal StringToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as StringToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(StringToken other) + { + return this == other; + } + + public static bool operator ==(StringToken st1, StringToken st2) + { + return st1.token == st2.token; + } + + public static bool operator !=(StringToken st1, StringToken st2) + { + return st1.token != st2.token; + } + + } + +} diff --git a/src/IKVM.Reflection/Emit/Tokens.cs b/src/IKVM.Reflection/Emit/Tokens.cs deleted file mode 100644 index d88b493b56..0000000000 --- a/src/IKVM.Reflection/Emit/Tokens.cs +++ /dev/null @@ -1,271 +0,0 @@ -/* - Copyright (C) 2008 Jeroen Frijters - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jeroen Frijters - jeroen@frijters.net - -*/ - -namespace IKVM.Reflection.Emit -{ - public struct EventToken - { - public static readonly EventToken Empty; - private readonly int token; - - internal EventToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as EventToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(EventToken other) - { - return this == other; - } - - public static bool operator ==(EventToken et1, EventToken et2) - { - return et1.token == et2.token; - } - - public static bool operator !=(EventToken et1, EventToken et2) - { - return et1.token != et2.token; - } - } - - public struct FieldToken - { - public static readonly FieldToken Empty; - private readonly int token; - - internal FieldToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as FieldToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(FieldToken other) - { - return this == other; - } - - public static bool operator ==(FieldToken ft1, FieldToken ft2) - { - return ft1.token == ft2.token; - } - - public static bool operator !=(FieldToken ft1, FieldToken ft2) - { - return ft1.token != ft2.token; - } - } - - public struct MethodToken - { - public static readonly MethodToken Empty; - private readonly int token; - - internal MethodToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as MethodToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(MethodToken other) - { - return this == other; - } - - public static bool operator ==(MethodToken mt1, MethodToken mt2) - { - return mt1.token == mt2.token; - } - - public static bool operator !=(MethodToken mt1, MethodToken mt2) - { - return mt1.token != mt2.token; - } - } - - public struct SignatureToken - { - public static readonly SignatureToken Empty; - private readonly int token; - - internal SignatureToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as SignatureToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(SignatureToken other) - { - return this == other; - } - - public static bool operator ==(SignatureToken st1, SignatureToken st2) - { - return st1.token == st2.token; - } - - public static bool operator !=(SignatureToken st1, SignatureToken st2) - { - return st1.token != st2.token; - } - } - - public struct StringToken - { - private readonly int token; - - internal StringToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as StringToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(StringToken other) - { - return this == other; - } - - public static bool operator ==(StringToken st1, StringToken st2) - { - return st1.token == st2.token; - } - - public static bool operator !=(StringToken st1, StringToken st2) - { - return st1.token != st2.token; - } - } - - public struct TypeToken - { - public static readonly TypeToken Empty; - private readonly int token; - - internal TypeToken(int token) - { - this.token = token; - } - - public int Token - { - get { return token; } - } - - public override bool Equals(object obj) - { - return obj as TypeToken? == this; - } - - public override int GetHashCode() - { - return token; - } - - public bool Equals(TypeToken other) - { - return this == other; - } - - public static bool operator ==(TypeToken tt1, TypeToken tt2) - { - return tt1.token == tt2.token; - } - - public static bool operator !=(TypeToken tt1, TypeToken tt2) - { - return tt1.token != tt2.token; - } - } -} diff --git a/src/IKVM.Reflection/Emit/TypeToken.cs b/src/IKVM.Reflection/Emit/TypeToken.cs new file mode 100644 index 0000000000..4494df1845 --- /dev/null +++ b/src/IKVM.Reflection/Emit/TypeToken.cs @@ -0,0 +1,71 @@ +/* + Copyright (C) 2008 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ + +namespace IKVM.Reflection.Emit +{ + + public struct TypeToken + { + + public static readonly TypeToken Empty; + private readonly int token; + + internal TypeToken(int token) + { + this.token = token; + } + + public int Token + { + get { return token; } + } + + public override bool Equals(object obj) + { + return obj as TypeToken? == this; + } + + public override int GetHashCode() + { + return token; + } + + public bool Equals(TypeToken other) + { + return this == other; + } + + public static bool operator ==(TypeToken tt1, TypeToken tt2) + { + return tt1.token == tt2.token; + } + + public static bool operator !=(TypeToken tt1, TypeToken tt2) + { + return tt1.token != tt2.token; + } + + } + +} diff --git a/src/IKVM.Reflection/Emit/UnmanagedExport.cs b/src/IKVM.Reflection/Emit/UnmanagedExport.cs index 263dde42d8..0224ac95bd 100644 --- a/src/IKVM.Reflection/Emit/UnmanagedExport.cs +++ b/src/IKVM.Reflection/Emit/UnmanagedExport.cs @@ -27,10 +27,12 @@ namespace IKVM.Reflection.Emit struct UnmanagedExport { + internal string name; internal int ordinal; internal RelativeVirtualAddress rva; internal MethodBuilder mb; + } }