-
Notifications
You must be signed in to change notification settings - Fork 7
/
asm.awk
executable file
·107 lines (105 loc) · 2.55 KB
/
asm.awk
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
# -*- Mode: AWK; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*-
BEGIN {
LET1="a"
GFILE= TEMP "/asm_a.gperf"
print "struct asm_id { char *name; InstID id; };" > GFILE
print "%%" > GFILE
opMap["ar.pfs"] = "A";
opMap["ar.ccv"] = "A";
opMap["ar.csd"] = "A";
opMap["ar3"] = "A";
opMap["cr3"] = "C";
opMap["b1"] = "B";
opMap["b2"] = "B";
opMap["f1"] = "F";
opMap["f2"] = "F";
opMap["f3"] = "F";
opMap["f4"] = "F";
opMap["p1"] = "P";
opMap["p2"] = "P";
opMap["r0"] = "R";
opMap["r1"] = "R";
opMap["r2"] = "R";
opMap["r3"] = "R";
opMap["1"] = "I";
opMap["8"] = "I";
opMap["16"] = "I";
opMap["count2"] = "I";
opMap["count5"] = "I";
opMap["count6"] = "I";
opMap["fclass9"] = "I";
opMap["amask7"] = "I";
opMap["omask7"] = "I";
opMap["pos6"] = "I";
opMap["len4"] = "I";
opMap["len6"] = "I";
opMap["imm1"] = "I";
opMap["imm2"] = "I";
opMap["imm8"] = "I";
opMap["imm9"] = "I";
opMap["imm14"] = "I";
opMap["imm21"] = "I";
opMap["imm22"] = "I";
opMap["imm24"] = "I";
opMap["imm44"] = "I";
opMap["imm62"] = "I";
opMap["imm64"] = "I";
opMap["inc3"] = "I";
opMap["mask17"] = "I";
opMap["mbtype4"] = "I";
opMap["mhtype8"] = "I";
opMap["tag13"] = "I";
opMap["target25"] = "I";
opMap["target64"] = "I";
opMap["i"] = "I";
opMap["l"] = "I";
opMap["o"] = "I";
opMap["r"] = "I";
opMap["[r3]"] = "M";
opMap["rr[r3]"] = "rr";
opMap["dbr[r3]"] = "dbr";
opMap["ibr[r3]"] = "ibr";
opMap["pkr[r3]"] = "pkr";
opMap["pmc[r3]"] = "pmc";
opMap["pmd[r3]"] = "pmd";
opMap["msr[r3]"] = "msr";
opMap["dtr[r3]"] = "dtr";
opMap["itr[r3]"] = "itr";
opMap["cpuid[r3]"] = "cpuid";
}
/^#/ {
next
}
{
format = $1;
mnem = $2;
mnem_start = index($0, $2);
first = substr(mnem,1,1);
if (first != LET1) {
close(GFILE);
GFILE= TEMP "/asm_" first ".gperf";
LET1 = first;
print "struct asm_id { char *name; InstID id; };" > GFILE;
print "%%" > GFILE
}
sub(/:.*$/, "")
inst = substr($0, mnem_start)
gsub(/-/, "m", inst)
gsub(/[^a-zA-Z0-9.]/, "_", inst)
gsub(/__+/, "_", inst)
sub(/_$/, "", inst)
instID = "EM_" toupper(inst)
gsub(/\./, "_", instID)
ops = ""
for (i = 3; i <= NF; i++) {
gsub(/[=,]/, "", $i);
if ($i in opMap)
ops = ops opMap[$i];
else
ops = ops $i;
}
if (ops == "")
print mnem ", " instID > GFILE;
else
print mnem "_" ops ", " instID > GFILE
}