|
1 | 1 | import cllvm
|
2 | 2 |
|
| 3 | +/// `Visibility` enumerates available visibility styles. |
| 4 | +public enum Visibility { |
| 5 | + /// On targets that use the ELF object file format, default visibility means |
| 6 | + /// that the declaration is visible to other modules and, in shared libraries, |
| 7 | + /// means that the declared entity may be overridden. On Darwin, default |
| 8 | + /// visibility means that the declaration is visible to other modules. Default |
| 9 | + /// visibility corresponds to "external linkage" in the language. |
| 10 | + case `default` |
| 11 | + /// Two declarations of an object with hidden visibility refer to the same |
| 12 | + /// object if they are in the same shared object. Usually, hidden visibility |
| 13 | + /// indicates that the symbol will not be placed into the dynamic symbol |
| 14 | + /// table, so no other module (executable or shared library) can reference it |
| 15 | + /// directly. |
| 16 | + case hidden |
| 17 | + /// On ELF, protected visibility indicates that the symbol will be placed in |
| 18 | + /// the dynamic symbol table, but that references within the defining module |
| 19 | + /// will bind to the local symbol. That is, the symbol cannot be overridden by |
| 20 | + /// another module. |
| 21 | + case protected |
| 22 | + |
| 23 | + static let visibilityMapping: [Visibility: LLVMVisibility] = [ |
| 24 | + .default: LLVMDefaultVisibility, |
| 25 | + .hidden: LLVMHiddenVisibility, |
| 26 | + .protected: LLVMProtectedVisibility, |
| 27 | + ] |
| 28 | + |
| 29 | + internal init(llvm: LLVMVisibility) { |
| 30 | + switch llvm { |
| 31 | + case LLVMDefaultVisibility: self = .default |
| 32 | + case LLVMHiddenVisibility: self = .hidden |
| 33 | + case LLVMProtectedVisibility: self = .protected |
| 34 | + default: fatalError("unknown visibility type \(llvm)") |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /// Retrieves the corresponding `LLVMLinkage`. |
| 39 | + public var llvm: LLVMVisibility { |
| 40 | + return Visibility.visibilityMapping[self]! |
| 41 | + } |
| 42 | +} |
| 43 | + |
3 | 44 | /// `Linkage` enumerates the supported kinds of linkage for global values. All
|
4 | 45 | /// global variables and functions have a linkage.
|
5 | 46 | public enum Linkage {
|
|
0 commit comments