• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __ANDROID_BCINFO_METADATAEXTRACTOR_H__
18 #define __ANDROID_BCINFO_METADATAEXTRACTOR_H__
19 
20 #include <cstddef>
21 #include <stdint.h>
22 
23 namespace llvm {
24   class NamedMDNode;
25 }
26 
27 namespace bcinfo {
28 
29 class MetadataExtractor {
30  private:
31   const char *mBitcode;
32   size_t mBitcodeSize;
33 
34   size_t mExportVarCount;
35   size_t mExportFuncCount;
36   size_t mExportForEachSignatureCount;
37   const uint32_t *mExportForEachSignatureList;
38 
39   size_t mPragmaCount;
40   const char **mPragmaKeyList;
41   const char **mPragmaValueList;
42 
43   size_t mObjectSlotCount;
44   const uint32_t *mObjectSlotList;
45 
46   // Helper functions for extraction
47   bool populateForEachMetadata(const llvm::NamedMDNode *ExportForEachMetadata);
48   bool populateObjectSlotMetadata(const llvm::NamedMDNode *ObjectSlotMetadata);
49   void populatePragmaMetadata(const llvm::NamedMDNode *PragmaMetadata);
50 
51  public:
52   /**
53    * Reads metadata from \p bitcode.
54    *
55    * \param bitcode - input bitcode string.
56    * \param bitcodeSize - length of \p bitcode string (in bytes).
57    */
58   MetadataExtractor(const char *bitcode, size_t bitcodeSize);
59 
60   ~MetadataExtractor();
61 
62   /**
63    * Extract the actual metadata from the supplied bitcode.
64    *
65    * \return true on success and false if an error occurred.
66    */
67   bool extract();
68 
69   /**
70    * \return number of exported global variables (slots) in this script/module.
71    */
getExportVarCount()72   size_t getExportVarCount() const {
73     return mExportVarCount;
74   }
75 
76   /**
77    * \return number of exported global functions (slots) in this script/module.
78    */
getExportFuncCount()79   size_t getExportFuncCount() const {
80     return mExportFuncCount;
81   }
82 
83   /**
84    * \return number of exported ForEach functions in this script/module.
85    */
getExportForEachSignatureCount()86   size_t getExportForEachSignatureCount() const {
87     return mExportForEachSignatureCount;
88   }
89 
90   /**
91    * \return array of ForEach function signatures.
92    */
getExportForEachSignatureList()93   const uint32_t *getExportForEachSignatureList() const {
94     return mExportForEachSignatureList;
95   }
96 
97   /**
98    * \return number of pragmas contained in pragmaKeyList and pragmaValueList.
99    */
getPragmaCount()100   size_t getPragmaCount() const {
101     return mPragmaCount;
102   }
103 
104   /**
105    * \return pragma keys (the name for the pragma).
106    */
getPragmaKeyList()107   const char **getPragmaKeyList() const {
108     return mPragmaKeyList;
109   }
110 
111   /**
112    * \return pragma values (contents corresponding to a particular pragma key).
113    */
getPragmaValueList()114   const char **getPragmaValueList() const {
115     return mPragmaValueList;
116   }
117 
118   /**
119    * \return number of object slots contained in objectSlotList.
120    */
getObjectSlotCount()121   size_t getObjectSlotCount() const {
122     return mObjectSlotCount;
123   }
124 
125   /**
126    * \return array of object slot numbers that must be cleaned up by driver
127    *         on script teardown.
128    */
getObjectSlotList()129   const uint32_t *getObjectSlotList() const {
130     return mObjectSlotList;
131   }
132 };
133 
134 }  // namespace bcinfo
135 
136 #endif  // __ANDROID_BCINFO_METADATAEXTRACTOR_H__
137