from functools import wraps
from soc.decoder.orderedset import OrderedSet
from soc.decoder.selectable_int import SelectableInt, selectconcat
+from collections import namedtuple
import math
+instruction_info = namedtuple('instruction_info',
+ 'func read_regs uninit_regs write_regs op_fields form asmregs')
+
+
def create_args(reglist, extra=None):
args = OrderedSet()
for reg in reglist:
args = [extra] + args
return args
+
class Mem:
def __init__(self, bytes_per_word=8):
def call(self, name):
# TODO, asmregs is from the spec, e.g. add RT,RA,RB
# see http://bugs.libre-riscv.org/show_bug.cgi?id=282
- fn, read_regs, uninit_regs, write_regs, op_fields, form, asmregs \
- = self.instrs[name]
- yield from self.prep_namespace(form, op_fields)
+ info = self.instrs[name]
+ yield from self.prep_namespace(info.form, info.op_fields)
- input_names = create_args(read_regs | uninit_regs)
+ input_names = create_args(info.read_regs | info.uninit_regs)
print(input_names)
inputs = []
print('reading reg %d' % regnum)
inputs.append(self.gpr(regnum))
print(inputs)
- results = fn(self, *inputs)
+ results = info.func(self, *inputs)
print(results)
- if write_regs:
- output_names = create_args(write_regs)
+ if info.write_regs:
+ output_names = create_args(info.write_regs)
for name, output in zip(output_names, results):
regnum = yield getattr(self.decoder, name)
print('writing reg %d' % regnum)
header = """\
# auto-generated by pywriter.py, do not edit or commit
-from soc.decoder.isa.caller import inject
+from soc.decoder.isa.caller import inject, instruction_info
from soc.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
from soc.decoder.selectable_int import SelectableInt
from soc.decoder.selectable_int import selectconcat as concat
"""
-iinfo_template = """(%s, %s,
- %s, %s,
- %s, '%s',
- %s)"""
+iinfo_template = """instruction_info(func=%s,
+ read_regs=%s,
+ uninit_regs=%s, write_regs=%s,
+ op_fields=%s, form='%s',
+ asmregs=%s)"""
class PyISAWriter(ISA):
def __init__(self):