OpenASIP  2.0
LinkBitcode.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2020 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file LinkBitcode.cc
26  *
27  * Links other bitcode module to module.
28  *
29  * @author Mikael Lepistö 2008 (mikael.lepisto@tut.fi)
30  */
31 
32 #define DEBUG_TYPE "linkbitcode"
33 
34 #include "CompilerWarnings.hh"
35 IGNORE_COMPILER_WARNING("-Wunused-parameter")
36 
37 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/Debug.h"
39 #include "llvm/Support/raw_ostream.h"
40 #include "tce_config.h"
41 #include "llvm/IR/Module.h"
42 #include "llvm/Pass.h"
43 #include "llvm/Linker/Linker.h"
44 
45 
47 
48 using namespace llvm;
49 
50 #include <iostream>
51 #include <memory>
52 #include <map>
53 
54 namespace {
55  class LinkBitcode : public FunctionPass {
56  public:
57  static char ID; // Pass ID, replacement for typeid
58  LinkBitcode(Module& input);
59  virtual ~LinkBitcode();
60 
61  // from llvm::Pass:
62  bool doInitialization(Module &M);
63  bool doFinalization (Module &M);
64 
65  // to suppress Clang warnings
66  using llvm::FunctionPass::doInitialization;
67  using llvm::FunctionPass::doFinalization;
68  bool runOnFunction(Function &F);
69 
70  private:
71  Module& inputModule_;
72  };
73 
74  char LinkBitcode::ID = 0;
75 // cannot be used as plugin pass right now..
76 // RegisterPass<LinkBitcode>
77 // X("linkbitcode", "Links in other bitcode module to currently handled module.");
78 }
79 
80 
81 /**
82  * Constructor
83  */
84 LinkBitcode::LinkBitcode(Module& input) :
85  FunctionPass(ID),
86  inputModule_(input) {
87 }
88 
89 /**
90  * Destructor
91  */
92 LinkBitcode::~LinkBitcode() {}
93 
94 
95 // Publically exposed interface to pass.
96 // const PassInfo* LinkBitcodeID = X.getPassInfo();
97 
98 Pass* createLinkBitcodePass(Module& input) {
99  return new LinkBitcode(input);
100 }
101 
102 bool
103 LinkBitcode::doFinalization(Module& /*M*/) {
104  return true;
105 }
106 
107 bool
108 LinkBitcode::doInitialization(Module& M) {
109  if (Linker::linkModules(M, std::unique_ptr<Module>(&inputModule_))) {
110  errs() << "Error during linking in LinkBitcodePass: " << "\n";
111  }
112  return true;
113 }
114 
115 bool
116 LinkBitcode::runOnFunction(Function&) {
117  return true;
118 }
llvm
Definition: InlineAsmParser.hh:49
BlocksTranslator::FU_TYPE::ID
@ ID
createLinkBitcodePass
Pass * createLinkBitcodePass(Module &input)
Definition: LinkBitcode.cc:98
IGNORE_COMPILER_WARNING
#define IGNORE_COMPILER_WARNING(X)
Definition: CompilerWarnings.hh:51
POP_COMPILER_DIAGS
#define POP_COMPILER_DIAGS
Definition: CompilerWarnings.hh:68
CompilerWarnings.hh