File tree Expand file tree Collapse file tree 4 files changed +22
-39
lines changed Expand file tree Collapse file tree 4 files changed +22
-39
lines changed Original file line number Diff line number Diff line change @@ -2,21 +2,9 @@ import cllvm
2
2
3
3
/// An `Alias` represents a global alias in an LLVM module - a new symbol and
4
4
/// corresponding metadata for an existing position
5
- public struct Alias : IRValue {
5
+ public struct Alias : IRGlobal {
6
6
internal let llvm : LLVMValueRef
7
7
8
- /// Retrieves the linkage information for this alias.
9
- public var linkage : Linkage {
10
- get { return Linkage ( llvm: LLVMGetLinkage ( asLLVM ( ) ) ) }
11
- set { LLVMSetLinkage ( asLLVM ( ) , newValue. llvm) }
12
- }
13
-
14
- /// Retrieves the visibility style for this alias.
15
- public var visibility : Visibility {
16
- get { return Visibility ( llvm: LLVMGetVisibility ( asLLVM ( ) ) ) }
17
- set { LLVMSetVisibility ( asLLVM ( ) , newValue. llvm) }
18
- }
19
-
20
8
/// Retrieves the underlying LLVM value object.
21
9
public func asLLVM( ) -> LLVMValueRef {
22
10
return llvm
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import cllvm
3
3
/// A `Function` represents a named function body in LLVM IR source. Functions
4
4
/// in LLVM IR encapsulate a list of parameters and a sequence of basic blocks
5
5
/// and provide a way to append to that sequence to build out its body.
6
- public class Function : IRValue {
6
+ public class Function : IRGlobal {
7
7
internal let llvm : LLVMValueRef
8
8
internal init ( llvm: LLVMValueRef ) {
9
9
self . llvm = llvm
@@ -107,18 +107,6 @@ public class Function: IRValue {
107
107
LLVMDeleteFunction ( llvm)
108
108
}
109
109
110
- /// Retrieves the linkage information for this function.
111
- public var linkage : Linkage {
112
- get { return Linkage ( llvm: LLVMGetLinkage ( asLLVM ( ) ) ) }
113
- set { LLVMSetLinkage ( asLLVM ( ) , newValue. llvm) }
114
- }
115
-
116
- /// Retrieves the visibility style for this function.
117
- public var visibility : Visibility {
118
- get { return Visibility ( llvm: LLVMGetVisibility ( asLLVM ( ) ) ) }
119
- set { LLVMSetVisibility ( asLLVM ( ) , newValue. llvm) }
120
- }
121
-
122
110
/// Retrieves the underlying LLVM value object.
123
111
public func asLLVM( ) -> LLVMValueRef {
124
112
return llvm
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import cllvm
3
3
/// A `Global` represents a region of memory allocated at compile time instead
4
4
/// of at runtime. A global variable must either have an initializer, or make
5
5
/// reference to an external definition that has an initializer.
6
- public struct Global : IRValue {
6
+ public struct Global : IRGlobal {
7
7
internal let llvm : LLVMValueRef
8
8
9
9
/// Returns whether this global variable has no initializer because it makes
@@ -33,18 +33,6 @@ public struct Global: IRValue {
33
33
set { LLVMSetThreadLocal ( asLLVM ( ) , newValue. llvm) }
34
34
}
35
35
36
- /// Retrieves the linkage information for this global value.
37
- public var linkage : Linkage {
38
- get { return Linkage ( llvm: LLVMGetLinkage ( asLLVM ( ) ) ) }
39
- set { LLVMSetLinkage ( asLLVM ( ) , newValue. llvm) }
40
- }
41
-
42
- /// Retrieves the visibility style for this global value.
43
- public var visibility : Visibility {
44
- get { return Visibility ( llvm: LLVMGetVisibility ( asLLVM ( ) ) ) }
45
- set { LLVMSetVisibility ( asLLVM ( ) , newValue. llvm) }
46
- }
47
-
48
36
/// Deletes the global variable from its containing module.
49
37
/// - note: This does not remove references to this global from the
50
38
/// module. Ensure you have removed all insructions that reference
Original file line number Diff line number Diff line change
1
+ import cllvm
2
+
3
+ /// An `IRGlobal` is a value, alias, or function that exists at the top level of
4
+ /// an LLVM module.
5
+ public protocol IRGlobal : IRValue { }
6
+
7
+ extension IRGlobal {
8
+ /// Retrieves the linkage information for this global.
9
+ public var linkage : Linkage {
10
+ get { return Linkage ( llvm: LLVMGetLinkage ( asLLVM ( ) ) ) }
11
+ set { LLVMSetLinkage ( asLLVM ( ) , newValue. llvm) }
12
+ }
13
+
14
+ /// Retrieves the visibility style for this global.
15
+ public var visibility : Visibility {
16
+ get { return Visibility ( llvm: LLVMGetVisibility ( asLLVM ( ) ) ) }
17
+ set { LLVMSetVisibility ( asLLVM ( ) , newValue. llvm) }
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments