Skip to content

Commit 17f30e5

Browse files
committed
Auto merge of #84107 - Amanieu:global_asm2, r=nagisa
Add support for const operands and options to global_asm! On x86, the default syntax is also switched to Intel to match asm!. Currently `global_asm!` only supports `const` operands and the `att_syntax` option. In the future, `sym` operands will also be supported. However there is no plan to support any of the other operand types or options since they don't make sense in the context of `global_asm!`. r? `@nagisa`
2 parents 6d395a1 + a7ed6a5 commit 17f30e5

File tree

56 files changed

+1424
-842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1424
-842
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ dependencies = [
655655

656656
[[package]]
657657
name = "compiler_builtins"
658-
version = "0.1.39"
658+
version = "0.1.43"
659659
source = "registry+https://github.com/rust-lang/crates.io-index"
660-
checksum = "3748f82c7d366a0b4950257d19db685d4958d2fa27c6d164a3f069fec42b748b"
660+
checksum = "65af2dcae4779003dfa91aedc6ade7bdc7ba685944e50a8b4f9380df376a4466"
661661
dependencies = [
662662
"cc",
663663
"rustc-std-workspace-core",

compiler/rustc_ast/src/ast.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -2279,14 +2279,6 @@ pub struct ForeignMod {
22792279
pub items: Vec<P<ForeignItem>>,
22802280
}
22812281

2282-
/// Global inline assembly.
2283-
///
2284-
/// Also known as "module-level assembly" or "file-scoped assembly".
2285-
#[derive(Clone, Encodable, Decodable, Debug, Copy)]
2286-
pub struct GlobalAsm {
2287-
pub asm: Symbol,
2288-
}
2289-
22902282
#[derive(Clone, Encodable, Decodable, Debug)]
22912283
pub struct EnumDef {
22922284
pub variants: Vec<Variant>,
@@ -2669,7 +2661,7 @@ pub enum ItemKind {
26692661
/// E.g., `extern {}` or `extern "C" {}`.
26702662
ForeignMod(ForeignMod),
26712663
/// Module-level inline assembly (from `global_asm!()`).
2672-
GlobalAsm(GlobalAsm),
2664+
GlobalAsm(InlineAsm),
26732665
/// A type alias (`type`).
26742666
///
26752667
/// E.g., `type Foo = Bar<u8>;`.

compiler/rustc_ast/src/mut_visit.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
965965
ModKind::Unloaded => {}
966966
},
967967
ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
968-
ItemKind::GlobalAsm(_ga) => {}
968+
ItemKind::GlobalAsm(asm) => noop_visit_inline_asm(asm, vis),
969969
ItemKind::TyAlias(box TyAliasKind(_, generics, bounds, ty)) => {
970970
vis.visit_generics(generics);
971971
visit_bounds(bounds, vis);
@@ -1170,6 +1170,28 @@ pub fn noop_visit_anon_const<T: MutVisitor>(AnonConst { id, value }: &mut AnonCo
11701170
vis.visit_expr(value);
11711171
}
11721172

1173+
fn noop_visit_inline_asm<T: MutVisitor>(asm: &mut InlineAsm, vis: &mut T) {
1174+
for (op, _) in &mut asm.operands {
1175+
match op {
1176+
InlineAsmOperand::In { expr, .. }
1177+
| InlineAsmOperand::InOut { expr, .. }
1178+
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
1179+
InlineAsmOperand::Out { expr, .. } => {
1180+
if let Some(expr) = expr {
1181+
vis.visit_expr(expr);
1182+
}
1183+
}
1184+
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1185+
vis.visit_expr(in_expr);
1186+
if let Some(out_expr) = out_expr {
1187+
vis.visit_expr(out_expr);
1188+
}
1189+
}
1190+
InlineAsmOperand::Const { anon_const, .. } => vis.visit_anon_const(anon_const),
1191+
}
1192+
}
1193+
}
1194+
11731195
pub fn noop_visit_expr<T: MutVisitor>(
11741196
Expr { kind, id, span, attrs, tokens }: &mut Expr,
11751197
vis: &mut T,
@@ -1288,27 +1310,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
12881310
ExprKind::Ret(expr) => {
12891311
visit_opt(expr, |expr| vis.visit_expr(expr));
12901312
}
1291-
ExprKind::InlineAsm(asm) => {
1292-
for (op, _) in &mut asm.operands {
1293-
match op {
1294-
InlineAsmOperand::In { expr, .. }
1295-
| InlineAsmOperand::InOut { expr, .. }
1296-
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
1297-
InlineAsmOperand::Out { expr, .. } => {
1298-
if let Some(expr) = expr {
1299-
vis.visit_expr(expr);
1300-
}
1301-
}
1302-
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1303-
vis.visit_expr(in_expr);
1304-
if let Some(out_expr) = out_expr {
1305-
vis.visit_expr(out_expr);
1306-
}
1307-
}
1308-
InlineAsmOperand::Const { anon_const, .. } => vis.visit_anon_const(anon_const),
1309-
}
1310-
}
1311-
}
1313+
ExprKind::InlineAsm(asm) => noop_visit_inline_asm(asm, vis),
13121314
ExprKind::LlvmInlineAsm(asm) => {
13131315
let LlvmInlineAsm {
13141316
asm: _,

compiler/rustc_ast/src/visit.rs

+24-31
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ pub trait Visitor<'ast>: Sized {
9090
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) {
9191
walk_foreign_item(self, i)
9292
}
93-
fn visit_global_asm(&mut self, ga: &'ast GlobalAsm) {
94-
walk_global_asm(self, ga)
95-
}
9693
fn visit_item(&mut self, i: &'ast Item) {
9794
walk_item(self, i)
9895
}
@@ -299,7 +296,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
299296
ItemKind::ForeignMod(ref foreign_module) => {
300297
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
301298
}
302-
ItemKind::GlobalAsm(ref ga) => visitor.visit_global_asm(ga),
299+
ItemKind::GlobalAsm(ref asm) => walk_inline_asm(visitor, asm),
303300
ItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref ty)) => {
304301
visitor.visit_generics(generics);
305302
walk_list!(visitor, visit_param_bound, bounds);
@@ -557,10 +554,6 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
557554
}
558555
}
559556

560-
pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) {
561-
// Empty!
562-
}
563-
564557
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
565558
match *bound {
566559
GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier),
@@ -708,6 +701,28 @@ pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonCo
708701
visitor.visit_expr(&constant.value);
709702
}
710703

704+
fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) {
705+
for (op, _) in &asm.operands {
706+
match op {
707+
InlineAsmOperand::In { expr, .. }
708+
| InlineAsmOperand::InOut { expr, .. }
709+
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
710+
InlineAsmOperand::Out { expr, .. } => {
711+
if let Some(expr) = expr {
712+
visitor.visit_expr(expr);
713+
}
714+
}
715+
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
716+
visitor.visit_expr(in_expr);
717+
if let Some(out_expr) = out_expr {
718+
visitor.visit_expr(out_expr);
719+
}
720+
}
721+
InlineAsmOperand::Const { anon_const, .. } => visitor.visit_anon_const(anon_const),
722+
}
723+
}
724+
}
725+
711726
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
712727
walk_list!(visitor, visit_attribute, expression.attrs.iter());
713728

@@ -830,29 +845,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
830845
}
831846
ExprKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
832847
ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression),
833-
ExprKind::InlineAsm(ref ia) => {
834-
for (op, _) in &ia.operands {
835-
match op {
836-
InlineAsmOperand::In { expr, .. }
837-
| InlineAsmOperand::InOut { expr, .. }
838-
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
839-
InlineAsmOperand::Out { expr, .. } => {
840-
if let Some(expr) = expr {
841-
visitor.visit_expr(expr);
842-
}
843-
}
844-
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
845-
visitor.visit_expr(in_expr);
846-
if let Some(out_expr) = out_expr {
847-
visitor.visit_expr(out_expr);
848-
}
849-
}
850-
InlineAsmOperand::Const { anon_const, .. } => {
851-
visitor.visit_anon_const(anon_const)
852-
}
853-
}
854-
}
855-
}
848+
ExprKind::InlineAsm(ref asm) => walk_inline_asm(visitor, asm),
856849
ExprKind::LlvmInlineAsm(ref ia) => {
857850
for &(_, ref input) in &ia.inputs {
858851
visitor.visit_expr(input)

0 commit comments

Comments
 (0)