Skip to content

Commit e9dded3

Browse files
committed
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.
1 parent 8582a90 commit e9dded3

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/codegen/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault,
2020
CanDerivePartialEq, CanDeriveEq, CannotDeriveReason};
2121
use ir::dot;
2222
use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue};
23-
use ir::function::{Abi, Function, FunctionSig};
23+
use ir::function::{Abi, Function, FunctionSig, Linkage};
2424
use ir::int::IntKind;
2525
use ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath};
2626
use ir::item_kind::ItemKind;
@@ -3127,6 +3127,11 @@ impl CodeGenerator for Function {
31273127
debug!("<Function as CodeGenerator>::codegen: item = {:?}", item);
31283128
debug_assert!(item.is_enabled_for_codegen(ctx));
31293129

3130+
match self.linkage() {
3131+
Linkage::Internal => return,
3132+
_ => {}
3133+
}
3134+
31303135
// Similar to static member variables in a class template, we can't
31313136
// generate bindings to template functions, because the set of
31323137
// instantiations is open ended and we have no way of knowing which

src/ir/function.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ impl FunctionKind {
4949
}
5050
}
5151

52+
#[derive(Debug, Clone, Copy)]
53+
pub enum Linkage {
54+
External,
55+
Internal
56+
}
57+
5258
/// A function declaration, with a signature, arguments, and argument names.
5359
///
5460
/// The argument names vector must be the same length as the ones in the
@@ -69,6 +75,9 @@ pub struct Function {
6975

7076
/// The kind of function this is.
7177
kind: FunctionKind,
78+
79+
// The linkage of the function.
80+
linkage: Linkage,
7281
}
7382

7483
impl Function {
@@ -79,13 +88,15 @@ impl Function {
7988
sig: TypeId,
8089
comment: Option<String>,
8190
kind: FunctionKind,
91+
linkage: Linkage
8292
) -> Self {
8393
Function {
8494
name: name,
8595
mangled_name: mangled_name,
8696
signature: sig,
8797
comment: comment,
8898
kind: kind,
99+
linkage: linkage
89100
}
90101
}
91102

@@ -108,6 +119,12 @@ impl Function {
108119
pub fn kind(&self) -> FunctionKind {
109120
self.kind
110121
}
122+
123+
/// Get this function's linkage.
124+
pub fn linkage(&self) -> Linkage {
125+
self.linkage
126+
}
127+
111128
}
112129

113130
impl DotAttributes for Function {
@@ -477,11 +494,11 @@ impl ClangSubItemParser for Function {
477494
}
478495

479496
let linkage = cursor.linkage();
480-
if linkage != CXLinkage_External &&
481-
linkage != CXLinkage_UniqueExternal
482-
{
483-
return Err(ParseError::Continue);
484-
}
497+
let linkage = match linkage {
498+
CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External,
499+
CXLinkage_Internal => Linkage::Internal,
500+
_ => return Err(ParseError::Continue)
501+
};
485502

486503
// Grab the signature using Item::from_ty.
487504
let sig =
@@ -511,7 +528,7 @@ impl ClangSubItemParser for Function {
511528

512529
let comment = cursor.raw_comment();
513530

514-
let function = Self::new(name, mangled_name, sig, comment, kind);
531+
let function = Self::new(name, mangled_name, sig, comment, kind, linkage);
515532
Ok(ParseResult::New(function, Some(cursor)))
516533
}
517534
}

0 commit comments

Comments
 (0)