Ejemplo n.º 1
0
        void ParseTypeSection(BinaryReader reader)
        {
            int num_types = Convert.ToInt32(Parser.ParseLEBSigned(reader, 32));

            Console.WriteLine("Parse type section:  #types: {0}", num_types);

            this.types = new WebassemblyFunctionType [num_types];

            for (int i = 0; i < num_types; i++)
            {
                var form       = Parser.ParseLEBSigned(reader, 7);
                var parameters = Parser.ParseLEBUnsignedArray(reader);
                var results    = Parser.ParseLEBUnsignedArray(reader);
                var type       = new WebassemblyFunctionType(form, parameters, results);
                this.types [i] = type;
            }
        }
Ejemplo n.º 2
0
        public MethodInfo Emit(WebassemblyFunctionType type, TypeBuilder tb, string name)
        {
            var param_types = type.EmitParams();
            var return_type = type.EmitReturn();
            var method      = tb.DefineMethod(name, MethodAttributes.Public, return_type, param_types);
            var ilgen       = method.GetILGenerator();

            var outputLocals = new LocalBuilder [num_locals];
            var index        = 0;

            for (int i = 0; i < locals.Length; i++)
            {
                var ty = locals [i].AsType();
                for (int j = 0; j < locals [i].Count; j++)
                {
                    outputLocals [index++] = ilgen.DeclareLocal(ty);
                }
            }

            expr.Body.Emit(ilgen, param_types != null ? param_types.Length : 0);

            return(method);
        }