Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
Line
Count
Source
1
// WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- 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
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
10
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
11
12
#include "WebAssemblyMachineFunctionInfo.h"
13
#include "WebAssemblySubtarget.h"
14
#include "llvm/CodeGen/AsmPrinter.h"
15
#include "llvm/MC/MCStreamer.h"
16
#include "llvm/Target/TargetMachine.h"
17
18
namespace llvm {
19
class MCSymbol;
20
class WebAssemblyTargetStreamer;
21
class WebAssemblyMCInstLower;
22
23
class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
24
  const WebAssemblySubtarget *Subtarget;
25
  const MachineRegisterInfo *MRI;
26
  WebAssemblyFunctionInfo *MFI;
27
  // TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
28
  std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
29
30
public:
31
  explicit WebAssemblyAsmPrinter(TargetMachine &TM,
32
                                 std::unique_ptr<MCStreamer> Streamer)
33
      : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
34
425
        MFI(nullptr) {}
35
36
4.45k
  StringRef getPassName() const override {
37
4.45k
    return "WebAssembly Assembly Printer";
38
4.45k
  }
39
40
772
  const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
41
5.57k
  void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
42
5.57k
    Signatures.push_back(std::move(Sig));
43
5.57k
  }
44
45
  //===------------------------------------------------------------------===//
46
  // MachineFunctionPass Implementation.
47
  //===------------------------------------------------------------------===//
48
49
4.45k
  bool runOnMachineFunction(MachineFunction &MF) override {
50
4.45k
    Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
51
4.45k
    MRI = &MF.getRegInfo();
52
4.45k
    MFI = MF.getInfo<WebAssemblyFunctionInfo>();
53
4.45k
    return AsmPrinter::runOnMachineFunction(MF);
54
4.45k
  }
55
56
  //===------------------------------------------------------------------===//
57
  // AsmPrinter Implementation.
58
  //===------------------------------------------------------------------===//
59
60
  void EmitEndOfAsmFile(Module &M) override;
61
  void EmitProducerInfo(Module &M);
62
  void EmitTargetFeatures(Module &M);
63
  void EmitJumpTableInfo() override;
64
  void EmitConstantPool() override;
65
  void EmitFunctionBodyStart() override;
66
  void EmitInstruction(const MachineInstr *MI) override;
67
  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
68
                       const char *ExtraCode, raw_ostream &OS) override;
69
  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
70
                             const char *ExtraCode, raw_ostream &OS) override;
71
72
  MVT getRegType(unsigned RegNo) const;
73
  std::string regToString(const MachineOperand &MO);
74
  WebAssemblyTargetStreamer *getTargetStreamer();
75
};
76
77
} // end namespace llvm
78
79
#endif