Lines Matching refs:Ctx

71 static uint8_t readUint8(WasmObjectFile::ReadContext &Ctx) {  in readUint8()  argument
72 if (Ctx.Ptr == Ctx.End) in readUint8()
74 return *Ctx.Ptr++; in readUint8()
77 static uint32_t readUint32(WasmObjectFile::ReadContext &Ctx) { in readUint32() argument
78 if (Ctx.Ptr + 4 > Ctx.End) in readUint32()
80 uint32_t Result = support::endian::read32le(Ctx.Ptr); in readUint32()
81 Ctx.Ptr += 4; in readUint32()
85 static int32_t readFloat32(WasmObjectFile::ReadContext &Ctx) { in readFloat32() argument
86 if (Ctx.Ptr + 4 > Ctx.End) in readFloat32()
89 memcpy(&Result, Ctx.Ptr, sizeof(Result)); in readFloat32()
90 Ctx.Ptr += sizeof(Result); in readFloat32()
94 static int64_t readFloat64(WasmObjectFile::ReadContext &Ctx) { in readFloat64() argument
95 if (Ctx.Ptr + 8 > Ctx.End) in readFloat64()
98 memcpy(&Result, Ctx.Ptr, sizeof(Result)); in readFloat64()
99 Ctx.Ptr += sizeof(Result); in readFloat64()
103 static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx) { in readULEB128() argument
106 uint64_t Result = decodeULEB128(Ctx.Ptr, &Count, Ctx.End, &Error); in readULEB128()
109 Ctx.Ptr += Count; in readULEB128()
113 static StringRef readString(WasmObjectFile::ReadContext &Ctx) { in readString() argument
114 uint32_t StringLen = readULEB128(Ctx); in readString()
115 if (Ctx.Ptr + StringLen > Ctx.End) in readString()
118 StringRef(reinterpret_cast<const char *>(Ctx.Ptr), StringLen); in readString()
119 Ctx.Ptr += StringLen; in readString()
123 static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx) { in readLEB128() argument
126 uint64_t Result = decodeSLEB128(Ctx.Ptr, &Count, Ctx.End, &Error); in readLEB128()
129 Ctx.Ptr += Count; in readLEB128()
133 static uint8_t readVaruint1(WasmObjectFile::ReadContext &Ctx) { in readVaruint1() argument
134 int64_t result = readLEB128(Ctx); in readVaruint1()
140 static int32_t readVarint32(WasmObjectFile::ReadContext &Ctx) { in readVarint32() argument
141 int64_t result = readLEB128(Ctx); in readVarint32()
147 static uint32_t readVaruint32(WasmObjectFile::ReadContext &Ctx) { in readVaruint32() argument
148 uint64_t result = readULEB128(Ctx); in readVaruint32()
154 static int64_t readVarint64(WasmObjectFile::ReadContext &Ctx) { in readVarint64() argument
155 return readLEB128(Ctx); in readVarint64()
158 static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx) { in readOpcode() argument
159 return readUint8(Ctx); in readOpcode()
163 WasmObjectFile::ReadContext &Ctx) { in readInitExpr() argument
164 Expr.Opcode = readOpcode(Ctx); in readInitExpr()
168 Expr.Value.Int32 = readVarint32(Ctx); in readInitExpr()
171 Expr.Value.Int64 = readVarint64(Ctx); in readInitExpr()
174 Expr.Value.Float32 = readFloat32(Ctx); in readInitExpr()
177 Expr.Value.Float64 = readFloat64(Ctx); in readInitExpr()
180 Expr.Value.Global = readULEB128(Ctx); in readInitExpr()
187 uint8_t EndOpcode = readOpcode(Ctx); in readInitExpr()
195 static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) { in readLimits() argument
197 Result.Flags = readVaruint32(Ctx); in readLimits()
198 Result.Initial = readVaruint32(Ctx); in readLimits()
200 Result.Maximum = readVaruint32(Ctx); in readLimits()
204 static wasm::WasmTable readTable(WasmObjectFile::ReadContext &Ctx) { in readTable() argument
206 Table.ElemType = readUint8(Ctx); in readTable()
207 Table.Limits = readLimits(Ctx); in readTable()
211 static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, in readSection() argument
213 Section.Offset = Ctx.Ptr - Ctx.Start; in readSection()
214 Section.Type = readUint8(Ctx); in readSection()
216 uint32_t Size = readVaruint32(Ctx); in readSection()
220 if (Ctx.Ptr + Size > Ctx.End) in readSection()
225 SectionCtx.Start = Ctx.Ptr; in readSection()
226 SectionCtx.Ptr = Ctx.Ptr; in readSection()
227 SectionCtx.End = Ctx.Ptr + Size; in readSection()
232 Ctx.Ptr += SectionNameSize; in readSection()
242 Section.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size); in readSection()
243 Ctx.Ptr += Size; in readSection()
257 ReadContext Ctx; in WasmObjectFile() local
258 Ctx.Start = getPtr(0); in WasmObjectFile()
259 Ctx.Ptr = Ctx.Start + 4; in WasmObjectFile()
260 Ctx.End = Ctx.Start + getData().size(); in WasmObjectFile()
262 if (Ctx.Ptr + 4 > Ctx.End) { in WasmObjectFile()
268 Header.Version = readUint32(Ctx); in WasmObjectFile()
277 while (Ctx.Ptr < Ctx.End) { in WasmObjectFile()
278 if ((Err = readSection(Sec, Ctx, Checker))) in WasmObjectFile()
288 ReadContext Ctx; in parseSection() local
289 Ctx.Start = Sec.Content.data(); in parseSection()
290 Ctx.End = Ctx.Start + Sec.Content.size(); in parseSection()
291 Ctx.Ptr = Ctx.Start; in parseSection()
294 return parseCustomSection(Sec, Ctx); in parseSection()
296 return parseTypeSection(Ctx); in parseSection()
298 return parseImportSection(Ctx); in parseSection()
300 return parseFunctionSection(Ctx); in parseSection()
302 return parseTableSection(Ctx); in parseSection()
304 return parseMemorySection(Ctx); in parseSection()
306 return parseGlobalSection(Ctx); in parseSection()
308 return parseEventSection(Ctx); in parseSection()
310 return parseExportSection(Ctx); in parseSection()
312 return parseStartSection(Ctx); in parseSection()
314 return parseElemSection(Ctx); in parseSection()
316 return parseCodeSection(Ctx); in parseSection()
318 return parseDataSection(Ctx); in parseSection()
325 Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) { in parseDylinkSection() argument
327 DylinkInfo.MemorySize = readVaruint32(Ctx); in parseDylinkSection()
328 DylinkInfo.MemoryAlignment = readVaruint32(Ctx); in parseDylinkSection()
329 DylinkInfo.TableSize = readVaruint32(Ctx); in parseDylinkSection()
330 DylinkInfo.TableAlignment = readVaruint32(Ctx); in parseDylinkSection()
331 uint32_t Count = readVaruint32(Ctx); in parseDylinkSection()
333 DylinkInfo.Needed.push_back(readString(Ctx)); in parseDylinkSection()
335 if (Ctx.Ptr != Ctx.End) in parseDylinkSection()
341 Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { in parseNameSection() argument
348 while (Ctx.Ptr < Ctx.End) { in parseNameSection()
349 uint8_t Type = readUint8(Ctx); in parseNameSection()
350 uint32_t Size = readVaruint32(Ctx); in parseNameSection()
351 const uint8_t *SubSectionEnd = Ctx.Ptr + Size; in parseNameSection()
354 uint32_t Count = readVaruint32(Ctx); in parseNameSection()
356 uint32_t Index = readVaruint32(Ctx); in parseNameSection()
360 StringRef Name = readString(Ctx); in parseNameSection()
373 Ctx.Ptr += Size; in parseNameSection()
376 if (Ctx.Ptr != SubSectionEnd) in parseNameSection()
381 if (Ctx.Ptr != Ctx.End) in parseNameSection()
387 Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { in parseLinkingSection() argument
395 LinkingData.Version = readVaruint32(Ctx); in parseLinkingSection()
403 const uint8_t *OrigEnd = Ctx.End; in parseLinkingSection()
404 while (Ctx.Ptr < OrigEnd) { in parseLinkingSection()
405 Ctx.End = OrigEnd; in parseLinkingSection()
406 uint8_t Type = readUint8(Ctx); in parseLinkingSection()
407 uint32_t Size = readVaruint32(Ctx); in parseLinkingSection()
410 Ctx.End = Ctx.Ptr + Size; in parseLinkingSection()
413 if (Error Err = parseLinkingSectionSymtab(Ctx)) in parseLinkingSection()
417 uint32_t Count = readVaruint32(Ctx); in parseLinkingSection()
422 DataSegments[i].Data.Name = readString(Ctx); in parseLinkingSection()
423 DataSegments[i].Data.Alignment = readVaruint32(Ctx); in parseLinkingSection()
424 DataSegments[i].Data.Flags = readVaruint32(Ctx); in parseLinkingSection()
429 uint32_t Count = readVaruint32(Ctx); in parseLinkingSection()
433 Init.Priority = readVaruint32(Ctx); in parseLinkingSection()
434 Init.Symbol = readVaruint32(Ctx); in parseLinkingSection()
444 if (Error Err = parseLinkingSectionComdat(Ctx)) in parseLinkingSection()
448 Ctx.Ptr += Size; in parseLinkingSection()
451 if (Ctx.Ptr != Ctx.End) in parseLinkingSection()
455 if (Ctx.Ptr != OrigEnd) in parseLinkingSection()
461 Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { in parseLinkingSectionSymtab() argument
462 uint32_t Count = readVaruint32(Ctx); in parseLinkingSectionSymtab()
488 Info.Kind = readUint8(Ctx); in parseLinkingSectionSymtab()
489 Info.Flags = readVaruint32(Ctx); in parseLinkingSectionSymtab()
494 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
500 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
509 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
519 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
529 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
538 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
548 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
550 uint32_t Index = readVaruint32(Ctx); in parseLinkingSectionSymtab()
554 uint32_t Offset = readVaruint32(Ctx); in parseLinkingSectionSymtab()
555 uint32_t Size = readVaruint32(Ctx); in parseLinkingSectionSymtab()
569 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
577 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
587 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
598 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
629 Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) { in parseLinkingSectionComdat() argument
630 uint32_t ComdatCount = readVaruint32(Ctx); in parseLinkingSectionComdat()
633 StringRef Name = readString(Ctx); in parseLinkingSectionComdat()
639 uint32_t Flags = readVaruint32(Ctx); in parseLinkingSectionComdat()
644 uint32_t EntryCount = readVaruint32(Ctx); in parseLinkingSectionComdat()
646 unsigned Kind = readVaruint32(Ctx); in parseLinkingSectionComdat()
647 unsigned Index = readVaruint32(Ctx); in parseLinkingSectionComdat()
676 Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { in parseRelocSection() argument
677 uint32_t SectionIndex = readVaruint32(Ctx); in parseRelocSection()
682 uint32_t RelocCount = readVaruint32(Ctx); in parseRelocSection()
687 Reloc.Type = readVaruint32(Ctx); in parseRelocSection()
688 Reloc.Offset = readVaruint32(Ctx); in parseRelocSection()
693 Reloc.Index = readVaruint32(Ctx); in parseRelocSection()
723 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
729 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
735 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
758 if (Ctx.Ptr != Ctx.End) in parseRelocSection()
764 Error WasmObjectFile::parseCustomSection(WasmSection &Sec, ReadContext &Ctx) { in parseCustomSection() argument
766 if (Error Err = parseDylinkSection(Ctx)) in parseCustomSection()
769 if (Error Err = parseNameSection(Ctx)) in parseCustomSection()
772 if (Error Err = parseLinkingSection(Ctx)) in parseCustomSection()
775 if (Error Err = parseRelocSection(Sec.Name, Ctx)) in parseCustomSection()
781 Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) { in parseTypeSection() argument
782 uint32_t Count = readVaruint32(Ctx); in parseTypeSection()
786 uint8_t Form = readUint8(Ctx); in parseTypeSection()
791 uint32_t ParamCount = readVaruint32(Ctx); in parseTypeSection()
794 uint32_t ParamType = readUint8(Ctx); in parseTypeSection()
797 uint32_t ReturnCount = readVaruint32(Ctx); in parseTypeSection()
803 Sig.Returns.push_back(wasm::ValType(readUint8(Ctx))); in parseTypeSection()
807 if (Ctx.Ptr != Ctx.End) in parseTypeSection()
813 Error WasmObjectFile::parseImportSection(ReadContext &Ctx) { in parseImportSection() argument
814 uint32_t Count = readVaruint32(Ctx); in parseImportSection()
818 Im.Module = readString(Ctx); in parseImportSection()
819 Im.Field = readString(Ctx); in parseImportSection()
820 Im.Kind = readUint8(Ctx); in parseImportSection()
824 Im.SigIndex = readVaruint32(Ctx); in parseImportSection()
828 Im.Global.Type = readUint8(Ctx); in parseImportSection()
829 Im.Global.Mutable = readVaruint1(Ctx); in parseImportSection()
832 Im.Memory = readLimits(Ctx); in parseImportSection()
835 Im.Table = readTable(Ctx); in parseImportSection()
842 Im.Event.Attribute = readVarint32(Ctx); in parseImportSection()
843 Im.Event.SigIndex = readVarint32(Ctx); in parseImportSection()
851 if (Ctx.Ptr != Ctx.End) in parseImportSection()
857 Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) { in parseFunctionSection() argument
858 uint32_t Count = readVaruint32(Ctx); in parseFunctionSection()
862 uint32_t Type = readVaruint32(Ctx); in parseFunctionSection()
868 if (Ctx.Ptr != Ctx.End) in parseFunctionSection()
874 Error WasmObjectFile::parseTableSection(ReadContext &Ctx) { in parseTableSection() argument
875 uint32_t Count = readVaruint32(Ctx); in parseTableSection()
878 Tables.push_back(readTable(Ctx)); in parseTableSection()
884 if (Ctx.Ptr != Ctx.End) in parseTableSection()
890 Error WasmObjectFile::parseMemorySection(ReadContext &Ctx) { in parseMemorySection() argument
891 uint32_t Count = readVaruint32(Ctx); in parseMemorySection()
894 Memories.push_back(readLimits(Ctx)); in parseMemorySection()
896 if (Ctx.Ptr != Ctx.End) in parseMemorySection()
902 Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) { in parseGlobalSection() argument
904 uint32_t Count = readVaruint32(Ctx); in parseGlobalSection()
909 Global.Type.Type = readUint8(Ctx); in parseGlobalSection()
910 Global.Type.Mutable = readVaruint1(Ctx); in parseGlobalSection()
911 if (Error Err = readInitExpr(Global.InitExpr, Ctx)) in parseGlobalSection()
915 if (Ctx.Ptr != Ctx.End) in parseGlobalSection()
921 Error WasmObjectFile::parseEventSection(ReadContext &Ctx) { in parseEventSection() argument
923 uint32_t Count = readVarint32(Ctx); in parseEventSection()
928 Event.Type.Attribute = readVaruint32(Ctx); in parseEventSection()
929 Event.Type.SigIndex = readVarint32(Ctx); in parseEventSection()
933 if (Ctx.Ptr != Ctx.End) in parseEventSection()
939 Error WasmObjectFile::parseExportSection(ReadContext &Ctx) { in parseExportSection() argument
940 uint32_t Count = readVaruint32(Ctx); in parseExportSection()
944 Ex.Name = readString(Ctx); in parseExportSection()
945 Ex.Kind = readUint8(Ctx); in parseExportSection()
946 Ex.Index = readVaruint32(Ctx); in parseExportSection()
972 if (Ctx.Ptr != Ctx.End) in parseExportSection()
1037 Error WasmObjectFile::parseStartSection(ReadContext &Ctx) { in parseStartSection() argument
1038 StartFunction = readVaruint32(Ctx); in parseStartSection()
1045 Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) { in parseCodeSection() argument
1047 uint32_t FunctionCount = readVaruint32(Ctx); in parseCodeSection()
1055 const uint8_t *FunctionStart = Ctx.Ptr; in parseCodeSection()
1056 uint32_t Size = readVaruint32(Ctx); in parseCodeSection()
1057 const uint8_t *FunctionEnd = Ctx.Ptr + Size; in parseCodeSection()
1059 Function.CodeOffset = Ctx.Ptr - FunctionStart; in parseCodeSection()
1061 Function.CodeSectionOffset = FunctionStart - Ctx.Start; in parseCodeSection()
1064 uint32_t NumLocalDecls = readVaruint32(Ctx); in parseCodeSection()
1068 Decl.Count = readVaruint32(Ctx); in parseCodeSection()
1069 Decl.Type = readUint8(Ctx); in parseCodeSection()
1073 uint32_t BodySize = FunctionEnd - Ctx.Ptr; in parseCodeSection()
1074 Function.Body = ArrayRef<uint8_t>(Ctx.Ptr, BodySize); in parseCodeSection()
1077 Ctx.Ptr += BodySize; in parseCodeSection()
1078 assert(Ctx.Ptr == FunctionEnd); in parseCodeSection()
1081 if (Ctx.Ptr != Ctx.End) in parseCodeSection()
1087 Error WasmObjectFile::parseElemSection(ReadContext &Ctx) { in parseElemSection() argument
1088 uint32_t Count = readVaruint32(Ctx); in parseElemSection()
1092 Segment.TableIndex = readVaruint32(Ctx); in parseElemSection()
1097 if (Error Err = readInitExpr(Segment.Offset, Ctx)) in parseElemSection()
1099 uint32_t NumElems = readVaruint32(Ctx); in parseElemSection()
1101 Segment.Functions.push_back(readVaruint32(Ctx)); in parseElemSection()
1105 if (Ctx.Ptr != Ctx.End) in parseElemSection()
1111 Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { in parseDataSection() argument
1113 uint32_t Count = readVaruint32(Ctx); in parseDataSection()
1117 Segment.Data.MemoryIndex = readVaruint32(Ctx); in parseDataSection()
1118 if (Error Err = readInitExpr(Segment.Data.Offset, Ctx)) in parseDataSection()
1120 uint32_t Size = readVaruint32(Ctx); in parseDataSection()
1121 if (Size > (size_t)(Ctx.End - Ctx.Ptr)) in parseDataSection()
1124 Segment.Data.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size); in parseDataSection()
1130 Segment.SectionOffset = Ctx.Ptr - Ctx.Start; in parseDataSection()
1131 Ctx.Ptr += Size; in parseDataSection()
1134 if (Ctx.Ptr != Ctx.End) in parseDataSection()