2020#include " clang/Driver/Options.h"
2121#include " llvm/Option/ArgList.h"
2222#include " llvm/Support/Path.h"
23+ #include " llvm/Support/TargetParser.h"
2324#include " llvm/Support/VirtualFileSystem.h"
2425#include < system_error>
2526
@@ -43,9 +44,9 @@ XtensaGCCToolchainDetector::XtensaGCCToolchainDetector(
4344
4445 if (CPUName.equals (" esp32" ))
4546 ToolchainName = " xtensa-esp32-elf" ;
46- else if (CPUName.equals (" esp32-s2" ))
47+ else if (CPUName.equals (" esp32-s2" ) || CPUName. equals ( " esp32s2 " ) )
4748 ToolchainName = " xtensa-esp32s2-elf" ;
48- else if (CPUName.equals (" esp32-s3" ))
49+ else if (CPUName.equals (" esp32-s3" ) || CPUName. equals ( " esp32s3 " ) )
4950 ToolchainName = " xtensa-esp32s3-elf" ;
5051 else if (CPUName.equals (" esp8266" ))
5152 ToolchainName = " xtensa-lx106-elf" ;
@@ -151,11 +152,11 @@ XtensaToolChain::XtensaToolChain(const Driver &D, const llvm::Triple &Triple,
151152}
152153
153154Tool *XtensaToolChain::buildLinker () const {
154- return new tools::Xtensa ::Linker (*this );
155+ return new tools::xtensa ::Linker (*this );
155156}
156157
157158Tool *XtensaToolChain::buildAssembler () const {
158- return new tools::Xtensa ::Assembler (*this );
159+ return new tools::xtensa ::Assembler (*this );
159160}
160161
161162void XtensaToolChain::AddClangSystemIncludeArgs (const ArgList &DriverArgs,
@@ -220,7 +221,7 @@ const StringRef XtensaToolChain::GetTargetCPUVersion(const ArgList &Args) {
220221 return " esp32" ;
221222}
222223
223- void tools::Xtensa ::Assembler::ConstructJob (Compilation &C, const JobAction &JA,
224+ void tools::xtensa ::Assembler::ConstructJob (Compilation &C, const JobAction &JA,
224225 const InputInfo &Output,
225226 const InputInfoList &Inputs,
226227 const ArgList &Args,
@@ -264,7 +265,7 @@ void tools::Xtensa::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
264265 JA, *this , ResponseFileSupport::AtFileCurCP (), Asm, CmdArgs, Inputs));
265266}
266267
267- void Xtensa ::Linker::ConstructJob (Compilation &C, const JobAction &JA,
268+ void xtensa ::Linker::ConstructJob (Compilation &C, const JobAction &JA,
268269 const InputInfo &Output,
269270 const InputInfoList &Inputs,
270271 const ArgList &Args,
@@ -297,3 +298,31 @@ void Xtensa::Linker::ConstructJob(Compilation &C, const JobAction &JA,
297298 std::make_unique<Command>(JA, *this , ResponseFileSupport::AtFileCurCP (),
298299 Args.MakeArgString (Linker), CmdArgs, Inputs));
299300}
301+
302+ // Get features by CPU name
303+ static void getXtensaFeaturesFromMcpu (const Driver &D,
304+ const llvm::opt::ArgList &Args,
305+ const llvm::opt::Arg *A, StringRef Mcpu,
306+ std::vector<StringRef> &Features) {
307+ if (llvm::Xtensa::parseCPUKind (Mcpu) == llvm::Xtensa::CK_INVALID) {
308+ D.Diag (clang::diag::err_drv_clang_unsupported) << A->getAsString (Args);
309+ } else {
310+ SmallVector<StringRef, 16 > CPUFeatures;
311+ llvm::Xtensa::getCPUFeatures (Mcpu, CPUFeatures);
312+ for (auto &F : CPUFeatures) {
313+ Features.push_back (F);
314+ }
315+ }
316+ }
317+
318+ // Xtensa target features.
319+ void xtensa::getXtensaTargetFeatures (const Driver &D, const ArgList &Args,
320+ std::vector<StringRef> &Features) {
321+ if (Arg *A = Args.getLastArg (options::OPT_mcpu_EQ))
322+ getXtensaFeaturesFromMcpu (D, Args, A, A->getValue (), Features);
323+
324+ // Now add any that the user explicitly requested on the command line,
325+ // which may override the defaults.
326+ handleTargetFeaturesGroup (Args, Features,
327+ options::OPT_m_xtensa_Features_Group);
328+ }
0 commit comments