| ... | @@ -1,9 +1,8 @@ | ... | @@ -1,9 +1,8 @@ |
| 1 | //===-- cc1as_main.cpp - Clang Assembler ---------------------------------===// | 1 | //===-- cc1as_main.cpp - Clang Assembler ---------------------------------===// |
| 2 | // | 2 | // |
| 3 | // The LLVM Compiler Infrastructure | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // | 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // This file is distributed under the University of Illinois Open Source | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // License. See LICENSE.TXT for details. | | |
| 7 | // | 6 | // |
| 8 | //===----------------------------------------------------------------------===// | 7 | //===----------------------------------------------------------------------===// |
| 9 | // | 8 | // |
| ... | @@ -99,7 +98,7 @@ struct AssemblerInvocation { | ... | @@ -99,7 +98,7 @@ struct AssemblerInvocation { |
| 99 | llvm::DebugCompressionType CompressDebugSections = | 98 | llvm::DebugCompressionType CompressDebugSections = |
| 100 | llvm::DebugCompressionType::None; | 99 | llvm::DebugCompressionType::None; |
| 101 | std::string MainFileName; | 100 | std::string MainFileName; |
| 102 | std::string SplitDwarfFile; | 101 | std::string SplitDwarfOutput; |
| 103 | | 102 | |
| 104 | /// @} | 103 | /// @} |
| 105 | /// @name Frontend Options | 104 | /// @name Frontend Options |
| ... | @@ -138,6 +137,10 @@ struct AssemblerInvocation { | ... | @@ -138,6 +137,10 @@ struct AssemblerInvocation { |
| 138 | /// The name of the relocation model to use. | 137 | /// The name of the relocation model to use. |
| 139 | std::string RelocationModel; | 138 | std::string RelocationModel; |
| 140 | | 139 | |
| | 140 | /// The ABI targeted by the backend. Specified using -target-abi. Empty |
| | 141 | /// otherwise. |
| | 142 | std::string TargetABI; |
| | 143 | |
| 141 | /// @} | 144 | /// @} |
| 142 | | 145 | |
| 143 | public: | 146 | public: |
| ... | @@ -255,7 +258,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, | ... | @@ -255,7 +258,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 255 | } | 258 | } |
| 256 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); | 259 | Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm); |
| 257 | Opts.OutputPath = Args.getLastArgValue(OPT_o); | 260 | Opts.OutputPath = Args.getLastArgValue(OPT_o); |
| 258 | Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); | 261 | Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output); |
| 259 | if (Arg *A = Args.getLastArg(OPT_filetype)) { | 262 | if (Arg *A = Args.getLastArg(OPT_filetype)) { |
| 260 | StringRef Name = A->getValue(); | 263 | StringRef Name = A->getValue(); |
| 261 | unsigned OutputType = StringSwitch<unsigned>(Name) | 264 | unsigned OutputType = StringSwitch<unsigned>(Name) |
| ... | @@ -283,6 +286,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, | ... | @@ -283,6 +286,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 283 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); | 286 | Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); |
| 284 | Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); | 287 | Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); |
| 285 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); | 288 | Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); |
| | 289 | Opts.TargetABI = Args.getLastArgValue(OPT_target_abi); |
| 286 | Opts.IncrementalLinkerCompatible = | 290 | Opts.IncrementalLinkerCompatible = |
| 287 | Args.hasArg(OPT_mincremental_linker_compatible); | 291 | Args.hasArg(OPT_mincremental_linker_compatible); |
| 288 | Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); | 292 | Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); |
| ... | @@ -337,7 +341,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -337,7 +341,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 337 | SourceMgr SrcMgr; | 341 | SourceMgr SrcMgr; |
| 338 | | 342 | |
| 339 | // Tell SrcMgr about this buffer, which is what the parser will pick up. | 343 | // Tell SrcMgr about this buffer, which is what the parser will pick up. |
| 340 | SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc()); | 344 | unsigned BufferIndex = SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc()); |
| 341 | | 345 | |
| 342 | // Record the location of the include directories so that the lexer can find | 346 | // Record the location of the include directories so that the lexer can find |
| 343 | // it later. | 347 | // it later. |
| ... | @@ -363,8 +367,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -363,8 +367,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 363 | if (!FDOS) | 367 | if (!FDOS) |
| 364 | return true; | 368 | return true; |
| 365 | std::unique_ptr<raw_fd_ostream> DwoOS; | 369 | std::unique_ptr<raw_fd_ostream> DwoOS; |
| 366 | if (!Opts.SplitDwarfFile.empty()) | 370 | if (!Opts.SplitDwarfOutput.empty()) |
| 367 | DwoOS = getOutputStream(Opts.SplitDwarfFile, Diags, IsBinary); | 371 | DwoOS = getOutputStream(Opts.SplitDwarfOutput, Diags, IsBinary); |
| 368 | | 372 | |
| 369 | // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and | 373 | // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and |
| 370 | // MCObjectFileInfo needs a MCContext reference in order to initialize itself. | 374 | // MCObjectFileInfo needs a MCContext reference in order to initialize itself. |
| ... | @@ -394,12 +398,21 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -394,12 +398,21 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 394 | Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer)); | 398 | Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer)); |
| 395 | if (!Opts.DebugCompilationDir.empty()) | 399 | if (!Opts.DebugCompilationDir.empty()) |
| 396 | Ctx.setCompilationDir(Opts.DebugCompilationDir); | 400 | Ctx.setCompilationDir(Opts.DebugCompilationDir); |
| | 401 | else { |
| | 402 | // If no compilation dir is set, try to use the current directory. |
| | 403 | SmallString<128> CWD; |
| | 404 | if (!sys::fs::current_path(CWD)) |
| | 405 | Ctx.setCompilationDir(CWD); |
| | 406 | } |
| 397 | if (!Opts.DebugPrefixMap.empty()) | 407 | if (!Opts.DebugPrefixMap.empty()) |
| 398 | for (const auto &KV : Opts.DebugPrefixMap) | 408 | for (const auto &KV : Opts.DebugPrefixMap) |
| 399 | Ctx.addDebugPrefixMapEntry(KV.first, KV.second); | 409 | Ctx.addDebugPrefixMapEntry(KV.first, KV.second); |
| 400 | if (!Opts.MainFileName.empty()) | 410 | if (!Opts.MainFileName.empty()) |
| 401 | Ctx.setMainFileName(StringRef(Opts.MainFileName)); | 411 | Ctx.setMainFileName(StringRef(Opts.MainFileName)); |
| 402 | Ctx.setDwarfVersion(Opts.DwarfVersion); | 412 | Ctx.setDwarfVersion(Opts.DwarfVersion); |
| | 413 | if (Opts.GenDwarfForAssembly) |
| | 414 | Ctx.setGenDwarfRootFile(Opts.InputFile, |
| | 415 | SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer()); |
| 403 | | 416 | |
| 404 | // Build up the feature string from the target feature list. | 417 | // Build up the feature string from the target feature list. |
| 405 | std::string FS; | 418 | std::string FS; |
| ... | @@ -418,6 +431,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -418,6 +431,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 418 | raw_pwrite_stream *Out = FDOS.get(); | 431 | raw_pwrite_stream *Out = FDOS.get(); |
| 419 | std::unique_ptr<buffer_ostream> BOS; | 432 | std::unique_ptr<buffer_ostream> BOS; |
| 420 | | 433 | |
| | 434 | MCTargetOptions MCOptions; |
| | 435 | MCOptions.ABIName = Opts.TargetABI; |
| | 436 | |
| 421 | // FIXME: There is a bit of code duplication with addPassesToEmitFile. | 437 | // FIXME: There is a bit of code duplication with addPassesToEmitFile. |
| 422 | if (Opts.OutputType == AssemblerInvocation::FT_Asm) { | 438 | if (Opts.OutputType == AssemblerInvocation::FT_Asm) { |
| 423 | MCInstPrinter *IP = TheTarget->createMCInstPrinter( | 439 | MCInstPrinter *IP = TheTarget->createMCInstPrinter( |
| ... | @@ -426,7 +442,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -426,7 +442,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 426 | std::unique_ptr<MCCodeEmitter> CE; | 442 | std::unique_ptr<MCCodeEmitter> CE; |
| 427 | if (Opts.ShowEncoding) | 443 | if (Opts.ShowEncoding) |
| 428 | CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); | 444 | CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); |
| 429 | MCTargetOptions MCOptions; | | |
| 430 | std::unique_ptr<MCAsmBackend> MAB( | 445 | std::unique_ptr<MCAsmBackend> MAB( |
| 431 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); | 446 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); |
| 432 | | 447 | |
| ... | @@ -447,7 +462,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -447,7 +462,6 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 447 | | 462 | |
| 448 | std::unique_ptr<MCCodeEmitter> CE( | 463 | std::unique_ptr<MCCodeEmitter> CE( |
| 449 | TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); | 464 | TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); |
| 450 | MCTargetOptions MCOptions; | | |
| 451 | std::unique_ptr<MCAsmBackend> MAB( | 465 | std::unique_ptr<MCAsmBackend> MAB( |
| 452 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); | 466 | TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); |
| 453 | std::unique_ptr<MCObjectWriter> OW = | 467 | std::unique_ptr<MCObjectWriter> OW = |
| ... | @@ -481,9 +495,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -481,9 +495,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 481 | createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); | 495 | createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); |
| 482 | | 496 | |
| 483 | // FIXME: init MCTargetOptions from sanitizer flags here. | 497 | // FIXME: init MCTargetOptions from sanitizer flags here. |
| 484 | MCTargetOptions Options; | | |
| 485 | std::unique_ptr<MCTargetAsmParser> TAP( | 498 | std::unique_ptr<MCTargetAsmParser> TAP( |
| 486 | TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options)); | 499 | TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions)); |
| 487 | if (!TAP) | 500 | if (!TAP) |
| 488 | Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; | 501 | Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; |
| 489 | | 502 | |
| ... | @@ -514,8 +527,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, | ... | @@ -514,8 +527,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 514 | if (Failed) { | 527 | if (Failed) { |
| 515 | if (Opts.OutputPath != "-") | 528 | if (Opts.OutputPath != "-") |
| 516 | sys::fs::remove(Opts.OutputPath); | 529 | sys::fs::remove(Opts.OutputPath); |
| 517 | if (!Opts.SplitDwarfFile.empty() && Opts.SplitDwarfFile != "-") | 530 | if (!Opts.SplitDwarfOutput.empty() && Opts.SplitDwarfOutput != "-") |
| 518 | sys::fs::remove(Opts.SplitDwarfFile); | 531 | sys::fs::remove(Opts.SplitDwarfOutput); |
| 519 | } | 532 | } |
| 520 | | 533 | |
| 521 | return Failed; | 534 | return Failed; |
| ... | @@ -594,4 +607,3 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { | ... | @@ -594,4 +607,3 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 594 | | 607 | |
| 595 | return !!Failed; | 608 | return !!Failed; |
| 596 | } | 609 | } |
| 597 | | | |