Generate an enum with all the register units in a target.
It is sometimes useful to create constant lists of register units by name. The generated RU enum can be used for that.
This commit is contained in:
@@ -30,6 +30,19 @@ def gen_regbank(regbank, fmt):
|
|||||||
fmt.format('num_toprcs: {},', len(regbank.toprcs))
|
fmt.format('num_toprcs: {},', len(regbank.toprcs))
|
||||||
|
|
||||||
|
|
||||||
|
def gen_regbank_units(regbank, fmt):
|
||||||
|
# type: (RegBank, srcgen.Formatter) -> None
|
||||||
|
"""
|
||||||
|
Emit constants for all the register units in `regbank`.
|
||||||
|
"""
|
||||||
|
for unit in range(regbank.units):
|
||||||
|
v = unit + regbank.first_unit
|
||||||
|
if unit < len(regbank.names):
|
||||||
|
fmt.format("{} = {},", regbank.names[unit], v)
|
||||||
|
else:
|
||||||
|
fmt.format("{}{} = {},", regbank.prefix, unit, v)
|
||||||
|
|
||||||
|
|
||||||
def gen_regclass(rc, fmt):
|
def gen_regclass(rc, fmt):
|
||||||
# type: (RegClass, srcgen.Formatter) -> None
|
# type: (RegClass, srcgen.Formatter) -> None
|
||||||
"""
|
"""
|
||||||
@@ -77,6 +90,13 @@ def gen_isa(isa, fmt):
|
|||||||
'pub const {}: RegClass = &CLASSES[{}];'
|
'pub const {}: RegClass = &CLASSES[{}];'
|
||||||
.format(rc.name, rc.index))
|
.format(rc.name, rc.index))
|
||||||
|
|
||||||
|
# Emit constants for all the register units.
|
||||||
|
fmt.line('#[allow(dead_code, non_camel_case_types)]')
|
||||||
|
fmt.line('#[derive(Clone, Copy)]')
|
||||||
|
with fmt.indented('pub enum RU {', '}'):
|
||||||
|
for regbank in isa.regbanks:
|
||||||
|
gen_regbank_units(regbank, fmt)
|
||||||
|
|
||||||
|
|
||||||
def generate(isas, out_dir):
|
def generate(isas, out_dir):
|
||||||
# type: (Sequence[TargetISA], str) -> None
|
# type: (Sequence[TargetISA], str) -> None
|
||||||
|
|||||||
Reference in New Issue
Block a user