]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - wasm/InputSegment.h
Vendor import of lld trunk r321530:
[FreeBSD/FreeBSD.git] / wasm / InputSegment.h
1 //===- InputSegment.h -------------------------------------------*- C++ -*-===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Represents a WebAssembly data segment which can be included as part of
11 // an output data segments.  Note that in WebAssembly, unlike ELF and other
12 // formats, used the term "data segment" to refer to the continous regions of
13 // memory that make on the data section. See:
14 // https://webassembly.github.io/spec/syntax/modules.html#syntax-data
15 //
16 // For example, by default, clang will produce a separate data section for
17 // each global variable.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLD_WASM_INPUT_SEGMENT_H
22 #define LLD_WASM_INPUT_SEGMENT_H
23
24 #include "WriterUtils.h"
25 #include "lld/Common/ErrorHandler.h"
26 #include "llvm/Object/Wasm.h"
27
28 using llvm::object::WasmSegment;
29 using llvm::wasm::WasmRelocation;
30
31 namespace lld {
32 namespace wasm {
33
34 class ObjFile;
35 class OutputSegment;
36
37 class InputSegment {
38 public:
39   InputSegment(const WasmSegment *Seg, const ObjFile *F)
40       : Segment(Seg), File(F) {}
41
42   // Translate an offset in the input segment to an offset in the output
43   // segment.
44   uint32_t translateVA(uint32_t Address) const;
45
46   const OutputSegment *getOutputSegment() const { return OutputSeg; }
47
48   uint32_t getOutputSegmentOffset() const { return OutputSegmentOffset; }
49
50   uint32_t getInputSectionOffset() const { return Segment->SectionOffset; }
51
52   void setOutputSegment(const OutputSegment *Segment, uint32_t Offset) {
53     OutputSeg = Segment;
54     OutputSegmentOffset = Offset;
55   }
56
57   uint32_t getSize() const { return Segment->Data.Content.size(); }
58   uint32_t getAlignment() const { return Segment->Data.Alignment; }
59   uint32_t startVA() const { return Segment->Data.Offset.Value.Int32; }
60   uint32_t endVA() const { return startVA() + getSize(); }
61   StringRef getName() const { return Segment->Data.Name; }
62
63   const WasmSegment *Segment;
64   const ObjFile *File;
65   std::vector<WasmRelocation> Relocations;
66   std::vector<OutputRelocation> OutRelocations;
67
68 protected:
69   const OutputSegment *OutputSeg = nullptr;
70   uint32_t OutputSegmentOffset = 0;
71 };
72
73 } // namespace wasm
74 } // namespace lld
75
76 #endif // LLD_WASM_INPUT_SEGMENT_H