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)) '''.format(isa.name))
if len(isa.all_recipes) == 0: if len(isa.all_recipes) == 0:
# No encoding recipes: Emit a stub. # No encoding recipes: Emit a stub.
with fmt.indented( with fmt.indented('pub fn emit_inst<CS: CodeSink + ?Sized>('):
'pub fn emit_inst<CS: CodeSink + ?Sized>' fmt.line('func: &Function,')
'(func: &Function, inst: Inst, ' fmt.line('inst: Inst,')
'_divert: &mut RegDiversions, _sink: &mut CS) {', '}'): fmt.line('_divert: &mut RegDiversions,')
fmt.line('_sink: &mut CS,')
with fmt.indented(') {', '}'):
fmt.line('bad_encoding(func, inst)') fmt.line('bad_encoding(func, inst)')
else: else:
fmt.line('#[allow(unused_variables, unreachable_code)]') fmt.line('#[allow(unused_variables, unreachable_code)]')
with fmt.indented( with fmt.indented('pub fn emit_inst<CS: CodeSink + ?Sized>('):
'pub fn emit_inst<CS: CodeSink + ?Sized>' fmt.line('func: &Function,')
'(func: &Function, inst: Inst, ' fmt.line('inst: Inst,')
'divert: &mut RegDiversions, sink: &mut CS) {', '}'): fmt.line('divert: &mut RegDiversions,')
fmt.line('sink: &mut CS,')
with fmt.indented(') {', '}'):
fmt.line('let encoding = func.encodings[inst];') fmt.line('let encoding = func.encodings[inst];')
fmt.line('let bits = encoding.bits();') fmt.line('let bits = encoding.bits();')
with fmt.indented('match func.encodings[inst].recipe() {', '}'): with fmt.indented('match func.encodings[inst].recipe() {', '}'):
@@ -151,7 +155,7 @@ def gen_isa(isa, fmt):
fmt.comment(recipe.name) fmt.comment(recipe.name)
with fmt.indented('{} => {{'.format(i), '}'): with fmt.indented('{} => {{'.format(i), '}'):
gen_recipe(recipe, fmt) gen_recipe(recipe, fmt)
fmt.line('_ => {}') fmt.line('_ => {},')
# Allow for un-encoded ghost instructions. # Allow for un-encoded ghost instructions.
# Verifier checks the details. # Verifier checks the details.
with fmt.indented('if encoding.is_legal() {', '}'): with fmt.indented('if encoding.is_legal() {', '}'):

View File

@@ -271,7 +271,7 @@ def gen_opcodes(groups, fmt):
'Opcode::{} => true,', 'Opcode::{} => true,',
i.camel_name, i.name) i.camel_name, i.name)
fmt.line('_ => false') fmt.line('_ => false,')
# Generate a private opcode_format table. # Generate a private opcode_format table.
with fmt.indented( with fmt.indented(

View File

@@ -62,7 +62,7 @@ def gen_getter(setting, sgrp, fmt):
.format(setting.byte_offset), '}'): .format(setting.byte_offset), '}'):
for i, v in enumerate(setting.values): for i, v in enumerate(setting.values):
fmt.line('{} => {}::{},'.format(i, ty, camel_case(v))) fmt.line('{} => {}::{},'.format(i, ty, camel_case(v)))
fmt.line('_ => panic!("Invalid enum value")') fmt.line('_ => panic!("Invalid enum value"),')
else: else:
raise AssertionError("Unknown setting kind") raise AssertionError("Unknown setting kind")

View File

@@ -131,11 +131,13 @@ Iret = EncRecipe(
emit=''' emit='''
// Return instructions are always a jalr to %x1. // Return instructions are always a jalr to %x1.
// The return address is provided as a special-purpose link argument. // The return address is provided as a special-purpose link argument.
put_i(bits, put_i(
bits,
1, // rs1 = %x1 1, // rs1 = %x1
0, // no offset. 0, // no offset.
0, // rd = %x0: no address written. 0, // rd = %x0: no address written.
sink); sink,
);
''') ''')
# I-type encoding for `jalr` as an indirect call. # I-type encoding for `jalr` as an indirect call.
@@ -143,11 +145,13 @@ Icall = EncRecipe(
'Icall', IndirectCall, size=4, ins=GPR, outs=(), 'Icall', IndirectCall, size=4, ins=GPR, outs=(),
emit=''' emit='''
// Indirect instructions are jalr with rd=%x1. // Indirect instructions are jalr with rd=%x1.
put_i(bits, put_i(
bits,
in_reg0, in_reg0,
0, // no offset. 0, // no offset.
1, // rd = %x1: link register. 1, // rd = %x1: link register.
sink); sink,
);
''') ''')