Make generated code more consistent with current rustfmt.
This commit is contained in:
@@ -133,17 +133,21 @@ def gen_isa(isa, fmt):
|
||||
'''.format(isa.name))
|
||||
if len(isa.all_recipes) == 0:
|
||||
# No encoding recipes: Emit a stub.
|
||||
with fmt.indented(
|
||||
'pub fn emit_inst<CS: CodeSink + ?Sized>'
|
||||
'(func: &Function, inst: Inst, '
|
||||
'_divert: &mut RegDiversions, _sink: &mut CS) {', '}'):
|
||||
with fmt.indented('pub fn emit_inst<CS: CodeSink + ?Sized>('):
|
||||
fmt.line('func: &Function,')
|
||||
fmt.line('inst: Inst,')
|
||||
fmt.line('_divert: &mut RegDiversions,')
|
||||
fmt.line('_sink: &mut CS,')
|
||||
with fmt.indented(') {', '}'):
|
||||
fmt.line('bad_encoding(func, inst)')
|
||||
else:
|
||||
fmt.line('#[allow(unused_variables, unreachable_code)]')
|
||||
with fmt.indented(
|
||||
'pub fn emit_inst<CS: CodeSink + ?Sized>'
|
||||
'(func: &Function, inst: Inst, '
|
||||
'divert: &mut RegDiversions, sink: &mut CS) {', '}'):
|
||||
with fmt.indented('pub fn emit_inst<CS: CodeSink + ?Sized>('):
|
||||
fmt.line('func: &Function,')
|
||||
fmt.line('inst: Inst,')
|
||||
fmt.line('divert: &mut RegDiversions,')
|
||||
fmt.line('sink: &mut CS,')
|
||||
with fmt.indented(') {', '}'):
|
||||
fmt.line('let encoding = func.encodings[inst];')
|
||||
fmt.line('let bits = encoding.bits();')
|
||||
with fmt.indented('match func.encodings[inst].recipe() {', '}'):
|
||||
@@ -151,7 +155,7 @@ def gen_isa(isa, fmt):
|
||||
fmt.comment(recipe.name)
|
||||
with fmt.indented('{} => {{'.format(i), '}'):
|
||||
gen_recipe(recipe, fmt)
|
||||
fmt.line('_ => {}')
|
||||
fmt.line('_ => {},')
|
||||
# Allow for un-encoded ghost instructions.
|
||||
# Verifier checks the details.
|
||||
with fmt.indented('if encoding.is_legal() {', '}'):
|
||||
|
||||
@@ -97,7 +97,7 @@ def gen_arguments_method(fmt, is_mut):
|
||||
capture = 'ref {}args, '.format(mut)
|
||||
arg = 'args'
|
||||
fmt.line(
|
||||
'{} {{ {} .. }} => {},'
|
||||
'{} {{ {}.. }} => {},'
|
||||
.format(n, capture, arg))
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ def gen_opcodes(groups, fmt):
|
||||
'Opcode::{} => true,',
|
||||
i.camel_name, i.name)
|
||||
|
||||
fmt.line('_ => false')
|
||||
fmt.line('_ => false,')
|
||||
|
||||
# Generate a private opcode_format table.
|
||||
with fmt.indented(
|
||||
@@ -352,7 +352,7 @@ def gen_typesets_table(fmt, type_sets):
|
||||
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; {}] = ['
|
||||
'const TYPE_SETS: [ir::instructions::ValueTypeSet; {}] = ['
|
||||
.format(len(type_sets.table)), '];'):
|
||||
for ts in type_sets.table:
|
||||
with fmt.indented('ir::instructions::ValueTypeSet {', '},'):
|
||||
@@ -385,7 +385,7 @@ def gen_type_constraints(fmt, instrs):
|
||||
|
||||
fmt.comment('Table of opcode constraints.')
|
||||
with fmt.indented(
|
||||
'const OPCODE_CONSTRAINTS : [OpcodeConstraints; {}] = ['
|
||||
'const OPCODE_CONSTRAINTS: [OpcodeConstraints; {}] = ['
|
||||
.format(len(instrs)), '];'):
|
||||
for i in instrs:
|
||||
# Collect constraints for the value results, not including
|
||||
@@ -442,7 +442,7 @@ def gen_type_constraints(fmt, instrs):
|
||||
|
||||
fmt.comment('Table of operand constraint sequences.')
|
||||
with fmt.indented(
|
||||
'const OPERAND_CONSTRAINTS : [OperandConstraint; {}] = ['
|
||||
'const OPERAND_CONSTRAINTS: [OperandConstraint; {}] = ['
|
||||
.format(len(operand_seqs.table)), '];'):
|
||||
for c in operand_seqs.table:
|
||||
fmt.line('OperandConstraint::{},'.format(c))
|
||||
|
||||
@@ -62,7 +62,7 @@ def gen_getter(setting, sgrp, fmt):
|
||||
.format(setting.byte_offset), '}'):
|
||||
for i, v in enumerate(setting.values):
|
||||
fmt.line('{} => {}::{},'.format(i, ty, camel_case(v)))
|
||||
fmt.line('_ => panic!("Invalid enum value")')
|
||||
fmt.line('_ => panic!("Invalid enum value"),')
|
||||
else:
|
||||
raise AssertionError("Unknown setting kind")
|
||||
|
||||
@@ -197,7 +197,7 @@ def gen_template(sgrp, fmt):
|
||||
fmt.line('enumerators: &ENUMERATORS,')
|
||||
fmt.line('hash_table: &HASH_TABLE,')
|
||||
vs = ', '.join('{:#04x}'.format(x) for x in v)
|
||||
fmt.line('defaults: &[ {} ],'.format(vs))
|
||||
fmt.line('defaults: &[{}],'.format(vs))
|
||||
fmt.line('presets: &PRESETS,')
|
||||
|
||||
fmt.doc_comment(
|
||||
|
||||
@@ -131,11 +131,13 @@ Iret = EncRecipe(
|
||||
emit='''
|
||||
// Return instructions are always a jalr to %x1.
|
||||
// The return address is provided as a special-purpose link argument.
|
||||
put_i(bits,
|
||||
1, // rs1 = %x1
|
||||
0, // no offset.
|
||||
0, // rd = %x0: no address written.
|
||||
sink);
|
||||
put_i(
|
||||
bits,
|
||||
1, // rs1 = %x1
|
||||
0, // no offset.
|
||||
0, // rd = %x0: no address written.
|
||||
sink,
|
||||
);
|
||||
''')
|
||||
|
||||
# I-type encoding for `jalr` as an indirect call.
|
||||
@@ -143,11 +145,13 @@ Icall = EncRecipe(
|
||||
'Icall', IndirectCall, size=4, ins=GPR, outs=(),
|
||||
emit='''
|
||||
// Indirect instructions are jalr with rd=%x1.
|
||||
put_i(bits,
|
||||
in_reg0,
|
||||
0, // no offset.
|
||||
1, // rd = %x1: link register.
|
||||
sink);
|
||||
put_i(
|
||||
bits,
|
||||
in_reg0,
|
||||
0, // no offset.
|
||||
1, // rd = %x1: link register.
|
||||
sink,
|
||||
);
|
||||
''')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user