Skip to content

Commit 6512a8d

Browse files
tltaoTony Tao
and
Tony Tao
authored
[SystemZ] Split SystemZInstPrinter to two classes based on Asm dialect (#112975)
In preparation for future work on separating the output of the GNU/HLASM ASM dialects, we first separate the SystemZInstPrinter classes to two versions, one for each ASM dialect. The common code remains in a SystemZInstPrinterCommon class instead. --------- Co-authored-by: Tony Tao <[email protected]>
1 parent 6761b24 commit 6512a8d

13 files changed

+455
-297
lines changed

llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "MCTargetDesc/SystemZInstPrinter.h"
9+
#include "MCTargetDesc/SystemZGNUInstPrinter.h"
1010
#include "MCTargetDesc/SystemZMCAsmInfo.h"
1111
#include "MCTargetDesc/SystemZMCTargetDesc.h"
1212
#include "SystemZTargetStreamer.h"
@@ -721,7 +721,7 @@ void SystemZOperand::print(raw_ostream &OS) const {
721721
OS << "Token:" << getToken();
722722
break;
723723
case KindReg:
724-
OS << "Reg:" << SystemZInstPrinter::getRegisterName(getReg());
724+
OS << "Reg:" << SystemZGNUInstPrinter::getRegisterName(getReg());
725725
break;
726726
case KindImm:
727727
OS << "Imm:";
@@ -743,10 +743,10 @@ void SystemZOperand::print(raw_ostream &OS) const {
743743
if (Op.MemKind == BDLMem)
744744
OS << *cast<MCConstantExpr>(Op.Length.Imm) << ",";
745745
else if (Op.MemKind == BDRMem)
746-
OS << SystemZInstPrinter::getRegisterName(Op.Length.Reg) << ",";
746+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Length.Reg) << ",";
747747
if (Op.Index)
748-
OS << SystemZInstPrinter::getRegisterName(Op.Index) << ",";
749-
OS << SystemZInstPrinter::getRegisterName(Op.Base);
748+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Index) << ",";
749+
OS << SystemZGNUInstPrinter::getRegisterName(Op.Base);
750750
OS << ")";
751751
}
752752
break;

llvm/lib/Target/SystemZ/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ add_llvm_component_group(SystemZ HAS_JIT)
33
set(LLVM_TARGET_DEFINITIONS SystemZ.td)
44

55
tablegen(LLVM SystemZGenAsmMatcher.inc -gen-asm-matcher)
6-
tablegen(LLVM SystemZGenAsmWriter.inc -gen-asm-writer)
6+
tablegen(LLVM SystemZGenGNUAsmWriter.inc -gen-asm-writer)
7+
tablegen(LLVM SystemZGenHLASMAsmWriter.inc -gen-asm-writer -asmwriternum=1)
78
tablegen(LLVM SystemZGenCallingConv.inc -gen-callingconv)
89
tablegen(LLVM SystemZGenDAGISel.inc -gen-dag-isel)
910
tablegen(LLVM SystemZGenDisassemblerTables.inc -gen-disassembler)

llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
add_llvm_component_library(LLVMSystemZDesc
22
SystemZELFObjectWriter.cpp
3+
SystemZGNUInstPrinter.cpp
34
SystemZGOFFObjectWriter.cpp
4-
SystemZInstPrinter.cpp
5+
SystemZHLASMInstPrinter.cpp
6+
SystemZInstPrinterCommon.cpp
57
SystemZMCAsmBackend.cpp
68
SystemZMCAsmInfo.cpp
79
SystemZMCCodeEmitter.cpp
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- SystemZGNUInstPrinter.cpp - Convert SystemZ MCInst to GNU assembly -===//
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+
#include "SystemZGNUInstPrinter.h"
10+
#include "llvm/MC/MCInst.h"
11+
#include "llvm/MC/MCRegister.h"
12+
#include "llvm/Support/raw_ostream.h"
13+
14+
using namespace llvm;
15+
16+
#define DEBUG_TYPE "asm-printer"
17+
18+
#include "SystemZGenGNUAsmWriter.inc"
19+
20+
void SystemZGNUInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
21+
MCRegister Reg,
22+
raw_ostream &O) const {
23+
const char *RegName = getRegisterName(Reg);
24+
markup(O, Markup::Register) << '%' << RegName;
25+
}
26+
27+
void SystemZGNUInstPrinter::printInst(const MCInst *MI, uint64_t Address,
28+
StringRef Annot,
29+
const MCSubtargetInfo &STI,
30+
raw_ostream &O) {
31+
printInstruction(MI, Address, O);
32+
printAnnotation(O, Annot);
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//=- SystemZGNUInstPrinter.h - Convert SystemZ MCInst to assembly -*- 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+
// This class prints a SystemZ MCInst to a .s file in GNU assembly format.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
15+
16+
#include "SystemZInstPrinterCommon.h"
17+
#include "llvm/MC/MCInstPrinter.h"
18+
#include <cstdint>
19+
20+
namespace llvm {
21+
22+
class MCOperand;
23+
24+
class SystemZGNUInstPrinter : public SystemZInstPrinterCommon {
25+
public:
26+
SystemZGNUInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27+
const MCRegisterInfo &MRI)
28+
: SystemZInstPrinterCommon(MAI, MII, MRI) {}
29+
30+
// Automatically generated by tblgen.
31+
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
32+
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
33+
static const char *getRegisterName(MCRegister Reg);
34+
35+
// Override MCInstPrinter.
36+
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
37+
const MCSubtargetInfo &STI, raw_ostream &O) override;
38+
39+
private:
40+
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
41+
raw_ostream &O) const override;
42+
};
43+
44+
} // end namespace llvm
45+
46+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZGNUINSTPRINTER_H
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//=- SystemZHLASMInstPrinter.cpp - Convert SystemZ MCInst to HLASM assembly -=//
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+
#include "SystemZHLASMInstPrinter.h"
10+
#include "llvm/MC/MCInst.h"
11+
#include "llvm/MC/MCRegister.h"
12+
#include "llvm/Support/raw_ostream.h"
13+
14+
using namespace llvm;
15+
16+
#define DEBUG_TYPE "asm-printer"
17+
18+
#include "SystemZGenHLASMAsmWriter.inc"
19+
20+
void SystemZHLASMInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
21+
MCRegister Reg,
22+
raw_ostream &O) const {
23+
const char *RegName = getRegisterName(Reg);
24+
// Skip register prefix so that only register number is left
25+
assert(isalpha(RegName[0]) && isdigit(RegName[1]));
26+
markup(O, Markup::Register) << (RegName + 1);
27+
}
28+
29+
void SystemZHLASMInstPrinter::printInst(const MCInst *MI, uint64_t Address,
30+
StringRef Annot,
31+
const MCSubtargetInfo &STI,
32+
raw_ostream &O) {
33+
printInstruction(MI, Address, O);
34+
printAnnotation(O, Annot);
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//- SystemZHLASMInstPrinter.h - Convert SystemZ MCInst to assembly -*- 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+
// This class prints a SystemZ MCInst to a .s file in HLASM assembly format.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H
15+
16+
#include "SystemZInstPrinterCommon.h"
17+
#include "llvm/MC/MCInstPrinter.h"
18+
#include <cstdint>
19+
20+
namespace llvm {
21+
22+
class MCOperand;
23+
24+
class SystemZHLASMInstPrinter : public SystemZInstPrinterCommon {
25+
public:
26+
SystemZHLASMInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27+
const MCRegisterInfo &MRI)
28+
: SystemZInstPrinterCommon(MAI, MII, MRI) {}
29+
30+
// Automatically generated by tblgen.
31+
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
32+
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
33+
static const char *getRegisterName(MCRegister Reg);
34+
35+
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
36+
const MCSubtargetInfo &STI, raw_ostream &O) override;
37+
38+
private:
39+
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg,
40+
raw_ostream &O) const override;
41+
};
42+
43+
} // end namespace llvm
44+
45+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMINSTPRINTER_H

0 commit comments

Comments
 (0)