~charles/awk-riscv

ref: ce30c930be0f157a14442b738993e54d8d0dc52f awk-riscv/scripts/make_op2str.py -rwxr-xr-x 814 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
19
20
21
22
23
#!/usr/bin/env python3

# This script reads instructions.txt and generates a list of AWK if statements
# for converting the opcode to a string.

import sys

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)
    m=line[0]
    if len(line) == 4:
        print("if (opcode(v) == 0x{:x}) {{ return \"{}\" }}".format(o, m))
    elif len(line) == 6:
        funct7=int(line[2], 2)
        funct3=int(line[3], 2)
        print("if ((opcode(v) == 0x{:x}) && (funct7(v) == 0x{:x}) && (funct3(v) == 0x{:x})) {{return \"{}\"}}".format(o, funct7, funct3, m))
    elif len(line) == 5:
        funct3=int(line[2], 2)
        print("if ((opcode(v) == 0x{:x}) && (funct3(v) == 0x{:x})) {{return \"{}\"}}".format(o, funct3, m))