1 //===- InputTable.h --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_WASM_INPUT_TABLE_H
10 #define LLD_WASM_INPUT_TABLE_H
11 
12 #include "Config.h"
13 #include "InputFiles.h"
14 #include "WriterUtils.h"
15 #include "lld/Common/ErrorHandler.h"
16 #include "llvm/Object/Wasm.h"
17 
18 namespace lld {
19 namespace wasm {
20 
21 // Represents a single Wasm Table within an input file. These are combined to
22 // form the final TABLES section.
23 class InputTable {
24 public:
InputTable(const WasmTable & t,ObjFile * f)25   InputTable(const WasmTable &t, ObjFile *f)
26       : file(f), table(t), live(!config->gcSections) {}
27 
getName()28   StringRef getName() const { return table.SymbolName; }
getType()29   const WasmTableType &getType() const { return table.Type; }
30 
31   // Somewhat confusingly, we generally use the term "table index" to refer to
32   // the offset of a function in the well-known indirect function table.  We
33   // refer to different tables instead by "table numbers".
getTableNumber()34   uint32_t getTableNumber() const { return tableNumber.getValue(); }
hasTableNumber()35   bool hasTableNumber() const { return tableNumber.hasValue(); }
setTableNumber(uint32_t n)36   void setTableNumber(uint32_t n) {
37     assert(!hasTableNumber());
38     tableNumber = n;
39   }
40 
setLimits(const WasmLimits & limits)41   void setLimits(const WasmLimits &limits) { table.Type.Limits = limits; }
42 
43   ObjFile *file;
44   WasmTable table;
45 
46   bool live = false;
47 
48 protected:
49   llvm::Optional<uint32_t> tableNumber;
50 };
51 
52 } // namespace wasm
53 
toString(const wasm::InputTable * t)54 inline std::string toString(const wasm::InputTable *t) {
55   return (toString(t->file) + ":(" + t->getName() + ")").str();
56 }
57 
58 } // namespace lld
59 
60 #endif // LLD_WASM_INPUT_TABLE_H
61