Add Definition kind for asm register operand
This commit is contained in:
parent
44e3b7d205
commit
304f54e023
@ -51,6 +51,7 @@ pub enum Definition {
|
||||
ToolModule(ToolModule),
|
||||
ExternCrateDecl(ExternCrateDecl),
|
||||
InlineAsmRegOrRegClass(()),
|
||||
InlineAsmRegOperand(()),
|
||||
}
|
||||
|
||||
impl Definition {
|
||||
@ -89,7 +90,8 @@ pub fn module(&self, db: &RootDatabase) -> Option<Module> {
|
||||
| Definition::BuiltinLifetime(_)
|
||||
| Definition::TupleField(_)
|
||||
| Definition::ToolModule(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => return None,
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::InlineAsmRegOperand(_) => return None,
|
||||
};
|
||||
Some(module)
|
||||
}
|
||||
@ -124,7 +126,8 @@ pub fn visibility(&self, db: &RootDatabase) -> Option<Visibility> {
|
||||
| Definition::GenericParam(_)
|
||||
| Definition::Label(_)
|
||||
| Definition::DeriveHelper(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => return None,
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::InlineAsmRegOperand(_) => return None,
|
||||
};
|
||||
Some(vis)
|
||||
}
|
||||
@ -153,7 +156,9 @@ pub fn name(&self, db: &RootDatabase) -> Option<Name> {
|
||||
Definition::ToolModule(_) => return None, // FIXME
|
||||
Definition::DeriveHelper(it) => it.name(db),
|
||||
Definition::ExternCrateDecl(it) => return it.alias_or_name(db),
|
||||
Definition::InlineAsmRegOrRegClass(_) => return None, // FIXME
|
||||
Definition::InlineAsmRegOrRegClass(_) | Definition::InlineAsmRegOperand(_) => {
|
||||
return None
|
||||
} // FIXME
|
||||
};
|
||||
Some(name)
|
||||
}
|
||||
@ -216,7 +221,7 @@ pub fn docs(
|
||||
Definition::ToolModule(_) => None,
|
||||
Definition::DeriveHelper(_) => None,
|
||||
Definition::TupleField(_) => None,
|
||||
Definition::InlineAsmRegOrRegClass(_) => None,
|
||||
Definition::InlineAsmRegOrRegClass(_) | Definition::InlineAsmRegOperand(_) => None,
|
||||
};
|
||||
|
||||
docs.or_else(|| {
|
||||
@ -275,6 +280,7 @@ pub fn label(&self, db: &RootDatabase, edition: Edition) -> String {
|
||||
}
|
||||
// FIXME
|
||||
Definition::InlineAsmRegOrRegClass(_) => "inline_asm_reg_or_reg_class".to_owned(),
|
||||
Definition::InlineAsmRegOperand(_) => "inline_asm_reg_operand".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -706,6 +712,9 @@ pub fn classify(
|
||||
NameRefClass::ExternCrateShorthand { krate, decl: extern_crate }
|
||||
})
|
||||
},
|
||||
ast::AsmRegSpec(_) => {
|
||||
Some(NameRefClass::Definition(Definition::InlineAsmRegOrRegClass(())))
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +207,8 @@ pub fn range_for_rename(self, sema: &Semantics<'_, RootDatabase>) -> Option<File
|
||||
| Definition::ToolModule(_)
|
||||
| Definition::TupleField(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => return None,
|
||||
// FIXME:
|
||||
Definition::InlineAsmRegOperand(_) => return None,
|
||||
// FIXME: This should be doable in theory
|
||||
Definition::DeriveHelper(_) => return None,
|
||||
};
|
||||
|
@ -220,7 +220,8 @@ pub(crate) fn resolve_doc_path_for_def(
|
||||
| Definition::GenericParam(_)
|
||||
| Definition::Label(_)
|
||||
| Definition::DeriveHelper(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => None,
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::InlineAsmRegOperand(_) => None,
|
||||
}
|
||||
.map(Definition::from)
|
||||
}
|
||||
@ -674,7 +675,8 @@ fn filename_and_frag_for_def(
|
||||
| Definition::BuiltinLifetime(_)
|
||||
| Definition::ToolModule(_)
|
||||
| Definition::DeriveHelper(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => return None,
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::InlineAsmRegOperand(_) => return None,
|
||||
};
|
||||
|
||||
Some((def, res, None))
|
||||
|
@ -223,7 +223,7 @@ pub(crate) fn def_to_kind(db: &RootDatabase, def: Definition) -> SymbolInformati
|
||||
Variable
|
||||
}
|
||||
}
|
||||
Definition::Label(..) => Variable, // For lack of a better variant
|
||||
Definition::Label(..) | Definition::InlineAsmRegOperand(_) => Variable, // For lack of a better variant
|
||||
Definition::DeriveHelper(..) => Attribute,
|
||||
Definition::BuiltinAttr(..) => Attribute,
|
||||
Definition::ToolModule(..) => Module,
|
||||
@ -322,7 +322,8 @@ pub(crate) fn def_to_moniker(
|
||||
| Definition::BuiltinLifetime(_)
|
||||
| Definition::BuiltinAttr(_)
|
||||
| Definition::ToolModule(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_) => return None,
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::InlineAsmRegOperand(_) => return None,
|
||||
|
||||
Definition::Local(local) => {
|
||||
if !local.is_param(db) {
|
||||
|
@ -244,6 +244,8 @@ fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarg
|
||||
| Definition::ToolModule(_)
|
||||
| Definition::InlineAsmRegOrRegClass(_)
|
||||
| Definition::BuiltinAttr(_) => None,
|
||||
// FIXME
|
||||
Definition::InlineAsmRegOperand(_) => None,
|
||||
// FIXME: The focus range should be set to the helper declaration
|
||||
Definition::DeriveHelper(it) => it.derive().try_to_nav(db),
|
||||
}
|
||||
|
@ -537,6 +537,7 @@ pub(super) fn highlight_def(
|
||||
Definition::InlineAsmRegOrRegClass(_) => {
|
||||
Highlight::new(HlTag::Symbol(SymbolKind::InlineAsmRegOrRegClass))
|
||||
}
|
||||
Definition::InlineAsmRegOperand(_) => Highlight::new(HlTag::Symbol(SymbolKind::Local)),
|
||||
};
|
||||
|
||||
let def_crate = def.krate(db);
|
||||
|
@ -316,6 +316,7 @@ fn module_def_to_hl_tag(def: Definition) -> HlTag {
|
||||
Definition::ToolModule(_) => SymbolKind::ToolModule,
|
||||
Definition::DeriveHelper(_) => SymbolKind::DeriveHelper,
|
||||
Definition::InlineAsmRegOrRegClass(_) => SymbolKind::InlineAsmRegOrRegClass,
|
||||
Definition::InlineAsmRegOperand(_) => SymbolKind::Local,
|
||||
};
|
||||
HlTag::Symbol(symbol)
|
||||
}
|
||||
|
@ -51,18 +51,17 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">o</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
|
||||
<span class="module crate_root default_library library">core</span><span class="operator">::</span><span class="module default_library library">arch</span><span class="operator">::</span><span class="macro default_library library unsafe">asm</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span>
|
||||
<span class="string_literal macro">"%input = OpLoad _ {0}"</span><span class="comma macro">,</span>
|
||||
<span class="macro default_library library macro">concat</span><span class="macro_bang macro">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"%result = "</span><span class="comma macro">,</span> <span class="unresolved_reference macro">bar</span><span class="comma macro">,</span> <span class="string_literal macro">" _ %input"</span><span class="parenthesis macro">)</span><span class="comma macro">,</span>
|
||||
<span class="macro default_library library macro">concat</span><span class="macro_bang macro">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"%result = "</span><span class="comma macro">,</span> <span class="string_literal macro">"bar"</span><span class="comma macro">,</span> <span class="string_literal macro">" _ %input"</span><span class="parenthesis macro">)</span><span class="comma macro">,</span>
|
||||
<span class="string_literal macro">"OpStore {1} %result"</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="unresolved_reference macro">reg</span><span class="parenthesis macro">)</span> <span class="operator macro">&</span><span class="variable macro">foo</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="unresolved_reference macro">reg</span><span class="parenthesis macro">)</span> <span class="operator macro">&</span><span class="keyword macro">mut</span> <span class="variable macro mutable">o</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="reg library macro">reg</span><span class="parenthesis macro">)</span> <span class="operator macro">&</span><span class="variable macro">foo</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="reg library macro">reg</span><span class="parenthesis macro">)</span> <span class="operator macro">&</span><span class="keyword macro">mut</span> <span class="variable macro mutable">o</span><span class="comma macro">,</span>
|
||||
<span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
<span class="variable mutable">o</span>
|
||||
|
||||
<span class="keyword">let</span> <span class="variable declaration">thread_id</span><span class="colon">:</span> <span class="builtin_type">usize</span><span class="semicolon">;</span>
|
||||
<span class="module crate_root default_library library">core</span><span class="operator">::</span><span class="module default_library library">arch</span><span class="operator">::</span><span class="macro default_library library unsafe">asm</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span><span class="string_literal macro">"
|
||||
mov {0}, gs:[0x30]
|
||||
mov {0}, [{0}+0x48]
|
||||
"</span><span class="comma macro">,</span> <span class="keyword macro">out</span><span class="parenthesis macro">(</span><span class="unresolved_reference macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">thread_id</span><span class="comma macro">,</span> <span class="keyword macro">options</span><span class="parenthesis macro">(</span><span class="keyword macro">pure</span><span class="comma macro">,</span> <span class="keyword macro">readonly</span><span class="comma macro">,</span> <span class="keyword macro">nostack</span><span class="parenthesis macro">)</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
"</span><span class="comma macro">,</span> <span class="keyword macro">out</span><span class="parenthesis macro">(</span><span class="reg library macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">thread_id</span><span class="comma macro">,</span> <span class="keyword macro">options</span><span class="parenthesis macro">(</span><span class="keyword macro">pure</span><span class="comma macro">,</span> <span class="keyword macro">readonly</span><span class="comma macro">,</span> <span class="keyword macro">nostack</span><span class="parenthesis macro">)</span><span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="static declaration">UNMAP_BASE</span><span class="colon">:</span> <span class="builtin_type">usize</span><span class="semicolon">;</span>
|
||||
<span class="keyword const">const</span> <span class="constant const declaration">MEM_RELEASE</span><span class="colon">:</span> <span class="builtin_type">usize</span><span class="semicolon">;</span>
|
||||
|
@ -168,8 +168,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="module crate_root default_library library">core</span><span class="operator">::</span><span class="module default_library library">arch</span><span class="operator">::</span><span class="macro default_library library unsafe">asm</span><span class="macro_bang">!</span><span class="parenthesis macro">(</span>
|
||||
<span class="string_literal macro">"mov {0}, {1}"</span><span class="comma macro">,</span>
|
||||
<span class="string_literal macro">"add {0}, 5"</span><span class="comma macro">,</span>
|
||||
<span class="keyword macro">out</span><span class="parenthesis macro">(</span><span class="unresolved_reference macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">o</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="unresolved_reference macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">i</span><span class="comma macro">,</span>
|
||||
<span class="keyword macro">out</span><span class="parenthesis macro">(</span><span class="reg library macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">o</span><span class="comma macro">,</span>
|
||||
<span class="keyword control macro">in</span><span class="parenthesis macro">(</span><span class="reg library macro">reg</span><span class="parenthesis macro">)</span> <span class="variable macro">i</span><span class="comma macro">,</span>
|
||||
<span class="parenthesis macro">)</span><span class="semicolon">;</span>
|
||||
|
||||
<span class="keyword const">const</span> <span class="constant const declaration">CONSTANT</span><span class="colon">:</span> <span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="colon">:</span>
|
||||
|
@ -1287,12 +1287,11 @@ fn main() {
|
||||
let mut o = 0;
|
||||
core::arch::asm!(
|
||||
"%input = OpLoad _ {0}",
|
||||
concat!("%result = ", bar, " _ %input"),
|
||||
concat!("%result = ", "bar", " _ %input"),
|
||||
"OpStore {1} %result",
|
||||
in(reg) &foo,
|
||||
in(reg) &mut o,
|
||||
);
|
||||
o
|
||||
|
||||
let thread_id: usize;
|
||||
core::arch::asm!("
|
||||
|
@ -453,9 +453,13 @@ fn parse_clobber_abi(p: &mut Parser<'_>) {
|
||||
fn parse_reg(p: &mut Parser<'_>) {
|
||||
p.expect(T!['(']);
|
||||
if p.at(T![ident]) {
|
||||
name_ref(p)
|
||||
let m = p.start();
|
||||
name_ref(p);
|
||||
m.complete(p, ASM_REG_SPEC);
|
||||
} else if p.at(T![string]) {
|
||||
p.bump_any()
|
||||
let m = p.start();
|
||||
p.bump_any();
|
||||
m.complete(p, ASM_REG_SPEC);
|
||||
} else {
|
||||
p.err_and_bump("expected register name");
|
||||
}
|
||||
|
@ -35,16 +35,18 @@ SOURCE_FILE
|
||||
STRING "\"add {x}, {tmp}\""
|
||||
COMMA ","
|
||||
WHITESPACE "\n "
|
||||
NAME
|
||||
IDENT "x"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
ASM_REG_OPERAND
|
||||
INOUT_KW "inout"
|
||||
NAME
|
||||
IDENT "x"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
ASM_DIR_SPEC
|
||||
INOUT_KW "inout"
|
||||
L_PAREN "("
|
||||
NAME_REF
|
||||
IDENT "reg"
|
||||
ASM_REG_SPEC
|
||||
NAME_REF
|
||||
IDENT "reg"
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
PATH_EXPR
|
||||
@ -54,16 +56,18 @@ SOURCE_FILE
|
||||
IDENT "x"
|
||||
COMMA ","
|
||||
WHITESPACE "\n "
|
||||
NAME
|
||||
IDENT "tmp"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
ASM_REG_OPERAND
|
||||
OUT_KW "out"
|
||||
NAME
|
||||
IDENT "tmp"
|
||||
WHITESPACE " "
|
||||
EQ "="
|
||||
WHITESPACE " "
|
||||
ASM_DIR_SPEC
|
||||
OUT_KW "out"
|
||||
L_PAREN "("
|
||||
NAME_REF
|
||||
IDENT "reg"
|
||||
ASM_REG_SPEC
|
||||
NAME_REF
|
||||
IDENT "reg"
|
||||
R_PAREN ")"
|
||||
WHITESPACE " "
|
||||
UNDERSCORE_EXPR
|
||||
|
Loading…
Reference in New Issue
Block a user