Skip to content

Commit 9e61d5c

Browse files
committed
First attempt at global_asm! macro
1 parent 6f10e2f commit 9e61d5c

File tree

31 files changed

+184
-7
lines changed

31 files changed

+184
-7
lines changed

src/librustc/hir/def.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub enum Def {
5656
// Macro namespace
5757
Macro(DefId, MacroKind),
5858

59+
GlobalAsm(DefId),
60+
5961
// Both namespaces
6062
Err,
6163
}
@@ -142,7 +144,8 @@ impl Def {
142144
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
143145
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
144146
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
145-
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) => {
147+
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) |
148+
Def::GlobalAsm(id) => {
146149
id
147150
}
148151

@@ -183,6 +186,7 @@ impl Def {
183186
Def::Label(..) => "label",
184187
Def::SelfTy(..) => "self type",
185188
Def::Macro(..) => "macro",
189+
Def::GlobalAsm(..) => "global asm",
186190
Def::Err => "unresolved item",
187191
}
188192
}

src/librustc/hir/intravisit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
474474
visitor.visit_id(item.id);
475475
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
476476
}
477+
ItemGlobalAsm(_) => {}
477478
ItemTy(ref typ, ref type_parameters) => {
478479
visitor.visit_id(item.id);
479480
visitor.visit_ty(typ);

src/librustc/hir/lowering.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ impl<'a> LoweringContext<'a> {
486486
}
487487
}
488488

489+
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
490+
P(hir::GlobalAsm {
491+
asm: ga.asm,
492+
asm_str_style: ga.asm_str_style,
493+
expn_id: ga.expn_id,
494+
})
495+
}
496+
489497
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
490498
Spanned {
491499
node: hir::Variant_ {
@@ -1098,6 +1106,7 @@ impl<'a> LoweringContext<'a> {
10981106
}
10991107
ItemKind::Mod(ref m) => hir::ItemMod(self.lower_mod(m)),
11001108
ItemKind::ForeignMod(ref nm) => hir::ItemForeignMod(self.lower_foreign_mod(nm)),
1109+
ItemKind::GlobalAsm(ref ga) => hir::ItemGlobalAsm(self.lower_global_asm(ga)),
11011110
ItemKind::Ty(ref t, ref generics) => {
11021111
hir::ItemTy(self.lower_ty(t), self.lower_generics(generics))
11031112
}

src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
110110
DefPathData::ValueNs(i.ident.name.as_str()),
111111
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_str()),
112112
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id, false),
113+
ItemKind::GlobalAsm(..) => DefPathData::Misc,
113114
ItemKind::Use(ref view_path) => {
114115
match view_path.node {
115116
ViewPathGlob(..) => {}

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10521052
ItemFn(..) => "fn",
10531053
ItemMod(..) => "mod",
10541054
ItemForeignMod(..) => "foreign mod",
1055+
ItemGlobalAsm(..) => "global asm",
10551056
ItemTy(..) => "ty",
10561057
ItemEnum(..) => "enum",
10571058
ItemStruct(..) => "struct",

src/librustc/hir/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,13 @@ pub struct ForeignMod {
14051405
pub items: HirVec<ForeignItem>,
14061406
}
14071407

1408+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1409+
pub struct GlobalAsm {
1410+
pub asm: Symbol,
1411+
pub asm_str_style: StrStyle,
1412+
pub expn_id: ExpnId
1413+
}
1414+
14081415
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14091416
pub struct EnumDef {
14101417
pub variants: HirVec<Variant>,
@@ -1584,6 +1591,8 @@ pub enum Item_ {
15841591
ItemMod(Mod),
15851592
/// An external module
15861593
ItemForeignMod(ForeignMod),
1594+
/// Module-level inline assembly (from global_asm!)
1595+
ItemGlobalAsm(P<GlobalAsm>),
15871596
/// A type alias, e.g. `type Foo = Bar<u8>`
15881597
ItemTy(P<Ty>, Generics),
15891598
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
@@ -1618,6 +1627,7 @@ impl Item_ {
16181627
ItemFn(..) => "function",
16191628
ItemMod(..) => "module",
16201629
ItemForeignMod(..) => "foreign module",
1630+
ItemGlobalAsm(..) => "global asm",
16211631
ItemTy(..) => "type alias",
16221632
ItemEnum(..) => "enum",
16231633
ItemStruct(..) => "struct",

src/librustc/hir/print.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,11 @@ impl<'a> State<'a> {
630630
self.print_foreign_mod(nmod, &item.attrs)?;
631631
self.bclose(item.span)?;
632632
}
633+
hir::ItemGlobalAsm(ref ga) => {
634+
self.head(&visibility_qualified(&item.vis, "global asm"))?;
635+
word(&mut self.s, &ga.asm.as_str())?;
636+
self.end()?
637+
}
633638
hir::ItemTy(ref ty, ref params) => {
634639
self.ibox(indent_unit)?;
635640
self.ibox(0)?;

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
265265
hir::ItemMod(..) | hir::ItemForeignMod(..) |
266266
hir::ItemImpl(..) | hir::ItemTrait(..) |
267267
hir::ItemStruct(..) | hir::ItemEnum(..) |
268-
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) => {}
268+
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) |
269+
hir::ItemGlobalAsm(..) => {}
269270
}
270271
}
271272
hir_map::NodeTraitItem(trait_method) => {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
314314
hir::ItemUse(..) |
315315
hir::ItemMod(..) |
316316
hir::ItemDefaultImpl(..) |
317-
hir::ItemForeignMod(..) => {
317+
hir::ItemForeignMod(..) |
318+
hir::ItemGlobalAsm(..) => {
318319
// These sorts of items have no lifetime parameters at all.
319320
intravisit::walk_item(self, item);
320321
}

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ enum SawItemComponent {
366366
SawItemFn(Unsafety, Constness, Abi),
367367
SawItemMod,
368368
SawItemForeignMod(Abi),
369+
SawItemGlobalAsm,
369370
SawItemTy,
370371
SawItemEnum,
371372
SawItemStruct,
@@ -384,6 +385,7 @@ fn saw_item(node: &Item_) -> SawItemComponent {
384385
ItemFn(_, unsafety, constness, abi, _, _) => SawItemFn(unsafety, constness, abi),
385386
ItemMod(..) => SawItemMod,
386387
ItemForeignMod(ref fm) => SawItemForeignMod(fm.abi),
388+
ItemGlobalAsm(..) => SawItemGlobalAsm,
387389
ItemTy(..) => SawItemTy,
388390
ItemEnum(..) => SawItemEnum,
389391
ItemStruct(..) => SawItemStruct,
@@ -933,7 +935,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
933935
Def::AssociatedConst(..) |
934936
Def::Local(..) |
935937
Def::Upvar(..) |
936-
Def::Macro(..) => {
938+
Def::Macro(..) |
939+
Def::GlobalAsm(..) => {
937940
DefHash::SawDefId.hash(self.st);
938941
self.hash_def_id(def.def_id());
939942
}

0 commit comments

Comments
 (0)