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.
This commit is contained in:
Jakob Stoklund Olesen
2017-08-18 14:14:23 -07:00
parent 6bcb24b3a6
commit c7b9bc1abf
6 changed files with 26 additions and 23 deletions

View File

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

View File

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

View File

@@ -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<ValueList>`
- `pub fn put_value_list(&mut self, args: ValueList>`
- `pub fn take_value_list(&mut self) -> Option<ir::ValueList>`
- `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<Value> {', '}'):
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<ValueList> {',
'pub fn take_value_list(&mut self) -> Option<ir::ValueList> {',
'}'):
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(

View File

@@ -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.
///

View File

@@ -1,6 +1,5 @@
//! Encoding tables for RISC-V.
use ir::condcodes::IntCC;
use ir;
use isa;
use isa::constraints::*;

View File

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