WebAssemblyTargetStreamer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //==-- WebAssemblyTargetStreamer.h - WebAssembly Target Streamer -*- 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. /// \file
  10. /// This file declares WebAssembly-specific target streamer classes.
  11. /// These are for implementing support for target-specific assembly directives.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
  15. #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYTARGETSTREAMER_H
  16. #include "llvm/BinaryFormat/Wasm.h"
  17. #include "llvm/MC/MCStreamer.h"
  18. #include "llvm/Support/MachineValueType.h"
  19. namespace llvm {
  20. class MCSymbolWasm;
  21. class formatted_raw_ostream;
  22. /// WebAssembly-specific streamer interface, to implement support
  23. /// WebAssembly-specific assembly directives.
  24. class WebAssemblyTargetStreamer : public MCTargetStreamer {
  25. public:
  26. explicit WebAssemblyTargetStreamer(MCStreamer &S);
  27. /// .local
  28. virtual void emitLocal(ArrayRef<wasm::ValType> Types) = 0;
  29. /// .functype
  30. virtual void emitFunctionType(const MCSymbolWasm *Sym) = 0;
  31. /// .indidx
  32. virtual void emitIndIdx(const MCExpr *Value) = 0;
  33. /// .globaltype
  34. virtual void emitGlobalType(const MCSymbolWasm *Sym) = 0;
  35. /// .tabletype
  36. virtual void emitTableType(const MCSymbolWasm *Sym) = 0;
  37. /// .tagtype
  38. virtual void emitTagType(const MCSymbolWasm *Sym) = 0;
  39. /// .import_module
  40. virtual void emitImportModule(const MCSymbolWasm *Sym,
  41. StringRef ImportModule) = 0;
  42. /// .import_name
  43. virtual void emitImportName(const MCSymbolWasm *Sym,
  44. StringRef ImportName) = 0;
  45. /// .export_name
  46. virtual void emitExportName(const MCSymbolWasm *Sym,
  47. StringRef ExportName) = 0;
  48. protected:
  49. void emitValueType(wasm::ValType Type);
  50. };
  51. /// This part is for ascii assembly output
  52. class WebAssemblyTargetAsmStreamer final : public WebAssemblyTargetStreamer {
  53. formatted_raw_ostream &OS;
  54. public:
  55. WebAssemblyTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
  56. void emitLocal(ArrayRef<wasm::ValType> Types) override;
  57. void emitFunctionType(const MCSymbolWasm *Sym) override;
  58. void emitIndIdx(const MCExpr *Value) override;
  59. void emitGlobalType(const MCSymbolWasm *Sym) override;
  60. void emitTableType(const MCSymbolWasm *Sym) override;
  61. void emitTagType(const MCSymbolWasm *Sym) override;
  62. void emitImportModule(const MCSymbolWasm *Sym, StringRef ImportModule) override;
  63. void emitImportName(const MCSymbolWasm *Sym, StringRef ImportName) override;
  64. void emitExportName(const MCSymbolWasm *Sym, StringRef ExportName) override;
  65. };
  66. /// This part is for Wasm object output
  67. class WebAssemblyTargetWasmStreamer final : public WebAssemblyTargetStreamer {
  68. public:
  69. explicit WebAssemblyTargetWasmStreamer(MCStreamer &S);
  70. void emitLocal(ArrayRef<wasm::ValType> Types) override;
  71. void emitFunctionType(const MCSymbolWasm *Sym) override {}
  72. void emitIndIdx(const MCExpr *Value) override;
  73. void emitGlobalType(const MCSymbolWasm *Sym) override {}
  74. void emitTableType(const MCSymbolWasm *Sym) override {}
  75. void emitTagType(const MCSymbolWasm *Sym) override {}
  76. void emitImportModule(const MCSymbolWasm *Sym,
  77. StringRef ImportModule) override {}
  78. void emitImportName(const MCSymbolWasm *Sym,
  79. StringRef ImportName) override {}
  80. void emitExportName(const MCSymbolWasm *Sym,
  81. StringRef ExportName) override {}
  82. };
  83. /// This part is for null output
  84. class WebAssemblyTargetNullStreamer final : public WebAssemblyTargetStreamer {
  85. public:
  86. explicit WebAssemblyTargetNullStreamer(MCStreamer &S)
  87. : WebAssemblyTargetStreamer(S) {}
  88. void emitLocal(ArrayRef<wasm::ValType>) override {}
  89. void emitFunctionType(const MCSymbolWasm *) override {}
  90. void emitIndIdx(const MCExpr *) override {}
  91. void emitGlobalType(const MCSymbolWasm *) override {}
  92. void emitTableType(const MCSymbolWasm *) override {}
  93. void emitTagType(const MCSymbolWasm *) override {}
  94. void emitImportModule(const MCSymbolWasm *, StringRef) override {}
  95. void emitImportName(const MCSymbolWasm *, StringRef) override {}
  96. void emitExportName(const MCSymbolWasm *, StringRef) override {}
  97. };
  98. } // end namespace llvm
  99. #endif