Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/CosmosOS/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fanoI committed Jan 4, 2016
2 parents f4d627d + 438ac96 commit 0d07f9b
Show file tree
Hide file tree
Showing 17 changed files with 456 additions and 468 deletions.
6 changes: 6 additions & 0 deletions source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@
<Compile Include="System\Assemblers\Array_get_Length.cs" />
<Compile Include="System\Assemblers\Array_InternalCopy.cs" />
<Compile Include="System\Assemblers\Buffer_BlockCopy.cs" />
<Compile Include="System\Assemblers\DelegateImpl.cs" />
<Compile Include="System\Assemblers\GetMulticastInvokeAssembler.cs" />
<Compile Include="System\Assemblers\InvokeImplAssembler.cs" />
<Compile Include="System\Assemblers\MulticastDelegate_Invoke.cs" />
<Compile Include="System\Buffer.cs" />
<Compile Include="System\DelegateImpl.cs" />
<Compile Include="System\MulticastDelegateImpl.cs" />
<Compile Include="System\NormalDelegateImpl.cs" />
<Compile Include="System\StringImpl.cs" />
<Compile Include="GCImplementionImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
27 changes: 27 additions & 0 deletions source/Cosmos.Core.Plugs/System/Assemblers/DelegateImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

using Cosmos.IL2CPU.Plugs;
using Cosmos.IL2CPU.Plugs.Assemblers;

namespace Cosmos.Core.Plugs.System.Assemblers
{
[Plug(Target = typeof(Delegate), Inheritable = true)]
[PlugField(FieldType = typeof(int), FieldId = "$$ArgSize$$")]
public static class DelegateImpl
{

[PlugMethod(Assembler = typeof(CtorImplAssembler), IsWildcard = true, WildcardMatchParameters = true)]
public static void Ctor(Delegate aThis, object aTarget, IntPtr aMethod)
{
//aFldTarget = aObject;
//aFldMethod = aMethod;
throw new NotImplementedException("Implemented by method assembler");
}

[PlugMethod(IsWildcard = true, Assembler = typeof(InvokeImplAssembler))]
public static void Invoke()
{
throw new NotImplementedException("Implemented by method assembler");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Reflection;

using Cosmos.IL2CPU;
using Cosmos.IL2CPU.Plugs;

using CPUx86 = Cosmos.Assembler.x86;
using MethodInfo = Cosmos.IL2CPU.MethodInfo;

namespace Cosmos.IL2CPU.Plugs.Assemblers
namespace Cosmos.Core.Plugs.System.Assemblers
{
public class GetMulticastInvokeAssembler: AssemblerMethod
public class GetMulticastInvokeAssembler : AssemblerMethod
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
Expand Down
315 changes: 315 additions & 0 deletions source/Cosmos.Core.Plugs/System/Assemblers/InvokeImplAssembler.cs

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions source/Cosmos.Core.Plugs/System/DelegateImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;

using Cosmos.IL2CPU;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.Core.Plugs.System
{
[Plug(Target = typeof(Delegate))]
//[PlugField(FieldId = "$$Method$$", FieldType = typeof(object))]
//[PlugField(FieldId = "$$Object$$", FieldType = typeof(object))]
[PlugField(FieldType = typeof(int), FieldId = "$$ReturnsValue$$")]
public static class DelegateImpl
{

[PlugMethod(Signature = "System_MulticastDelegate__System_Delegate_InternalAllocLike_System_Delegate_")]
public unsafe static uint InternalAllocLike(uint* aDelegate)
{
uint xNeededSize = 1024; // 24 is needed fields for Multicast Delegate
xNeededSize += 12;
uint xResultAddr = GCImplementation.AllocNewObject(xNeededSize);
byte* xResult = (byte*)xResultAddr;
byte* xDelegateAsByte = (byte*)aDelegate;
for (int i = 0; i < 1024; i++)
{
xResult[i] = xDelegateAsByte[i];
}
return xResultAddr;
}

//[PlugMethod(Signature = "System_Void__System_Delegate__ctor___")]
//public static void Ctor(Delegate d, [FieldAccess(Name = "$$ReturnsValue$$")] ref bool hasReturnvalue)
//{
// hasReturnvalue = d.Method.ReturnType != typeof(void);
//}

public static IntPtr GetInvokeMethod(Delegate aThis)
{
return IntPtr.Zero;
}

public static bool Equals(Delegate aThis, object aThat)
{
// todo: implement proper Delegate.Equals(object)
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using System;

namespace Cosmos.IL2CPU.Plugs.System {

[Plug(Target = typeof(MulticastDelegate))]
// [PlugField(FieldType = typeof(int), FieldId = "$$ArgSize$$")]
public class MulticastDelegateImpl {

// there is no such thing as MulticastDelegate.InvokeMulticase. New scanner is more strict
// so I commented this out for now.
//[PlugMethod(Assembler = typeof(Assemblers.MulticastDelegate_Invoke, IsWildcard=true))]
//public static void InvokeMulticast(MulticastDelegate aThis) {
// throw new Exception("This method should be implemented using a MethodAssembler");
//}

public static bool Equals(MulticastDelegate aThis, object aThat) {
// todo: implement MulticastDelegate.Equals(MulticastDelegate)
return false;
}
}
}
using System;

namespace Cosmos.IL2CPU.Plugs.System {

[Plug(Target = typeof(MulticastDelegate))]
// [PlugField(FieldType = typeof(int), FieldId = "$$ArgSize$$")]
public class MulticastDelegateImpl {

// there is no such thing as MulticastDelegate.InvokeMulticase. New scanner is more strict
// so I commented this out for now.
//[PlugMethod(Assembler = typeof(Assemblers.MulticastDelegate_Invoke, IsWildcard=true))]
//public static void InvokeMulticast(MulticastDelegate aThis) {
// throw new Exception("This method should be implemented using a MethodAssembler");
//}

public static bool Equals(MulticastDelegate aThis, object aThat) {
// todo: implement MulticastDelegate.Equals(MulticastDelegate)
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;

using Cosmos.Core.Plugs.System.Assemblers;
using Cosmos.IL2CPU.Plugs.Assemblers;

namespace Cosmos.IL2CPU.Plugs.System
{
[Plug(Target=typeof(Delegate))]
[Plug(Target = typeof(Delegate))]
public static class NormalDelegateImpl
{
[PlugMethod(Assembler = typeof(GetMulticastInvokeAssembler))]
Expand All @@ -13,4 +14,4 @@ public static IntPtr GetMulticastInvoke(Delegate aThis)
return IntPtr.Zero;
}
}
}
}
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/CompilerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public bool Execute()
using (var xScanner = new ILScanner(xAsm))
{
xScanner.LogException = LogException;
xScanner.TempDebug += x => LogMessage(x);
CompilerHelpers.DebugEvent += LogMessage;
if (EnableLogging)
{
var xLogFile = xOutputFilename + ".log.html";
Expand Down
44 changes: 20 additions & 24 deletions source/Cosmos.IL2CPU/CompilerHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
using global::System.Diagnostics;
using System;

using global::System.Diagnostics;

namespace Cosmos.IL2CPU
{
public static class CompilerHelpers
{
private static global::Cosmos.Debug.Kernel.Debugger mDebugger = new global::Cosmos.Debug.Kernel.Debugger("IL2CPU", "Debug");
public static event Action<string> DebugEvent;

private static void DoDebug(string message)
{
if (DebugEvent != null)
{
DebugEvent(message);
}
else
{
global::System.Diagnostics.Debug.WriteLine(message);
}
}

[Conditional("COSMOSDEBUG")]
public static void Debug(string aMessage, params object[] aParams)
Expand All @@ -13,42 +27,24 @@ public static void Debug(string aMessage, params object[] aParams)

if (aParams != null)
{
aMessage = aMessage + " : ";
xMessage = xMessage + " : ";
for (int i = 0; i < aParams.Length; i++)
{
string xParam = aParams[i].ToString();
if (!string.IsNullOrWhiteSpace(xParam))
{
aMessage = aMessage + " " + xParam;
xMessage = xMessage + " " + xParam;
}
}
}

mDebugger.Send("FileSystem Trace: " + aMessage);
DoDebug(xMessage);
}

[Conditional("COSMOSDEBUG")]
public static void Debug(string aMessage)
{
mDebugger.Send("FAT Debug: " + aMessage);
}

[Conditional("COSMOSDEBUG")]
public static void DebugNumber(uint aValue)
{
mDebugger.SendNumber(aValue);
}

[Conditional("COSMOSDEBUG")]
public static void DebugNumber(ulong aValue)
{
mDebugger.Send(((uint)aValue).ToString() + ((uint)aValue >> 32).ToString());
}

[Conditional("COSMOSDEBUG")]
public static void DevDebug(string message)
{
mDebugger.Send("FAT DevDebug: " + message);
DoDebug(aMessage);
}
}
}
9 changes: 1 addition & 8 deletions source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
<Compile Include="CompilerExtensionAttribute.cs" />
<Compile Include="CompilerExtensionBase.cs" />
<Compile Include="Plugs\AssemblerImpl.cs" />
<Compile Include="Plugs\System\ArrayImpl.cs" />
<Compile Include="Plugs\System\EnvironmentImpl.cs">
<SubType>
</SubType>
Expand Down Expand Up @@ -339,15 +338,9 @@
<Compile Include="Plugs\Diagnostics\DebuggerImpl.cs" />
<Compile Include="Plugs\Diagnostics\DebugImpl.cs" />
<Compile Include="Plugs\Assemblers\CtorImplAssembler.cs" />
<Compile Include="Plugs\Assemblers\DelegateImpl.cs" />
<Compile Include="Plugs\Assemblers\GetMulticastInvokeAssembler.cs" />
<Compile Include="Plugs\Assemblers\InvokeImplAssembler.cs" />
<Compile Include="Plugs\System\NormalDelegateImpl.cs" />
<Compile Include="Plugs\System\Runtime\CompilerServices\RuntimeHelpersImpl.cs" />
<Compile Include="Plugs\System\DelegateImpl.cs" />
<Compile Include="Plugs\System\EventHandlerImpl.cs" />
<Compile Include="Plugs\System\ExceptionImpl.cs" />
<Compile Include="Plugs\System\MulticastDelegateImpl.cs" />
<Compile Include="Plugs\System\OutOfMemoryExceptionImpl.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -416,4 +409,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
24 changes: 6 additions & 18 deletions source/Cosmos.IL2CPU/ILScanner.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
#define COSMOSDEBUG

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Cosmos.IL2CPU;

using Cosmos.IL2CPU.Plugs;
using SR = System.Reflection;
using Cosmos.Assembler;
using System.Reflection.Emit;

using _MemberInfo = System.Runtime.InteropServices._MemberInfo;
using SysReflection = System.Reflection;

Expand Down Expand Up @@ -140,19 +141,6 @@ protected void Queue(_MemberInfo aItem, object aSrc, string aSrcType, string sou
}
}

public event Action<string> TempDebug;
private void DoTempDebug(string message)
{
if (TempDebug != null)
{
TempDebug(message);
}
else
{
global::System.Diagnostics.Debug.WriteLine(message);
}
}

public void Execute(SysReflection.MethodBase aStartMethod)
{
if (aStartMethod == null)
Expand Down Expand Up @@ -215,7 +203,7 @@ public void Execute(SysReflection.MethodBase aStartMethod)
mPlugManager.ScanFoundPlugs();
foreach (var xPlug in mPlugManager.PlugImpls)
{
DoTempDebug(String.Format("Plug found: '{0}'", xPlug.Key.FullName));
CompilerHelpers.Debug($"Plug found: '{xPlug.Key.FullName}'");
}

ILOp.mPlugManager = mPlugManager;
Expand Down
1 change: 1 addition & 0 deletions source/Cosmos.IL2CPU/PlugManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ public MethodBase ResolvePlug(Type aTargetType, List<Type> aImpls, MethodBase aM
{
if (Queue != null)
{
CompilerHelpers.Debug("Queueing Plug:", xResult.DeclaringType, "::", xResult.Name);
Queue(xResult, null, "Plug Method");
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/Plugs/Assemblers/CtorImplAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
Stfld.DoExecute(xAssembler, xMethodInfo, "$$ArgSize$$", xMethodInfo.MethodBase.DeclaringType, true, false);


//public static void Ctor(Delegate aThis, object aObject, IntPtr aMethod,
//[FieldAccess(Name = "System.Object System.Delegate._target")] ref object aFldTarget,
//public static void Ctor(Delegate aThis, object aObject, IntPtr aMethod,
//[FieldAccess(Name = "System.Object System.Delegate._target")] ref object aFldTarget,
//[FieldAccess(Name = "System.IntPtr System.Delegate._methodPtr")] ref IntPtr aFldMethod) {
}
}
Expand Down
20 changes: 0 additions & 20 deletions source/Cosmos.IL2CPU/Plugs/Assemblers/DelegateImpl.cs

This file was deleted.

Loading

0 comments on commit 0d07f9b

Please sign in to comment.