1//=- SystemZTargetStreamer.h - SystemZ Target Streamer ----------*- 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_SYSTEMZ_SYSTEMZTARGETSTREAMER_H
10#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H
11
12#include "llvm/ADT/StringRef.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCInst.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/MC/MCSymbol.h"
18#include "llvm/Support/FormattedStream.h"
19#include <map>
20#include <utility>
21
22namespace llvm {
23class MCGOFFStreamer;
24class SystemZHLASMAsmStreamer;
25
26class SystemZTargetStreamer : public MCTargetStreamer {
27public:
28 SystemZTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
29
30 typedef std::pair<MCInst, const MCSubtargetInfo *> MCInstSTIPair;
31 struct CmpMCInst {
32 bool operator()(const MCInstSTIPair &MCI_STI_A,
33 const MCInstSTIPair &MCI_STI_B) const {
34 if (MCI_STI_A.second != MCI_STI_B.second)
35 return uintptr_t(MCI_STI_A.second) < uintptr_t(MCI_STI_B.second);
36 const MCInst &A = MCI_STI_A.first;
37 const MCInst &B = MCI_STI_B.first;
38 assert(A.getNumOperands() == B.getNumOperands() &&
39 A.getNumOperands() == 5 && A.getOperand(2).getImm() == 1 &&
40 B.getOperand(2).getImm() == 1 && "Unexpected EXRL target MCInst");
41 if (A.getOpcode() != B.getOpcode())
42 return A.getOpcode() < B.getOpcode();
43 if (A.getOperand(i: 0).getReg() != B.getOperand(i: 0).getReg())
44 return A.getOperand(i: 0).getReg() < B.getOperand(i: 0).getReg();
45 if (A.getOperand(i: 1).getImm() != B.getOperand(i: 1).getImm())
46 return A.getOperand(i: 1).getImm() < B.getOperand(i: 1).getImm();
47 if (A.getOperand(i: 3).getReg() != B.getOperand(i: 3).getReg())
48 return A.getOperand(i: 3).getReg() < B.getOperand(i: 3).getReg();
49 if (A.getOperand(i: 4).getImm() != B.getOperand(i: 4).getImm())
50 return A.getOperand(i: 4).getImm() < B.getOperand(i: 4).getImm();
51 return false;
52 }
53 };
54 typedef std::map<MCInstSTIPair, MCSymbol *, CmpMCInst> EXRLT2SymMap;
55 EXRLT2SymMap EXRLTargets2Sym;
56
57 void emitConstantPools() override;
58
59 virtual void emitMachine(StringRef CPUOrCommand) {};
60
61 virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
62 const MCSymbol *Lo) {
63 return nullptr;
64 }
65};
66
67class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {
68public:
69 SystemZTargetGOFFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}
70 const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
71 const MCSymbol *Lo) override;
72};
73
74class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
75 formatted_raw_ostream &OS;
76
77public:
78 SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)
79 : SystemZTargetStreamer(S), OS(OS) {}
80 SystemZHLASMAsmStreamer &getHLASMStreamer();
81 const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
82 const MCSymbol *Lo) override;
83};
84
85class SystemZTargetELFStreamer : public SystemZTargetStreamer {
86public:
87 SystemZTargetELFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}
88 void emitMachine(StringRef CPUOrCommand) override {}
89};
90
91class SystemZTargetGNUStreamer : public SystemZTargetStreamer {
92 formatted_raw_ostream &OS;
93
94public:
95 SystemZTargetGNUStreamer(MCStreamer &S, formatted_raw_ostream &OS)
96 : SystemZTargetStreamer(S), OS(OS) {}
97 void emitMachine(StringRef CPUOrCommand) override {
98 OS << "\t.machine " << CPUOrCommand << "\n";
99 }
100};
101
102} // end namespace llvm
103
104#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETSTREAMER_H
105