@@ -18,6 +18,9 @@ public class Context: ContextRef {
1818 /// Retrieves the underlying LLVM type object.
1919 public var contextRef : LLVMContextRef { llvm }
2020
21+ /// Diagnostic handler type
22+ public typealias DiagnosticHandler = @convention ( c) ( LLVMDiagnosticInfoRef , UnsafeMutableRawPointer ? ) -> Void
23+
2124 /// Retrieves the global context instance.
2225 ///
2326 /// The global context is an particularly convenient instance managed by LLVM
@@ -41,14 +44,34 @@ public class Context: ContextRef {
4144 self . llvm = llvm
4245 }
4346
47+ /// Get the diagnostic handler of current context.
48+ public var getContextDiagnosticHandler : DiagnosticHandler ? {
49+ if let handler = LLVMContextGetDiagnosticHandler ( contextRef) {
50+ return unsafeBitCast ( handler, to: DiagnosticHandler . self)
51+ } else {
52+ return nil
53+ }
54+ }
55+
56+ /// Set the diagnostic handler for current context.
57+ public func setContextDiagnosticHandler( handler: LLVMDiagnosticHandler ? , diagnosticContext: UnsafeMutableRawPointer ? ) {
58+ LLVMContextSetDiagnosticHandler ( contextRef, handler, diagnosticContext)
59+ }
60+
4461 /// Returns whether the given context is set to discard all value names.
4562 ///
4663 /// If true, only the names of GlobalValue objects will be available in
4764 /// the IR. This can be used to save memory and processing time, especially
4865 /// in release environments.
4966 public var discardValueNames : Bool {
50- get { return LLVMContextShouldDiscardValueNames ( llvm) != 0 }
51- set { LLVMContextSetDiscardValueNames ( llvm, newValue. llvm) }
67+ get {
68+ // Retrieve whether the given context is set to discard all value names.
69+ return LLVMContextShouldDiscardValueNames ( llvm) != 0
70+ }
71+ set {
72+ // Set whether the given context discards all value names.
73+ LLVMContextSetDiscardValueNames ( llvm, newValue. llvm)
74+ }
5275 }
5376
5477 /// Deinitialize this value and dispose of its resources.
0 commit comments