clang 10.0.0git

InterfaceStubs.cpp
Go to the documentation of this file.
1 //===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations C++ ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "InterfaceStubs.h"
10 #include "CommonArgs.h"
11 #include "clang/Driver/Compilation.h"
12 #include "llvm/Support/Path.h"
13
14 namespace clang {
15 namespace driver {
16 namespace tools {
17 namespace ifstool {
18 void Merger::ConstructJob(Compilation &C, const JobAction &JA,
19 const InputInfo &Output, const InputInfoList &Inputs,
20 const llvm::opt::ArgList &Args,
21 const char *LinkingOutput) const {
22 std::string Merger = getToolChain().GetProgramPath(getShortName());
23 llvm::opt::ArgStringList CmdArgs;
24 CmdArgs.push_back("-action");
25 const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);
26 CmdArgs.push_back(WriteBin ? "write-bin" : "write-ifs");
27 CmdArgs.push_back("-o");
28
29 // Normally we want to write to a side-car file ending in ".ifso" so for
30 // example if `clang -emit-interface-stubs -shared -o libhello.so` were
31 // invoked then we would like to get libhello.so and libhello.ifso. If the
32 // stdout stream is given as the output file (ie `-o -`), that is the one
33 // exception where we will just append to the same filestream as the normal
34 // output.
35 SmallString<128> OutputFilename(Output.getFilename());
36 if (OutputFilename != "-") {
37 if (Args.hasArg(options::OPT_shared))
38 llvm::sys::path::replace_extension(OutputFilename,
39 (WriteBin ? "ifso" : "ifs"));
40 else
41 OutputFilename += (WriteBin ? ".ifso" : ".ifs");
42 }
43
44 CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));
45
46 // Here we append the input files. If the input files are object files, then
47 // we look for .ifs files present in the same location as the object files.
48 for (const auto &Input : Inputs) {
49 if (!Input.isFilename())
50 continue;
51 SmallString<128> InputFilename(Input.getFilename());
52 if (Input.getType() == types::TY_Object)
53 llvm::sys::path::replace_extension(InputFilename, ".ifs");
54 CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));
55 }
56
57 C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Merger),
58 CmdArgs, Inputs));
59 }
60 } // namespace ifstool
61 } // namespace tools
62 } // namespace driver
63 } // namespace clang
clang::driver::tools::ifstool::Merger
Definition: InterfaceStubs.h:19
clang::driver::tools::ifstool::Merger::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: InterfaceStubs.cpp:18
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
CommonArgs.h
clang::driver::JobAction
Definition: Action.h:375
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
llvm::SmallString< 128 >
Compilation.h
clang::driver::Compilation::addCommand
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
llvm::SmallVector
Definition: LLVM.h:35
clang::driver::Tool::getShortName
const char * getShortName() const
Definition: Tool.h:81
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
InterfaceStubs.h
clang::driver::Tool::getToolChain
const ToolChain & getToolChain() const
Definition: Tool.h:83
clang::driver::ToolChain::GetProgramPath
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:516