Skip to content

Commit ae7e00f

Browse files
committed
SwiftCompilerSources: diagnostics bridging.
1 parent 69c99ab commit ae7e00f

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import AST
1314
import SIL
1415
import OptimizerBridging
1516

@@ -40,6 +41,12 @@ extension Context {
4041
}
4142
}
4243

44+
extension Context {
45+
var diagnosticEngine: DiagnosticEngine {
46+
return DiagnosticEngine(bridged: _bridged.getDiagnosticEngine())
47+
}
48+
}
49+
4350
/// A context which allows mutation of a function's SIL.
4451
protocol MutatingContext : Context {
4552
// Called by all instruction mutations, including inserted new instructions.

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public struct Location: Equatable, CustomStringConvertible {
1818
public var description: String {
1919
return String(taking: bridged.getDebugDescription())
2020
}
21+
22+
public var sourceLoc: SourceLoc? {
23+
return SourceLoc(bridged: bridged.getSourceLocation())
24+
}
2125

2226
/// Keeps the debug scope but marks it as auto-generated.
2327
public var autoGenerated: Location {

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ struct BridgedLocation {
438438
BRIDGED_INLINE bool hasValidLineNumber() const;
439439
BRIDGED_INLINE bool isAutoGenerated() const;
440440
BRIDGED_INLINE bool isEqualTo(BridgedLocation rhs) const;
441+
BRIDGED_INLINE BridgedSourceLoc getSourceLocation() const;
441442
BRIDGED_INLINE bool hasSameSourceLocation(BridgedLocation rhs) const;
442443
static BRIDGED_INLINE BridgedLocation getArtificialUnreachableLocation();
443444
};

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ bool BridgedLocation::isAutoGenerated() const {
359359
bool BridgedLocation::isEqualTo(BridgedLocation rhs) const {
360360
return getLoc().isEqualTo(rhs.getLoc());
361361
}
362+
BridgedSourceLoc BridgedLocation::getSourceLocation() const {
363+
swift::SILDebugLocation debugLoc = getLoc();
364+
swift::SILLocation silLoc = debugLoc.getLocation();
365+
swift::SourceLoc sourceLoc = silLoc.getSourceLoc();
366+
return BridgedSourceLoc(sourceLoc.getOpaquePointerValue());
367+
}
362368
bool BridgedLocation::hasSameSourceLocation(BridgedLocation rhs) const {
363369
return getLoc().hasSameSourceLocation(rhs.getLoc());
364370
}

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// Function implementations should be placed into OptimizerBridgingImpl.h or PassManager.cpp
1818
// (under OptimizerBridging) andrequired header files should be added there.
1919
//
20+
#include "swift/AST/ASTBridging.h"
2021
#include "swift/SIL/SILBridging.h"
2122

2223
#ifdef USED_IN_CPP_SOURCE
@@ -177,6 +178,11 @@ struct BridgedPassContext {
177178
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedPostDomTree getPostDomTree() const;
178179
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNominalTypeDecl getSwiftArrayDecl() const;
179180

181+
// AST
182+
183+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
184+
BridgedDiagnosticEngine getDiagnosticEngine() const;
185+
180186
// SIL modifications
181187

182188
struct DevirtResult {

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ BridgedNominalTypeDecl BridgedPassContext::getSwiftArrayDecl() const {
172172
return {mod->getASTContext().getArrayDecl()};
173173
}
174174

175+
// AST
176+
177+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
178+
BridgedDiagnosticEngine BridgedPassContext::getDiagnosticEngine() const {
179+
swift::SILModule *mod = invocation->getPassManager()->getModule();
180+
return {&mod->getASTContext().Diags};
181+
}
182+
175183
// SIL modifications
176184

177185
BridgedBasicBlock BridgedPassContext::splitBlock(BridgedInstruction bridgedInst) const {

0 commit comments

Comments
 (0)