Пример #1
0
        public void AcceptSection(WasmSection section)
        {
            var reader = new WasmReader(section.Payload);

            switch (section.Code)
            {
            case WasmSectionCode.Type:
                TypeSections.Add(reader.ReadTypeSection());
                break;

            case WasmSectionCode.Import:
                ImportSections.Add(reader.ReadImportSection());
                break;

            case WasmSectionCode.Function:
                FunctionSections.Add(reader.ReadFunctionSection());
                break;

            case WasmSectionCode.Table:
                TableSections.Add(reader.ReadTableSection());
                break;

            case WasmSectionCode.Memory:
                MemorySections.Add(reader.ReadMemorySection());
                break;

            case WasmSectionCode.Global:
                GlobalSections.Add(reader.ReadGlobalSection());
                break;

            case WasmSectionCode.Export:
                ExportSections.Add(reader.ReadExportSection());
                break;

            case WasmSectionCode.Start:
                StartSections.Add(reader.ReadStartSection());
                break;

            case WasmSectionCode.Element:
                ElementSections.Add(reader.ReadElementSection());
                break;

            case WasmSectionCode.Code:
                CodeSections.Add(reader.ReadCodeSection());
                break;

            case WasmSectionCode.Data:
                DataSections.Add(reader.ReadDataSection());
                break;

            default:
                CustomSections.Add(section);
                break;
            }
        }
Пример #2
0
        public WasmFunctionBody ReadFunctionBody()
        {
            var bodySize    = ReadVarUInt32();
            var bodyBytes   = ReadBytes(bodySize);
            var bodyReader  = new WasmReader(bodyBytes);
            var localsCount = bodyReader.ReadVarUInt32();
            var locals      = new List <WasmLocalEntry>((int)localsCount);

            for (var i = 0; i < localsCount; i++)
            {
                locals.Add(bodyReader.ReadLocalEntry());
            }
            var opcodes = new List <BaseOpcode>();

            while (!bodyReader.Eof)
            {
                opcodes.Add(bodyReader.ReadOpcode());
            }
            var res = new WasmFunctionBody(locals, opcodes);

            return(res);
        }