2015-06-30 07:51:55 +08:00
|
|
|
// WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This class prints an WebAssembly MCInst to wasm file syntax.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H
|
|
|
|
|
2015-12-07 03:42:29 +08:00
|
|
|
#include "llvm/CodeGen/MachineValueType.h"
|
2016-01-20 13:54:22 +08:00
|
|
|
#include "llvm/MC/MCInstPrinter.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 {
|
[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
|
|
|
uint64_t ControlFlowCounter;
|
|
|
|
SmallVector<std::pair<uint64_t, bool>, 0> ControlFlowStack;
|
|
|
|
|
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);
|
2016-01-26 11:39:31 +08:00
|
|
|
void printWebAssemblyP2AlignOperand(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 {
|
|
|
|
|
|
|
|
const char *TypeToString(MVT Ty);
|
|
|
|
|
|
|
|
} // end namespace WebAssembly
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|