Beispiel #1
0
        /// <summary>
        /// Adds an import to this module's import section, defining
        /// a new import section if one doesn't exist already.
        /// </summary>
        /// <param name="import">The import to add.</param>
        /// <returns>The index in the import section of the newly added import.</returns>
        public uint AddImport(ImportedValue import)
        {
            var imports = GetFirstSectionOrNull <ImportSection>();

            if (imports == null)
            {
                InsertSection(imports = new ImportSection());
            }
            imports.Imports.Add(import);
            return((uint)imports.Imports.Count - 1);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the import 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 ImportSection ReadSectionPayload(
            SectionHeader Header, BinaryWasmReader Reader)
        {
            long startPos = Reader.Position;
            // Read the imported values.
            uint count        = Reader.ReadVarUInt32();
            var  importedVals = new List <ImportedValue>();

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

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

            return(new ImportSection(importedVals, extraPayload));
        }