2015-06-30 07:51:55 +08:00
|
|
|
// WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-30 07:51:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This class prints an WebAssembly MCInst to wasm file syntax.
|
2015-06-30 07:51:55 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
|
|
|
|
|
2016-04-18 20:21:59 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Wasm.h"
|
2016-01-20 13:54:22 +08:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2018-03-24 07:58:25 +08:00
|
|
|
#include "llvm/Support/MachineValueType.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MCSubtargetInfo;
|
|
|
|
|
2015-11-26 00:29:24 +08:00
|
|
|
class WebAssemblyInstPrinter final : public MCInstPrinter {
|
2018-10-26 07:45:48 +08:00
|
|
|
uint64_t ControlFlowCounter = 0;
|
|
|
|
uint64_t EHPadStackCounter = 0;
|
|
|
|
SmallVector<std::pair<uint64_t, bool>, 4> ControlFlowStack;
|
|
|
|
SmallVector<uint64_t, 4> EHPadStack;
|
|
|
|
|
|
|
|
enum EHInstKind { TRY, CATCH, END_TRY };
|
|
|
|
EHInstKind LastSeenEHInst = END_TRY;
|
[WebAssembly] Make CFG stackification independent of basic-block labels.
This patch changes the way labels are referenced. Instead of referencing the
basic-block label name (eg. .LBB0_0), instructions now just have an immediate
which indicates the depth in the control-flow stack to find a label to jump to.
This makes them much closer to what we expect to have in the binary encoding,
and avoids the problem of basic-block label names not being explicit in the
binary encoding.
Also, it terminates blocks and loops with end_block and end_loop instructions,
rather than basic-block label names, for similar reasons.
This will also fix problems where two constructs appear to have the same label,
because we no longer explicitly use labels, so consumers that need labels will
presumably create their own labels, and presumably they won't reuse labels
when they do.
This patch does make the code a little more awkward to read; as a partial
mitigation, this patch also introduces comments showing where the labels are,
and comments on each branch showing where it's branching to.
llvm-svn: 257505
2016-01-13 03:14:46 +08:00
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
public:
|
|
|
|
WebAssemblyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
|
|
|
|
const MCRegisterInfo &MRI);
|
|
|
|
|
|
|
|
void printRegName(raw_ostream &OS, unsigned RegNo) const override;
|
|
|
|
void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot,
|
|
|
|
const MCSubtargetInfo &STI) override;
|
2015-07-23 05:28:15 +08:00
|
|
|
|
2015-08-25 06:16:48 +08:00
|
|
|
// Used by tblegen code.
|
|
|
|
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
[WebAssembly] Fix assembler parsing of br_table.
Summary:
We use `variable_ops` in the tablegen defs to denote the list of
branch targets in `br_table`, but unlike other uses of `variable_ops`
(e.g. call) the these branch targets need to actually be encoded in the
instruction. The existing tables for `variable_ops` cause not operands
to be accepted by the assembly matcher.
Following the example of ARM:
https://github.com/llvm-mirror/llvm/blob/2cc0a7da876c1d8c32775b0119e1e15aaa759b9e/lib/Target/ARM/ARMInstrInfo.td#L550-L555
we introduce a new operand type to capture this list, and we use the
same {} syntax as ARM as well to differentiate them from regular
integer operands.
Also removed definition and use of TSFlags in tablegen defs, since
`br_table` now has a non-variable_ops immediate operand, so the
previous logic of only the variable_ops arguments being labels didn't
make sense anymore.
Reviewers: dschuff, aheejin, sunfish
Subscribers: javed.absar, sbc100, jgravelle-google, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D55401
llvm-svn: 349405
2018-12-18 06:04:44 +08:00
|
|
|
void printBrList(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
2016-01-26 11:39:31 +08:00
|
|
|
void printWebAssemblyP2AlignOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O);
|
2016-10-07 06:29:32 +08:00
|
|
|
void printWebAssemblySignatureOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O);
|
2015-08-25 06:16:48 +08:00
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
// Autogenerated by tblgen.
|
|
|
|
void printInstruction(const MCInst *MI, raw_ostream &O);
|
|
|
|
static const char *getRegisterName(unsigned RegNo);
|
2015-06-30 07:51:55 +08:00
|
|
|
};
|
|
|
|
|
2015-12-07 03:42:29 +08:00
|
|
|
namespace WebAssembly {
|
|
|
|
|
2019-01-04 06:59:59 +08:00
|
|
|
const char *typeToString(wasm::ValType Ty);
|
|
|
|
const char *anyTypeToString(unsigned Ty);
|
2015-12-07 03:42:29 +08:00
|
|
|
|
|
|
|
} // end namespace WebAssembly
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|