Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Implement simple casting #14

Merged
merged 1 commit into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ILToNative/reproNative/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extern "C" Object * __allocate_array(MethodTable * pMT, size_t elements);
__declspec(noreturn) void __throw_exception(void * pEx);
Object * __load_string_literal(const char * string);

Object * __castclass_class(void * p, MethodTable * pMT);
Object * __isinst_class(void * p, MethodTable * pMT);
extern "C" Object * __castclass_class(void * p, MethodTable * pMT);
extern "C" Object * __isinst_class(void * p, MethodTable * pMT);

void __range_check(void * a, size_t elem);

Expand Down
4 changes: 2 additions & 2 deletions src/ILToNative/reproNative/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Object * __load_string_literal(const char * string)

// TODO: Rewrite in C#

Object * __castclass_class(void * p, MethodTable * pTargetMT)
extern "C" Object * __castclass_class(void * p, MethodTable * pTargetMT)
{
Object * o = (Object *)p;

Expand All @@ -259,7 +259,7 @@ Object * __castclass_class(void * p, MethodTable * pTargetMT)
throw 1;
}

Object * __isinst_class(void * p, MethodTable * pTargetMT)
extern "C" Object * __isinst_class(void * p, MethodTable * pTargetMT)
{
Object * o = (Object *)p;

Expand Down
28 changes: 27 additions & 1 deletion src/ILToNative/src/Compiler/AsmWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,28 @@ void OutputReadyToHelpers()
}

Debug.Assert(methodSlot != -1);
Out.Write(8 /* sizeof(EEType */ + (baseSlots + methodSlot) * _typeSystemContext.Target.PointerSize);
Out.Write(16 /* sizeof(EEType */ + (baseSlots + methodSlot) * _typeSystemContext.Target.PointerSize);
}

Out.WriteLine("(%rax)");
break;

case ReadyToRunHelperId.IsInstanceOf:
Out.Write("leaq __EEType_");
Out.Write(GetMangledTypeName((TypeDesc)helper.Target));
Out.WriteLine("(%rip), %rdx");

Out.WriteLine("jmp __isinst_class");
break;

case ReadyToRunHelperId.CastClass:
Out.Write("leaq __EEType_");
Out.Write(GetMangledTypeName((TypeDesc)helper.Target));
Out.WriteLine("(%rip), %rdx");

Out.WriteLine("jmp __castclass_class");
break;

default:
throw new NotImplementedException();
}
Expand All @@ -227,6 +243,16 @@ void OutputEETypes()

Out.WriteLine(".int 0, 24");

if (t.Type.BaseType != null)
{
Out.Write(".quad __EEType_");
Out.WriteLine(GetMangledTypeName(t.Type.BaseType));
}
else
{
Out.WriteLine(".quad 0");
}

if (t.Constructed)
OutputVirtualSlots(t.Type, t.Type);

Expand Down
8 changes: 7 additions & 1 deletion src/ILToNative/src/Compiler/ReadyToRunHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace ILToNative
public enum ReadyToRunHelperId
{
NewHelper,
VirtualCall
VirtualCall,
IsInstanceOf,
CastClass,
}

class ReadyToRunHelper
Expand Down Expand Up @@ -42,6 +44,10 @@ public string MangledName
return "__NewHelper_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
case ReadyToRunHelperId.VirtualCall:
return "__VirtualCall_" + _compilation.GetMangledMethodName((MethodDesc)this.Target);
case ReadyToRunHelperId.IsInstanceOf:
return "__IsInstanceOf_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
case ReadyToRunHelperId.CastClass:
return "__CastClass_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
default:
throw new NotImplementedException();
}
Expand Down
21 changes: 20 additions & 1 deletion src/JitInterface/src/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,22 @@ void getReadyToRunHelper(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken
pLookup.addr = (void*)ObjectToHandle(_compilation.GetReadyToRunHelper(ReadyToRunHelperId.NewHelper, type));
}
break;
case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_ISINSTANCEOF:
{
var type = HandleToObject(pResolvedToken.hClass);
_compilation.AddType(type);

pLookup.addr = (void*)ObjectToHandle(_compilation.GetReadyToRunHelper(ReadyToRunHelperId.IsInstanceOf, type));
}
break;
case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_CHKCAST:
{
var type = HandleToObject(pResolvedToken.hClass);
_compilation.AddType(type);

pLookup.addr = (void*)ObjectToHandle(_compilation.GetReadyToRunHelper(ReadyToRunHelperId.CastClass, type));
}
break;
default:
throw new NotImplementedException();
}
Expand Down Expand Up @@ -749,7 +765,10 @@ uint getArrayRank(IntPtr _this, CORINFO_CLASS_STRUCT_* cls)
void* getArrayInitializationData(IntPtr _this, CORINFO_FIELD_STRUCT_* field, uint size)
{ throw new NotImplementedException(); }
CorInfoIsAccessAllowedResult canAccessClass(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_METHOD_STRUCT_* callerHandle, ref CORINFO_HELPER_DESC pAccessHelper)
{ throw new NotImplementedException(); }
{
// TODO: Access check
return CorInfoIsAccessAllowedResult.CORINFO_ACCESS_ALLOWED;
}

byte* getFieldName(IntPtr _this, CORINFO_FIELD_STRUCT_* ftn, byte** moduleName)
{
Expand Down