-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathx86.pl
131 lines (116 loc) · 2.8 KB
/
x86.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# ======================================= x86 backend =======================================
use strict;
use warnings;
use feature qw/say/;
use Data::Dump qw/pp/;
use Carp qw/carp croak/;
use JSON::XS;
sub get_arch { 'x86' }
my @widths = ();
sub WIDTH(@) {
my ($name) = shift;
push @widths, { name => $name, width16 => shift, width32 => shift, width64 => shift };
}
sub SWIZZLE($) {
my ($hash) = @_;
$hash->{type} = 'swizzle_tv';
$hash->{ordered} = $hash->{array} = 1;
$hash;
}
require 'core.pl';
require 'node.pl';
require "db/attrs.pl";
require "db/x86/nodes.pl";
require 'db/x86/macros.pl';
require 'db/x86/width.pl';
require 'db/x86/registers.pl';
require 'db/x86/enums.pl';
foreach my $key (qw/base float system fpsimd simd advsimd amd via knc/) {
-f "db/x86/$key/tables.pl" and require "db/x86/$key/tables.pl";
require "db/x86/$key/pages.pl";
require "db/x86/$key/encodings.pl";
require "db/x86/$key/templates.pl";
-f "db/x86/$key/skiped.pl" and do {
warn sprintf "skiped.pl found in '%s' folder", $key;
require "db/x86/$key/skiped.pl";
}
}
sub TE { { error => 1 } }
sub parse_diagram {
local ($_) = @_;
my @fields = ();
while (/\G(\s*(\w+)\s*)/gc) {
my $name = $2;
/\G(=\s*)/gc or return undef;
/\G(\w+)/gc or return undef;
my $value = $1;
push @fields, { name => $name, value => $value };
}
return { fields => \@fields };
}
sub parse_metadata {
local ($_) = @_;
$_ = expand_macros($_);
return parse_docvars($_);
}
sub T($) {
my ($array) = @_;
local $_ = shift @$array;
my $bitdiffs = shift @$array;
my $encoding = shift @$array;
my $metadata = shift @$array;
$metadata = parse_metadata($metadata);
my $seen = seen();
$encoding =~ s/\s+//g;
my $syntax = {
text => $_,
mnem => '',
};
$syntax->{text} =~ s/(^\s*|\s+$)//g;
my $result = {
syntax => $syntax,
bitdiffs => undef,
metadata => $metadata,
};
if (s/^\s*(\w+)\s*//) {
$syntax->{mnem} = $1;
}
else {
carp sprintf "unable to get mnem from '%s'", $_;
return TE;
}
my $ast = parse_node($_);
$ast or return TE;
$syntax->{ast} = $ast;
if ( exists $seen->{$encoding} ) {
my $record = $seen->{$encoding};
push @{ $record->{templates} }, $result;
if ( $bitdiffs !~ /^\s*NONE\s*$/i ) {
my $diagram = parse_diagram($bitdiffs);
$result->{bitdiffs} = { fields => $diagram->{fields} };
}
}
else {
carp sprintf "unable to find encoding '%s'", $encoding;
return TE;
}
return $result;
}
my $records = records();
my $tables = tables();
my $enums = enums();
my $registers = registers();
my $environment = {
arch => 'x86',
version => '3',
enums => $enums,
records => $records,
tables => $tables,
widths => \@widths,
registers => $registers,
};
my $json = JSON::XS->new->pretty(1)->encode($environment);
open my $fh, '>', 'json/x86.json';
print $fh $json;
close $fh;
1;