コード例 #1
0
ファイル: WasmReader.cs プロジェクト: kg/wasmstripcs
        public void Read()
        {
            var reader = new ModuleReader(Input);

            Program.Assert(reader.ReadHeader(), "ReadHeader");

            SectionHeader sh;

            while (reader.ReadSectionHeader(out sh))
            {
                if (sh.StreamPayloadEnd > reader.Reader.BaseStream.Length)
                {
                    throw new Exception("Invalid header");
                }

                SectionHeaders.Add(sh);

                switch (sh.id)
                {
                case SectionTypes.Type:
                    Program.Assert(reader.ReadTypeSection(out Types));
                    break;

                case SectionTypes.Import:
                    Program.Assert(reader.ReadImportSection(out Imports));
                    break;

                case SectionTypes.Function:
                    Program.Assert(reader.ReadFunctionSection(out Functions));
                    break;

                case SectionTypes.Table:
                    // FIXME: Not tested
                    Program.Assert(reader.ReadTableSection(out Tables));
                    break;

                case SectionTypes.Global:
                    Program.Assert(reader.ReadGlobalSection(out Globals));
                    break;

                case SectionTypes.Export:
                    Program.Assert(reader.ReadExportSection(out Exports));
                    break;

                case SectionTypes.Element:
                    Program.Assert(reader.ReadElementSection(out Elements));
                    break;

                case SectionTypes.Code:
                    Program.Assert(reader.ReadCodeSection(out Code, FunctionBodyCallback));
                    break;

                case SectionTypes.Data:
                    DataSection ds;
                    Program.Assert(reader.ReadDataSection(out ds));
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;

                case SectionTypes.Custom:
                    if (sh.name == "name")
                    {
                        ReadNameSection(reader, Input, sh);
                    }
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;

                default:
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;
                }
            }
        }