Lines Matching refs:Ctx

72 static uint8_t readUint8(WasmObjectFile::ReadContext &Ctx) {  in readUint8()  argument
73 if (Ctx.Ptr == Ctx.End) in readUint8()
75 return *Ctx.Ptr++; in readUint8()
78 static uint32_t readUint32(WasmObjectFile::ReadContext &Ctx) { in readUint32() argument
79 if (Ctx.Ptr + 4 > Ctx.End) in readUint32()
81 uint32_t Result = support::endian::read32le(Ctx.Ptr); in readUint32()
82 Ctx.Ptr += 4; in readUint32()
86 static int32_t readFloat32(WasmObjectFile::ReadContext &Ctx) { in readFloat32() argument
87 if (Ctx.Ptr + 4 > Ctx.End) in readFloat32()
90 memcpy(&Result, Ctx.Ptr, sizeof(Result)); in readFloat32()
91 Ctx.Ptr += sizeof(Result); in readFloat32()
95 static int64_t readFloat64(WasmObjectFile::ReadContext &Ctx) { in readFloat64() argument
96 if (Ctx.Ptr + 8 > Ctx.End) in readFloat64()
99 memcpy(&Result, Ctx.Ptr, sizeof(Result)); in readFloat64()
100 Ctx.Ptr += sizeof(Result); in readFloat64()
104 static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx) { in readULEB128() argument
107 uint64_t Result = decodeULEB128(Ctx.Ptr, &Count, Ctx.End, &Error); in readULEB128()
110 Ctx.Ptr += Count; in readULEB128()
114 static StringRef readString(WasmObjectFile::ReadContext &Ctx) { in readString() argument
115 uint32_t StringLen = readULEB128(Ctx); in readString()
116 if (Ctx.Ptr + StringLen > Ctx.End) in readString()
119 StringRef(reinterpret_cast<const char *>(Ctx.Ptr), StringLen); in readString()
120 Ctx.Ptr += StringLen; in readString()
124 static int64_t readLEB128(WasmObjectFile::ReadContext &Ctx) { in readLEB128() argument
127 uint64_t Result = decodeSLEB128(Ctx.Ptr, &Count, Ctx.End, &Error); in readLEB128()
130 Ctx.Ptr += Count; in readLEB128()
134 static uint8_t readVaruint1(WasmObjectFile::ReadContext &Ctx) { in readVaruint1() argument
135 int64_t Result = readLEB128(Ctx); in readVaruint1()
141 static int32_t readVarint32(WasmObjectFile::ReadContext &Ctx) { in readVarint32() argument
142 int64_t Result = readLEB128(Ctx); in readVarint32()
148 static uint32_t readVaruint32(WasmObjectFile::ReadContext &Ctx) { in readVaruint32() argument
149 uint64_t Result = readULEB128(Ctx); in readVaruint32()
155 static int64_t readVarint64(WasmObjectFile::ReadContext &Ctx) { in readVarint64() argument
156 return readLEB128(Ctx); in readVarint64()
159 static uint64_t readVaruint64(WasmObjectFile::ReadContext &Ctx) { in readVaruint64() argument
160 return readULEB128(Ctx); in readVaruint64()
163 static uint8_t readOpcode(WasmObjectFile::ReadContext &Ctx) { in readOpcode() argument
164 return readUint8(Ctx); in readOpcode()
168 WasmObjectFile::ReadContext &Ctx) { in readInitExpr() argument
169 Expr.Opcode = readOpcode(Ctx); in readInitExpr()
173 Expr.Value.Int32 = readVarint32(Ctx); in readInitExpr()
176 Expr.Value.Int64 = readVarint64(Ctx); in readInitExpr()
179 Expr.Value.Float32 = readFloat32(Ctx); in readInitExpr()
182 Expr.Value.Float64 = readFloat64(Ctx); in readInitExpr()
185 Expr.Value.Global = readULEB128(Ctx); in readInitExpr()
188 wasm::ValType Ty = static_cast<wasm::ValType>(readULEB128(Ctx)); in readInitExpr()
200 uint8_t EndOpcode = readOpcode(Ctx); in readInitExpr()
208 static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) { in readLimits() argument
210 Result.Flags = readVaruint32(Ctx); in readLimits()
211 Result.Minimum = readVaruint64(Ctx); in readLimits()
213 Result.Maximum = readVaruint64(Ctx); in readLimits()
217 static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) { in readTableType() argument
219 TableType.ElemType = readUint8(Ctx); in readTableType()
220 TableType.Limits = readLimits(Ctx); in readTableType()
224 static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx, in readSection() argument
226 Section.Offset = Ctx.Ptr - Ctx.Start; in readSection()
227 Section.Type = readUint8(Ctx); in readSection()
229 uint32_t Size = readVaruint32(Ctx); in readSection()
233 if (Ctx.Ptr + Size > Ctx.End) in readSection()
238 SectionCtx.Start = Ctx.Ptr; in readSection()
239 SectionCtx.Ptr = Ctx.Ptr; in readSection()
240 SectionCtx.End = Ctx.Ptr + Size; in readSection()
245 Ctx.Ptr += SectionNameSize; in readSection()
255 Section.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size); in readSection()
256 Ctx.Ptr += Size; in readSection()
270 ReadContext Ctx; in WasmObjectFile() local
271 Ctx.Start = getData().bytes_begin(); in WasmObjectFile()
272 Ctx.Ptr = Ctx.Start + 4; in WasmObjectFile()
273 Ctx.End = Ctx.Start + getData().size(); in WasmObjectFile()
275 if (Ctx.Ptr + 4 > Ctx.End) { in WasmObjectFile()
281 Header.Version = readUint32(Ctx); in WasmObjectFile()
291 while (Ctx.Ptr < Ctx.End) { in WasmObjectFile()
292 if ((Err = readSection(Sec, Ctx, Checker))) in WasmObjectFile()
302 ReadContext Ctx; in parseSection() local
303 Ctx.Start = Sec.Content.data(); in parseSection()
304 Ctx.End = Ctx.Start + Sec.Content.size(); in parseSection()
305 Ctx.Ptr = Ctx.Start; in parseSection()
308 return parseCustomSection(Sec, Ctx); in parseSection()
310 return parseTypeSection(Ctx); in parseSection()
312 return parseImportSection(Ctx); in parseSection()
314 return parseFunctionSection(Ctx); in parseSection()
316 return parseTableSection(Ctx); in parseSection()
318 return parseMemorySection(Ctx); in parseSection()
320 return parseTagSection(Ctx); in parseSection()
322 return parseGlobalSection(Ctx); in parseSection()
324 return parseExportSection(Ctx); in parseSection()
326 return parseStartSection(Ctx); in parseSection()
328 return parseElemSection(Ctx); in parseSection()
330 return parseCodeSection(Ctx); in parseSection()
332 return parseDataSection(Ctx); in parseSection()
334 return parseDataCountSection(Ctx); in parseSection()
341 Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) { in parseDylinkSection() argument
344 DylinkInfo.MemorySize = readVaruint32(Ctx); in parseDylinkSection()
345 DylinkInfo.MemoryAlignment = readVaruint32(Ctx); in parseDylinkSection()
346 DylinkInfo.TableSize = readVaruint32(Ctx); in parseDylinkSection()
347 DylinkInfo.TableAlignment = readVaruint32(Ctx); in parseDylinkSection()
348 uint32_t Count = readVaruint32(Ctx); in parseDylinkSection()
350 DylinkInfo.Needed.push_back(readString(Ctx)); in parseDylinkSection()
352 if (Ctx.Ptr != Ctx.End) in parseDylinkSection()
358 Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { in parseNameSection() argument
367 while (Ctx.Ptr < Ctx.End) { in parseNameSection()
368 uint8_t Type = readUint8(Ctx); in parseNameSection()
369 uint32_t Size = readVaruint32(Ctx); in parseNameSection()
370 const uint8_t *SubSectionEnd = Ctx.Ptr + Size; in parseNameSection()
375 uint32_t Count = readVaruint32(Ctx); in parseNameSection()
377 uint32_t Index = readVaruint32(Ctx); in parseNameSection()
378 StringRef Name = readString(Ctx); in parseNameSection()
414 Ctx.Ptr += Size; in parseNameSection()
417 if (Ctx.Ptr != SubSectionEnd) in parseNameSection()
422 if (Ctx.Ptr != Ctx.End) in parseNameSection()
428 Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { in parseLinkingSection() argument
436 LinkingData.Version = readVaruint32(Ctx); in parseLinkingSection()
444 const uint8_t *OrigEnd = Ctx.End; in parseLinkingSection()
445 while (Ctx.Ptr < OrigEnd) { in parseLinkingSection()
446 Ctx.End = OrigEnd; in parseLinkingSection()
447 uint8_t Type = readUint8(Ctx); in parseLinkingSection()
448 uint32_t Size = readVaruint32(Ctx); in parseLinkingSection()
451 Ctx.End = Ctx.Ptr + Size; in parseLinkingSection()
454 if (Error Err = parseLinkingSectionSymtab(Ctx)) in parseLinkingSection()
458 uint32_t Count = readVaruint32(Ctx); in parseLinkingSection()
463 DataSegments[I].Data.Name = readString(Ctx); in parseLinkingSection()
464 DataSegments[I].Data.Alignment = readVaruint32(Ctx); in parseLinkingSection()
465 DataSegments[I].Data.LinkingFlags = readVaruint32(Ctx); in parseLinkingSection()
470 uint32_t Count = readVaruint32(Ctx); in parseLinkingSection()
474 Init.Priority = readVaruint32(Ctx); in parseLinkingSection()
475 Init.Symbol = readVaruint32(Ctx); in parseLinkingSection()
485 if (Error Err = parseLinkingSectionComdat(Ctx)) in parseLinkingSection()
489 Ctx.Ptr += Size; in parseLinkingSection()
492 if (Ctx.Ptr != Ctx.End) in parseLinkingSection()
496 if (Ctx.Ptr != OrigEnd) in parseLinkingSection()
502 Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { in parseLinkingSectionSymtab() argument
503 uint32_t Count = readVaruint32(Ctx); in parseLinkingSectionSymtab()
534 Info.Kind = readUint8(Ctx); in parseLinkingSectionSymtab()
535 Info.Flags = readVaruint32(Ctx); in parseLinkingSectionSymtab()
540 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
546 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
555 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
568 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
578 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
587 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
600 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
610 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
619 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
632 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
634 auto Index = readVaruint32(Ctx); in parseLinkingSectionSymtab()
638 auto Offset = readVaruint64(Ctx); in parseLinkingSectionSymtab()
639 auto Size = readVaruint64(Ctx); in parseLinkingSectionSymtab()
656 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
664 Info.ElementIndex = readVaruint32(Ctx); in parseLinkingSectionSymtab()
674 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
685 Info.Name = readString(Ctx); in parseLinkingSectionSymtab()
720 Error WasmObjectFile::parseLinkingSectionComdat(ReadContext &Ctx) { in parseLinkingSectionComdat() argument
721 uint32_t ComdatCount = readVaruint32(Ctx); in parseLinkingSectionComdat()
724 StringRef Name = readString(Ctx); in parseLinkingSectionComdat()
730 uint32_t Flags = readVaruint32(Ctx); in parseLinkingSectionComdat()
735 uint32_t EntryCount = readVaruint32(Ctx); in parseLinkingSectionComdat()
737 unsigned Kind = readVaruint32(Ctx); in parseLinkingSectionComdat()
738 unsigned Index = readVaruint32(Ctx); in parseLinkingSectionComdat()
776 Error WasmObjectFile::parseProducersSection(ReadContext &Ctx) { in parseProducersSection() argument
778 uint32_t Fields = readVaruint32(Ctx); in parseProducersSection()
780 StringRef FieldName = readString(Ctx); in parseProducersSection()
798 uint32_t ValueCount = readVaruint32(Ctx); in parseProducersSection()
801 StringRef Name = readString(Ctx); in parseProducersSection()
802 StringRef Version = readString(Ctx); in parseProducersSection()
811 if (Ctx.Ptr != Ctx.End) in parseProducersSection()
817 Error WasmObjectFile::parseTargetFeaturesSection(ReadContext &Ctx) { in parseTargetFeaturesSection() argument
819 uint32_t FeatureCount = readVaruint32(Ctx); in parseTargetFeaturesSection()
822 Feature.Prefix = readUint8(Ctx); in parseTargetFeaturesSection()
832 Feature.Name = std::string(readString(Ctx)); in parseTargetFeaturesSection()
840 if (Ctx.Ptr != Ctx.End) in parseTargetFeaturesSection()
847 Error WasmObjectFile::parseRelocSection(StringRef Name, ReadContext &Ctx) { in parseRelocSection() argument
848 uint32_t SectionIndex = readVaruint32(Ctx); in parseRelocSection()
853 uint32_t RelocCount = readVaruint32(Ctx); in parseRelocSection()
858 uint32_t type = readVaruint32(Ctx); in parseRelocSection()
860 Reloc.Offset = readVaruint32(Ctx); in parseRelocSection()
865 Reloc.Index = readVaruint32(Ctx); in parseRelocSection()
916 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
926 Reloc.Addend = readVarint64(Ctx); in parseRelocSection()
932 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
938 Reloc.Addend = readVarint64(Ctx); in parseRelocSection()
944 Reloc.Addend = readVarint32(Ctx); in parseRelocSection()
977 if (Ctx.Ptr != Ctx.End) in parseRelocSection()
983 Error WasmObjectFile::parseCustomSection(WasmSection &Sec, ReadContext &Ctx) { in parseCustomSection() argument
985 if (Error Err = parseDylinkSection(Ctx)) in parseCustomSection()
988 if (Error Err = parseNameSection(Ctx)) in parseCustomSection()
991 if (Error Err = parseLinkingSection(Ctx)) in parseCustomSection()
994 if (Error Err = parseProducersSection(Ctx)) in parseCustomSection()
997 if (Error Err = parseTargetFeaturesSection(Ctx)) in parseCustomSection()
1000 if (Error Err = parseRelocSection(Sec.Name, Ctx)) in parseCustomSection()
1006 Error WasmObjectFile::parseTypeSection(ReadContext &Ctx) { in parseTypeSection() argument
1007 uint32_t Count = readVaruint32(Ctx); in parseTypeSection()
1011 uint8_t Form = readUint8(Ctx); in parseTypeSection()
1016 uint32_t ParamCount = readVaruint32(Ctx); in parseTypeSection()
1019 uint32_t ParamType = readUint8(Ctx); in parseTypeSection()
1022 uint32_t ReturnCount = readVaruint32(Ctx); in parseTypeSection()
1024 uint32_t ReturnType = readUint8(Ctx); in parseTypeSection()
1029 if (Ctx.Ptr != Ctx.End) in parseTypeSection()
1035 Error WasmObjectFile::parseImportSection(ReadContext &Ctx) { in parseImportSection() argument
1036 uint32_t Count = readVaruint32(Ctx); in parseImportSection()
1040 Im.Module = readString(Ctx); in parseImportSection()
1041 Im.Field = readString(Ctx); in parseImportSection()
1042 Im.Kind = readUint8(Ctx); in parseImportSection()
1046 Im.SigIndex = readVaruint32(Ctx); in parseImportSection()
1050 Im.Global.Type = readUint8(Ctx); in parseImportSection()
1051 Im.Global.Mutable = readVaruint1(Ctx); in parseImportSection()
1054 Im.Memory = readLimits(Ctx); in parseImportSection()
1059 Im.Table = readTableType(Ctx); in parseImportSection()
1070 Im.Tag.Attribute = readUint8(Ctx); in parseImportSection()
1071 Im.Tag.SigIndex = readVarint32(Ctx); in parseImportSection()
1079 if (Ctx.Ptr != Ctx.End) in parseImportSection()
1085 Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) { in parseFunctionSection() argument
1086 uint32_t Count = readVaruint32(Ctx); in parseFunctionSection()
1091 uint32_t Type = readVaruint32(Ctx); in parseFunctionSection()
1097 if (Ctx.Ptr != Ctx.End) in parseFunctionSection()
1103 Error WasmObjectFile::parseTableSection(ReadContext &Ctx) { in parseTableSection() argument
1105 uint32_t Count = readVaruint32(Ctx); in parseTableSection()
1109 T.Type = readTableType(Ctx); in parseTableSection()
1119 if (Ctx.Ptr != Ctx.End) in parseTableSection()
1125 Error WasmObjectFile::parseMemorySection(ReadContext &Ctx) { in parseMemorySection() argument
1126 uint32_t Count = readVaruint32(Ctx); in parseMemorySection()
1129 auto Limits = readLimits(Ctx); in parseMemorySection()
1134 if (Ctx.Ptr != Ctx.End) in parseMemorySection()
1140 Error WasmObjectFile::parseTagSection(ReadContext &Ctx) { in parseTagSection() argument
1142 uint32_t Count = readVaruint32(Ctx); in parseTagSection()
1147 Tag.Type.Attribute = readUint8(Ctx); in parseTagSection()
1148 Tag.Type.SigIndex = readVaruint32(Ctx); in parseTagSection()
1152 if (Ctx.Ptr != Ctx.End) in parseTagSection()
1158 Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) { in parseGlobalSection() argument
1160 uint32_t Count = readVaruint32(Ctx); in parseGlobalSection()
1165 Global.Type.Type = readUint8(Ctx); in parseGlobalSection()
1166 Global.Type.Mutable = readVaruint1(Ctx); in parseGlobalSection()
1167 if (Error Err = readInitExpr(Global.InitExpr, Ctx)) in parseGlobalSection()
1171 if (Ctx.Ptr != Ctx.End) in parseGlobalSection()
1177 Error WasmObjectFile::parseExportSection(ReadContext &Ctx) { in parseExportSection() argument
1178 uint32_t Count = readVaruint32(Ctx); in parseExportSection()
1182 Ex.Name = readString(Ctx); in parseExportSection()
1183 Ex.Kind = readUint8(Ctx); in parseExportSection()
1184 Ex.Index = readVaruint32(Ctx); in parseExportSection()
1212 if (Ctx.Ptr != Ctx.End) in parseExportSection()
1295 Error WasmObjectFile::parseStartSection(ReadContext &Ctx) { in parseStartSection() argument
1296 StartFunction = readVaruint32(Ctx); in parseStartSection()
1303 Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) { in parseCodeSection() argument
1306 uint32_t FunctionCount = readVaruint32(Ctx); in parseCodeSection()
1314 const uint8_t *FunctionStart = Ctx.Ptr; in parseCodeSection()
1315 uint32_t Size = readVaruint32(Ctx); in parseCodeSection()
1316 const uint8_t *FunctionEnd = Ctx.Ptr + Size; in parseCodeSection()
1318 Function.CodeOffset = Ctx.Ptr - FunctionStart; in parseCodeSection()
1320 Function.CodeSectionOffset = FunctionStart - Ctx.Start; in parseCodeSection()
1323 uint32_t NumLocalDecls = readVaruint32(Ctx); in parseCodeSection()
1327 Decl.Count = readVaruint32(Ctx); in parseCodeSection()
1328 Decl.Type = readUint8(Ctx); in parseCodeSection()
1332 uint32_t BodySize = FunctionEnd - Ctx.Ptr; in parseCodeSection()
1333 Function.Body = ArrayRef<uint8_t>(Ctx.Ptr, BodySize); in parseCodeSection()
1336 Ctx.Ptr += BodySize; in parseCodeSection()
1337 assert(Ctx.Ptr == FunctionEnd); in parseCodeSection()
1339 if (Ctx.Ptr != Ctx.End) in parseCodeSection()
1345 Error WasmObjectFile::parseElemSection(ReadContext &Ctx) { in parseElemSection() argument
1346 uint32_t Count = readVaruint32(Ctx); in parseElemSection()
1350 Segment.Flags = readVaruint32(Ctx); in parseElemSection()
1360 Segment.TableNumber = readVaruint32(Ctx); in parseElemSection()
1371 if (Error Err = readInitExpr(Segment.Offset, Ctx)) in parseElemSection()
1376 Segment.ElemKind = readUint8(Ctx); in parseElemSection()
1398 uint32_t NumElems = readVaruint32(Ctx); in parseElemSection()
1400 Segment.Functions.push_back(readVaruint32(Ctx)); in parseElemSection()
1404 if (Ctx.Ptr != Ctx.End) in parseElemSection()
1410 Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { in parseDataSection() argument
1412 uint32_t Count = readVaruint32(Ctx); in parseDataSection()
1419 Segment.Data.InitFlags = readVaruint32(Ctx); in parseDataSection()
1422 ? readVaruint32(Ctx) in parseDataSection()
1425 if (Error Err = readInitExpr(Segment.Data.Offset, Ctx)) in parseDataSection()
1431 uint32_t Size = readVaruint32(Ctx); in parseDataSection()
1432 if (Size > (size_t)(Ctx.End - Ctx.Ptr)) in parseDataSection()
1435 Segment.Data.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size); in parseDataSection()
1441 Segment.SectionOffset = Ctx.Ptr - Ctx.Start; in parseDataSection()
1442 Ctx.Ptr += Size; in parseDataSection()
1445 if (Ctx.Ptr != Ctx.End) in parseDataSection()
1451 Error WasmObjectFile::parseDataCountSection(ReadContext &Ctx) { in parseDataCountSection() argument
1452 DataCount = readVaruint32(Ctx); in parseDataCountSection()