1 //===- InputEvent.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 // Wasm events are features that suspend the current execution and transfer the 10 // control flow to a corresponding handler. Currently the only supported event 11 // kind is exceptions. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLD_WASM_INPUT_EVENT_H 16 #define LLD_WASM_INPUT_EVENT_H 17 18 #include "Config.h" 19 #include "InputFiles.h" 20 #include "WriterUtils.h" 21 #include "lld/Common/ErrorHandler.h" 22 #include "llvm/Object/Wasm.h" 23 24 namespace lld { 25 namespace wasm { 26 27 // Represents a single Wasm Event within an input file. These are combined to 28 // form the final EVENTS section. 29 class InputEvent { 30 public: InputEvent(const WasmSignature & s,const WasmEvent & e,ObjFile * f)31 InputEvent(const WasmSignature &s, const WasmEvent &e, ObjFile *f) 32 : file(f), event(e), signature(s), live(!config->gcSections) {} 33 getName()34 StringRef getName() const { return event.SymbolName; } getType()35 const WasmEventType &getType() const { return event.Type; } 36 getEventIndex()37 uint32_t getEventIndex() const { return eventIndex.getValue(); } hasEventIndex()38 bool hasEventIndex() const { return eventIndex.hasValue(); } setEventIndex(uint32_t index)39 void setEventIndex(uint32_t index) { 40 assert(!hasEventIndex()); 41 eventIndex = index; 42 } 43 44 ObjFile *file; 45 WasmEvent event; 46 const WasmSignature &signature; 47 48 bool live = false; 49 50 protected: 51 llvm::Optional<uint32_t> eventIndex; 52 }; 53 54 } // namespace wasm 55 toString(const wasm::InputEvent * e)56inline std::string toString(const wasm::InputEvent *e) { 57 return (toString(e->file) + ":(" + e->getName() + ")").str(); 58 } 59 60 } // namespace lld 61 62 #endif // LLD_WASM_INPUT_EVENT_H 63