Esempio n. 1
0
        /// <summary>
        /// Reads the code section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <param name="Reader">A reader for a binary WebAssembly file.</param>
        /// <returns>The parsed section.</returns>
        public static CodeSection ReadSectionPayload(
            SectionHeader Header, BinaryWasmReader Reader)
        {
            long startPos = Reader.Position;
            // Read the function bodies.
            uint count      = Reader.ReadVarUInt32();
            var  funcBodies = new List <FunctionBody>();

            for (uint i = 0; i < count; i++)
            {
                funcBodies.Add(FunctionBody.ReadFrom(Reader));
            }

            // Skip any remaining bytes.
            var extraPayload = Reader.ReadRemainingPayload(startPos, Header);

            return(new CodeSection(funcBodies, extraPayload));
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a function definition to this module.
        /// </summary>
        /// <param name="functionTypeIndex">The index in the type section of the function's type.</param>
        /// <param name="functionBody">The body of the function to define.</param>
        /// <returns>The index in the function section of the newly added function definition.</returns>
        public uint AddFunction(uint functionTypeIndex, FunctionBody functionBody)
        {
            var funs = GetFirstSectionOrNull <FunctionSection>();

            if (funs == null)
            {
                InsertSection(funs = new FunctionSection());
            }
            var code = GetFirstSectionOrNull <CodeSection>();

            if (code == null)
            {
                InsertSection(code = new CodeSection());
            }
            funs.FunctionTypes.Add(functionTypeIndex);
            code.Bodies.Add(functionBody);
            return((uint)funs.FunctionTypes.Count - 1);
        }