Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
Line
Count
Source (jump to first uncovered line)
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
0
                          const char *LinkingOutput) const {
22
0
  std::string Merger = getToolChain().GetProgramPath(getShortName());
23
  // TODO: Use IFS library directly in the future.
24
0
  llvm::opt::ArgStringList CmdArgs;
25
0
  CmdArgs.push_back("--input-format=IFS");
26
0
  const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);
27
0
  CmdArgs.push_back(WriteBin ? "--output-format=ELF" : "--output-format=IFS");
28
0
  CmdArgs.push_back("-o");
29
30
  // Normally we want to write to a side-car file ending in ".ifso" so for
31
  // example if `clang -emit-interface-stubs -shared -o libhello.so` were
32
  // invoked then we would like to get libhello.so and libhello.ifso. If the
33
  // stdout stream is given as the output file (ie `-o -`), that is the one
34
  // exception where we will just append to the same filestream as the normal
35
  // output.
36
0
  SmallString<128> OutputFilename(Output.getFilename());
37
0
  if (OutputFilename != "-") {
38
0
    if (Args.hasArg(options::OPT_shared))
39
0
      llvm::sys::path::replace_extension(OutputFilename,
40
0
                                         (WriteBin ? "ifso" : "ifs"));
41
0
    else
42
0
      OutputFilename += (WriteBin ? ".ifso" : ".ifs");
43
0
  }
44
45
0
  CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));
46
47
  // Here we append the input files. If the input files are object files, then
48
  // we look for .ifs files present in the same location as the object files.
49
0
  for (const auto &Input : Inputs) {
50
0
    if (!Input.isFilename())
51
0
      continue;
52
0
    SmallString<128> InputFilename(Input.getFilename());
53
0
    if (Input.getType() == types::TY_Object)
54
0
      llvm::sys::path::replace_extension(InputFilename, ".ifs");
55
0
    CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));
56
0
  }
57
58
0
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
59
0
                                         Args.MakeArgString(Merger), CmdArgs,
60
0
                                         Inputs, Output));
61
0
}
62
} // namespace ifstool
63
} // namespace tools
64
} // namespace driver
65
} // namespace clang