-
Notifications
You must be signed in to change notification settings - Fork 4
/
opcodes.pl
executable file
·120 lines (89 loc) · 2.44 KB
/
opcodes.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
#!/usr/bin/perl
#
# Copyright (C) 1998,1999,2000,2001 Kazuyuki Shudo
#
# generate opcodes.h
# from javasrc/src/share/javavm/include/opcodes.list
$opcodes_list = "opcodes.list";
$opcodes_h = "opcodes.h";
$opcodes_c = "opcodes.c";
#$opcode_len_type = "unsigned char"; # don't work correctly...
$opcode_len_type = "unsigned short";
#$opcode_len_type = "int";
open(OPCODES_LIST, "$opcodes_list") || die "$!: $opcodes_list";
open(OPCODES_H, ">$opcodes_h") || die "$!: $opcodes_h";
open(OPCODES_C, ">$opcodes_c") || die "$!: $opcodes_c";
print OPCODES_H "// $opcodes_h\n";
print OPCODES_H "// Don't edit this file.\n";
print OPCODES_H "// This file is generated by the script opcodes.pl.\n";
print OPCODES_H "\n";
$count = 0;
while (<OPCODES_LIST>) {
chomp;
split;
$opcode = $_[0];
$length = $_[1];
$pop = $_[2];
$push = $_[3];
if ($opcode =~ /^#/ || !$opcode) {
# comment line or empty line
next;
}
push(@opcodes, $opcode);
push(@opcode_length, $length);
push(@opcode_pop, $pop);
push(@opcode_push, $push);
# define opc_<opcode> number
print OPCODES_H "#define opc_$opcode";
printf OPCODES_H "\t%d\t// 0x%.2x len:%d\n",
$count, $count, $length;
$count++;
}
print OPCODES_H "\n";
# length
print OPCODES_H "extern " . $opcode_len_type . " opcode_length[];\n";
print OPCODES_C $opcode_len_type . " opcode_length[] = { ";
#print OPCODES_C "($opcode_len_type)"; # type
print OPCODES_C shift(@opcode_length);
while (@opcode_length) {
$length = shift(@opcode_length);
print OPCODES_C ", ";
# print OPCODES_C "($opcode_len_type)"; # type
print OPCODES_C "$length";
}
print OPCODES_C " };\n";
print OPCODES_C "\n";
# opcode
print OPCODES_H "extern char *opcode_symbol[];\n";
print OPCODES_C "char *opcode_symbol[] = { ";
$opcode = shift(@opcodes);
print OPCODES_C "\"$opcode\"";
while (@opcodes) {
$opcode = shift(@opcodes);
print OPCODES_C ", \"$opcode\"";
}
print OPCODES_C " };\n";
#print OPCODES_C "\n";
# pop
#print OPCODES_C "char *opcode_pop[] = { ";
#$pop = shift(@opcode_pop);
#print OPCODES_C "\"$pop\"";
#while (@opcode_pop) {
# $pop = shift(@opcode_pop);
# print OPCODES_C ", \"$pop\"";
#}
#print OPCODES_C " };\n";
#print OPCODES_C "\n";
## push
#print OPCODES_C "char *opcode_push[] = { ";
#$push = shift(@opcode_push);
#print OPCODES_C "\"$push\"";
#while (@opcode_push) {
# $push = shift(@opcode_push);
# print OPCODES_C ", \"$push\"";
#}
#print OPCODES_C " };\n";
close(OPCODES_LIST);
close(OPCODES_H);
close(OPCODES_C);
0;