| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This class prints an WebAssembly MCInst to wasm file syntax. |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H |
| 15 | #define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H |
| 16 | |
| Eric Liu | 0179230 | 2016-04-18 12:21:59 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
| Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 18 | #include "llvm/BinaryFormat/Wasm.h" |
| Dan Gohman | 8394756 | 2016-01-20 05:54:22 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInstPrinter.h" |
| David Blaikie | 13e77db | 2018-03-23 23:58:25 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MachineValueType.h" |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 24 | class MCSubtargetInfo; |
| 25 | |
| Dan Gohman | fd4a88c | 2015-11-25 16:29:24 +0000 | [diff] [blame] | 26 | class WebAssemblyInstPrinter final : public MCInstPrinter { |
| Heejin Ahn | 3103d3d | 2018-10-25 23:45:48 +0000 | [diff] [blame] | 27 | uint64_t ControlFlowCounter = 0; |
| 28 | uint64_t EHPadStackCounter = 0; |
| 29 | SmallVector<std::pair<uint64_t, bool>, 4> ControlFlowStack; |
| 30 | SmallVector<uint64_t, 4> EHPadStack; |
| 31 | |
| 32 | enum EHInstKind { TRY, CATCH, END_TRY }; |
| 33 | EHInstKind LastSeenEHInst = END_TRY; |
| Dan Gohman | 1d68e80f | 2016-01-12 19:14:46 +0000 | [diff] [blame] | 34 | |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 35 | public: |
| 36 | WebAssemblyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, |
| 37 | const MCRegisterInfo &MRI); |
| 38 | |
| 39 | void printRegName(raw_ostream &OS, unsigned RegNo) const override; |
| 40 | void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, |
| 41 | const MCSubtargetInfo &STI) override; |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 42 | |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 43 | // Used by tblegen code. |
| 44 | void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); |
| Wouter van Oortmerssen | d3c544a | 2018-12-17 22:04:44 +0000 | [diff] [blame] | 45 | void printBrList(const MCInst *MI, unsigned OpNo, raw_ostream &O); |
| Dan Gohman | bb37224 | 2016-01-26 03:39:31 +0000 | [diff] [blame] | 46 | void printWebAssemblyP2AlignOperand(const MCInst *MI, unsigned OpNo, |
| 47 | raw_ostream &O); |
| Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame] | 48 | void printWebAssemblySignatureOperand(const MCInst *MI, unsigned OpNo, |
| 49 | raw_ostream &O); |
| JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 50 | |
| JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 51 | // Autogenerated by tblgen. |
| 52 | void printInstruction(const MCInst *MI, raw_ostream &O); |
| 53 | static const char *getRegisterName(unsigned RegNo); |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| Dan Gohman | 5e0886b | 2015-12-06 19:42:29 +0000 | [diff] [blame] | 56 | namespace WebAssembly { |
| 57 | |
| Wouter van Oortmerssen | 9843295 | 2019-01-03 22:59:59 +0000 | [diff] [blame] | 58 | const char *typeToString(wasm::ValType Ty); |
| 59 | const char *anyTypeToString(unsigned Ty); |
| Dan Gohman | 5e0886b | 2015-12-06 19:42:29 +0000 | [diff] [blame] | 60 | |
| Wouter van Oortmerssen | 87af0b1 | 2019-08-01 18:08:26 +0000 | [diff] [blame] | 61 | std::string typeListToString(ArrayRef<wasm::ValType> List); |
| 62 | std::string signatureToString(const wasm::WasmSignature *Sig); |
| 63 | |
| Dan Gohman | 5e0886b | 2015-12-06 19:42:29 +0000 | [diff] [blame] | 64 | } // end namespace WebAssembly |
| 65 | |
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 66 | } // end namespace llvm |
| 67 | |
| 68 | #endif |