initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 01c1358bf558f42a9aa5cba53bcd9331
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using Unity.CompilationPipeline.Common.Diagnostics;
|
||||
using Unity.CompilationPipeline.Common.ILPostProcessing;
|
||||
|
||||
namespace Unity.Collections.UnsafeUtility.CodeGen
|
||||
{
|
||||
internal class CollectionsUnsafeUtilityPostProcessor : ILPostProcessor
|
||||
{
|
||||
private static CollectionsUnsafeUtilityPostProcessor s_Instance;
|
||||
|
||||
public override ILPostProcessor GetInstance()
|
||||
{
|
||||
if (s_Instance == null)
|
||||
s_Instance = new CollectionsUnsafeUtilityPostProcessor();
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
public override bool WillProcess(ICompiledAssembly compiledAssembly)
|
||||
{
|
||||
if (compiledAssembly.Name == "Unity.Collections.LowLevel.ILSupport")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
|
||||
{
|
||||
if (!WillProcess(compiledAssembly))
|
||||
return null;
|
||||
|
||||
var assemblyDefinition = AssemblyDefinitionFor(compiledAssembly);
|
||||
|
||||
var ilSupportType = assemblyDefinition.MainModule.Types.FirstOrDefault(t => t.FullName == "Unity.Collections.LowLevel.Unsafe.ILSupport");
|
||||
if (ilSupportType == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
InjectUtilityAddressOfIn(ilSupportType);
|
||||
InjectUtilityAsRefIn(ilSupportType);
|
||||
|
||||
var pe = new MemoryStream();
|
||||
var pdb = new MemoryStream();
|
||||
var writerParameters = new WriterParameters
|
||||
{
|
||||
SymbolWriterProvider = new PortablePdbWriterProvider(), SymbolStream = pdb, WriteSymbols = true
|
||||
};
|
||||
|
||||
assemblyDefinition.Write(pe, writerParameters);
|
||||
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()));
|
||||
}
|
||||
|
||||
private void InjectUtilityAddressOfIn(TypeDefinition ctx)
|
||||
{
|
||||
var method = ctx.Methods.Single(m => m.Name.Equals("AddressOf") && m.Parameters[0].IsIn);
|
||||
var il = GetILProcessorForMethod(method);
|
||||
|
||||
il.Append(il.Create(OpCodes.Ldarg_0));
|
||||
il.Append(il.Create(OpCodes.Ret));
|
||||
}
|
||||
|
||||
private void InjectUtilityAsRefIn(TypeDefinition ctx)
|
||||
{
|
||||
var method = ctx.Methods.Single(m => m.Name.Equals("AsRef") && m.Parameters[0].IsIn);
|
||||
var il = GetILProcessorForMethod(method);
|
||||
|
||||
il.Append(il.Create(OpCodes.Ldarg_0));
|
||||
il.Append(il.Create(OpCodes.Ret));
|
||||
}
|
||||
|
||||
internal static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compiledAssembly)
|
||||
{
|
||||
var readerParameters = new ReaderParameters
|
||||
{
|
||||
SymbolStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PdbData.ToArray()),
|
||||
SymbolReaderProvider = new PortablePdbReaderProvider(),
|
||||
ReadingMode = ReadingMode.Immediate
|
||||
};
|
||||
|
||||
var peStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PeData.ToArray());
|
||||
var assemblyDefinition = AssemblyDefinition.ReadAssembly(peStream, readerParameters);
|
||||
|
||||
return assemblyDefinition;
|
||||
}
|
||||
|
||||
private static ILProcessor GetILProcessorForMethod(TypeDefinition ctx, string methodName, bool clear = true)
|
||||
{
|
||||
var method = ctx.Methods.Single(m => m.Name.Equals(methodName) && m.HasGenericParameters);
|
||||
return GetILProcessorForMethod(method, clear);
|
||||
}
|
||||
|
||||
private static ILProcessor GetILProcessorForMethod(MethodDefinition method, bool clear = true)
|
||||
{
|
||||
var ilProcessor = method.Body.GetILProcessor();
|
||||
|
||||
if (clear)
|
||||
{
|
||||
ilProcessor.Body.Instructions.Clear();
|
||||
ilProcessor.Body.Variables.Clear();
|
||||
ilProcessor.Body.ExceptionHandlers.Clear();
|
||||
}
|
||||
|
||||
return ilProcessor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c40712b5124e4c33b9040e81f566b22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "Unity.Collections.LowLevel.ILSupport.CodeGen",
|
||||
"references": [
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"Mono.Cecil.dll",
|
||||
"Mono.Cecil.Rocks.dll",
|
||||
"Mono.Cecil.Pdb.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 851faa33f0fe11de69f86c5599d17c88
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 38f5d8a8dc0e00d1fb83ec98cc122c85
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.Collections")]
|
||||
|
||||
namespace Unity.Collections.LowLevel.Unsafe
|
||||
{
|
||||
internal unsafe static class ILSupport
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void* AddressOf<T>(in T thing)
|
||||
where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ref T AsRef<T>(in T thing)
|
||||
where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ed138ce0eef88e8898615fee7b8acf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "Unity.Collections.LowLevel.ILSupport",
|
||||
"references": [
|
||||
],
|
||||
"includePlatforms": [
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"autoReferenced": false,
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": true
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 231b25ba64524e26aa697960dbc7d0d0
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue