Skip to content

Commit 3adc2a0

Browse files
committed
[SystemZ/zOS/GOFF] Implement GOFF writer for empty files.
Set ups the infrastructure to create an empty GOFF file. Also adds a GOFF writer which writes only HDR/END records. Reviewed By: jhenderson, kpn Differential Revision: https://reviews.llvm.org/D111437
1 parent 2e12fc3 commit 3adc2a0

File tree

14 files changed

+551
-25
lines changed

14 files changed

+551
-25
lines changed

llvm/include/llvm/BinaryFormat/GOFF.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// constants for the GOFF file format.
1111
//
1212
// GOFF specifics can be found in MVS Program Management: Advanced Facilities.
13+
// See
14+
// https://www.ibm.com/docs/en/zos/3.1.0?topic=facilities-generalized-object-file-format-goff
1315
//
1416
//===----------------------------------------------------------------------===//
1517

@@ -19,13 +21,24 @@
1921
#include "llvm/Support/DataTypes.h"
2022

2123
namespace llvm {
24+
2225
namespace GOFF {
2326

27+
/// \brief Length of the parts of a physical GOFF record.
2428
constexpr uint8_t RecordLength = 80;
2529
constexpr uint8_t RecordPrefixLength = 3;
2630
constexpr uint8_t PayloadLength = 77;
31+
constexpr uint8_t RecordContentLength = RecordLength - RecordPrefixLength;
32+
33+
/// \brief Maximum data length before starting a new card for RLD and TXT data.
34+
///
35+
/// The maximum number of bytes that can be included in an RLD or TXT record and
36+
/// their continuations is a SIGNED 16 bit int despite what the spec says. The
37+
/// number of bytes we allow ourselves to attach to a card is thus arbitrarily
38+
/// limited to 32K-1 bytes.
39+
constexpr uint16_t MaxDataLength = 32 * 1024 - 1;
2740

28-
// Prefix byte on every record. This indicates GOFF format.
41+
/// \brief Prefix byte on every record. This indicates GOFF format.
2942
constexpr uint8_t PTVPrefix = 0x03;
3043

3144
enum RecordType : uint8_t {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===- MCGOFFObjectWriter.h - GOFF Object Writer ----------------*- 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_MC_MCGOFFOBJECTWRITER_H
10+
#define LLVM_MC_MCGOFFOBJECTWRITER_H
11+
12+
#include "llvm/MC/MCObjectWriter.h"
13+
14+
namespace llvm {
15+
class MCObjectWriter;
16+
class raw_pwrite_stream;
17+
18+
class MCGOFFObjectTargetWriter : public MCObjectTargetWriter {
19+
protected:
20+
MCGOFFObjectTargetWriter() = default;
21+
22+
public:
23+
virtual ~MCGOFFObjectTargetWriter() = default;
24+
25+
Triple::ObjectFormatType getFormat() const override { return Triple::GOFF; }
26+
27+
static bool classof(const MCObjectTargetWriter *W) {
28+
return W->getFormat() == Triple::GOFF;
29+
}
30+
};
31+
32+
/// \brief Construct a new GOFF writer instance.
33+
///
34+
/// \param MOTW - The target-specific GOFF writer subclass.
35+
/// \param OS - The stream to write to.
36+
/// \returns The constructed object writer.
37+
std::unique_ptr<MCObjectWriter>
38+
createGOFFObjectWriter(std::unique_ptr<MCGOFFObjectTargetWriter> MOTW,
39+
raw_pwrite_stream &OS);
40+
} // namespace llvm
41+
42+
#endif

llvm/include/llvm/MC/MCGOFFStreamer.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- MCGOFFStreamer.h - MCStreamer GOFF Object File Interface--*- 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_MC_MCGOFFSTREAMER_H
10+
#define LLVM_MC_MCGOFFSTREAMER_H
11+
12+
#include "llvm/MC/MCObjectStreamer.h"
13+
#include "llvm/MC/MCObjectWriter.h"
14+
15+
namespace llvm {
16+
17+
class MCGOFFStreamer : public MCObjectStreamer {
18+
public:
19+
MCGOFFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
20+
std::unique_ptr<MCObjectWriter> OW,
21+
std::unique_ptr<MCCodeEmitter> Emitter)
22+
: MCObjectStreamer(Context, std::move(MAB), std::move(OW),
23+
std::move(Emitter)) {}
24+
25+
~MCGOFFStreamer() override;
26+
27+
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
28+
return false;
29+
}
30+
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
31+
Align ByteAlignment) override {}
32+
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override {}
33+
void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
34+
uint64_t Size = 0, Align ByteAlignment = Align(1),
35+
SMLoc Loc = SMLoc()) override {}
36+
};
37+
38+
} // end namespace llvm
39+
40+
#endif

llvm/include/llvm/MC/TargetRegistry.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ MCStreamer *createELFStreamer(MCContext &Ctx,
9494
std::unique_ptr<MCObjectWriter> &&OW,
9595
std::unique_ptr<MCCodeEmitter> &&CE,
9696
bool RelaxAll);
97+
MCStreamer *createGOFFStreamer(MCContext &Ctx,
98+
std::unique_ptr<MCAsmBackend> &&TAB,
99+
std::unique_ptr<MCObjectWriter> &&OW,
100+
std::unique_ptr<MCCodeEmitter> &&CE,
101+
bool RelaxAll);
97102
MCStreamer *createMachOStreamer(MCContext &Ctx,
98103
std::unique_ptr<MCAsmBackend> &&TAB,
99104
std::unique_ptr<MCObjectWriter> &&OW,
@@ -195,6 +200,10 @@ class Target {
195200
std::unique_ptr<MCAsmBackend> &&TAB,
196201
std::unique_ptr<MCObjectWriter> &&OW,
197202
std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
203+
using GOFFStreamerCtorTy =
204+
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
205+
std::unique_ptr<MCObjectWriter> &&OW,
206+
std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
198207
using MachOStreamerCtorTy =
199208
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
200209
std::unique_ptr<MCObjectWriter> &&OW,
@@ -327,6 +336,7 @@ class Target {
327336

328337
// Construction functions for the various object formats, if registered.
329338
COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
339+
GOFFStreamerCtorTy GOFFStreamerCtorFn = nullptr;
330340
MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
331341
ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
332342
WasmStreamerCtorTy WasmStreamerCtorFn = nullptr;
@@ -597,7 +607,13 @@ class Target {
597607
std::move(Emitter), RelaxAll);
598608
break;
599609
case Triple::GOFF:
600-
report_fatal_error("GOFF MCObjectStreamer not implemented yet");
610+
if (GOFFStreamerCtorFn)
611+
S = GOFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
612+
std::move(Emitter), RelaxAll);
613+
else
614+
S = createGOFFStreamer(Ctx, std::move(TAB), std::move(OW),
615+
std::move(Emitter), RelaxAll);
616+
break;
601617
case Triple::XCOFF:
602618
if (XCOFFStreamerCtorFn)
603619
S = XCOFFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
@@ -1004,6 +1020,10 @@ struct TargetRegistry {
10041020
T.COFFStreamerCtorFn = Fn;
10051021
}
10061022

1023+
static void RegisterGOFFStreamer(Target &T, Target::GOFFStreamerCtorTy Fn) {
1024+
T.GOFFStreamerCtorFn = Fn;
1025+
}
1026+
10071027
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
10081028
T.MachOStreamerCtorFn = Fn;
10091029
}

llvm/lib/MC/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_llvm_component_library(LLVMMC
22
ConstantPools.cpp
33
DXContainerPSVInfo.cpp
44
ELFObjectWriter.cpp
5+
GOFFObjectWriter.cpp
56
MCAsmBackend.cpp
67
MCAsmInfo.cpp
78
MCAsmInfoCOFF.cpp
@@ -23,6 +24,7 @@ add_llvm_component_library(LLVMMC
2324
MCELFStreamer.cpp
2425
MCExpr.cpp
2526
MCFragment.cpp
27+
MCGOFFStreamer.cpp
2628
MCInst.cpp
2729
MCInstPrinter.cpp
2830
MCInstrAnalysis.cpp

0 commit comments

Comments
 (0)