diff options
author | Blealtan <blealtan@outlook.com> | 2018-02-03 08:15:17 +0300 |
---|---|---|
committer | Morgan Brown <morganbr@users.noreply.github.com> | 2018-02-03 08:15:17 +0300 |
commit | 3470b34c127f1709180ce018ba2dfd3c860412cf (patch) | |
tree | bf53d1ea0ff4ee9931d441222a49cf6a2c5a46a9 /src/ILCompiler.WebAssembly | |
parent | 569871f97d8f003e9cddd25e231f7f16bacd2a43 (diff) |
Implement castclass & isinst for WebAssembly (#5325)
* Implement castclass & isinst for wasm (#4510)
Implement castclass and isinst opcodes in ILToWebAssemblyImporter by
doing related function calls to methods in System.Runtime.TypeCast.
Fix #4510
Add castclass & isinst test in HelloWasm.
This includes three types of casting:
* castclass/isinst to classes.
* castclass/isinst to interfaces.
* castclass/isinst to array types.
For now, the second and third part of test is failing due to runtime
implementation problems which should be further digged into.
Diffstat (limited to 'src/ILCompiler.WebAssembly')
-rw-r--r-- | src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs index c31744076..a24c1efe9 100644 --- a/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs +++ b/src/ILCompiler.WebAssembly/src/CodeGen/ILToWebAssemblyImporter.cs @@ -818,6 +818,25 @@ namespace Internal.IL private void ImportCasting(ILOpcode opcode, int token) { + TypeDesc type = ResolveTypeToken(token); + + //TODO: call GetCastingHelperNameForType from JitHelper.cs (needs refactoring) + string function; + bool throwing = opcode == ILOpcode.castclass; + if (type.IsArray) + function = throwing ? "CheckCastArray" : "IsInstanceOfArray"; + else if (type.IsInterface) + function = throwing ? "CheckCastInterface" : "IsInstanceOfInterface"; + else + function = throwing ? "CheckCastClass" : "IsInstanceOfClass"; + + var arguments = new StackEntry[] + { + _stack.Pop(), + new LoadExpressionEntry(StackValueKind.ValueType, "eeType", GetEETypePointerForTypeDesc(type, true), _compilation.TypeSystemContext.SystemModule.GetKnownType("System", "EETypePtr")) + }; + + _stack.Push(CallRuntime(_compilation.TypeSystemContext, TypeCast, function, arguments, type)); } private void ImportLoadNull() @@ -2344,6 +2363,7 @@ namespace Internal.IL private const string RuntimeExport = "RuntimeExports"; private const string RuntimeImport = "RuntimeImports"; private const string InternalCalls = "InternalCalls"; + private const string TypeCast = "TypeCast"; private ExpressionEntry CallRuntime(TypeSystemContext context, string className, string methodName, StackEntry[] arguments, TypeDesc forcedReturnType = null) { MetadataType helperType = context.SystemModule.GetKnownType("System.Runtime", className); |