1 from enum
import Enum
, unique
7 def download_wiki_file(name
):
8 file_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
9 file_path
= os
.path
.join(file_dir
, name
)
10 if not os
.path
.isfile(file_path
):
11 url
= 'https://libre-riscv.org/openpower/isatables/' + name
12 r
= requests
.get(url
, allow_redirects
=True)
13 with
open(file_path
, 'w') as outfile
:
14 outfile
.write(r
.content
.decode("utf-8"))
19 file_path
= download_wiki_file(name
)
20 with
open(file_path
, 'r') as csvfile
:
21 reader
= csv
.DictReader(csvfile
)
25 # names of the fields in the tables that don't correspond to an enum
26 single_bit_flags
= ['CR in', 'CR out', 'inv A', 'inv out',
27 'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
28 'sgn', 'lk', 'sgl pipe']
30 # default values for fields in the table
31 default_values
= {'unit': "NONE", 'internal op': "OP_ILLEGAL",
32 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
34 'rc' : 'NONE', 'cry in' : 'ZERO', 'form': 'NONE'}
36 def get_signal_name(name
):
39 return name
.lower().replace(' ', '_')
82 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
84 class InternalOp(Enum
):
85 OP_ILLEGAL
= 0 # important that this is zero (see power_decoder.py)
218 # SPRs - Special-Purpose Registers. See V3.0B Figure 18 p971 and
219 # http://libre-riscv.org/openpower/isatables/sprs.csv
220 # http://bugs.libre-riscv.org/show_bug.cgi?id=261
222 spr_csv
= get_csv("sprs.csv")
223 fields
= [(row
['SPR'], int(row
['Idx'])) for row
in spr_csv
]
224 SPR
= Enum('SPR', fields
)