clang  10.0.0git
Flang.cpp
Go to the documentation of this file.
1 //===-- Flang.cpp - Flang+LLVM ToolChain 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 
10 #include "Flang.h"
11 #include "CommonArgs.h"
12 
13 #include "clang/Driver/Options.h"
14 
15 #include <cassert>
16 
17 using namespace clang::driver;
18 using namespace clang::driver::tools;
19 using namespace clang;
20 using namespace llvm::opt;
21 
23  const InputInfo &Output, const InputInfoList &Inputs,
24  const ArgList &Args, const char *LinkingOutput) const {
25  const auto &TC = getToolChain();
26  const llvm::Triple &Triple = TC.getEffectiveTriple();
27  const std::string &TripleStr = Triple.getTriple();
28 
29  ArgStringList CmdArgs;
30 
31  CmdArgs.push_back("-fc1");
32 
33  CmdArgs.push_back("-triple");
34  CmdArgs.push_back(Args.MakeArgString(TripleStr));
35 
36  if (isa<PreprocessJobAction>(JA)) {
37  CmdArgs.push_back("-E");
38  } else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
39  if (JA.getType() == types::TY_Nothing) {
40  CmdArgs.push_back("-fsyntax-only");
41  } else if (JA.getType() == types::TY_AST) {
42  CmdArgs.push_back("-emit-ast");
43  } else if (JA.getType() == types::TY_LLVM_IR ||
44  JA.getType() == types::TY_LTO_IR) {
45  CmdArgs.push_back("-emit-llvm");
46  } else if (JA.getType() == types::TY_LLVM_BC ||
47  JA.getType() == types::TY_LTO_BC) {
48  CmdArgs.push_back("-emit-llvm-bc");
49  } else if (JA.getType() == types::TY_PP_Asm) {
50  CmdArgs.push_back("-S");
51  } else {
52  assert(false && "Unexpected output type!");
53  }
54  } else if (isa<AssembleJobAction>(JA)) {
55  CmdArgs.push_back("-emit-obj");
56  } else {
57  assert(false && "Unexpected action class for Flang tool.");
58  }
59 
60  if (Output.isFilename()) {
61  CmdArgs.push_back("-o");
62  CmdArgs.push_back(Output.getFilename());
63  } else {
64  assert(Output.isNothing() && "Invalid output.");
65  }
66 
67  const InputInfo &Input = Inputs[0];
68  assert(Input.isFilename() && "Invalid input.");
69  CmdArgs.push_back(Input.getFilename());
70 
71  const auto& D = C.getDriver();
72  const char* Exec = Args.MakeArgString(D.GetProgramPath("flang", TC));
73  C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
74 }
75 
77  : Tool("flang", "flang frontend", TC, RF_Full) {}
78 
const char * getFilename() const
Definition: InputInfo.h:83
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
types::ID getType() const
Definition: Action.h:142
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
Flang(const ToolChain &TC)
Definition: Flang.cpp:76
Dataflow Directional Tag Classes.
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
const Driver & getDriver() const
Definition: Compilation.h:133
bool isNothing() const
Definition: InputInfo.h:74
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: Flang.cpp:22
bool isFilename() const
Definition: InputInfo.h:75
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88