Make generated code more consistent with current rustfmt.

This commit is contained in:
Dan Gohman
2017-10-30 10:06:23 -07:00
parent 1b61d5cd1e
commit fae5ffb556
4 changed files with 34 additions and 26 deletions

View File

@@ -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() {', '}'):

View File

@@ -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(

View File

@@ -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")

View File

@@ -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,
put_i(
bits,
1, // rs1 = %x1
0, // no offset.
0, // rd = %x0: no address written.
sink);
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,
put_i(
bits,
in_reg0,
0, // no offset.
1, // rd = %x1: link register.
sink);
sink,
);
''')