blob: cf37778099a08db2f4dcbf209b0742f27856be84 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This class prints an WebAssembly MCInst to wasm file syntax.
Dan Gohman10e730a2015-06-29 23:51:55 +000011///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
15#define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
16
Eric Liu01792302016-04-18 12:21:59 +000017#include "llvm/ADT/SmallVector.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000018#include "llvm/BinaryFormat/Wasm.h"
Dan Gohman83947562016-01-20 05:54:22 +000019#include "llvm/MC/MCInstPrinter.h"
David Blaikie13e77db2018-03-23 23:58:25 +000020#include "llvm/Support/MachineValueType.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000021
22namespace llvm {
23
Dan Gohman10e730a2015-06-29 23:51:55 +000024class MCSubtargetInfo;
25
Dan Gohmanfd4a88c2015-11-25 16:29:24 +000026class WebAssemblyInstPrinter final : public MCInstPrinter {
Heejin Ahn3103d3d2018-10-25 23:45:48 +000027 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 Gohman1d68e80f2016-01-12 19:14:46 +000034
Dan Gohman10e730a2015-06-29 23:51:55 +000035public:
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 Bastienb9073fb2015-07-22 21:28:15 +000042
JF Bastienaf111db2015-08-24 22:16:48 +000043 // Used by tblegen code.
44 void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
Wouter van Oortmerssend3c544a2018-12-17 22:04:44 +000045 void printBrList(const MCInst *MI, unsigned OpNo, raw_ostream &O);
Dan Gohmanbb372242016-01-26 03:39:31 +000046 void printWebAssemblyP2AlignOperand(const MCInst *MI, unsigned OpNo,
47 raw_ostream &O);
Dan Gohman2726b882016-10-06 22:29:32 +000048 void printWebAssemblySignatureOperand(const MCInst *MI, unsigned OpNo,
49 raw_ostream &O);
JF Bastienaf111db2015-08-24 22:16:48 +000050
JF Bastienb9073fb2015-07-22 21:28:15 +000051 // Autogenerated by tblgen.
52 void printInstruction(const MCInst *MI, raw_ostream &O);
53 static const char *getRegisterName(unsigned RegNo);
Dan Gohman10e730a2015-06-29 23:51:55 +000054};
55
Dan Gohman5e0886b2015-12-06 19:42:29 +000056namespace WebAssembly {
57
Wouter van Oortmerssen98432952019-01-03 22:59:59 +000058const char *typeToString(wasm::ValType Ty);
59const char *anyTypeToString(unsigned Ty);
Dan Gohman5e0886b2015-12-06 19:42:29 +000060
Wouter van Oortmerssen87af0b12019-08-01 18:08:26 +000061std::string typeListToString(ArrayRef<wasm::ValType> List);
62std::string signatureToString(const wasm::WasmSignature *Sig);
63
Dan Gohman5e0886b2015-12-06 19:42:29 +000064} // end namespace WebAssembly
65
Dan Gohman10e730a2015-06-29 23:51:55 +000066} // end namespace llvm
67
68#endif