[meta] Use the Rust crate for opcodes/inst_builder code generation;

This commit is contained in:
Benjamin Bouvier
2019-03-11 19:50:31 +01:00
parent b5595aadd2
commit 9b156fd9bb
4 changed files with 44 additions and 817 deletions

View File

@@ -15,7 +15,6 @@ from cdsl.ast import Var
from cdsl.ti import ti_rtl, TypeEnv, get_type_env, TypesEqual,\
InTypeset, WiderOrEq
from unique_table import UniqueTable
from gen_instr import gen_typesets_table
from cdsl.typevar import TypeVar
try:
@@ -29,6 +28,27 @@ except ImportError:
pass
# TypeSet indexes are encoded in 8 bits, with `0xff` reserved.
typeset_limit = 0xff
def gen_typesets_table(fmt, type_sets):
# type: (Formatter, UniqueTable) -> None
"""
Generate the table of ValueTypeSets described by type_sets.
"""
if len(type_sets.table) == 0:
return
fmt.comment('Table of value type sets.')
assert len(type_sets.table) <= typeset_limit, "Too many type sets"
with fmt.indented(
'const TYPE_SETS: [ir::instructions::ValueTypeSet; {}] = ['
.format(len(type_sets.table)), '];'):
for ts in type_sets.table:
with fmt.indented('ir::instructions::ValueTypeSet {', '},'):
ts.emit_fields(fmt)
def get_runtime_typechecks(xform):
# type: (XForm) -> List[TypeConstraint]
"""