[SystemZ][HLASM] Emit END instruction (#146110)
A HLASM source file must end with the END instruction. It is implemented by adding a new function to the target streamer. This change also turns SystemZHLASMSAsmString.h into a proper header file, and only uses the SystemZTargetHLASMStreamer when HLASM output is generated.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
#include "llvm/Support/Signals.h"
|
#include "llvm/Support/Signals.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <cmath>
|
using namespace llvm;
|
||||||
|
|
||||||
void SystemZHLASMAsmStreamer::EmitEOL() {
|
void SystemZHLASMAsmStreamer::EmitEOL() {
|
||||||
// Comments are emitted on a new line before the instruction.
|
// Comments are emitted on a new line before the instruction.
|
||||||
@@ -280,3 +280,8 @@ void SystemZHLASMAsmStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
|
|||||||
emitHLASMValueImpl(Value, Size, true);
|
emitHLASMValueImpl(Value, Size, true);
|
||||||
EmitEOL();
|
EmitEOL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemZHLASMAsmStreamer::emitEnd() {
|
||||||
|
OS << " END";
|
||||||
|
EmitEOL();
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
|
||||||
|
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
|
||||||
|
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/MC/MCAsmBackend.h"
|
#include "llvm/MC/MCAsmBackend.h"
|
||||||
@@ -24,7 +27,7 @@
|
|||||||
#include "llvm/MC/MCTargetOptions.h"
|
#include "llvm/MC/MCTargetOptions.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
|
|
||||||
using namespace llvm;
|
namespace llvm {
|
||||||
|
|
||||||
class SystemZHLASMAsmStreamer final : public MCStreamer {
|
class SystemZHLASMAsmStreamer final : public MCStreamer {
|
||||||
constexpr static size_t InstLimit = 80;
|
constexpr static size_t InstLimit = 80;
|
||||||
@@ -119,4 +122,9 @@ public:
|
|||||||
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,
|
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,
|
||||||
bool Parens = false);
|
bool Parens = false);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
void emitEnd();
|
||||||
};
|
};
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,
|
|||||||
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
|
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
|
||||||
formatted_raw_ostream &OS,
|
formatted_raw_ostream &OS,
|
||||||
MCInstPrinter *InstPrint) {
|
MCInstPrinter *InstPrint) {
|
||||||
if (S.getContext().getTargetTriple().isOSzOS())
|
if (S.getContext().getTargetTriple().isOSzOS() && !GNUAsOnzOSCL)
|
||||||
return new SystemZTargetHLASMStreamer(S, OS);
|
return new SystemZTargetHLASMStreamer(S, OS);
|
||||||
else
|
else
|
||||||
return new SystemZTargetGNUStreamer(S, OS);
|
return new SystemZTargetGNUStreamer(S, OS);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "SystemZTargetStreamer.h"
|
#include "SystemZTargetStreamer.h"
|
||||||
|
#include "SystemZHLASMAsmStreamer.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCObjectFileInfo.h"
|
#include "llvm/MC/MCObjectFileInfo.h"
|
||||||
|
|
||||||
@@ -33,10 +34,16 @@ void SystemZTargetStreamer::emitConstantPools() {
|
|||||||
EXRLTargets2Sym.clear();
|
EXRLTargets2Sym.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemZHLASMAsmStreamer &SystemZTargetHLASMStreamer::getHLASMStreamer() {
|
||||||
|
return static_cast<SystemZHLASMAsmStreamer &>(getStreamer());
|
||||||
|
}
|
||||||
|
|
||||||
void SystemZTargetHLASMStreamer::emitExtern(StringRef Sym) {
|
void SystemZTargetHLASMStreamer::emitExtern(StringRef Sym) {
|
||||||
getStreamer().emitRawText(Twine(" EXTRN ") + Twine(Sym));
|
getStreamer().emitRawText(Twine(" EXTRN ") + Twine(Sym));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemZTargetHLASMStreamer::emitEnd() { getHLASMStreamer().emitEnd(); }
|
||||||
|
|
||||||
// HLASM statements can only perform a single operation at a time
|
// HLASM statements can only perform a single operation at a time
|
||||||
const MCExpr *SystemZTargetHLASMStreamer::createWordDiffExpr(
|
const MCExpr *SystemZTargetHLASMStreamer::createWordDiffExpr(
|
||||||
MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) {
|
MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class SystemZHLASMAsmStreamer;
|
||||||
|
|
||||||
class SystemZTargetStreamer : public MCTargetStreamer {
|
class SystemZTargetStreamer : public MCTargetStreamer {
|
||||||
public:
|
public:
|
||||||
@@ -57,6 +58,7 @@ public:
|
|||||||
virtual void emitMachine(StringRef CPUOrCommand) {};
|
virtual void emitMachine(StringRef CPUOrCommand) {};
|
||||||
|
|
||||||
virtual void emitExtern(StringRef Str) {};
|
virtual void emitExtern(StringRef Str) {};
|
||||||
|
virtual void emitEnd() {};
|
||||||
|
|
||||||
virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
|
virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
|
||||||
const MCSymbol *Lo) {
|
const MCSymbol *Lo) {
|
||||||
@@ -77,7 +79,9 @@ class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
|
|||||||
public:
|
public:
|
||||||
SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)
|
SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)
|
||||||
: SystemZTargetStreamer(S), OS(OS) {}
|
: SystemZTargetStreamer(S), OS(OS) {}
|
||||||
|
SystemZHLASMAsmStreamer &getHLASMStreamer();
|
||||||
void emitExtern(StringRef Sym) override;
|
void emitExtern(StringRef Sym) override;
|
||||||
|
void emitEnd() override;
|
||||||
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
|
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
|
||||||
const MCSymbol *Lo) override;
|
const MCSymbol *Lo) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1114,6 +1114,9 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
|
|||||||
emitIDRLSection(M);
|
emitIDRLSection(M);
|
||||||
}
|
}
|
||||||
emitAttributes(M);
|
emitAttributes(M);
|
||||||
|
// Emit the END instruction in case of HLASM output. This must be the last
|
||||||
|
// instruction in the source file.
|
||||||
|
getTargetStreamer()->emitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemZAsmPrinter::emitADASection() {
|
void SystemZAsmPrinter::emitADASection() {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ define void @foo() {
|
|||||||
; CHECK: DS 0B
|
; CHECK: DS 0B
|
||||||
; CHECK-LABEL: L#.str.1 DS 0H
|
; CHECK-LABEL: L#.str.1 DS 0H
|
||||||
; CHECK: DC XL6'576F726C6400'
|
; CHECK: DC XL6'576F726C6400'
|
||||||
|
; CHECK: END
|
||||||
entry:
|
entry:
|
||||||
%0 = load ptr, ptr @Greeting, align 8
|
%0 = load ptr, ptr @Greeting, align 8
|
||||||
call void (ptr, ...) @outs(ptr noundef %0, ptr noundef @.str.1)
|
call void (ptr, ...) @outs(ptr noundef %0, ptr noundef @.str.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user