16
16
#include " swift/Basic/StringExtras.h"
17
17
#include " swift/Frontend/Frontend.h"
18
18
19
+ #include " clang/Basic/TargetInfo.h"
19
20
#include " llvm/Support/raw_ostream.h"
20
21
21
22
using namespace swift ;
@@ -52,9 +53,11 @@ static void printCompatibilityLibrary(
52
53
printedAny = true ;
53
54
}
54
55
56
+ namespace swift {
57
+ namespace targetinfo {
55
58
// / Print information about the selected target in JSON.
56
- void targetinfo:: printTargetInfo (const CompilerInvocation &invocation,
57
- llvm::raw_ostream &out) {
59
+ void printTargetInfo (const CompilerInvocation &invocation,
60
+ llvm::raw_ostream &out) {
58
61
out << " {\n " ;
59
62
60
63
// Compiler version, as produced by --version.
@@ -67,12 +70,12 @@ void targetinfo::printTargetInfo(const CompilerInvocation &invocation,
67
70
invocation.getIRGenOptions ().AutolinkRuntimeCompatibilityLibraryVersion ;
68
71
auto &langOpts = invocation.getLangOptions ();
69
72
out << " \" target\" : " ;
70
- printTripleInfo (langOpts.Target , runtimeVersion, out);
73
+ printTripleInfo (invocation, langOpts.Target , runtimeVersion, out);
71
74
out << " ,\n " ;
72
75
73
76
if (auto &variant = langOpts.TargetVariant ) {
74
77
out << " \" targetVariant\" : " ;
75
- printTripleInfo (*variant, runtimeVersion, out);
78
+ printTripleInfo (invocation, *variant, runtimeVersion, out);
76
79
out << " ,\n " ;
77
80
}
78
81
@@ -112,9 +115,10 @@ void targetinfo::printTargetInfo(const CompilerInvocation &invocation,
112
115
}
113
116
114
117
// Print information about the target triple in JSON.
115
- void targetinfo::printTripleInfo (
116
- const llvm::Triple &triple,
117
- std::optional<llvm::VersionTuple> runtimeVersion, llvm::raw_ostream &out) {
118
+ void printTripleInfo (const CompilerInvocation &invocation,
119
+ const llvm::Triple &triple,
120
+ std::optional<llvm::VersionTuple> runtimeVersion,
121
+ llvm::raw_ostream &out) {
118
122
out << " {\n " ;
119
123
120
124
out << " \" triple\" : \" " ;
@@ -130,7 +134,21 @@ void targetinfo::printTripleInfo(
130
134
out << " \" ,\n " ;
131
135
132
136
out << " \" platform\" : \" " << getPlatformNameForTriple (triple) << " \" ,\n " ;
133
- out << " \" arch\" : \" " << swift::getMajorArchitectureName (triple) << " \" ,\n " ;
137
+ out << " \" arch\" : \" " << swift::getMajorArchitectureName (triple)
138
+ << " \" ,\n " ;
139
+
140
+ clang::DiagnosticsEngine DE{new clang::DiagnosticIDs (),
141
+ new clang::DiagnosticOptions (),
142
+ new clang::IgnoringDiagConsumer ()};
143
+ std::shared_ptr<clang::TargetOptions> TO =
144
+ std::make_shared<clang::TargetOptions>();
145
+ TO->Triple = triple.str ();
146
+ clang::TargetInfo *TI = clang::TargetInfo::CreateTargetInfo (DE, TO);
147
+ out << " \" pointerWidthInBits\" : "
148
+ << TI->getPointerWidth (clang::LangAS::Default) << " ,\n " ;
149
+ out << " \" pointerWidthInBytes\" : "
150
+ << TI->getPointerWidth (clang::LangAS::Default) / TI->getCharWidth ()
151
+ << " ,\n " ;
134
152
135
153
if (runtimeVersion) {
136
154
out << " \" swiftRuntimeCompatibilityVersion\" : \" " ;
@@ -140,15 +158,14 @@ void targetinfo::printTripleInfo(
140
158
// Compatibility libraries that need to be linked.
141
159
out << " \" compatibilityLibraries\" : [" ;
142
160
bool printedAnyCompatibilityLibrary = false ;
143
- #define BACK_DEPLOYMENT_LIB (Version, Filter, LibraryName, ForceLoad ) \
144
- printCompatibilityLibrary ( \
145
- *runtimeVersion, llvm::VersionTuple Version, #Filter, LibraryName, \
146
- ForceLoad, printedAnyCompatibilityLibrary, out);
147
- #include " swift/Frontend/BackDeploymentLibs.def"
161
+ #define BACK_DEPLOYMENT_LIB (Version, Filter, LibraryName, ForceLoad ) \
162
+ printCompatibilityLibrary (*runtimeVersion, llvm::VersionTuple Version, \
163
+ #Filter, LibraryName, ForceLoad, \
164
+ printedAnyCompatibilityLibrary, out);
165
+ #include " swift/Frontend/BackDeploymentLibs.def"
148
166
149
- if (printedAnyCompatibilityLibrary) {
167
+ if (printedAnyCompatibilityLibrary)
150
168
out << " \n " ;
151
- }
152
169
out << " ],\n " ;
153
170
} else {
154
171
out << " \" compatibilityLibraries\" : [ ],\n " ;
@@ -160,3 +177,5 @@ void targetinfo::printTripleInfo(
160
177
161
178
out << " }" ;
162
179
}
180
+ } // namespace targetinfo
181
+ } // namespace swift
0 commit comments