~charles/awk-riscv

ref: ce30c930be0f157a14442b738993e54d8d0dc52f awk-riscv/scripts/make_type.py -rwxr-xr-x 436 bytes
ce30c930Charles Daniels tweak comments a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3

# This script reads instructions.txt and generates a list of AWK if statements
# for checking the return type.

import sys

seen = []
for line in sys.stdin:
    line = [s.strip() for s in line.strip().split()]
    if len(line) < 1:
        continue
    t=line[-1]
    o=int(line[-2], 2)
    if o in seen:
        continue
    seen.append(o)
    print("if (opcode(v) == 0x{:x}) {{ return \"{}\" }}".format(o, t))