]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/xray-extract.h
Update ELF Tool Chain to upstream r3520
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / xray-extract.h
1 //===- xray-extract.h - XRay Instrumentation Map Extraction ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Defines the interface for extracting the instrumentation map from an
11 // XRay-instrumented binary.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TOOLS_XRAY_EXTRACT_H
16 #define LLVM_TOOLS_XRAY_EXTRACT_H
17
18 #include <deque>
19 #include <map>
20 #include <string>
21 #include <unordered_map>
22
23 #include "xray-sleds.h"
24 #include "llvm/Support/Error.h"
25 #include "llvm/Support/raw_ostream.h"
26
27 namespace llvm {
28 namespace xray {
29
30 class InstrumentationMapExtractor {
31 public:
32   typedef std::unordered_map<int32_t, uint64_t> FunctionAddressMap;
33   typedef std::unordered_map<uint64_t, int32_t> FunctionAddressReverseMap;
34
35   enum class InputFormats { ELF, YAML };
36
37 private:
38   std::deque<SledEntry> Sleds;
39   FunctionAddressMap FunctionAddresses;
40   FunctionAddressReverseMap FunctionIds;
41
42 public:
43   /// Loads the instrumentation map from |Filename|. Updates |EC| in case there
44   /// were errors encountered opening the file. |Format| defines what the input
45   /// instrumentation map is in.
46   InstrumentationMapExtractor(std::string Filename, InputFormats Format,
47                               Error &EC);
48
49   const FunctionAddressMap &getFunctionAddresses() { return FunctionAddresses; }
50
51   /// Exports the loaded function address map as YAML through |OS|.
52   void exportAsYAML(raw_ostream &OS);
53 };
54
55 } // namespace xray
56 } // namespace llvm
57
58 #endif // LLVM_TOOLS_XRAY_EXTRACT_H