mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
zig cc: update driver files to LLVM 21
This commit is contained in:
parent
008affa645
commit
b7a8c045ef
4 changed files with 57 additions and 34 deletions
|
|
@ -111,9 +111,10 @@ static void ensureSufficientStack() {}
|
|||
|
||||
/// Print supported cpus of the given target.
|
||||
static int PrintSupportedCPUs(std::string TargetStr) {
|
||||
llvm::Triple Triple(TargetStr);
|
||||
std::string Error;
|
||||
const llvm::Target *TheTarget =
|
||||
llvm::TargetRegistry::lookupTarget(TargetStr, Error);
|
||||
llvm::TargetRegistry::lookupTarget(Triple, Error);
|
||||
if (!TheTarget) {
|
||||
llvm::errs() << Error;
|
||||
return 1;
|
||||
|
|
@ -122,15 +123,16 @@ static int PrintSupportedCPUs(std::string TargetStr) {
|
|||
// the target machine will handle the mcpu printing
|
||||
llvm::TargetOptions Options;
|
||||
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
|
||||
TheTarget->createTargetMachine(TargetStr, "", "+cpuhelp", Options,
|
||||
TheTarget->createTargetMachine(Triple, "", "+cpuhelp", Options,
|
||||
std::nullopt));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PrintSupportedExtensions(std::string TargetStr) {
|
||||
llvm::Triple Triple(TargetStr);
|
||||
std::string Error;
|
||||
const llvm::Target *TheTarget =
|
||||
llvm::TargetRegistry::lookupTarget(TargetStr, Error);
|
||||
llvm::TargetRegistry::lookupTarget(Triple, Error);
|
||||
if (!TheTarget) {
|
||||
llvm::errs() << Error;
|
||||
return 1;
|
||||
|
|
@ -138,7 +140,7 @@ static int PrintSupportedExtensions(std::string TargetStr) {
|
|||
|
||||
llvm::TargetOptions Options;
|
||||
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
|
||||
TheTarget->createTargetMachine(TargetStr, "", "", Options, std::nullopt));
|
||||
TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));
|
||||
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
|
||||
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
|
||||
const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
|
||||
|
|
@ -165,9 +167,10 @@ static int PrintSupportedExtensions(std::string TargetStr) {
|
|||
}
|
||||
|
||||
static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
|
||||
llvm::Triple Triple(TargetOpts.Triple);
|
||||
std::string Error;
|
||||
const llvm::Target *TheTarget =
|
||||
llvm::TargetRegistry::lookupTarget(TargetOpts.Triple, Error);
|
||||
llvm::TargetRegistry::lookupTarget(Triple, Error);
|
||||
if (!TheTarget) {
|
||||
llvm::errs() << Error;
|
||||
return 1;
|
||||
|
|
@ -179,7 +182,8 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
|
|||
llvm::TargetOptions BackendOptions;
|
||||
std::string FeaturesStr = llvm::join(TargetOpts.FeaturesAsWritten, ",");
|
||||
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
|
||||
TheTarget->createTargetMachine(TargetOpts.Triple, TargetOpts.CPU, FeaturesStr, BackendOptions, std::nullopt));
|
||||
TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
|
||||
BackendOptions, std::nullopt));
|
||||
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
|
||||
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
|
||||
|
||||
|
|
@ -213,11 +217,10 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
|
|||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
ensureSufficientStack();
|
||||
|
||||
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
|
||||
// Register the support for object-file-wrapped Clang modules.
|
||||
auto PCHOps = Clang->getPCHContainerOperations();
|
||||
auto PCHOps = std::make_shared<PCHContainerOperations>();
|
||||
PCHOps->registerWriter(std::make_unique<ObjectFilePCHContainerWriter>());
|
||||
PCHOps->registerReader(std::make_unique<ObjectFilePCHContainerReader>());
|
||||
|
||||
|
|
@ -229,17 +232,21 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|||
|
||||
// Buffer diagnostics from argument parsing so that we can output them using a
|
||||
// well formed diagnostic object.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagsBuffer);
|
||||
|
||||
// Setup round-trip remarks for the DiagnosticsEngine used in CreateFromArgs.
|
||||
if (find(Argv, StringRef("-Rround-trip-cc1-args")) != Argv.end())
|
||||
Diags.setSeverity(diag::remark_cc1_round_trip_generated,
|
||||
diag::Severity::Remark, {});
|
||||
|
||||
bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
|
||||
Argv, Diags, Argv0);
|
||||
auto Invocation = std::make_shared<CompilerInvocation>();
|
||||
bool Success =
|
||||
CompilerInvocation::CreateFromArgs(*Invocation, Argv, Diags, Argv0);
|
||||
|
||||
auto Clang = std::make_unique<CompilerInstance>(std::move(Invocation),
|
||||
std::move(PCHOps));
|
||||
|
||||
if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
|
||||
llvm::timeTraceProfilerInitialize(
|
||||
|
|
@ -292,7 +299,14 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|||
|
||||
// If any timers were active but haven't been destroyed yet, print their
|
||||
// results now. This happens in -disable-free mode.
|
||||
llvm::TimerGroup::printAll(llvm::errs());
|
||||
std::unique_ptr<raw_ostream> IOFile = llvm::CreateInfoOutputFile();
|
||||
if (Clang->getCodeGenOpts().TimePassesJson) {
|
||||
*IOFile << "{\n";
|
||||
llvm::TimerGroup::printAllJSONValues(*IOFile, "");
|
||||
*IOFile << "\n}\n";
|
||||
} else {
|
||||
llvm::TimerGroup::printAll(*IOFile);
|
||||
}
|
||||
llvm::TimerGroup::clearAll();
|
||||
|
||||
if (llvm::timeTraceProfilerEnabled()) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCCodeEmitter.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCInstPrinter.h"
|
||||
#include "llvm/MC/MCInstrInfo.h"
|
||||
#include "llvm/MC/MCObjectFileInfo.h"
|
||||
#include "llvm/MC/MCObjectWriter.h"
|
||||
|
|
@ -541,8 +542,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
|
|||
|
||||
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
|
||||
if (Opts.OutputType == AssemblerInvocation::FT_Asm) {
|
||||
MCInstPrinter *IP = TheTarget->createMCInstPrinter(
|
||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI);
|
||||
std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
|
||||
llvm::Triple(Opts.Triple), Opts.OutputAsmVariant, *MAI, *MCII, *MRI));
|
||||
|
||||
std::unique_ptr<MCCodeEmitter> CE;
|
||||
if (Opts.ShowEncoding)
|
||||
|
|
@ -551,7 +552,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
|
|||
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
||||
|
||||
auto FOut = std::make_unique<formatted_raw_ostream>(*Out);
|
||||
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP,
|
||||
Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), std::move(IP),
|
||||
std::move(CE), std::move(MAB)));
|
||||
} else if (Opts.OutputType == AssemblerInvocation::FT_Null) {
|
||||
Str.reset(createNullStreamer(Ctx));
|
||||
|
|
@ -576,7 +577,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
|
|||
Triple T(Opts.Triple);
|
||||
Str.reset(TheTarget->createMCObjectStreamer(
|
||||
T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
|
||||
Str.get()->initSections(Opts.NoExecStack, *STI);
|
||||
Str->initSections(Opts.NoExecStack, *STI);
|
||||
if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
|
||||
Triple *TVT = Opts.DarwinTargetVariantTriple
|
||||
? &*Opts.DarwinTargetVariantTriple
|
||||
|
|
@ -591,14 +592,14 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
|
|||
if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) {
|
||||
MCSection *AsmLabel = Ctx.getMachOSection(
|
||||
"__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
|
||||
Str.get()->switchSection(AsmLabel);
|
||||
Str.get()->emitZeros(1);
|
||||
Str->switchSection(AsmLabel);
|
||||
Str->emitZeros(1);
|
||||
}
|
||||
|
||||
bool Failed = false;
|
||||
|
||||
std::unique_ptr<MCAsmParser> Parser(
|
||||
createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI));
|
||||
createMCAsmParser(SrcMgr, Ctx, *Str, *MAI));
|
||||
|
||||
// FIXME: init MCTargetOptions from sanitizer flags here.
|
||||
std::unique_ptr<MCTargetAsmParser> TAP(
|
||||
|
|
@ -618,7 +619,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
|
|||
}
|
||||
|
||||
if (!Failed) {
|
||||
Parser->setTargetParser(*TAP.get());
|
||||
Parser->setTargetParser(*TAP);
|
||||
Failed = Parser->Run(Opts.NoInitialTextSection);
|
||||
}
|
||||
|
||||
|
|
@ -657,12 +658,12 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
|||
InitializeAllAsmParsers();
|
||||
|
||||
// Construct our diagnostic client.
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
|
||||
TextDiagnosticPrinter *DiagClient
|
||||
= new TextDiagnosticPrinter(errs(), &*DiagOpts);
|
||||
DiagnosticOptions DiagOpts;
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(errs(), DiagOpts);
|
||||
DiagClient->setPrefix("clang -cc1as");
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
||||
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagClient);
|
||||
|
||||
// Set an error handler, so that any LLVM backend diagnostics go through our
|
||||
// error handler.
|
||||
|
|
|
|||
|
|
@ -153,6 +153,11 @@ static bool SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|||
}
|
||||
|
||||
const char *FilteringStr = ::getenv("CC_PRINT_HEADERS_FILTERING");
|
||||
if (!FilteringStr) {
|
||||
TheDriver.Diag(clang::diag::err_drv_print_header_env_var_invalid_format)
|
||||
<< EnvVar;
|
||||
return false;
|
||||
}
|
||||
HeaderIncludeFilteringKind Filtering;
|
||||
if (!stringToHeaderIncludeFiltering(FilteringStr, Filtering)) {
|
||||
TheDriver.Diag(clang::diag::err_drv_print_header_env_var)
|
||||
|
|
@ -163,7 +168,7 @@ static bool SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
|
|||
if ((TheDriver.CCPrintHeadersFormat == HIFMT_Textual &&
|
||||
Filtering != HIFIL_None) ||
|
||||
(TheDriver.CCPrintHeadersFormat == HIFMT_JSON &&
|
||||
Filtering != HIFIL_Only_Direct_System)) {
|
||||
Filtering == HIFIL_None)) {
|
||||
TheDriver.Diag(clang::diag::err_drv_print_header_env_var_combination)
|
||||
<< EnvVar << FilteringStr;
|
||||
return false;
|
||||
|
|
@ -295,7 +300,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
|||
if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
|
||||
// FIXME: Driver shouldn't take extra initial argument.
|
||||
driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
|
||||
&llvm::errs());
|
||||
"CCC_OVERRIDE_OPTIONS", &llvm::errs());
|
||||
}
|
||||
|
||||
std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
|
||||
|
|
@ -311,21 +316,24 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
|||
.Case("-fintegrated-cc1", false)
|
||||
.Default(UseNewCC1Process);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
|
||||
CreateAndPopulateDiagOpts(Args);
|
||||
std::unique_ptr<DiagnosticOptions> DiagOpts = CreateAndPopulateDiagOpts(Args);
|
||||
// Driver's diagnostics don't use suppression mappings, so don't bother
|
||||
// parsing them. CC1 still receives full args, so this doesn't impact other
|
||||
// actions.
|
||||
DiagOpts->DiagnosticSuppressionMappingsFile.clear();
|
||||
|
||||
TextDiagnosticPrinter *DiagClient
|
||||
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
|
||||
TextDiagnosticPrinter *DiagClient =
|
||||
new TextDiagnosticPrinter(llvm::errs(), *DiagOpts);
|
||||
FixupDiagPrefixExeName(DiagClient, ProgName);
|
||||
|
||||
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
||||
|
||||
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
|
||||
DiagnosticsEngine Diags(DiagID, *DiagOpts, DiagClient);
|
||||
|
||||
if (!DiagOpts->DiagnosticSerializationFile.empty()) {
|
||||
auto SerializedConsumer =
|
||||
clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
|
||||
&*DiagOpts, /*MergeChildRecords=*/true);
|
||||
*DiagOpts, /*MergeChildRecords=*/true);
|
||||
Diags.setClient(new ChainedDiagnosticConsumer(
|
||||
Diags.takeClient(), std::move(SerializedConsumer)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ MODIFIERS:
|
|||
<< "USAGE: " + ToolName +
|
||||
" [options] [-]<operation>[modifiers] [relpos] "
|
||||
"[count] <archive> [files]\n"
|
||||
<< " " + ToolName + " -M [<mri-script]\n\n";
|
||||
<< " " + ToolName + " -M [< mri-script]\n\n";
|
||||
|
||||
outs() << ArOptions;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue