clang 8.0.0

Minix.cpp
Go to the documentation of this file.
1 //===--- Minix.cpp - Minix ToolChain Implementations ------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "Minix.h"
11 #include "CommonArgs.h"
12 #include "InputInfo.h"
13 #include "clang/Driver/Compilation.h"
14 #include "clang/Driver/Driver.h"
15 #include "clang/Driver/Options.h"
16 #include "llvm/Option/ArgList.h"
17 #include "llvm/Support/VirtualFileSystem.h"
18
19 using namespace clang::driver;
20 using namespace clang;
21 using namespace llvm::opt;
22
23 void tools::minix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
24 const InputInfo &Output,
25 const InputInfoList &Inputs,
26 const ArgList &Args,
27 const char *LinkingOutput) const {
28 claimNoWarnArgs(Args);
29 ArgStringList CmdArgs;
30
31 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
32
33 CmdArgs.push_back("-o");
34 CmdArgs.push_back(Output.getFilename());
35
36 for (const auto &II : Inputs)
37 CmdArgs.push_back(II.getFilename());
38
39 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
40 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
41 }
42
43 void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
44 const InputInfo &Output,
45 const InputInfoList &Inputs,
46 const ArgList &Args,
47 const char *LinkingOutput) const {
48 const Driver &D = getToolChain().getDriver();
49 ArgStringList CmdArgs;
50
51 if (Output.isFilename()) {
52 CmdArgs.push_back("-o");
53 CmdArgs.push_back(Output.getFilename());
54 } else {
55 assert(Output.isNothing() && "Invalid output.");
56 }
57
58 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
59 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
60 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
61 CmdArgs.push_back(
62 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
63 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
64 }
65
66 Args.AddAllArgs(CmdArgs,
67 {options::OPT_L, options::OPT_T_Group, options::OPT_e});
68
69 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
70
71 getToolChain().addProfileRTLibs(Args, CmdArgs);
72
73 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
74 if (D.CCCIsCXX()) {
75 if (getToolChain().ShouldLinkCXXStdlib(Args))
76 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
77 CmdArgs.push_back("-lm");
78 }
79 }
80
81 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
82 if (Args.hasArg(options::OPT_pthread))
83 CmdArgs.push_back("-lpthread");
84 CmdArgs.push_back("-lc");
85 CmdArgs.push_back("-lCompilerRT-Generic");
86 CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
87 CmdArgs.push_back(
88 Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
89 }
90
91 const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
92 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
93 }
94
95 /// Minix - Minix tool chain which can call as(1) and ld(1) directly.
96
97 toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple,
98 const ArgList &Args)
99 : Generic_ELF(D, Triple, Args) {
100 getFilePaths().push_back(getDriver().Dir + "/../lib");
101 getFilePaths().push_back("/usr/lib");
102 }
103
104 Tool *toolchains::Minix::buildAssembler() const {
105 return new tools::minix::Assembler(*this);
106 }
107
108 Tool *toolchains::Minix::buildLinker() const {
109 return new tools::minix::Linker(*this);
110 }
clang::driver::tools::minix::Assembler
Definition: Minix.h:22
clang::driver::toolchains::Minix::buildAssembler
Tool * buildAssembler() const override
Definition: Minix.cpp:104
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:84
CommonArgs.h
clang::driver::JobAction
Definition: Action.h:374
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:224
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
Driver.h
Compilation.h
clang::driver::toolchains::Minix::buildLinker
Tool * buildLinker() const override
Definition: Minix.cpp:108
clang::driver::toolchains::Generic_ELF
Definition: Gnu.h:340
llvm::opt
Definition: Action.h:24
clang::driver::tools::minix::Linker
Definition: Minix.h:35
clang::driver::Compilation::addCommand
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:206
clang::driver::tools::minix::Linker::ConstructJob
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Minix.cpp:43
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:186
clang::driver::Driver::CCCIsCXX
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:173
llvm::SmallVector
Definition: LLVM.h:36
Options.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
Minix.h
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
InputInfo.h
clang::driver::tools::minix::Assembler::ConstructJob
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Minix.cpp:23
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
clang::driver::toolchains::Minix::Minix
Minix(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Minix - Minix tool chain which can call as(1) and ld(1) directly.
Definition: Minix.cpp:97
clang::driver
Definition: Action.h:32
clang::driver::InputInfo::isNothing
bool isNothing() const
Definition: InputInfo.h:75
clang::driver::InputInfo::isFilename
bool isFilename() const
Definition: InputInfo.h:76