Use Symbol for inline asm register class names

This takes care of one "FIXME":
// FIXME: use direct symbol comparison for register class names

Instead of using string literals, this uses Symbol for register
class names.
This commit is contained in:
Arlie Davis 2020-12-10 13:51:56 -08:00
parent d32c320d7e
commit 40ed0f6857
2 changed files with 45 additions and 29 deletions

View File

@ -460,6 +460,9 @@ symbols! {
document_private_items, document_private_items,
dotdot_in_tuple_patterns, dotdot_in_tuple_patterns,
dotdoteq_in_patterns, dotdoteq_in_patterns,
dreg,
dreg_low16,
dreg_low8,
drop, drop,
drop_in_place, drop_in_place,
drop_types_in_const, drop_types_in_const,
@ -544,6 +547,7 @@ symbols! {
format_args_capture, format_args_capture,
format_args_nl, format_args_nl,
freeze, freeze,
freg,
frem_fast, frem_fast,
from, from,
from_desugaring, from_desugaring,
@ -627,6 +631,7 @@ symbols! {
iter, iter,
keyword, keyword,
kind, kind,
kreg,
label, label,
label_break_value, label_break_value,
lang, lang,
@ -652,6 +657,7 @@ symbols! {
lint_reasons, lint_reasons,
literal, literal,
llvm_asm, llvm_asm,
local,
local_inner_macros, local_inner_macros,
log10f32, log10f32,
log10f64, log10f64,
@ -854,6 +860,9 @@ symbols! {
pub_restricted, pub_restricted,
pure, pure,
pushpop_unsafe, pushpop_unsafe,
qreg,
qreg_low4,
qreg_low8,
quad_precision_float, quad_precision_float,
question_mark, question_mark,
quote, quote,
@ -875,6 +884,13 @@ symbols! {
reexport_test_harness_main, reexport_test_harness_main,
reference, reference,
reflect, reflect,
reg,
reg16,
reg32,
reg64,
reg_abcd,
reg_byte,
reg_thumb,
register_attr, register_attr,
register_tool, register_tool,
relaxed_adts, relaxed_adts,
@ -1060,6 +1076,8 @@ symbols! {
spotlight, spotlight,
sqrtf32, sqrtf32,
sqrtf64, sqrtf64,
sreg,
sreg_low16,
sse4a_target_feature, sse4a_target_feature,
stable, stable,
staged_api, staged_api,
@ -1215,6 +1233,8 @@ symbols! {
volatile_load, volatile_load,
volatile_set_memory, volatile_set_memory,
volatile_store, volatile_store,
vreg,
vreg_low16,
warn, warn,
wasm_import_module, wasm_import_module,
wasm_target_feature, wasm_target_feature,
@ -1226,6 +1246,9 @@ symbols! {
wrapping_mul, wrapping_mul,
wrapping_sub, wrapping_sub,
write_bytes, write_bytes,
xmm_reg,
ymm_reg,
zmm_reg,
} }
} }

View File

@ -20,16 +20,16 @@ macro_rules! def_reg_class {
} }
impl $arch_regclass { impl $arch_regclass {
pub fn name(self) -> &'static str { pub fn name(self) -> rustc_span::Symbol {
match self { match self {
$(Self::$class => stringify!($class),)* $(Self::$class => rustc_span::symbol::sym::$class,)*
} }
} }
pub fn parse(_arch: super::InlineAsmArch, name: &str) -> Result<Self, &'static str> { pub fn parse(_arch: super::InlineAsmArch, name: rustc_span::Symbol) -> Result<Self, &'static str> {
match name { match name {
$( $(
stringify!($class) => Ok(Self::$class), rustc_span::sym::$class => Ok(Self::$class),
)* )*
_ => Err("unknown register class"), _ => Err("unknown register class"),
} }
@ -327,7 +327,7 @@ pub enum InlineAsmRegClass {
} }
impl InlineAsmRegClass { impl InlineAsmRegClass {
pub fn name(self) -> &'static str { pub fn name(self) -> Symbol {
match self { match self {
Self::X86(r) => r.name(), Self::X86(r) => r.name(),
Self::Arm(r) => r.name(), Self::Arm(r) => r.name(),
@ -422,29 +422,22 @@ impl InlineAsmRegClass {
} }
pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static str> { pub fn parse(arch: InlineAsmArch, name: Symbol) -> Result<Self, &'static str> {
// FIXME: use direct symbol comparison for register class names Ok(match arch {
name.with(|name| { InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
Ok(match arch { Self::X86(X86InlineAsmRegClass::parse(arch, name)?)
InlineAsmArch::X86 | InlineAsmArch::X86_64 => { }
Self::X86(X86InlineAsmRegClass::parse(arch, name)?) InlineAsmArch::Arm => Self::Arm(ArmInlineAsmRegClass::parse(arch, name)?),
} InlineAsmArch::AArch64 => Self::AArch64(AArch64InlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::Arm => Self::Arm(ArmInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {
InlineAsmArch::AArch64 => { Self::RiscV(RiscVInlineAsmRegClass::parse(arch, name)?)
Self::AArch64(AArch64InlineAsmRegClass::parse(arch, name)?) }
} InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => { InlineAsmArch::Hexagon => Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?),
Self::RiscV(RiscVInlineAsmRegClass::parse(arch, name)?) InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
} Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmRegClass::parse(arch, name)?), }
InlineAsmArch::Hexagon => { InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?) InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
}
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
}
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
})
}) })
} }
@ -484,7 +477,7 @@ impl fmt::Display for InlineAsmRegOrRegClass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Reg(r) => write!(f, "\"{}\"", r.name()), Self::Reg(r) => write!(f, "\"{}\"", r.name()),
Self::RegClass(r) => f.write_str(r.name()), Self::RegClass(r) => write!(f, "{}", r.name()),
} }
} }
} }