From c7b9bc1abfc900c357186524b7b0a29002d62d3f Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 18 Aug 2017 14:14:23 -0700 Subject: [PATCH] Prefer to use qualified type names in generated code. Emit type names like ir::Foo instead of just Foo to avoid very long manual use declarations in files including generated code. --- lib/cretonne/meta/base/immediates.py | 10 ++++++---- lib/cretonne/meta/cdsl/operands.py | 4 +++- lib/cretonne/meta/gen_instr.py | 25 +++++++++++++----------- lib/cretonne/src/ir/builder.rs | 8 +++----- lib/cretonne/src/isa/riscv/enc_tables.rs | 1 - lib/cretonne/src/legalizer/mod.rs | 1 - 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/cretonne/meta/base/immediates.py b/lib/cretonne/meta/base/immediates.py index 2cb73476e5..048a82dd12 100644 --- a/lib/cretonne/meta/base/immediates.py +++ b/lib/cretonne/meta/base/immediates.py @@ -62,7 +62,8 @@ boolean = ImmediateKind('bool', 'An immediate boolean.', intcc = ImmediateKind( 'intcc', 'An integer comparison condition code.', - default_member='cond', rust_type='IntCC', + default_member='cond', + rust_type='ir::condcodes::IntCC', values={ 'eq': 'Equal', 'ne': 'NotEqual', @@ -83,7 +84,8 @@ intcc = ImmediateKind( floatcc = ImmediateKind( 'floatcc', 'A floating point comparison condition code.', - default_member='cond', rust_type='FloatCC', + default_member='cond', + rust_type='ir::condcodes::FloatCC', values={ 'ord': 'Ordered', 'uno': 'Unordered', @@ -105,10 +107,10 @@ floatcc = ImmediateKind( memflags = ImmediateKind( 'memflags', 'Memory operation flags', - default_member='flags', rust_type='MemFlags') + default_member='flags', rust_type='ir::MemFlags') #: A register unit in the current target ISA. regunit = ImmediateKind( 'regunit', 'A register unit in the target ISA', - rust_type='RegUnit') + rust_type='isa::RegUnit') diff --git a/lib/cretonne/meta/cdsl/operands.py b/lib/cretonne/meta/cdsl/operands.py index c80632f22a..ea59de5b3e 100644 --- a/lib/cretonne/meta/cdsl/operands.py +++ b/lib/cretonne/meta/cdsl/operands.py @@ -32,7 +32,7 @@ class OperandKind(object): self.default_member = default_member # The camel-cased name of an operand kind is also the Rust type used to # represent it. - self.rust_type = rust_type or camel_case(name) + self.rust_type = rust_type or ('ir::' + camel_case(name)) def __str__(self): # type: () -> str @@ -82,6 +82,8 @@ class ImmediateKind(OperandKind): rust_type=None, values=None): # type: (str, str, str, str, Dict[str, str]) -> None + if rust_type is None: + rust_type = 'ir::immediates::' + camel_case(name) super(ImmediateKind, self).__init__( name, doc, default_member, rust_type) self.values = values diff --git a/lib/cretonne/meta/gen_instr.py b/lib/cretonne/meta/gen_instr.py index ade66e643c..104f779e2d 100644 --- a/lib/cretonne/meta/gen_instr.py +++ b/lib/cretonne/meta/gen_instr.py @@ -68,7 +68,8 @@ def gen_arguments_method(fmt, is_mut): as_slice = 'as_mut_slice' with fmt.indented( - 'pub fn {f}<\'a>(&\'a {m}self, pool: &\'a {m}ValueListPool) -> ' + 'pub fn {f}<\'a>(&\'a {m}self, ' + 'pool: &\'a {m}ir::ValueListPool) -> ' '&{m}[Value] {{' .format(f=method, m=mut), '}'): with fmt.indented('match *self {', '}'): @@ -111,8 +112,8 @@ def gen_instruction_data_impl(fmt): - `pub fn opcode(&self) -> Opcode` - `pub fn arguments(&self, &pool) -> &[Value]` - `pub fn arguments_mut(&mut self, &pool) -> &mut [Value]` - - `pub fn take_value_list(&mut self) -> Option` - - `pub fn put_value_list(&mut self, args: ValueList>` + - `pub fn take_value_list(&mut self) -> Option` + - `pub fn put_value_list(&mut self, args: ir::ValueList>` """ # The `opcode` method simply reads the `opcode` members. This is really a @@ -128,7 +129,7 @@ def gen_instruction_data_impl(fmt): fmt.doc_comment('Get the controlling type variable operand.') with fmt.indented( - 'pub fn typevar_operand(&self, pool: &ValueListPool) -> ' + 'pub fn typevar_operand(&self, pool: &ir::ValueListPool) -> ' 'Option {', '}'): with fmt.indented('match *self {', '}'): for f in InstructionFormat.all_formats: @@ -174,7 +175,7 @@ def gen_instruction_data_impl(fmt): `put_value_list` to put the value list back. """) with fmt.indented( - 'pub fn take_value_list(&mut self) -> Option {', + 'pub fn take_value_list(&mut self) -> Option {', '}'): with fmt.indented('match *self {', '}'): for f in InstructionFormat.all_formats: @@ -194,7 +195,8 @@ def gen_instruction_data_impl(fmt): list is empty. This avoids leaking list pool memory. """) with fmt.indented( - 'pub fn put_value_list(&mut self, vlist: ValueList) {', '}'): + 'pub fn put_value_list(&mut self, vlist: ir::ValueList) {', + '}'): with fmt.indented('let args = match *self {', '};'): for f in InstructionFormat.all_formats: n = 'InstructionData::' + f.name @@ -466,21 +468,22 @@ def gen_format_constructor(iform, fmt): if iform.has_value_list: # Take all value arguments as a finished value list. The value lists # are created by the individual instruction constructors. - args.append('args: ValueList') + args.append('args: ir::ValueList') else: # Take a fixed number of value operands. for i in range(iform.num_value_operands): args.append('arg{}: Value'.format(i)) proto = '{}({})'.format(iform.name, ', '.join(args)) - proto += " -> (Inst, &'f mut DataFlowGraph)" + proto += " -> (Inst, &'f mut ir::DataFlowGraph)" fmt.doc_comment(str(iform)) fmt.line('#[allow(non_snake_case)]') with fmt.indented('fn {} {{'.format(proto), '}'): # Generate the instruction data. with fmt.indented( - 'let data = InstructionData::{} {{'.format(iform.name), '};'): + 'let data = ir::InstructionData::{} {{'.format(iform.name), + '};'): fmt.line('opcode,') gen_member_inits(iform, fmt) @@ -527,7 +530,7 @@ def gen_inst_builder(inst, fmt): # The controlling type variable will be inferred from the input values if # possible. Otherwise, it is the first method argument. if inst.is_polymorphic and not inst.use_typevar_operand: - args.append('{}: Type'.format(inst.ctrl_typevar.name)) + args.append('{}: ir::Type'.format(inst.ctrl_typevar.name)) tmpl_types = list() # type: List[str] into_args = list() # type: List[str] @@ -590,7 +593,7 @@ def gen_inst_builder(inst, fmt): # Finally, the value operands. if inst.format.has_value_list: # We need to build a value list with all the arguments. - fmt.line('let mut vlist = ValueList::default();') + fmt.line('let mut vlist = ir::ValueList::default();') args.append('vlist') with fmt.indented('{', '}'): fmt.line( diff --git a/lib/cretonne/src/ir/builder.rs b/lib/cretonne/src/ir/builder.rs index 3673788543..c4d2000bf6 100644 --- a/lib/cretonne/src/ir/builder.rs +++ b/lib/cretonne/src/ir/builder.rs @@ -3,13 +3,11 @@ //! A `Builder` provides a convenient interface for inserting instructions into a Cretonne //! function. Many of its methods are generated from the meta language instruction definitions. +use ir; use ir::types; use ir::{InstructionData, DataFlowGraph}; -use ir::{Opcode, Type, Inst, Value, Ebb, JumpTable, SigRef, FuncRef, StackSlot, GlobalVar, - ValueList, MemFlags}; -use ir::immediates::{Imm64, Uimm8, Ieee32, Ieee64, Offset32, Uoffset32}; -use ir::condcodes::{IntCC, FloatCC}; -use isa::RegUnit; +use ir::{Opcode, Type, Inst, Value}; +use isa; /// Base trait for instruction builders. /// diff --git a/lib/cretonne/src/isa/riscv/enc_tables.rs b/lib/cretonne/src/isa/riscv/enc_tables.rs index f095e67243..1f0f2e132d 100644 --- a/lib/cretonne/src/isa/riscv/enc_tables.rs +++ b/lib/cretonne/src/isa/riscv/enc_tables.rs @@ -1,6 +1,5 @@ //! Encoding tables for RISC-V. -use ir::condcodes::IntCC; use ir; use isa; use isa::constraints::*; diff --git a/lib/cretonne/src/legalizer/mod.rs b/lib/cretonne/src/legalizer/mod.rs index 9e96c61e5d..faed731c95 100644 --- a/lib/cretonne/src/legalizer/mod.rs +++ b/lib/cretonne/src/legalizer/mod.rs @@ -17,7 +17,6 @@ use cursor::{Cursor, FuncCursor}; use dominator_tree::DominatorTree; use flowgraph::ControlFlowGraph; use ir; -use ir::condcodes::IntCC; use isa::TargetIsa; use bitset::BitSet;