From 02dc2bff695ce6c3068ec4f53bb37f92b5873a84 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sun, 22 Oct 2017 18:38:50 -0400 Subject: [PATCH] Store function linkage in the ir This lets us capture 'static inline' functions in the ir and filter them later down the pipeline. This is the first step on the way to handling these functions better. --- src/codegen/mod.rs | 9 ++++++++- src/ir/function.rs | 32 ++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ac28244c54..e4928a452f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -20,7 +20,7 @@ use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDerivePartialEq, CanDeriveEq, CannotDeriveReason}; use ir::dot; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; -use ir::function::{Abi, Function, FunctionSig}; +use ir::function::{Abi, Function, FunctionSig, Linkage}; use ir::int::IntKind; use ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; use ir::item_kind::ItemKind; @@ -3127,6 +3127,13 @@ impl CodeGenerator for Function { debug!("::codegen: item = {:?}", item); debug_assert!(item.is_enabled_for_codegen(ctx)); + // We can't currently do anything with Internal functions so just + // avoid generating anything for them. + match self.linkage() { + Linkage::Internal => return, + Linkage::External => {} + } + // Similar to static member variables in a class template, we can't // generate bindings to template functions, because the set of // instantiations is open ended and we have no way of knowing which diff --git a/src/ir/function.rs b/src/ir/function.rs index 2eab663835..d5976744b4 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -49,6 +49,15 @@ impl FunctionKind { } } +/// The style of linkage +#[derive(Debug, Clone, Copy)] +pub enum Linkage { + /// Externally visible and can be linked against + External, + /// Not exposed externally. 'static inline' functions will have this kind of linkage + Internal +} + /// A function declaration, with a signature, arguments, and argument names. /// /// The argument names vector must be the same length as the ones in the @@ -69,6 +78,9 @@ pub struct Function { /// The kind of function this is. kind: FunctionKind, + + /// The linkage of the function. + linkage: Linkage, } impl Function { @@ -79,6 +91,7 @@ impl Function { sig: TypeId, comment: Option, kind: FunctionKind, + linkage: Linkage ) -> Self { Function { name: name, @@ -86,6 +99,7 @@ impl Function { signature: sig, comment: comment, kind: kind, + linkage: linkage } } @@ -108,6 +122,12 @@ impl Function { pub fn kind(&self) -> FunctionKind { self.kind } + + /// Get this function's linkage. + pub fn linkage(&self) -> Linkage { + self.linkage + } + } impl DotAttributes for Function { @@ -477,11 +497,11 @@ impl ClangSubItemParser for Function { } let linkage = cursor.linkage(); - if linkage != CXLinkage_External && - linkage != CXLinkage_UniqueExternal - { - return Err(ParseError::Continue); - } + let linkage = match linkage { + CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, + CXLinkage_Internal => Linkage::Internal, + _ => return Err(ParseError::Continue) + }; // Grab the signature using Item::from_ty. let sig = @@ -511,7 +531,7 @@ impl ClangSubItemParser for Function { let comment = cursor.raw_comment(); - let function = Self::new(name, mangled_name, sig, comment, kind); + let function = Self::new(name, mangled_name, sig, comment, kind, linkage); Ok(ParseResult::New(function, Some(cursor))) } }