@@ -5211,14 +5211,17 @@ void WasmBinaryReader::readDylink0(size_t payloadLen) {
5211
5211
}
5212
5212
}
5213
5213
5214
- void WasmBinaryReader::readBranchHints (size_t payloadLen) {
5214
+ template <typename ReadFunc>
5215
+ void WasmBinaryReader::readExpressionHints (Name sectionName,
5216
+ size_t payloadLen,
5217
+ ReadFunc read) {
5215
5218
auto sectionPos = pos;
5216
5219
5217
5220
auto numFuncs = getU32LEB ();
5218
5221
for (Index i = 0 ; i < numFuncs; i++) {
5219
5222
auto funcIndex = getU32LEB ();
5220
5223
if (funcIndex >= wasm.functions .size ()) {
5221
- throwError (" bad BranchHint function" );
5224
+ throwError (" bad function in " + sectionName. toString () );
5222
5225
}
5223
5226
5224
5227
auto & func = wasm.functions [funcIndex];
@@ -5243,22 +5246,11 @@ void WasmBinaryReader::readBranchHints(size_t payloadLen) {
5243
5246
5244
5247
auto iter = locationsMap.find (absoluteOffset);
5245
5248
if (iter == locationsMap.end ()) {
5246
- throwError (" bad BranchHint offset" );
5249
+ throwError (" bad offset in " + sectionName. toString () );
5247
5250
}
5248
5251
auto * expr = iter->second ;
5249
5252
5250
- auto size = getU32LEB ();
5251
- if (size != 1 ) {
5252
- throwError (" bad BranchHint size" );
5253
- }
5254
-
5255
- auto likely = getU32LEB ();
5256
- if (likely != 0 && likely != 1 ) {
5257
- throwError (" bad BranchHint value" );
5258
- }
5259
-
5260
- // Apply the valid hint.
5261
- func->codeAnnotations [expr].branchLikely = likely;
5253
+ read (func->codeAnnotations [expr]);
5262
5254
}
5263
5255
}
5264
5256
@@ -5267,6 +5259,25 @@ void WasmBinaryReader::readBranchHints(size_t payloadLen) {
5267
5259
}
5268
5260
}
5269
5261
5262
+ void WasmBinaryReader::readBranchHints (size_t payloadLen) {
5263
+ readExpressionHints (Annotations::BranchHint,
5264
+ payloadLen,
5265
+ [&](Function::CodeAnnotation& annotation) {
5266
+ auto size = getU32LEB ();
5267
+ if (size != 1 ) {
5268
+ throwError (" bad BranchHint size" );
5269
+ }
5270
+
5271
+ auto likely = getU32LEB ();
5272
+ if (likely != 0 && likely != 1 ) {
5273
+ throwError (" bad BranchHint value" );
5274
+ }
5275
+
5276
+ // Apply the valid hint.
5277
+ annotation.branchLikely = likely;
5278
+ });
5279
+ }
5280
+
5270
5281
Index WasmBinaryReader::readMemoryAccess (Address& alignment, Address& offset) {
5271
5282
auto rawAlignment = getU32LEB ();
5272
5283
bool hasMemIdx = false ;
0 commit comments