File: expr_ops.pm

package info (click to toggle)
moarvm 2018.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,196 kB
  • sloc: ansic: 223,172; perl: 7,638; sh: 4,452; makefile: 1,089; python: 568; asm: 8
file content (40 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package expr_ops;
use strict;
use warnings;
use File::Spec::Functions qw(catdir  updir catpath splitpath);
use constant EXPR_OPS_H => do {
    my ($path, $directory, $filename) = splitpath(__FILE__);
    catpath($path, catdir($directory, updir(), 'src','jit'), 'expr_ops.h');
};

sub parse_expr_ops {
    my ($file_name) = @_;
    open my $fh, '<', $file_name
      or die "Coulqd not open '$file_name': $!";
    while (<$fh>) { last if m/#define MVM_JIT_EXPR_OPS/; }
    my @expr_ops;
    while (<$fh>) {
        next unless (m/\((\w+),\s*(-?\d+),\s*(\d+)\)/);
        push @expr_ops, [$1, $2, $3];
    }
    close $fh;
    return @expr_ops;
}

sub import {
    my ($class, @args) = @_;
    my @keys     = qw(name num_operands num_params cast);
    my @expr_ops = parse_expr_ops(@args ? @args : EXPR_OPS_H);
    my %expr_ops = map {
        my ($i, $op) = ($_, $expr_ops[$_]);
        lc($op->[0]) => { map({ $keys[$_] => $op->[$_] } 1..$#$op), 'idx' => $i };
    } 0..$#expr_ops;
    my ($caller) = caller();
    {
        no strict 'refs';
        *{$caller . '::EXPR_OPS'} = \@expr_ops;
        *{$caller . '::EXPR_OPS'} = \%expr_ops;
    }
}

1;