Skip to content

Commit dd47dc5

Browse files
committed
Eliminate virtual Print from Inst to improve usefulness of -RegexBytecodeDebug
1 parent 1ca595a commit dd47dc5

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

lib/Parser/RegexRuntime.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,6 @@ namespace UnifiedRegex
386386
byte *currentByte = startByte;
387387
w->Print(_u("0x%p[+0x%03x](0x%03x) [%s]:"), startByte, offset, size, annotation);
388388

389-
if ((T *)this == that)
390-
{
391-
w->PrintEOL(_u(" (no unique data -- skipping)"));
392-
return;
393-
}
394-
395389
for (; currentByte < endByte; ++currentByte)
396390
{
397391
if ((currentByte - endByte) % 4 == 0)
@@ -412,7 +406,7 @@ namespace UnifiedRegex
412406
ptrdiff_t offsetToData = (byte *)&(start->tag) - ((byte *)start);
413407
size_t size = baseSize - offsetToData;
414408

415-
byte *startByte = (byte *)(&(start->tag)); // skip over the vtable pointer
409+
byte *startByte = (byte *)(&(start->tag));
416410
byte *endByte = startByte + size;
417411
byte *currentByte = startByte;
418412
w->Print(_u("0x%p[+0x%03x](0x%03x) [%s]:"), startByte, offsetToData, size, annotation);
@@ -5722,7 +5716,6 @@ namespace UnifiedRegex
57225716
return res;
57235717
}
57245718

5725-
57265719
#if ENABLE_REGEX_CONFIG_OPTIONS
57275720
void Matcher::Print(DebugWriter* w, const Char* const input, const CharCount inputLength, CharCount inputOffset, const uint8* instPointer, ContStack &contStack, AssertionStack &assertionStack) const
57285721
{
@@ -5759,7 +5752,28 @@ namespace UnifiedRegex
57595752
if (program->tag == Program::BOIInstructionsTag || program->tag == Program::InstructionsTag)
57605753
{
57615754
w->Print(_u("instPointer: "));
5762-
((const Inst*)instPointer)->Print(w, InstPointerToLabel(instPointer), program->rep.insts.litbuf);
5755+
5756+
const Inst* inst = (const Inst*)instPointer;
5757+
switch (inst->tag)
5758+
{
5759+
#define MBase(TagName, ClassName) \
5760+
case Inst::TagName: \
5761+
{ \
5762+
const ClassName *actualInst = static_cast<const ClassName *>(inst); \
5763+
actualInst->Print(w, InstPointerToLabel(instPointer), program->rep.insts.litbuf); \
5764+
break; \
5765+
}
5766+
#define M(TagName) MBase(TagName, TagName##Inst)
5767+
#define MTemplate(TagName, TemplateDeclaration, GenericClassName, SpecializedClassName) MBase(TagName, SpecializedClassName)
5768+
#include "RegexOpCodes.h"
5769+
#undef MBase
5770+
#undef M
5771+
#undef MTemplate
5772+
default:
5773+
Assert(false);
5774+
__assume(false);
5775+
}
5776+
57635777
w->PrintEOL(_u("groups:"));
57645778
w->Indent();
57655779
for (int i = 0; i < program->numGroups; i++)
@@ -5920,7 +5934,26 @@ namespace UnifiedRegex
59205934
int i = 0;
59215935
while (curr != instsLim)
59225936
{
5923-
curr += ((Inst*)curr)->Print(w, (Label)(isBaselineMode ? i++ : curr - rep.insts.insts), rep.insts.litbuf);
5937+
const Inst *inst = (const Inst*)curr;
5938+
switch (inst->tag)
5939+
{
5940+
#define MBase(TagName, ClassName) \
5941+
case Inst::TagName: \
5942+
{ \
5943+
const ClassName *actualInst = static_cast<const ClassName *>(inst); \
5944+
curr += actualInst->Print(w, (Label)(isBaselineMode ? i++ : curr - rep.insts.insts), rep.insts.litbuf); \
5945+
break; \
5946+
}
5947+
#define M(TagName) MBase(TagName, TagName##Inst)
5948+
#define MTemplate(TagName, TemplateDeclaration, GenericClassName, SpecializedClassName) MBase(TagName, SpecializedClassName)
5949+
#include "RegexOpCodes.h"
5950+
#undef MBase
5951+
#undef M
5952+
#undef MTemplate
5953+
default:
5954+
Assert(false);
5955+
__assume(false);
5956+
}
59245957
}
59255958
w->Unindent();
59265959
w->PrintEOL(_u("}"));

lib/Parser/RegexRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ namespace UnifiedRegex
723723
#if ENABLE_REGEX_CONFIG_OPTIONS
724724
static bool IsBaselineMode();
725725
static Label GetPrintLabel(Label label);
726-
virtual int Print(DebugWriter*w, Label label, const Char* litbuf) const = 0;
726+
727727
template <typename T>
728728
void PrintBytes(DebugWriter *w, Inst *inst, T *that, const char16 *annotation) const;
729729
#endif
@@ -737,7 +737,7 @@ namespace UnifiedRegex
737737
}
738738

739739
#if ENABLE_REGEX_CONFIG_OPTIONS
740-
#define INST_BODY_PRINT virtual int Print(DebugWriter*w, Label label, const Char* litbuf) const override;
740+
#define INST_BODY_PRINT int Print(DebugWriter*w, Label label, const Char* litbuf) const;
741741
#else
742742
#define INST_BODY_PRINT
743743
#endif

0 commit comments

Comments
 (0)