xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/JITLink/XCOFFLinkGraphBuilder.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===----- XCOFFLinkGraphBuilder.h - XCOFF LinkGraph builder ----*- C++ -*-===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric //
9*700637cbSDimitry Andric // Generic XCOFF LinkGraph building code.
10*700637cbSDimitry Andric //
11*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
12*700637cbSDimitry Andric 
13*700637cbSDimitry Andric #ifndef LIB_EXECUTIONENGINE_JITLINK_XCOFFLINKGRAPHBUILDER_H
14*700637cbSDimitry Andric #define LIB_EXECUTIONENGINE_JITLINK_XCOFFLINKGRAPHBUILDER_H
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric #include "llvm/ExecutionEngine/JITLink/JITLink.h"
17*700637cbSDimitry Andric #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
18*700637cbSDimitry Andric #include "llvm/Object/ObjectFile.h"
19*700637cbSDimitry Andric #include "llvm/Object/XCOFFObjectFile.h"
20*700637cbSDimitry Andric #include "llvm/TargetParser/SubtargetFeature.h"
21*700637cbSDimitry Andric #include <memory>
22*700637cbSDimitry Andric 
23*700637cbSDimitry Andric namespace llvm {
24*700637cbSDimitry Andric namespace jitlink {
25*700637cbSDimitry Andric 
26*700637cbSDimitry Andric class XCOFFLinkGraphBuilder {
27*700637cbSDimitry Andric public:
28*700637cbSDimitry Andric   virtual ~XCOFFLinkGraphBuilder() = default;
29*700637cbSDimitry Andric   Expected<std::unique_ptr<LinkGraph>> buildGraph();
30*700637cbSDimitry Andric 
31*700637cbSDimitry Andric public:
32*700637cbSDimitry Andric   XCOFFLinkGraphBuilder(const object::XCOFFObjectFile &Obj,
33*700637cbSDimitry Andric                         std::shared_ptr<orc::SymbolStringPool> SSP, Triple TT,
34*700637cbSDimitry Andric                         SubtargetFeatures Features,
35*700637cbSDimitry Andric                         LinkGraph::GetEdgeKindNameFunction GetEdgeKindName);
getGraph()36*700637cbSDimitry Andric   LinkGraph &getGraph() const { return *G; }
getObject()37*700637cbSDimitry Andric   const object::XCOFFObjectFile &getObject() const { return Obj; }
38*700637cbSDimitry Andric 
39*700637cbSDimitry Andric private:
40*700637cbSDimitry Andric   Error processSections();
41*700637cbSDimitry Andric   Error processCsectsAndSymbols();
42*700637cbSDimitry Andric   Error processRelocations();
43*700637cbSDimitry Andric 
44*700637cbSDimitry Andric private:
45*700637cbSDimitry Andric   const object::XCOFFObjectFile &Obj;
46*700637cbSDimitry Andric   std::unique_ptr<LinkGraph> G;
47*700637cbSDimitry Andric 
48*700637cbSDimitry Andric   Section *UndefSection;
49*700637cbSDimitry Andric 
50*700637cbSDimitry Andric   struct SectionEntry {
51*700637cbSDimitry Andric     jitlink::Section *Section;
52*700637cbSDimitry Andric     object::SectionRef SectionData;
53*700637cbSDimitry Andric   };
54*700637cbSDimitry Andric 
55*700637cbSDimitry Andric   DenseMap<uint16_t, SectionEntry> SectionTable;
56*700637cbSDimitry Andric   DenseMap<uint32_t, Block *> CsectTable;
57*700637cbSDimitry Andric   DenseMap<uint32_t, Symbol *> SymbolIndexTable;
58*700637cbSDimitry Andric };
59*700637cbSDimitry Andric 
60*700637cbSDimitry Andric } // namespace jitlink
61*700637cbSDimitry Andric } // namespace llvm
62*700637cbSDimitry Andric 
63*700637cbSDimitry Andric #endif // LIB_EXECUTIONENGINE_JITLINK_XCOFFLINKGRAPHBUILDER_H
64