mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Compare commits
4
Commits
seq-points
...
asmbinder
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2cc76c29 | ||
|
|
6542626e1c | ||
|
|
dbad80b39b | ||
|
|
e8f4c106a4 |
No files matched your search
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// AssemblyInfo.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar ([email protected])
|
||||
//
|
||||
// Copyright 2013 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about the assembly
|
||||
|
||||
[assembly: AssemblyTitle ("Mono.Runtime.dll")]
|
||||
[assembly: AssemblyDescription ("Mono.Runtime.dll")]
|
||||
[assembly: AssemblyDefaultAlias ("Mono.Runtime.dll")]
|
||||
|
||||
[assembly: AssemblyCompany (Consts.MonoCompany)]
|
||||
[assembly: AssemblyProduct (Consts.MonoProduct)]
|
||||
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
|
||||
[assembly: AssemblyVersion (Consts.FxVersion)]
|
||||
[assembly: SatelliteContractVersion (Consts.FxVersion)]
|
||||
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
|
||||
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
|
||||
|
||||
[assembly: NeutralResourcesLanguage ("en-US")]
|
||||
[assembly: CLSCompliant (true)]
|
||||
[assembly: AssemblyDelaySign (true)]
|
||||
|
||||
[assembly: AssemblyKeyFile ("../mono.pub")]
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
thisdir = class/Mono.Runtime
|
||||
SUBDIRS =
|
||||
include ../../build/rules.make
|
||||
|
||||
LIBRARY = Mono.Runtime.dll
|
||||
|
||||
LIB_MCS_FLAGS = -r:System.Core.dll -r:System.dll -unsafe
|
||||
|
||||
include ../../build/library.make
|
||||
@@ -0,0 +1,3 @@
|
||||
../../build/common/Consts.cs
|
||||
Assembly/AssemblyInfo.cs
|
||||
Mono.Runtime/InlineAsm.cs
|
||||
@@ -0,0 +1,244 @@
|
||||
//
|
||||
// InlineAsm.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar <[email protected]>
|
||||
//
|
||||
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mono.Runtime {
|
||||
|
||||
[Flags]
|
||||
public enum InlineAsmFlags {
|
||||
None = 0,
|
||||
ClobbersFlags = 1 << 1,
|
||||
ClobbersMemory = 1 << 2,
|
||||
Volatile = 1 << 3,
|
||||
}
|
||||
|
||||
// architecture constraints
|
||||
public enum Amd64Asm {
|
||||
Rax,
|
||||
Rcx,
|
||||
Rdx,
|
||||
Rbx,
|
||||
Rsp,
|
||||
Rbp,
|
||||
Rsi,
|
||||
Rdi,
|
||||
R8,
|
||||
R9,
|
||||
R10,
|
||||
R11,
|
||||
R12,
|
||||
R13,
|
||||
R14,
|
||||
R15,
|
||||
Xmm0,
|
||||
Xmm1,
|
||||
Xmm2,
|
||||
Xmm3,
|
||||
Xmm4,
|
||||
Xmm5,
|
||||
Xmm6,
|
||||
Xmm7,
|
||||
Xmm8,
|
||||
Xmm9,
|
||||
Xmm10,
|
||||
Xmm11,
|
||||
Xmm12,
|
||||
Xmm13,
|
||||
Xmm14,
|
||||
Xmm15,
|
||||
Input = 1 << 24,
|
||||
Output = 1 << 25,
|
||||
ArrayStart = 1 << 26,
|
||||
}
|
||||
|
||||
public enum X86Asm {
|
||||
Eax,
|
||||
Ecx,
|
||||
Edx,
|
||||
Ebx,
|
||||
Esp,
|
||||
Ebp,
|
||||
Esi,
|
||||
Edi,
|
||||
Xmm0,
|
||||
Xmm1,
|
||||
Xmm2,
|
||||
Xmm3,
|
||||
Xmm4,
|
||||
Xmm5,
|
||||
Xmm6,
|
||||
Xmm7,
|
||||
Input = 1 << 24,
|
||||
Output = 1 << 25,
|
||||
ArrayStart = 1 << 26,
|
||||
}
|
||||
|
||||
public enum ArmAsm {
|
||||
R0,
|
||||
R1,
|
||||
R2,
|
||||
R3,
|
||||
R4,
|
||||
R5,
|
||||
R6,
|
||||
R7,
|
||||
R8,
|
||||
R9,
|
||||
R10,
|
||||
R11,
|
||||
R12,
|
||||
R13,
|
||||
R14,
|
||||
R15,
|
||||
F0,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
F13,
|
||||
F14,
|
||||
F15,
|
||||
F16,
|
||||
F17,
|
||||
F18,
|
||||
F19,
|
||||
F20,
|
||||
F21,
|
||||
F22,
|
||||
F23,
|
||||
F24,
|
||||
F25,
|
||||
F26,
|
||||
F27,
|
||||
F28,
|
||||
F29,
|
||||
F30,
|
||||
F31,
|
||||
Input = 1 << 24,
|
||||
Output = 1 << 25,
|
||||
ArrayStart = 1 << 26,
|
||||
}
|
||||
|
||||
/*
|
||||
public class ArmXXX
|
||||
{
|
||||
public enum Descriptor
|
||||
{
|
||||
R0,
|
||||
R1,
|
||||
R2,
|
||||
R3,
|
||||
R4,
|
||||
R5,
|
||||
R6,
|
||||
R7,
|
||||
R8,
|
||||
R9,
|
||||
R10,
|
||||
R11,
|
||||
R12,
|
||||
R13,
|
||||
R14,
|
||||
R15,
|
||||
}
|
||||
|
||||
public Arm (object value, Descriptor descriptor)
|
||||
{
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static class InlineAsm {
|
||||
|
||||
// Each of the methods here is in practice an internal call: the JIT will
|
||||
// substitute the correct result inline, while on runtimes that don't support the
|
||||
// feature, the code executes as is and everything is disabled (the developer
|
||||
// should insert a fallback to handle this case)
|
||||
public static bool ArmSupported {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool X86Supported {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Amd64Supported {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SSE2Supported {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The following methods are never seen by the JIT (and even if someone tries to
|
||||
// sneak them in they do nothing). Instead, the C# compiler intercepts them and
|
||||
// replaces the call with a ldtoken/pop IL instruction sequence: the resulting IL
|
||||
// code is valid IL (and would do nothing anyway on a runtime without inline asm support).
|
||||
// the token references a field with a data blob that contains the serialized information
|
||||
// (flags, compiled assembly code, argument constraints, optionally the original assembly code).
|
||||
// this is similar to the ldtoken use for array initialization.
|
||||
// args contains pairs of local vars (including method arguments) and their constraints
|
||||
// the C# compiler needs to make sure the constraints are of the right type and constants
|
||||
// for arguments flagged with Output, the C# compiler should treat the variable like
|
||||
// if it was passed as out varname to a method for definitive assignment purposes
|
||||
//
|
||||
|
||||
public static void Arm (InlineAsmFlags options, string code, params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public static void X86 (InlineAsmFlags options, string code, params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public static void Amd64 (InlineAsmFlags options, string code, params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
// GPU code?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// asm.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar <[email protected]>
|
||||
//
|
||||
// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Mono.Runtime
|
||||
{
|
||||
public static class asm
|
||||
{
|
||||
public static void BindParameter (int register, object parameter)
|
||||
{
|
||||
throw CreateException ();
|
||||
}
|
||||
|
||||
[CLSCompliant (false)]
|
||||
public unsafe static void BindParameter (int register, void* parameter)
|
||||
{
|
||||
throw CreateException ();
|
||||
}
|
||||
|
||||
public static void BindVariable (int register, object variable)
|
||||
{
|
||||
throw CreateException ();
|
||||
}
|
||||
|
||||
[CLSCompliant (false)]
|
||||
public unsafe static void BindVariable (int register, void* variable)
|
||||
{
|
||||
throw CreateException ();
|
||||
}
|
||||
|
||||
static Exception CreateException ()
|
||||
{
|
||||
return new NotSupportedException ("The assembler binder requires Mono C# compiler to be used for compilation");
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
-51
@@ -1315,32 +1315,23 @@ namespace Mono.CSharp {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AttributeEncoder
|
||||
public class BlobEncoder
|
||||
{
|
||||
[Flags]
|
||||
public enum EncodedTypeProperties
|
||||
{
|
||||
None = 0,
|
||||
DynamicType = 1,
|
||||
TypeParameter = 1 << 1
|
||||
}
|
||||
|
||||
public static readonly byte[] Empty;
|
||||
|
||||
byte[] buffer;
|
||||
int pos;
|
||||
const ushort Version = 1;
|
||||
|
||||
static AttributeEncoder ()
|
||||
{
|
||||
Empty = new byte[4];
|
||||
Empty[0] = (byte) Version;
|
||||
}
|
||||
|
||||
public AttributeEncoder ()
|
||||
public BlobEncoder ()
|
||||
{
|
||||
buffer = new byte[32];
|
||||
Encode (Version);
|
||||
}
|
||||
|
||||
public void Add (byte[] data)
|
||||
{
|
||||
if (pos + data.Length > buffer.Length)
|
||||
Grow (data.Length);
|
||||
|
||||
Buffer.BlockCopy (data, 0, buffer, pos, data.Length);
|
||||
pos += data.Length;
|
||||
}
|
||||
|
||||
public void Encode (bool value)
|
||||
@@ -1353,7 +1344,7 @@ namespace Mono.CSharp {
|
||||
if (pos == buffer.Length)
|
||||
Grow (1);
|
||||
|
||||
buffer [pos++] = value;
|
||||
buffer[pos++] = value;
|
||||
}
|
||||
|
||||
public void Encode (sbyte value)
|
||||
@@ -1428,7 +1419,7 @@ namespace Mono.CSharp {
|
||||
return;
|
||||
}
|
||||
|
||||
var buf = Encoding.UTF8.GetBytes(value);
|
||||
var buf = Encoding.UTF8.GetBytes (value);
|
||||
WriteCompressedValue (buf.Length);
|
||||
|
||||
if (pos + buf.Length > buffer.Length)
|
||||
@@ -1438,6 +1429,62 @@ namespace Mono.CSharp {
|
||||
pos += buf.Length;
|
||||
}
|
||||
|
||||
|
||||
void Grow (int inc)
|
||||
{
|
||||
int size = System.Math.Max (pos * 4, pos + inc + 2);
|
||||
Array.Resize (ref buffer, size);
|
||||
}
|
||||
|
||||
public void WriteCompressedValue (int value)
|
||||
{
|
||||
if (value < 0x80) {
|
||||
Encode ((byte) value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value < 0x4000) {
|
||||
Encode ((byte) (0x80 | (value >> 8)));
|
||||
Encode ((byte) value);
|
||||
return;
|
||||
}
|
||||
|
||||
Encode (value);
|
||||
}
|
||||
|
||||
public byte[] ToArray ()
|
||||
{
|
||||
byte[] buf = new byte[pos];
|
||||
Array.Copy (buffer, buf, pos);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AttributeEncoder : BlobEncoder
|
||||
{
|
||||
[Flags]
|
||||
public enum EncodedTypeProperties
|
||||
{
|
||||
None = 0,
|
||||
DynamicType = 1,
|
||||
TypeParameter = 1 << 1
|
||||
}
|
||||
|
||||
public static readonly byte[] Empty;
|
||||
|
||||
const ushort Version = 1;
|
||||
|
||||
static AttributeEncoder ()
|
||||
{
|
||||
Empty = new byte[4];
|
||||
Empty[0] = (byte) Version;
|
||||
}
|
||||
|
||||
public AttributeEncoder ()
|
||||
{
|
||||
Encode (Version);
|
||||
}
|
||||
|
||||
public EncodedTypeProperties Encode (TypeSpec type)
|
||||
{
|
||||
switch (type.BuiltinType) {
|
||||
@@ -1567,35 +1614,6 @@ namespace Mono.CSharp {
|
||||
{
|
||||
Encode ((ushort) 0);
|
||||
}
|
||||
|
||||
void Grow (int inc)
|
||||
{
|
||||
int size = System.Math.Max (pos * 4, pos + inc + 2);
|
||||
Array.Resize (ref buffer, size);
|
||||
}
|
||||
|
||||
void WriteCompressedValue (int value)
|
||||
{
|
||||
if (value < 0x80) {
|
||||
Encode ((byte) value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value < 0x4000) {
|
||||
Encode ((byte) (0x80 | (value >> 8)));
|
||||
Encode ((byte) value);
|
||||
return;
|
||||
}
|
||||
|
||||
Encode (value);
|
||||
}
|
||||
|
||||
public byte[] ToArray ()
|
||||
{
|
||||
byte[] buf = new byte[pos];
|
||||
Array.Copy (buffer, buf, pos);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3721,6 +3721,9 @@ namespace Mono.CSharp {
|
||||
get {
|
||||
return best_candidate;
|
||||
}
|
||||
set {
|
||||
best_candidate = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TypeSpec BestCandidateReturnType {
|
||||
|
||||
@@ -5865,6 +5865,22 @@ namespace Mono.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVariableReferenceIndex : IntConstant
|
||||
{
|
||||
LocalVariable lvi;
|
||||
|
||||
public LocalVariableReferenceIndex (BuiltinTypes types, LocalVariable lvi, Location loc)
|
||||
: base (types, -1, loc)
|
||||
{
|
||||
this.lvi = lvi;
|
||||
}
|
||||
|
||||
public override void Emit (EmitContext ec)
|
||||
{
|
||||
ec.EmitInt (lvi.LocalIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This represents a reference to a parameter in the intermediate
|
||||
/// representation.
|
||||
@@ -6224,6 +6240,10 @@ namespace Mono.CSharp
|
||||
return DoResolveDynamic (ec, member_expr);
|
||||
|
||||
var method = mg.BestCandidate;
|
||||
if (method.DeclaringType == ec.Module.PredefinedTypes.InlineAsm.TypeSpec) {
|
||||
return new InlineAsmStatement (arguments, mg.BestCandidate).Resolve (ec);
|
||||
}
|
||||
|
||||
type = mg.BestCandidateReturnType;
|
||||
|
||||
if (arguments == null && method.DeclaringType.BuiltinType == BuiltinTypeSpec.Type.Object && method.Name == Destructor.MetadataName) {
|
||||
@@ -11289,4 +11309,164 @@ namespace Mono.CSharp
|
||||
this.loc = loc;
|
||||
}
|
||||
}
|
||||
|
||||
class InlineAsmStatement : ExpressionStatement
|
||||
{
|
||||
readonly Arguments arguments;
|
||||
readonly MethodSpec method;
|
||||
|
||||
public InlineAsmStatement (Arguments arguments, MethodSpec method)
|
||||
{
|
||||
this.arguments = arguments;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public override Expression CreateExpressionTree (ResolveContext ec)
|
||||
{
|
||||
throw new NotSupportedException ("ET");
|
||||
}
|
||||
|
||||
protected override Expression DoResolve (ResolveContext rc)
|
||||
{
|
||||
// TODO: Add proper arguments checks
|
||||
var c = arguments[0].Expr as Constant;
|
||||
if (c == null)
|
||||
throw new ArgumentException ();
|
||||
|
||||
c = arguments[1].Expr as Constant;
|
||||
if (c == null)
|
||||
throw new NotImplementedException ();
|
||||
|
||||
if (c.GetValueAsLiteral () == null)
|
||||
throw new NotImplementedException ();
|
||||
|
||||
var args = arguments[2].Expr;
|
||||
var args_array = args as ArrayCreation;
|
||||
if (args_array == null)
|
||||
throw new NotImplementedException ();
|
||||
|
||||
PredefinedType flags_type;
|
||||
switch (method.Name) {
|
||||
case "Arm":
|
||||
flags_type = rc.Module.PredefinedTypes.AsmArm;
|
||||
break;
|
||||
case "X86":
|
||||
flags_type = rc.Module.PredefinedTypes.AsmX86;
|
||||
break;
|
||||
case "Amd64":
|
||||
flags_type = rc.Module.PredefinedTypes.AsmAmd64;
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
var elements = args_array.Initializers.Elements;
|
||||
for (int i = 0; i < elements.Count / 2; ++i) {
|
||||
var expr = elements[i * 2];
|
||||
expr = ExtractInlineAsmArgument (rc, expr);
|
||||
if (expr == null)
|
||||
break;
|
||||
|
||||
elements[i * 2] = expr;
|
||||
|
||||
c = elements[i * 2 + 1] as Constant;
|
||||
if (c == null)
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
if (elements.Count % 2 != 0)
|
||||
rc.Report.Error (-101, args_array.Location, "Every argument requires associated `{0}' to be specified", flags_type.GetSignatureForError ());
|
||||
|
||||
type = rc.Module.Compiler.BuiltinTypes.Void;
|
||||
eclass = ExprClass.Value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override void EmitStatement (EmitContext ec)
|
||||
{
|
||||
var enc = new BlobEncoder ();
|
||||
enc.Encode ((byte) 1); // version
|
||||
|
||||
var c = (Constant) arguments[0].Expr;
|
||||
enc.Encode ((int) c.GetValueAsLong ()); // options
|
||||
|
||||
var args_array = (ArrayCreation) arguments[2].Expr;
|
||||
|
||||
var elements = args_array.Initializers.Elements;
|
||||
var count = elements.Count / 2;
|
||||
// TODO: Why byte?
|
||||
enc.Encode ((byte) count); // arguments count
|
||||
for (int i = 0; i < count; ++i) {
|
||||
// argument type
|
||||
EncodeInlineAsmArgument (enc, elements[i * 2]);
|
||||
|
||||
c = (Constant) elements[i * 2 + 1];
|
||||
// argument options
|
||||
enc.Encode ((int) c.GetValueAsLong ());
|
||||
}
|
||||
|
||||
c = (Constant) arguments[1].Expr;
|
||||
var code = c.GetValueAsLiteral ();
|
||||
|
||||
var fb = ec.CurrentTypeDefinition.Module.MakeInlineAsmData (enc.ToArray (), loc);
|
||||
ec.Emit (OpCodes.Ldtoken, fb);
|
||||
ec.Emit (OpCodes.Pop);
|
||||
}
|
||||
|
||||
static Expression ExtractInlineAsmArgument (ResolveContext rc, Expression expr)
|
||||
{
|
||||
var cast = expr as TypeCast;
|
||||
if (cast != null)
|
||||
return ExtractInlineAsmArgument (rc, cast.Child);
|
||||
|
||||
// TODO: check for hoisted version
|
||||
// TODO: reject out/ref parameters?
|
||||
if (expr is ParameterReference)
|
||||
return expr;
|
||||
|
||||
// TODO: check for hoisted version
|
||||
// TODO: check for local constant?
|
||||
// TODO: check for locked foreach/using variable
|
||||
if (expr is LocalVariableReference)
|
||||
return expr;
|
||||
|
||||
rc.Report.Error (-100, expr.Location, "Parameter binder argument must be local variable or parameter reference");
|
||||
return null;
|
||||
}
|
||||
|
||||
static void EncodeInlineAsmArgument (BlobEncoder encoder, Expression expr)
|
||||
{
|
||||
var pr = expr as ParameterReference;
|
||||
if (pr != null) {
|
||||
encoder.Encode ((byte) 0);
|
||||
encoder.WriteCompressedValue (pr.Parameter.PositionalIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
var lv = expr as LocalVariableReference;
|
||||
if (lv != null) {
|
||||
// TODO: check for hoisted version
|
||||
// TODO: check for local constant?
|
||||
// TODO: check for locked foreach/using variable
|
||||
encoder.Encode ((byte) 1);
|
||||
encoder.WriteCompressedValue (lv.local_info.LocalIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InternalErrorException ();
|
||||
}
|
||||
|
||||
static void EncodeInlineAsmCode (BlobEncoder enc, string code)
|
||||
{
|
||||
// TODO: Get it from external lib
|
||||
byte[] bcode = new byte[] { 1, 2, 3 };
|
||||
enc.WriteCompressedValue (bcode.Length);
|
||||
enc.Add (bcode);
|
||||
}
|
||||
|
||||
public override void Emit (EmitContext ec)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -41,8 +41,8 @@ namespace Mono.CSharp
|
||||
readonly Dictionary<int, Struct> size_types;
|
||||
int fields;
|
||||
|
||||
public StaticDataContainer (ModuleContainer module)
|
||||
: base (module, new MemberName ("<PrivateImplementationDetails>" + module.builder.ModuleVersionId.ToString ("B"), Location.Null),
|
||||
public StaticDataContainer (ModuleContainer module, string containerName = "<PrivateImplementationDetails>")
|
||||
: base (module, new MemberName (containerName + module.builder.ModuleVersionId.ToString ("B"), Location.Null),
|
||||
Modifiers.STATIC | Modifiers.INTERNAL)
|
||||
{
|
||||
size_types = new Dictionary<int, Struct> ();
|
||||
@@ -87,6 +87,7 @@ namespace Mono.CSharp
|
||||
}
|
||||
|
||||
StaticDataContainer static_data;
|
||||
StaticDataContainer inline_asm_data;
|
||||
|
||||
//
|
||||
// Makes const data field inside internal type container
|
||||
@@ -103,6 +104,19 @@ namespace Mono.CSharp
|
||||
|
||||
return static_data.DefineInitializedData (data, loc);
|
||||
}
|
||||
|
||||
public FieldSpec MakeInlineAsmData (byte[] data, Location loc)
|
||||
{
|
||||
if (inline_asm_data == null) {
|
||||
inline_asm_data = new StaticDataContainer (this, "<InlineAsmData>");
|
||||
inline_asm_data.CreateContainer ();
|
||||
inline_asm_data.DefineContainer ();
|
||||
|
||||
AddCompilerGeneratedClass (inline_asm_data);
|
||||
}
|
||||
|
||||
return inline_asm_data.DefineInitializedData (data, loc);
|
||||
}
|
||||
#endif
|
||||
|
||||
public CharSet? DefaultCharSet;
|
||||
|
||||
@@ -570,6 +570,12 @@ namespace Mono.CSharp {
|
||||
}
|
||||
}
|
||||
|
||||
public int PositionalIndex {
|
||||
get {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
|
||||
public Modifier ModFlags {
|
||||
get { return modFlags & ~Modifier.This; }
|
||||
}
|
||||
|
||||
@@ -2436,6 +2436,12 @@ namespace Mono.CSharp {
|
||||
}
|
||||
}
|
||||
|
||||
public int LocalIndex {
|
||||
get {
|
||||
return builder.LocalIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return name;
|
||||
|
||||
@@ -234,6 +234,14 @@ namespace Mono.CSharp
|
||||
public readonly PredefinedType INotifyCompletion;
|
||||
public readonly PredefinedType ICriticalNotifyCompletion;
|
||||
|
||||
//
|
||||
// Mono extensions
|
||||
//
|
||||
public readonly PredefinedType AsmAmd64;
|
||||
public readonly PredefinedType AsmX86;
|
||||
public readonly PredefinedType AsmArm;
|
||||
public readonly PredefinedType InlineAsm;
|
||||
|
||||
public PredefinedTypes (ModuleContainer module)
|
||||
{
|
||||
TypedReference = new PredefinedType (module, MemberKind.Struct, "System", "TypedReference");
|
||||
@@ -287,6 +295,11 @@ namespace Mono.CSharp
|
||||
INotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "INotifyCompletion");
|
||||
ICriticalNotifyCompletion = new PredefinedType (module, MemberKind.Interface, "System.Runtime.CompilerServices", "ICriticalNotifyCompletion");
|
||||
|
||||
InlineAsm = new PredefinedType (module, MemberKind.Class, "Mono.Runtime", "InlineAsm");
|
||||
AsmAmd64 = new PredefinedType (module, MemberKind.Enum, "Mono.Runtime", "Amd64Asm");
|
||||
AsmX86 = new PredefinedType (module, MemberKind.Enum, "Mono.Runtime", "X86Asm");
|
||||
AsmArm = new PredefinedType (module, MemberKind.Enum, "Mono.Runtime", "ArmAsm");
|
||||
|
||||
//
|
||||
// Define types which are used for comparison. It does not matter
|
||||
// if they don't exist as no error report is needed
|
||||
@@ -321,6 +334,8 @@ namespace Mono.CSharp
|
||||
Task.Define ();
|
||||
if (TaskGeneric.Define ())
|
||||
TaskGeneric.TypeSpec.IsGenericTask = true;
|
||||
|
||||
InlineAsm.Define ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,6 +406,7 @@ namespace Mono.CSharp
|
||||
var types = module.PredefinedTypes;
|
||||
var atypes = module.PredefinedAttributes;
|
||||
var btypes = module.Compiler.BuiltinTypes;
|
||||
var void_star = PointerContainer.MakeType (module, btypes.Void);
|
||||
|
||||
var tp = new TypeParameter (0, new MemberName ("T"), null, null, Variance.None);
|
||||
|
||||
|
||||
Reference in new issue
Block a user