forked from MahdiSafsafi/opcodesDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.pl
68 lines (62 loc) · 1.78 KB
/
base.pl
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use strict;
use warnings;
use Data::Dumper;
no warnings 'experimental::smartmatch';
sub getParent($$) {
( my $hash, local $_ ) = @_;
$hash = $hash->{$1} while (s/^([^\.]+)\.//);
return $hash;
}
sub setData($$$) {
( my $hash, my $name, local $_ ) = @_;
if ( ref( $hash->{$name} ) =~ /ARRAY/ ) {
push( @{ $hash->{$name} }, split /\|/ );
}
elsif ( ref( $hash->{$name} ) =~ /HASH/ ) {
$hash->{$name}->{$_} = 1 foreach ( split /\|/ );
}
else {
$hash->{$name} = $_;
}
}
sub applyShortCuts($$$) {
my ( $name, $value, $shortcuts ) = @_;
local $_ = '';
for ( my $i = 0 ; $i < scalar @$shortcuts ; $i += 2 ) {
my $shortcut = @$shortcuts[$i];
my @names = $shortcut =~ /^ARRAY\(.+\)$/ ? @$shortcut : $shortcut;
if ( $name ~~ @names ) {
$_ = @$shortcuts[ $i + 1 ];
s/\$/$name/;
last;
}
}
( $name, $value ) = ( $1, $2 // $value ) if (s/^([^\=]+)\=*(.+)*//);
return ( $name, $value );
}
sub processMetaData($$$) {
( my $template, local $_, my $shortcuts ) = @_;
while ($_) {
die "Can't match tokens in meta-data."
unless (s/^\s*([^\=\s+]+)(?:(?:\=(?|(?:"\s*(.+?)\s*")|(\S+))))*\s*//);
my ( $name, $value ) = applyShortCuts( $1, $2 // 1, $shortcuts );
my $parent = getParent( $template, $name );
$name =~ s/.+\.//;
setData( $parent, $name, $value );
}
}
sub getRegInfo($$) {
my ( $environment, $regname ) = @_;
foreach my $key ( keys %{ $environment->{registers} } ) {
my $hash = $environment->{registers}->{$key};
return ( name => '', type => $hash->{type}, size => $hash->{size} ) if ( $key eq $regname );
}
foreach my $key ( sort keys %{ $environment->{registers} } ) {
my $hash = $environment->{registers}->{$key};
foreach ( @{ $hash->{names} } ) {
return ( name => $_, type => $hash->{type}, size => $hash->{size} ) if ( $_ eq $regname );
}
}
();
}
1;