示例#1
0
        /// <summary>
        /// Reads the memory section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <param name="Reader">The WebAssembly file reader.</param>
        /// <returns>The parsed section.</returns>
        public static MemorySection ReadSectionPayload(SectionHeader Header, BinaryWasmReader Reader)
        {
            long startPos = Reader.Position;
            // Read the resizable limits.
            uint count  = Reader.ReadVarUInt32();
            var  limits = new List <MemoryType>();

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

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

            return(new MemorySection(limits, extraPayload));
        }
示例#2
0
        /// <summary>
        /// Reads an imported value from the given binary WebAssembly reader.
        /// </summary>
        /// <param name="Reader">The WebAssembly reader.</param>
        /// <returns>The imported value that was read.</returns>
        public static ImportedValue ReadFrom(BinaryWasmReader Reader)
        {
            string moduleName = Reader.ReadString();
            string fieldName  = Reader.ReadString();
            var    kind       = (ExternalKind)Reader.ReadByte();

            switch (kind)
            {
            case ExternalKind.Function:
                return(new ImportedFunction(moduleName, fieldName, Reader.ReadVarUInt32()));

            case ExternalKind.Global:
                return(new ImportedGlobal(moduleName, fieldName, GlobalType.ReadFrom(Reader)));

            case ExternalKind.Memory:
                return(new ImportedMemory(moduleName, fieldName, MemoryType.ReadFrom(Reader)));

            case ExternalKind.Table:
                return(new ImportedTable(moduleName, fieldName, TableType.ReadFrom(Reader)));

            default:
                throw new WasmException("Unknown imported value kind: " + kind);
            }
        }
示例#3
0
 /// <summary>
 /// Creates a memory import from the given module name, field and memory type.
 /// </summary>
 /// <param name="ModuleName">The name of the module from which a value is imported.</param>
 /// <param name="FieldName">The name of the value that is imported.</param>
 /// <param name="Memory">A description of the imported memory.</param>
 public ImportedMemory(string ModuleName, string FieldName, MemoryType Memory)
     : base(ModuleName, FieldName)
 {
     this.Memory = Memory;
 }
示例#4
0
 /// <summary>
 /// Creates a memory import from the given module name, field and memory type.
 /// </summary>
 /// <param name="moduleName">The name of the module from which a value is imported.</param>
 /// <param name="fieldName">The name of the value that is imported.</param>
 /// <param name="memory">A description of the imported memory.</param>
 public ImportedMemory(string moduleName, string fieldName, MemoryType memory)
     : base(moduleName, fieldName)
 {
     this.Memory = memory;
 }