Skip to content

Commit

Permalink
[JIT] Parse oplist operands
Browse files Browse the repository at this point in the history
Operand structure is pairlist of direction => type.
  • Loading branch information
bdw committed Jan 6, 2019
1 parent cc00d56 commit c529cbb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
11 changes: 2 additions & 9 deletions tools/expr-template-compiler.pl
Expand Up @@ -6,6 +6,7 @@ package template_compiler;
use Getopt::Long;
use File::Spec;
use Scalar::Util qw(looks_like_number refaddr reftype);
use List::Util qw(pairkeys);

# use my libs
use FindBin;
Expand All @@ -27,7 +28,6 @@ package template_compiler;
# options to compile
my %OPTIONS = (
prefix => 'MVM_JIT_',
oplist => File::Spec->catfile($FindBin::Bin, File::Spec->updir, qw(src core oplist)),
include => 1,
);
GetOptions(\%OPTIONS, qw(prefix=s list=s input=s output=s include! test));
Expand Down Expand Up @@ -91,18 +91,11 @@ END
# first read the correct order of opcodes
my %OPNAMES = map { $OPLIST[$_][0] => $_ } 0..$#OPLIST;

# cache operand direction
sub opcode_operand_direction {
$_[0] =~ m/^([rw])l?\(/ ? $1 : '';
}

# Pre compute exptected operand type and direction
my %MOAR_OPERAND_DIRECTION;
for my $opcode (@OPLIST) {
my ($opname, undef, $operands) = @$opcode;
$MOAR_OPERAND_DIRECTION{$opname} = [
map opcode_operand_direction($_), @$operands
];
$MOAR_OPERAND_DIRECTION{$opname} = [pairkeys @$operands];
}

# Need a global constant table
Expand Down
12 changes: 7 additions & 5 deletions tools/lib/oplist.pm
@@ -1,12 +1,12 @@
package oplist;
use strict;
use warnings;
use File::Spec;
use File::Spec::Functions qw(splitpath updir catpath catdir);
use constant OPLIST => do {
my ($path, $directory, $filename) = File::Spec->splitpath(__FILE__);
my $ud = File::Spec->updir();
File::Spec->catpath($path, File::Spec->catdir($directory, ($ud) x 2,, qw(src core)), 'oplist');
my ($path, $directory, $filename) = splitpath(__FILE__);
catpath($path, catdir($directory, (updir()) x 2, qw(src core)), 'oplist');
};

# Parse MoarVM oplist file and stash it in @OPLIST and %OPLIST
sub parse_oplist {
my ($fh) = @_;
Expand All @@ -22,8 +22,10 @@ sub parse_oplist {
$attribute = $_;
} elsif (m/^:\w+$/) {
push @adverbs, $_;
} elsif (m/^([rw])l?\((.+)\)$/) {
push @operands, $1 => $2;
} else {
push @operands, $_;
push @operands, '' => $_;
}
}
push @oplist, [ $name, $attribute, \@operands, \@adverbs ];
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/sexpr.pm
@@ -1,7 +1,6 @@
package sexpr;
use strict;
use warnings;
use Carp qw(croak);
use Exporter qw(import);
our @EXPORT = qw(sexpr_decode sexpr_encode);

Expand All @@ -16,6 +15,7 @@ our @EXPORT = qw(sexpr_decode sexpr_encode);

sub sexpr_encode {
my $list = shift;
return "'$list'" unless ref($list);
my $out = '(';
for my $item (@$list) {
if (ref($item) eq 'ARRAY') {
Expand Down

0 comments on commit c529cbb

Please sign in to comment.