Skip to content

Commit 768e902

Browse files
committed
First attempt at global_asm! macro
1 parent 14481f7 commit 768e902

File tree

31 files changed

+180
-6
lines changed

31 files changed

+180
-6
lines changed

src/librustc/hir/def.rs

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

60+
GlobalAsm(DefId),
61+
6062
// Both namespaces
6163
Err,
6264
}
@@ -144,7 +146,8 @@ impl Def {
144146
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
145147
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
146148
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
147-
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) => {
149+
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id, ..) |
150+
Def::GlobalAsm(id) => {
148151
id
149152
}
150153

@@ -185,6 +188,7 @@ impl Def {
185188
Def::Label(..) => "label",
186189
Def::SelfTy(..) => "self type",
187190
Def::Macro(..) => "macro",
191+
Def::GlobalAsm(..) => "global asm",
188192
Def::Err => "unresolved item",
189193
}
190194
}

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,13 @@ impl<'a> LoweringContext<'a> {
646646
}
647647
}
648648

649+
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
650+
P(hir::GlobalAsm {
651+
asm: ga.asm,
652+
ctxt: ga.ctxt,
653+
})
654+
}
655+
649656
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
650657
Spanned {
651658
node: hir::Variant_ {
@@ -1288,6 +1295,7 @@ impl<'a> LoweringContext<'a> {
12881295
}
12891296
ItemKind::Mod(ref m) => hir::ItemMod(self.lower_mod(m)),
12901297
ItemKind::ForeignMod(ref nm) => hir::ItemForeignMod(self.lower_foreign_mod(nm)),
1298+
ItemKind::GlobalAsm(ref ga) => hir::ItemGlobalAsm(self.lower_global_asm(ga)),
12911299
ItemKind::Ty(ref t, ref generics) => {
12921300
hir::ItemTy(self.lower_ty(t), self.lower_generics(generics))
12931301
}

src/librustc/hir/map/def_collector.rs

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

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10771077
ItemFn(..) => "fn",
10781078
ItemMod(..) => "mod",
10791079
ItemForeignMod(..) => "foreign mod",
1080+
ItemGlobalAsm(..) => "global asm",
10801081
ItemTy(..) => "ty",
10811082
ItemEnum(..) => "enum",
10821083
ItemStruct(..) => "struct",

src/librustc/hir/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,12 @@ pub struct ForeignMod {
14951495
pub items: HirVec<ForeignItem>,
14961496
}
14971497

1498+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1499+
pub struct GlobalAsm {
1500+
pub asm: Symbol,
1501+
pub ctxt: SyntaxContext,
1502+
}
1503+
14981504
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14991505
pub struct EnumDef {
15001506
pub variants: HirVec<Variant>,
@@ -1686,6 +1692,8 @@ pub enum Item_ {
16861692
ItemMod(Mod),
16871693
/// An external module
16881694
ItemForeignMod(ForeignMod),
1695+
/// Module-level inline assembly (from global_asm!)
1696+
ItemGlobalAsm(P<GlobalAsm>),
16891697
/// A type alias, e.g. `type Foo = Bar<u8>`
16901698
ItemTy(P<Ty>, Generics),
16911699
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
@@ -1720,6 +1728,7 @@ impl Item_ {
17201728
ItemFn(..) => "function",
17211729
ItemMod(..) => "module",
17221730
ItemForeignMod(..) => "foreign module",
1731+
ItemGlobalAsm(..) => "global asm",
17231732
ItemTy(..) => "type alias",
17241733
ItemEnum(..) => "enum",
17251734
ItemStruct(..) => "struct",

src/librustc/hir/print.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ impl<'a> State<'a> {
633633
self.print_foreign_mod(nmod, &item.attrs)?;
634634
self.bclose(item.span)?;
635635
}
636+
hir::ItemGlobalAsm(ref ga) => {
637+
self.head(&visibility_qualified(&item.vis, "global asm"))?;
638+
word(&mut self.s, &ga.asm.as_str())?;
639+
self.end()?
640+
}
636641
hir::ItemTy(ref ty, ref params) => {
637642
self.ibox(indent_unit)?;
638643
self.ibox(0)?;

src/librustc/ich/impls_hir.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,19 @@ impl_stable_hash_for!(struct hir::InlineAsmOutput {
10141014
is_indirect
10151015
});
10161016

1017+
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for hir::GlobalAsm {
1018+
fn hash_stable<W: StableHasherResult>(&self,
1019+
hcx: &mut StableHashingContext<'a, 'tcx>,
1020+
hasher: &mut StableHasher<W>) {
1021+
let hir::GlobalAsm {
1022+
asm,
1023+
ctxt: _
1024+
} = *self;
1025+
1026+
asm.hash_stable(hcx, hasher);
1027+
}
1028+
}
1029+
10171030
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for hir::InlineAsm {
10181031
fn hash_stable<W: StableHasherResult>(&self,
10191032
hcx: &mut StableHashingContext<'a, 'tcx>,

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
267267
hir::ItemMod(..) | hir::ItemForeignMod(..) |
268268
hir::ItemImpl(..) | hir::ItemTrait(..) |
269269
hir::ItemStruct(..) | hir::ItemEnum(..) |
270-
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) => {}
270+
hir::ItemUnion(..) | hir::ItemDefaultImpl(..) |
271+
hir::ItemGlobalAsm(..) => {}
271272
}
272273
}
273274
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
}

0 commit comments

Comments
 (0)