diff --git a/meta/gen_encoding.py b/meta/gen_encoding.py index 8fe8e1e304..e54d15f7fb 100644 --- a/meta/gen_encoding.py +++ b/meta/gen_encoding.py @@ -364,6 +364,19 @@ def offset_type(length): return 'u32' +def emit_recipe_names(isa, fmt): + """ + Emit a table of encoding recipe names keyed by recipe number. + + This is used for pretty-printing encodings. + """ + with fmt.indented( + 'pub static RECIPE_NAMES: [&\'static str; {}] = [' + .format(len(isa.all_recipes)), '];'): + for r in isa.all_recipes: + fmt.line('"{}",'.format(r.name)) + + def gen_isa(isa, fmt): # First assign numbers to relevant instruction predicates and generate the # check_instp() function.. @@ -398,6 +411,8 @@ def gen_isa(isa, fmt): emit_level1_hashtable( cpumode, level1_tables[cpumode], level1_offt, fmt) + emit_recipe_names(isa, fmt) + def generate(isas, out_dir): for isa in isas: diff --git a/src/libcretonne/isa/mod.rs b/src/libcretonne/isa/mod.rs index 60028415fd..18723a16a5 100644 --- a/src/libcretonne/isa/mod.rs +++ b/src/libcretonne/isa/mod.rs @@ -93,6 +93,12 @@ pub trait TargetIsa { /// /// This is also the main entry point for determining if an instruction is legal. fn encode(&self, dfg: &DataFlowGraph, inst: &InstructionData) -> Option; + + /// Get a static array of names associated with encoding recipes in this ISA. Encoding recipes + /// are numbered starting from 0, corresponding to indexes into th name array. + /// + /// This is just used for printing and parsing encodings in the textual IL format. + fn recipe_names(&self) -> &'static [&'static str]; } /// Bits needed to encode an instruction as binary machine code. diff --git a/src/libcretonne/isa/riscv/mod.rs b/src/libcretonne/isa/riscv/mod.rs index 0042b5e758..5211479f9c 100644 --- a/src/libcretonne/isa/riscv/mod.rs +++ b/src/libcretonne/isa/riscv/mod.rs @@ -52,4 +52,8 @@ impl TargetIsa for Isa { |isap| isap != 17) }) } + + fn recipe_names(&self) -> &'static [&'static str] { + &encoding::RECIPE_NAMES[..] + } }