예제 #1
0
        private static Instruction GetLocalInstruction(WasmFunctionBuilder functionBuilder, string localName)
        {
            // TODO: Determine correct type
            var localIndex = functionBuilder.GetLocalIndex(localName, WebAssembly.ValueType.Int32);

            return(new GetLocal(localIndex));
        }
예제 #2
0
        private static void CompileMethod(Mono.Cecil.MethodDefinition sourceMethod, WasmModuleBuilder wasmBuilder)
        {
            Console.WriteLine($"Compiling { sourceMethod.FullName }...");
            var fn = new WasmFunctionBuilder(sourceMethod.FullName, wasmBuilder)
            {
                ExportName = sourceMethod.IsPublic ? $"{sourceMethod.DeclaringType.Name}::{FormatMethodSignature(sourceMethod)}" : null,
                ResultType = ToWebAssemblyType(sourceMethod.ReturnType)
            };

            var paramTypes = sourceMethod.Parameters.Select(p => ToWebAssemblyType(p.ParameterType).Value);

            if (sourceMethod.HasThis)
            {
                paramTypes = paramTypes.Prepend(WebAssembly.ValueType.Int32); // "this"
            }

            var paramIndex = 0;

            foreach (var paramType in paramTypes)
            {
                fn.AddParameter(paramType);
                fn.GetLocalIndex($"arg{paramIndex}", paramType);
                paramIndex++;
            }

            fn.Instructions.AddRange(
                MethodBodyCompiler.Compile(sourceMethod, wasmBuilder, fn));

            ReplaceWithJSInteropCall(sourceMethod);
        }
예제 #3
0
        private static Instruction StoreLocalInstruction(WasmFunctionBuilder functionBuilder, string localName)
        {
            var localIndex = functionBuilder.GetLocalIndex(localName, WebAssembly.ValueType.Int32);

            return(new SetLocal(localIndex));
        }