X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=regcomp.pl;h=9370487a5cd13b715c3ac040a17d262132e73145;hb=c33ef3ac654cbe35caea1d36f34c68f0e4a134ba;hp=38c346cc0c1dc6d647c3e6a57beee2760873652d;hpb=2242947801b5a89c42ffba93b4c406f75e4cd049;p=p5sagit%2Fp5-mst-13.2.git diff --git a/regcomp.pl b/regcomp.pl index 38c346c..9370487 100644 --- a/regcomp.pl +++ b/regcomp.pl @@ -1,3 +1,18 @@ +#!/usr/bin/perl +# +# Regenerate (overwriting only if changed): +# +# regnodes.h +# +# from information stored in +# +# regcomp.sym +# regexp.h +# +# Accepts the standard regen_lib -q and -v args. +# +# This script is normally invoked from regen.pl. + BEGIN { # Get function prototypes require 'regen_lib.pl'; @@ -9,7 +24,7 @@ use warnings; open DESC, 'regcomp.sym'; my $ind = 0; -my (@name,@rest,@type,@code,@args,@longj); +my (@name,@rest,@type,@code,@args,@flags,@longj); my ($desc,$lastregop); while () { s/#.*$//; @@ -20,12 +35,12 @@ while () { next; } unless ($lastregop) { - $ind++; - ($name[$ind], $desc, $rest[$ind]) = split /\t+/, $_, 3; - ($type[$ind], $code[$ind], $args[$ind], $longj[$ind]) - = split /[,\s]\s*/, $desc, 4; + ($name[$ind], $desc, $rest[$ind]) = /^(\S+)\s+([^\t]+)\s*;\s*(.*)/; + ($type[$ind], $code[$ind], $args[$ind], $flags[$ind], $longj[$ind]) + = split /[,\s]\s*/, $desc; + ++$ind; } else { - my ($type,@lists)=split /\s*\t+\s*/, $_; + my ($type,@lists)=split /\s+/, $_; die "No list? $type" if !@lists; foreach my $list (@lists) { my ($names,$special)=split /:/, $list , 2; @@ -45,10 +60,10 @@ while () { die "unknown :type ':$special'"; } foreach my $suffix (@suffix) { - $ind++; $name[$ind]="$real$suffix"; $type[$ind]=$type; $rest[$ind]="state for $type"; + ++$ind; } } } @@ -64,15 +79,62 @@ close DESC; die "Too many regexp/state opcodes! Maximum is 256, but there are $lastregop in file!" if $lastregop>256; -my $tmp_h = 'tmp_reg.h'; +sub process_flags { + my ($flag, $varname, $comment) = @_; + $comment = '' unless defined $comment; + + $ind = 0; + my @selected; + my $bitmap = ''; + do { + my $set = $flags[$ind] && $flags[$ind] eq $flag ? 1 : 0; + # Whilst I could do this with vec, I'd prefer to do longhand the arithmetic + # ops in the C code. + my $current = do { + no warnings 'uninitialized'; + ord do { + no warnings 'substr'; + substr $bitmap, ($ind >> 3); + } + }; + substr $bitmap, ($ind >> 3), 1, chr($current | ($set << ($ind & 7))); + + push @selected, $name[$ind] if $set; + } while (++$ind < $lastregop); + my $out_string = join ', ', @selected, 0; + $out_string =~ s/(.{1,70},) /$1\n /g; + + my $out_mask = join ', ', map {sprintf "0x%02X", ord $_} split '', $bitmap; + + return $comment . <<"EOP"; +#define REGNODE_\U$varname\E(node) (PL_${varname}_bitmask[(node) >> 3] & (1 << ((node) & 7))) + +#ifndef DOINIT +EXTCONST U8 PL_${varname}[] __attribute__deprecated__; +#else +EXTCONST U8 PL_${varname}[] __attribute__deprecated__ = { + $out_string +}; +#endif /* DOINIT */ + +#ifndef DOINIT +EXTCONST U8 PL_${varname}_bitmask[]; +#else +EXTCONST U8 PL_${varname}_bitmask[] = { + $out_mask +}; +#endif /* DOINIT */ + +EOP +} + +my $tmp_h = 'regnodes.h-new'; unlink $tmp_h if -f $tmp_h; -open OUT, ">$tmp_h"; -#*OUT=\*STDOUT; -binmode OUT; +my $out = safer_open($tmp_h); -printf OUT <) { + if (/#define\s+(RXf_\w+)\s+(0x[A-F\d]+)/i) { + my $newval = eval $2; + if($val & $newval) { + die sprintf "Both $1 and $reverse{$newval} use %08X", $newval; + } + $val|=$newval; + $rxfv{$1}= $newval; + $reverse{$newval} = $1; + } +} +my %vrxf=reverse %rxfv; +printf $out "\t/* Bits in extflags defined: %032b */\n",$val; +for (0..31) { + my $n=$vrxf{2**$_}||"UNUSED_BIT_$_"; + $n=~s/^RXf_(PMf_)?//; + printf $out qq(\t%-20s/* 0x%08x */\n), + qq("$n",),2**$_; +} + +print $out <