@@ -214,6 +214,17 @@ SectionHeader WasmBinaryReader::ReadSectionHeader()
214214 return header;
215215}
216216
217+ #if ENABLE_DEBUG_CONFIG_OPTIONS
218+ Js::FunctionBody* WasmBinaryReader::GetFunctionBody () const
219+ {
220+ if (m_readerState == READER_STATE_FUNCTION)
221+ {
222+ return m_funcState.body ;
223+ }
224+ return nullptr ;
225+ }
226+ #endif
227+
217228#if DBG_DUMP
218229void WasmBinaryReader::PrintOps ()
219230{
@@ -244,6 +255,9 @@ void WasmBinaryReader::PrintOps()
244255 --j;
245256 }
246257 }
258+
259+ uint32 moduleId = m_module->GetWasmFunctionInfo (0 )->GetBody ()->GetSourceContextId ();
260+ Output::Print (_u (" Module #%u's current opcode distribution\n " ), moduleId);
247261 for (i = 0 ; i < count; ++i)
248262 {
249263 switch (ops[i])
@@ -305,10 +319,27 @@ void WasmBinaryReader::SeekToFunctionBody(class WasmFunctionInfo* funcInfo)
305319
306320 // Seek to the function start and skip function header (count)
307321 m_pc = m_start + readerInfo.startOffset ;
322+
308323 m_funcState.size = readerInfo.size ;
309324 m_funcState.count = 0 ;
310325 CheckBytesLeft (readerInfo.size );
311326 m_curFuncEnd = m_pc + m_funcState.size ;
327+ #if ENABLE_DEBUG_CONFIG_OPTIONS
328+ m_funcState.body = funcInfo->GetBody ();
329+ if (DO_WASM_TRACE_DECODER)
330+ {
331+ Output::Print (_u (" Decoding " ));
332+ m_funcState.body ->DumpFullFunctionName ();
333+ if (sizeof (intptr_t ) == 8 )
334+ {
335+ Output::Print (_u (" : start = 0x%llx, end = 0x%llx, size = 0x%x\n " ), (intptr_t )m_pc, (intptr_t )m_curFuncEnd, m_funcState.size );
336+ }
337+ else
338+ {
339+ Output::Print (_u (" : start = 0x%x, end = 0x%x, size = 0x%x\n " ), (intptr_t )m_pc, (intptr_t )m_curFuncEnd, m_funcState.size );
340+ }
341+ }
342+ #endif
312343
313344 uint32 length = 0 ;
314345 uint32 numLocalsEntries = LEB128 (length);
@@ -339,6 +370,9 @@ void WasmBinaryReader::SeekToFunctionBody(class WasmFunctionInfo* funcInfo)
339370void WasmBinaryReader::FunctionEnd ()
340371{
341372 m_readerState = READER_STATE_UNKNOWN;
373+ #if ENABLE_DEBUG_CONFIG_OPTIONS
374+ m_funcState.body = nullptr ;
375+ #endif
342376}
343377
344378bool WasmBinaryReader::IsCurrentFunctionCompleted () const
@@ -1156,39 +1190,20 @@ MaxAllowedType WasmBinaryReader::LEB128(uint32 &length, bool sgn)
11561190 result |= -((int64)1 << shamt);
11571191 }
11581192 }
1159-
1160- if (!sgn)
1161- {
1162- if (sizeof (MaxAllowedType) == 4 )
1163- {
1164- TRACE_WASM_LEB128 (_u (" Binary decoder: LEB128 length = %u, value = %u (0x%x)" ), length, result, result);
1165- }
1166- else if (sizeof (MaxAllowedType) == 8 )
1167- {
1168- TRACE_WASM_LEB128 (_u (" Binary decoder: LEB128 length = %u, value = %llu (0x%llx)" ), length, result, result);
1169- }
1170- }
1171-
11721193 return result;
11731194}
11741195
11751196// Signed LEB128
11761197template <>
11771198int32 WasmBinaryReader::SLEB128 (uint32 &length)
11781199{
1179- int32 result = LEB128<uint32>(length, true );
1180-
1181- TRACE_WASM_LEB128 (_u (" Binary decoder: SLEB128 length = %u, value = %d (0x%x)" ), length, result, result);
1182- return result;
1200+ return LEB128<uint32>(length, true );
11831201}
11841202
11851203template <>
11861204int64 WasmBinaryReader::SLEB128 (uint32 &length)
11871205{
1188- int64 result = LEB128<uint64>(length, true );
1189-
1190- TRACE_WASM_LEB128 (_u (" Binary decoder: SLEB128 length = %u, value = %lld (0x%llx)" ), length, result, result);
1191- return result;
1206+ return LEB128<uint64>(length, true );
11921207}
11931208
11941209WasmNode WasmBinaryReader::ReadInitExpr (bool isOffset)
@@ -1199,7 +1214,10 @@ WasmNode WasmBinaryReader::ReadInitExpr(bool isOffset)
11991214 }
12001215
12011216 m_funcState.count = 0 ;
1202- m_funcState.size = m_currentSection.end - m_pc;
1217+ m_funcState.size = (uint32)(m_currentSection.end - m_pc);
1218+ #if TARGET_64
1219+ Assert (m_pc + m_funcState.size == m_currentSection.end );
1220+ #endif
12031221 ReadExpr ();
12041222 WasmNode node = m_currentNode;
12051223 switch (node.op )
0 commit comments