Skip to content

Commit 58a0d04

Browse files
committed
op.c: Add debugging dump function
This function dumps out an inversion map
1 parent 84ac8fa commit 58a0d04

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

embed.fnc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ p |OP* |pmruntime |NN OP *o|NN OP *expr|NULLOK OP *repl \
15061506
#if defined(PERL_IN_OP_C)
15071507
S |OP* |pmtrans |NN OP* o|NN OP* expr|NN OP* repl
15081508
#endif
1509+
p |void |invmap_dump |NN SV* invlist|NN UV * map
15091510
Ap |void |pop_scope
15101511
Ap |void |push_scope
15111512
#if defined(PERL_IN_PERLY_C) || defined(PERL_IN_OP_C) || defined(PERL_IN_TOKE_C)
@@ -1919,7 +1920,9 @@ EXpR |SV* |_setup_canned_invlist|const STRLEN size|const UV element0|NN UV** oth
19191920
#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_SV_C)
19201921
EpX |SV* |invlist_clone |NN SV* const invlist|NULLOK SV* newlist
19211922
#endif
1922-
#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) || defined(PERL_IN_PP_C)
1923+
#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) \
1924+
|| defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) \
1925+
|| defined(PERL_IN_PP_C) || defined(PERL_IN_OP_C)
19231926
EiRT |UV* |invlist_array |NN SV* const invlist
19241927
EiRT |bool |is_invlist |NULLOK SV* const invlist
19251928
EiRT |bool* |get_invlist_offset_addr|NN SV* invlist

embed.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@
10941094
#endif
10951095
#define regprop(a,b,c,d,e) Perl_regprop(aTHX_ a,b,c,d,e)
10961096
# endif
1097-
# if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) || defined(PERL_IN_PP_C)
1097+
# if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) || defined(PERL_IN_PP_C) || defined(PERL_IN_OP_C)
10981098
#define _invlist_contains_cp S__invlist_contains_cp
10991099
#define _invlist_len S__invlist_len
11001100
#define _invlist_search Perl__invlist_search
@@ -1288,6 +1288,7 @@
12881288
#define init_named_cv(a,b) Perl_init_named_cv(aTHX_ a,b)
12891289
#define init_uniprops() Perl_init_uniprops(aTHX)
12901290
#define invert(a) Perl_invert(aTHX_ a)
1291+
#define invmap_dump(a,b) Perl_invmap_dump(aTHX_ a,b)
12911292
#define io_close(a,b,c,d) Perl_io_close(aTHX_ a,b,c,d)
12921293
#define isinfnansv(a) Perl_isinfnansv(aTHX_ a)
12931294
#define jmaybe(a) Perl_jmaybe(aTHX_ a)

invlist_inline.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
|| defined(PERL_IN_REGCOMP_C) \
1414
|| defined(PERL_IN_REGEXEC_C) \
1515
|| defined(PERL_IN_TOKE_C) \
16-
|| defined(PERL_IN_PP_C)
16+
|| defined(PERL_IN_PP_C) \
17+
|| defined(PERL_IN_OP_C)
1718

1819
/* An element is in an inversion list iff its index is even numbered: 0, 2, 4,
1920
* etc */

op.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ recursive, but it's recursive on basic blocks, not on tree nodes.
164164
#include "keywords.h"
165165
#include "feature.h"
166166
#include "regcomp.h"
167+
#include "invlist_inline.h"
167168

168169
#define CALL_PEEP(o) PL_peepp(aTHX_ o)
169170
#define CALL_RPEEP(o) PL_rpeepp(aTHX_ o)
@@ -6713,6 +6714,46 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
67136714
return fold_constants(op_integerize(op_std_init((OP *)binop)));
67146715
}
67156716

6717+
void
6718+
Perl_invmap_dump(pTHX_ SV* invlist, UV *map)
6719+
{
6720+
const char indent[] = " ";
6721+
6722+
UV len = _invlist_len(invlist);
6723+
UV * array = invlist_array(invlist);
6724+
UV i;
6725+
6726+
PERL_ARGS_ASSERT_INVMAP_DUMP;
6727+
6728+
for (i = 0; i < len; i++) {
6729+
UV start = array[i];
6730+
UV end = (i + 1 < len) ? array[i+1] - 1 : IV_MAX;
6731+
6732+
PerlIO_printf(Perl_debug_log, "%s[%" UVuf "] 0x%04" UVXf, indent, i, start);
6733+
if (end == IV_MAX) {
6734+
PerlIO_printf(Perl_debug_log, " .. INFTY");
6735+
}
6736+
else if (end != start) {
6737+
PerlIO_printf(Perl_debug_log, " .. 0x%04" UVXf, end);
6738+
}
6739+
else {
6740+
PerlIO_printf(Perl_debug_log, " ");
6741+
}
6742+
6743+
PerlIO_printf(Perl_debug_log, "\t");
6744+
6745+
if (map[i] == TR_UNLISTED) {
6746+
PerlIO_printf(Perl_debug_log, "TR_UNLISTED\n");
6747+
}
6748+
else if (map[i] == TR_SPECIAL_HANDLING) {
6749+
PerlIO_printf(Perl_debug_log, "TR_SPECIAL_HANDLING\n");
6750+
}
6751+
else {
6752+
PerlIO_printf(Perl_debug_log, "0x%04" UVXf "\n", map[i]);
6753+
}
6754+
}
6755+
}
6756+
67166757
/* Helper function for S_pmtrans(): comparison function to sort an array
67176758
* of codepoint range pairs. Sorts by start point, or if equal, by end
67186759
* point */

proto.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,9 @@ PERL_CALLCONV OP* Perl_invert(pTHX_ OP* cmd)
15481548
__attribute__warn_unused_result__;
15491549
#define PERL_ARGS_ASSERT_INVERT
15501550

1551+
PERL_CALLCONV void Perl_invmap_dump(pTHX_ SV* invlist, UV * map);
1552+
#define PERL_ARGS_ASSERT_INVMAP_DUMP \
1553+
assert(invlist); assert(map)
15511554
PERL_CALLCONV bool Perl_io_close(pTHX_ IO* io, GV *gv, bool not_implicit, bool warn_on_fail);
15521555
#define PERL_ARGS_ASSERT_IO_CLOSE \
15531556
assert(io)
@@ -5829,7 +5832,7 @@ PERL_CALLCONV void Perl_regprop(pTHX_ const regexp *prog, SV* sv, const regnode*
58295832
#define PERL_ARGS_ASSERT_REGPROP \
58305833
assert(sv); assert(o)
58315834
#endif
5832-
#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) || defined(PERL_IN_PP_C)
5835+
#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) || defined(PERL_IN_PP_C) || defined(PERL_IN_OP_C)
58335836
#ifndef PERL_NO_INLINE_FUNCTIONS
58345837
PERL_STATIC_INLINE bool S__invlist_contains_cp(SV* const invlist, const UV cp)
58355838
__attribute__warn_unused_result__;

0 commit comments

Comments
 (0)