1d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao/*
2d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * Copyright 2010-2012, The Android Open Source Project
3d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao *
4d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * Licensed under the Apache License, Version 2.0 (the "License");
5d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * you may not use this file except in compliance with the License.
6d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * You may obtain a copy of the License at
7d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao *
8d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao *     http://www.apache.org/licenses/LICENSE-2.0
9d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao *
10d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * Unless required by applicable law or agreed to in writing, software
11d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * distributed under the License is distributed on an "AS IS" BASIS,
12d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * See the License for the specific language governing permissions and
14d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao * limitations under the License.
15d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao */
16d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
17c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#ifndef BCC_SOURCE_H
18c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#define BCC_SOURCE_H
19d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
20d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao#include <string>
21d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
22d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaonamespace llvm {
23d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  class Module;
24d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao}
25d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
26d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaonamespace bcc {
27d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
28d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaoclass BCCContext;
29d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
30d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaoclass Source {
31d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaoprivate:
32a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni  const std::string mName; // A unique name
33d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  BCCContext &mContext;
34d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  llvm::Module *mModule;
35d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
36d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  // If true, destructor won't destroy the mModule.
37d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  bool mNoDelete;
38d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
39d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaoprivate:
40a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni  Source(const char* name, BCCContext &pContext, llvm::Module &pModule,
41a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni         bool pNoDelete = false);
42d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
43d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liaopublic:
44d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  static Source *CreateFromBuffer(BCCContext &pContext,
45d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                  const char *pName,
46d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                  const char *pBitcode,
47d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                  size_t pBitcodeSize);
48d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
49d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  static Source *CreateFromFile(BCCContext &pContext,
50d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                const std::string &pPath);
51d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
52d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  // Create a Source object from an existing module. If pNoDelete
53d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  // is true, destructor won't call delete on the given module.
54d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  static Source *CreateFromModule(BCCContext &pContext,
55a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni                                  const char* name,
56d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                  llvm::Module &pModule,
57d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao                                  bool pNoDelete = false);
58d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
59d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  static Source *CreateEmpty(BCCContext &pContext, const std::string &pName);
60d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
61a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni  const std::string& getName() const { return mName; }
62a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni
63a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni  // Merge the current source with pSource. pSource
64a4ded1373d7ad3e503f186e65bccf94126a0f020Yang Ni  // will be destroyed after successfully merged. Return false on error.
65579361346abc6696c805e3904a18178ebce4e4a3Stephen Hines  bool merge(Source &pSource);
66d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
67d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  inline BCCContext &getContext()
68d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  { return mContext; }
69d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  inline const BCCContext &getContext() const
70d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  { return mContext; }
71d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
7206731a6150ae8014d37258d5f32ef8bc14a3db63Stephen Hines  void setModule(llvm::Module *pModule);
7306731a6150ae8014d37258d5f32ef8bc14a3db63Stephen Hines
74d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  inline llvm::Module &getModule()
75d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  { return *mModule;  }
76d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  inline const llvm::Module &getModule() const
77d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  { return *mModule;  }
78d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
79d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  // Get the "identifier" of the bitcode. This will return the value of pName
80d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  // when it's created using CreateFromBuffer and pPath if CreateFromFile().
81d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  const std::string &getIdentifier() const;
82d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
8351ee77bd31e7d8ca6c89e37b5806c8fc2afcf0dcPirama Arumuga Nainar  void addBuildChecksumMetadata(const char *) const;
8451ee77bd31e7d8ca6c89e37b5806c8fc2afcf0dcPirama Arumuga Nainar
85d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao  ~Source();
86d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao};
87d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
88d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao} // namespace bcc
89d2a5a0eab7a1273797029702652e50b2ed9e6a6dShih-wei Liao
90c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#endif // BCC_SOURCE_H
91