From 411a3eff3ef2b55247a5b562a3c7815679f907fe Mon Sep 17 00:00:00 2001 From: Trevor Elliott Date: Fri, 17 Mar 2023 10:38:28 -0700 Subject: [PATCH] cranelift: Emit a table of opcodes in gen_inst (#6046) * Emit a table of opcodes in gen_inst * Remove accidental export of OPCODE_SIGNATURES * Generate `Opcode::all` instead of a table --- cranelift/codegen/meta/src/gen_inst.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index 4882969990..f3de73b57e 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -602,7 +602,22 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) { "side_effects_idempotent", "Despite having side effects, is this instruction okay to GVN?", fmt, - ) + ); + + // Generate an opcode list, for iterating over all known opcodes. + fmt.doc_comment("All cranelift opcodes."); + fmt.line("pub fn all() -> &'static [Opcode] {"); + fmt.indent(|fmt| { + fmt.line("return &["); + for inst in all_inst { + fmt.indent(|fmt| { + fmtln!(fmt, "Opcode::{},", inst.camel_name); + }); + } + fmt.line("];"); + }); + fmt.line("}"); + fmt.empty_line(); }); fmt.line("}"); fmt.empty_line();