1616#include " swift/Basic/StringExtras.h"
1717#include " swift/Frontend/Frontend.h"
1818
19+ #include " clang/Basic/TargetInfo.h"
1920#include " llvm/Support/raw_ostream.h"
2021
2122using namespace swift ;
@@ -52,9 +53,11 @@ static void printCompatibilityLibrary(
5253 printedAny = true ;
5354}
5455
56+ namespace swift {
57+ namespace targetinfo {
5558// / 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) {
5861 out << " {\n " ;
5962
6063 // Compiler version, as produced by --version.
@@ -67,12 +70,12 @@ void targetinfo::printTargetInfo(const CompilerInvocation &invocation,
6770 invocation.getIRGenOptions ().AutolinkRuntimeCompatibilityLibraryVersion ;
6871 auto &langOpts = invocation.getLangOptions ();
6972 out << " \" target\" : " ;
70- printTripleInfo (langOpts.Target , runtimeVersion, out);
73+ printTripleInfo (invocation, langOpts.Target , runtimeVersion, out);
7174 out << " ,\n " ;
7275
7376 if (auto &variant = langOpts.TargetVariant ) {
7477 out << " \" targetVariant\" : " ;
75- printTripleInfo (*variant, runtimeVersion, out);
78+ printTripleInfo (invocation, *variant, runtimeVersion, out);
7679 out << " ,\n " ;
7780 }
7881
@@ -112,9 +115,10 @@ void targetinfo::printTargetInfo(const CompilerInvocation &invocation,
112115}
113116
114117// 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) {
118122 out << " {\n " ;
119123
120124 out << " \" triple\" : \" " ;
@@ -130,7 +134,21 @@ void targetinfo::printTripleInfo(
130134 out << " \" ,\n " ;
131135
132136 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 " ;
134152
135153 if (runtimeVersion) {
136154 out << " \" swiftRuntimeCompatibilityVersion\" : \" " ;
@@ -140,15 +158,14 @@ void targetinfo::printTripleInfo(
140158 // Compatibility libraries that need to be linked.
141159 out << " \" compatibilityLibraries\" : [" ;
142160 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"
148166
149- if (printedAnyCompatibilityLibrary) {
167+ if (printedAnyCompatibilityLibrary)
150168 out << " \n " ;
151- }
152169 out << " ],\n " ;
153170 } else {
154171 out << " \" compatibilityLibraries\" : [ ],\n " ;
@@ -160,3 +177,5 @@ void targetinfo::printTripleInfo(
160177
161178 out << " }" ;
162179}
180+ } // namespace targetinfo
181+ } // namespace swift
0 commit comments