Skip to content

Commit 10f8086

Browse files
committed
Add -RegexBytecodeDebug Flag to display RegExp bytecode's binary layout
1 parent 9e68676 commit 10f8086

File tree

6 files changed

+986
-437
lines changed

6 files changed

+986
-437
lines changed

lib/Common/ConfigFlagsList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ PHASE(All)
509509
#define DEFAULT_CONFIG_RegexTracing (false)
510510
#define DEFAULT_CONFIG_RegexProfile (false)
511511
#define DEFAULT_CONFIG_RegexDebug (false)
512+
#define DEFAULT_CONFIG_RegexBytecodeDebug (false)
512513
#define DEFAULT_CONFIG_RegexOptimize (true)
513514
#define DEFAULT_CONFIG_DynamicRegexMruListSize (16)
514515
#define DEFAULT_CONFIG_GoptCleanupThreshold (25)
@@ -1435,6 +1436,7 @@ FLAGNR(Boolean, ValidateHeapEnum , "Validate that heap enumeration is repor
14351436
FLAGR (Boolean, RegexTracing , "Trace all Regex invocations to the output.", DEFAULT_CONFIG_RegexTracing)
14361437
FLAGR (Boolean, RegexProfile , "Collect usage statistics on all Regex invocations.", DEFAULT_CONFIG_RegexProfile)
14371438
FLAGR (Boolean, RegexDebug , "Trace compilation of UnifiedRegex expressions.", DEFAULT_CONFIG_RegexDebug)
1439+
FLAGR (Boolean, RegexBytecodeDebug , "Display layout of UnifiedRegex bytecode (requires -RegexDebug to view).", DEFAULT_CONFIG_RegexBytecodeDebug)
14381440
FLAGR (Boolean, RegexOptimize , "Optimize regular expressions in the unified Regex system (default: true)", DEFAULT_CONFIG_RegexOptimize)
14391441
FLAGR (Number, DynamicRegexMruListSize, "Size of the MRU list for dynamic regexes", DEFAULT_CONFIG_DynamicRegexMruListSize)
14401442
#endif

lib/Parser/RegexCompileTime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4633,7 +4633,7 @@ namespace UnifiedRegex
46334633
#if ENABLE_REGEX_CONFIG_OPTIONS
46344634
if (w != 0)
46354635
{
4636-
w->PrintEOL(_u("REGEX PROGRAM /%s/ "), PointerValue(program->source));
4636+
w->PrintEOL(_u("REGEX PROGRAM /%s/"), PointerValue(program->source));
46374637
program->Print(w);
46384638
w->Flush();
46394639
}

lib/Parser/RegexOpCodes.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
// ClassName == TagName##Inst
77
// MTemplate(TagName, TemplateDeclaration, GenericClassName, SpecializedClassName)
88

9+
// 0x00
10+
M(Nop) // Opcode byte 0x00 is a NOP (allows for NOP-sleds for alignment if necessary)
911
M(Fail)
1012
M(Succ)
1113
M(Jump)
1214
M(JumpIfNotChar)
1315
M(MatchCharOrJump)
1416
M(JumpIfNotSet)
1517
M(MatchSetOrJump)
18+
// 0x08
1619
M(Switch10)
1720
M(Switch20)
1821
M(SwitchAndConsume10)
@@ -21,6 +24,7 @@ M(BOITest)
2124
M(EOITest)
2225
M(BOLTest)
2326
M(EOLTest)
27+
// 0x10
2428
M(WordBoundaryTest)
2529
M(MatchChar)
2630
M(MatchChar2)
@@ -29,6 +33,7 @@ M(MatchChar4)
2933
MTemplate(MatchSet, template<bool IsNegation>, MatchSetInst, MatchSetInst<false>)
3034
MTemplate(MatchNegatedSet, template<bool IsNegation>, MatchSetInst, MatchSetInst<true>)
3135
M(MatchLiteral)
36+
// 0x18
3237
M(MatchLiteralEquiv)
3338
M(MatchTrie)
3439
M(OptMatchChar)
@@ -37,30 +42,35 @@ M(SyncToCharAndContinue)
3742
M(SyncToChar2SetAndContinue)
3843
MTemplate(SyncToSetAndContinue, template<bool IsNegation>, SyncToSetAndContinueInst, SyncToSetAndContinueInst<false>)
3944
MTemplate(SyncToNegatedSetAndContinue, template<bool IsNegation>, SyncToSetAndContinueInst, SyncToSetAndContinueInst<true>)
40-
M(SyncToChar2LiteralAndContinue)
41-
M(SyncToLiteralAndContinue)
42-
M(SyncToLinearLiteralAndContinue)
43-
M(SyncToLiteralEquivAndContinue)
44-
M(SyncToLiteralEquivTrivialLastPatCharAndContinue)
45+
// 0x20
46+
M(SyncToChar2LiteralAndContinue) // SyncToLiteralAndContinueInstT<Char2LiteralScannerMixin>
47+
M(SyncToLiteralAndContinue) // SyncToLiteralAndContinueInstT<ScannerMixin>
48+
M(SyncToLinearLiteralAndContinue) // SyncToLiteralAndContinueInstT<ScannerMixin_WithLinearCharMap>
49+
M(SyncToLiteralEquivAndContinue) // SyncToLiteralAndContinueInstT<EquivScannerMixin>
50+
M(SyncToLiteralEquivTrivialLastPatCharAndContinue) // SyncToLiteralAndContinueInstT<EquivTrivialLastPatCharScannerMixin>
4551
M(SyncToCharAndConsume)
4652
M(SyncToChar2SetAndConsume)
4753
MTemplate(SyncToSetAndConsume, template<bool IsNegation>, SyncToSetAndConsumeInst, SyncToSetAndConsumeInst<false>)
54+
// 0x28
4855
MTemplate(SyncToNegatedSetAndConsume, template<bool IsNegation>, SyncToSetAndConsumeInst, SyncToSetAndConsumeInst<true>)
49-
M(SyncToChar2LiteralAndConsume)
50-
M(SyncToLiteralAndConsume)
51-
M(SyncToLinearLiteralAndConsume)
52-
M(SyncToLiteralEquivAndConsume)
53-
M(SyncToLiteralEquivTrivialLastPatCharAndConsume)
56+
M(SyncToChar2LiteralAndConsume) // SyncToLiteralAndConsumeInstT<Char2LiteralScannerMixin>
57+
M(SyncToLiteralAndConsume) // SyncToLiteralAndConsumeInstT<ScannerMixin>
58+
M(SyncToLinearLiteralAndConsume) // SyncToLiteralAndConsumeInstT<ScannerMixin_WithLinearCharMap>
59+
M(SyncToLiteralEquivAndConsume) // SyncToLiteralAndConsumeInstT<EquivScannerMixin>
60+
M(SyncToLiteralEquivTrivialLastPatCharAndConsume) // SyncToLiteralAndConsumeInstT<EquivTrivialLastPatCharScannerMixin>
5461
M(SyncToCharAndBackup)
62+
// REVIEW (doilij): why not have a SyncToChar2SetAndBackup ?
5563
MTemplate(SyncToSetAndBackup, template<bool IsNegation>, SyncToSetAndBackupInst, SyncToSetAndBackupInst<false>)
64+
// 0x30
5665
MTemplate(SyncToNegatedSetAndBackup, template<bool IsNegation>, SyncToSetAndBackupInst, SyncToSetAndBackupInst<true>)
57-
M(SyncToChar2LiteralAndBackup)
58-
M(SyncToLiteralAndBackup)
59-
M(SyncToLinearLiteralAndBackup)
60-
M(SyncToLiteralEquivAndBackup)
61-
M(SyncToLiteralEquivTrivialLastPatCharAndBackup)
66+
M(SyncToChar2LiteralAndBackup) // SyncToLiteralAndBackupInstT<Char2LiteralScannerMixin>
67+
M(SyncToLiteralAndBackup) // SyncToLiteralAndBackupInstT<ScannerMixin>
68+
M(SyncToLinearLiteralAndBackup) // SyncToLiteralAndBackupInstT<ScannerMixin_WithLinearCharMap>
69+
M(SyncToLiteralEquivAndBackup) // SyncToLiteralAndBackupInstT<EquivScannerMixin>
70+
M(SyncToLiteralEquivTrivialLastPatCharAndBackup) // SyncToLiteralAndBackupInstT<EquivTrivialLastPatCharScannerMixin>
6271
M(SyncToLiteralsAndBackup)
6372
M(MatchGroup)
73+
// 0x38
6474
M(BeginDefineGroup)
6575
M(EndDefineGroup)
6676
M(DefineGroupFixed)
@@ -69,6 +79,7 @@ M(RepeatLoop)
6979
M(BeginLoopIfChar)
7080
M(BeginLoopIfSet)
7181
M(RepeatLoopIfChar)
82+
// 0x40
7283
M(RepeatLoopIfSet)
7384
M(BeginLoopFixed)
7485
M(RepeatLoopFixed)
@@ -77,6 +88,7 @@ M(LoopSetWithFollowFirst)
7788
M(BeginLoopFixedGroupLastIteration)
7889
M(RepeatLoopFixedGroupLastIteration)
7990
M(BeginGreedyLoopNoBacktrack)
91+
// 0x48
8092
M(RepeatGreedyLoopNoBacktrack)
8193
MTemplate(ChompCharStar, template<ChompMode Mode>, ChompCharInst, ChompCharInst<ChompMode::Star>)
8294
MTemplate(ChompCharPlus, template<ChompMode Mode>, ChompCharInst, ChompCharInst<ChompMode::Plus>)
@@ -85,6 +97,7 @@ MTemplate(ChompSetPlus, template<ChompMode Mode>, ChompSetInst, ChompSetInst<Cho
8597
MTemplate(ChompCharGroupStar, template<ChompMode Mode>, ChompCharGroupInst, ChompCharGroupInst<ChompMode::Star>)
8698
MTemplate(ChompCharGroupPlus, template<ChompMode Mode>, ChompCharGroupInst, ChompCharGroupInst<ChompMode::Plus>)
8799
MTemplate(ChompSetGroupStar, template<ChompMode Mode>, ChompSetGroupInst, ChompSetGroupInst<ChompMode::Star>)
100+
// 0x50
88101
MTemplate(ChompSetGroupPlus, template<ChompMode Mode>, ChompSetGroupInst, ChompSetGroupInst<ChompMode::Plus>)
89102
M(ChompCharBounded)
90103
M(ChompSetBounded)
@@ -93,6 +106,7 @@ M(Try)
93106
M(TryIfChar)
94107
M(TryMatchChar)
95108
M(TryIfSet)
109+
// 0x58
96110
M(TryMatchSet)
97111
M(BeginAssertion)
98112
M(EndAssertion)

0 commit comments

Comments
 (0)