41 auto EmitContinued = [
this](
StringRef Chunk) {
42 char C = Chunk.back();
43 bool IsValid =
isAlnum(
C) ||
C ==
'_' ||
C ==
'$' ||
C ==
'@' ||
C ==
'#';
44 FOS << Chunk.drop_back() << (IsValid ?
C :
'X');
48 while (!Remaining.
empty()) {
50 std::tie(S, Remaining) = Remaining.
split(
'\n');
56 EmitContinued(S.
take_front(ContIndicatorColumn));
59 size_t Emitted = ContIndicatorColumn - 1;
60 while (Emitted < S.
size()) {
62 FOS.PadToColumn(ContStartColumn);
63 if (Chunk.
size() < ContLen)
68 Emitted += ContLen - 1;
79 OS << Name <<
" XATTR ";
84 if (NotUnspecified || IsIndirectReference) {
85 OS << Sep <<
"REFERENCE(";
91 if (IsIndirectReference)
92 OS << SepRef <<
"INDIRECT";
98 OS << Sep <<
"PSECT(" << ADA->
getName() <<
")";
100 OS << Sep <<
"SCOPE(";
101 switch (BindingScope) {
128 OS << Name <<
" CATTR ";
129 OS <<
"ALIGN(" <<
static_cast<unsigned>(Alignment) <<
"),"
130 <<
"FILL(" <<
static_cast<unsigned>(FillByteValue) <<
")";
131 switch (LoadBehavior) {
141 switch (TaskingBehavior) {
154 switch (Executable) {
159 OS <<
",NOTEXECUTABLE";
187 OS <<
",PRIORITY(" << SortKey <<
")";
188 if (!PartName.
empty())
189 OS <<
",PART(" << PartName <<
")";
194 OS << Name <<
" ALIAS C'";
195 for (
char C : ExternalName) {
196 if (
C ==
'\'' ||
C ==
'&')
206 auto EmitExternalName = [&Sec,
this]() {
207 if (Sec.hasExternalName())
208 emitALIAS(OS, Sec.getName(), Sec.getExternalName());
210 switch (Sec.getSymbolType()) {
212 OS << Sec.getName() <<
" CSECT\n";
219 if (!Sec.isEmitted()) {
229 if (
auto *BeginSym =
static_cast<MCSymbolGOFF *
>(Sec.getBeginSymbol())) {
230 if (BeginSym->getADA()) {
231 emitXATTR(OS, BeginSym->getName(), BeginSym->getADA(),
240 OS << Sec.getName() <<
" CATTR\n";
246 if (!Sec.isEmitted()) {
268 OS << ED->
getName() <<
" CATTR PART(" << Sec.getName() <<
")\n";
279 std::optional<int64_t>
Value,
281 unsigned MaxBytesToEmit) {
285 OS.indent(Indent) <<
"DS 0";
310 OS << MAI->getCommentString() <<
T;
330 assert(Comments.
back() ==
'\n' &&
"Comment array not newline terminated");
333 size_t Position = std::min(InstLimit - 2, Comments.
find(
'\n'));
334 FOS << MAI->getCommentString() <<
' ' << Comments.
substr(0, Position)
337 if (Comments[Position] ==
'\n')
339 Comments = Comments.
substr(Position);
340 }
while (!Comments.
empty());
348 unsigned MaxBytesToEmit) {
354 unsigned MaxBytesToEmit) {
356 if (MAI->getTextAlignFillValue())
370 for (
char C :
Text) {
371 if (
C ==
'\'' ||
C ==
'&')
379 "Cannot emit contents before setting section!");
387 OS.indent(Indent) <<
"DC CE'";
393 OS.indent(Indent) <<
"DC CA'";
401 for (
size_t I = 0, E =
Data.size();
I < E;
I += MaxXLLen) {
403 if (!(MayBeString && Chunk.
size() > 1 && EmitAsString(Chunk)))
404 OS.indent(Indent) <<
"DC XL" << Chunk.
size() <<
'\'' <<
toHex(Chunk)
422 OS.indent(Indent) <<
"DC XL" <<
Size <<
'\''
431 if (!NumBytes.evaluateAsAbsolute(
Count)) {
439 if (
Count > 0x7FFFFFFF) {
446 OS.indent(Indent) <<
"DC " <<
Count <<
"XL1'"
467 FixupMap.
resize(Code.size() * 8);
468 for (
unsigned I = 0, E = Code.size() * 8;
I != E; ++
I)
471 for (
unsigned I = 0, E = Fixups.size();
I != E; ++
I) {
475 for (
unsigned J = 0; J != Info.TargetSize; ++J) {
476 unsigned Index =
F.getOffset() * 8 + Info.TargetOffset + J;
477 assert(Index < Code.size() * 8 &&
"Invalid offset in fixup!");
478 FixupMap[Index] = 1 +
I;
483 for (
unsigned I = 0, E = Code.size();
I != E; ++
I) {
488 uint8_t MapEntry = FixupMap[
I * 8 + 0];
489 for (
unsigned J = 1; J != 8; ++J) {
490 if (FixupMap[
I * 8 + J] == MapEntry)
497 if (MapEntry !=
uint8_t(~0U)) {
504 <<
char(
'A' + MapEntry - 1) <<
'\'';
506 OS <<
char(
'A' + MapEntry - 1);
511 for (
unsigned J = 8; J--;) {
512 unsigned Bit = (Code[
I] >> J) & 1;
513 unsigned FixupBit =
I * 8 + (7 - J);
514 if (
uint8_t MapEntry = FixupMap[FixupBit]) {
515 assert(Bit == 0 &&
"Encoder wrote into fixed up bit!");
516 OS <<
char(
'A' + MapEntry - 1);
524 for (
unsigned I = 0, E = Fixups.size();
I != E; ++
I) {
526 OS <<
" fixup " <<
char(
'A' +
I) <<
" - "
527 <<
"offset: " <<
F.getOffset() <<
", value: ";
528 MAI->printExpr(OS, *
F.getValue());
529 auto Kind =
F.getKind();
531 OS <<
", relocation type: " << Kind;
536 OS <<
"FK_PCRel_" << (Info.TargetSize / 8);
551 OS.indent(Indent - 1);
552 InstPrinter->printInst(&Inst, 0,
"", STI, OS);
563 bool EmitLabelAndEntry =
569 if (EmitLabelAndEntry) {
570 OS.indent(Indent) <<
"ENTRY " << Sym->
getName();
581 if (EmitLabelAndEntry) {
582 OS << Sym->
getName() <<
" DS 0H";
595 OS <<
"AL" <<
Size <<
'(';
604 Align ByteAlignment) {
607 Symbol->getSectionForCommonSymbol(
getContext(), ByteAlignment);
616 String.consume_back(
"\n");
624 unsigned Size,
bool Parens) {
625 switch (
Value->getKind()) {
628 OS <<
"XL" <<
Size <<
'\''
650 OS <<
'/' << (1 << Const);
669 "Unrecognized HLASM arithmetic expression!");
677 MAI->printExpr(OS, *
Value);
683 MAI->printExpr(OS, *
Value);
694 "Cannot emit contents before setting section!");
701 "(z/OS binder restriction IEW2572E)");
706 OS.indent(Indent) <<
"DC ";
713 if (Symbol.isTemporary() || !Symbol.isRegistered() || Symbol.isDefined())
717 OS << Sym.getADA()->getParent()->getExternalName() <<
" CATTR PART("
718 << Sym.getName() <<
")";
721 OS.indent(Indent) << (Sym.isWeak() ?
"WXTRN" :
"EXTRN") <<
" "
725 emitXATTR(OS, Sym.getName(), Sym.getADA(), Sym.isIndirect(),
726 Sym.getLinkage(), Sym.getCodeData(), Sym.getBindingScope());
728 if (Sym.hasExternalName())
729 emitALIAS(OS, Sym.getName(), Sym.getExternalName());
733 OS.indent(Indent) <<
"END";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_LIKELY(EXPR)
This file provides utility functions for converting between EBCDIC-1047 and UTF-8.
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
This file contains the MCSymbolGOFF class.
static void emitALIAS(raw_ostream &OS, StringRef Name, StringRef ExternalName)
static void emitQuotedText(raw_ostream &OS, StringRef Text)
static void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment, GOFF::ESDLoadingBehavior LoadBehavior, GOFF::ESDTaskingBehavior TaskingBehavior, GOFF::ESDExecutable Executable, bool IsReadOnly, bool IsRemovable, uint32_t SortKey, uint8_t FillByteValue, StringRef PartName)
static bool isPrintableText(StringRef Text)
static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA, bool IsIndirectReference, GOFF::ESDLinkageType Linkage, GOFF::ESDExecutable Executable, GOFF::ESDBindingScope BindingScope)
static void printAddrConstPrefix(raw_ostream &OS, unsigned Size)
Functions, function parameters, and return types can have attributes to indicate how they should be t...
A helper class to return the specified delimiter string after the first invocation of operator String...
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
std::unique_ptr< MCAssembler > Assembler
SmallString< 128 > CommentToEmit
MCAssembler & getAssembler()
raw_ostream & getCommentOS() override
Return a raw_ostream that comments can be written to.
raw_svector_ostream CommentStream
MCCodeEmitter & getEmitter() const
MCAsmBackend & getBackend() const
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
@ LShr
Logical shift right.
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
Base class for the full range of assembler expressions which are needed for parsing.
@ Constant
Constant expressions.
@ Target
Target specific expression.
@ Binary
Binary expressions.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Instances of this class represent a single low-level machine instruction.
GOFF::SDAttr getSDAttributes() const
GOFF::EDAttr getEDAttributes() const
GOFF::ESDAlignment getEDAlignment() const
MCSectionGOFF * getParent() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
StringRef getName() const
MCSymbol * getBeginSymbol()
virtual bool popSection()
Restore the current and previous section from the section stack.
virtual MCAssembler * getAssemblerPtr()
MCContext & getContext() const
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
void pushSection()
Save the current and previous section on the section stack.
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
MCSection * getCurrentSectionOnly() const
virtual void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
virtual void changeSection(MCSection *, uint32_t)
This is called by popSection and switchSection, if the current section changes.
Generic base class for all target subtargets.
StringRef getExternalName() const
GOFF::ESDExecutable getCodeData() const
bool hasExternalName() const
bool isInEDSection() const
GOFF::ESDBindingScope getBindingScope() const
GOFF::ESDLinkageType getLinkage() const
MCSectionGOFF * getADA() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
char back() const
Get the last character in the string.
constexpr size_t size() const
Get the string size.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size, bool Parens=false)
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void emitRawTextImpl(StringRef String) override
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void addEncodingComment(const MCInst &Inst, const MCSubtargetInfo &STI)
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitAlignmentDS(uint64_t ByteAlignment, std::optional< int64_t > Value, unsigned ValueSize, unsigned MaxBytesToEmit)
void emitIntValue(uint64_t Value, unsigned Size) override
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
void finishImpl() override
Streamer specific finalization.
void visitUsedSymbol(const MCSymbol &Sym) override
void AddComment(const Twine &T, bool EOL=true) override
Add a comment that can be emitted to the generated .s file to make the output of the compiler more re...
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void emitValueToAlignment(Align Alignment, int64_t Fill, uint8_t FillLen, unsigned MaxBytesToEmit) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitRawComment(const Twine &T, bool TabPrefix=false) override
Print T and prefix it with the comment string (normally #) and optionally a tab.
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
void changeSection(MCSection *Section, uint32_t Subsection) override
This is called by popSection and switchSection, if the current section changes.
void emitLabel(MCSymbol *Symbol, SMLoc Loc) override
Emit a label for Symbol into the current section.
void emitBinaryData(StringRef Data) override
Functionally identical to EmitBytes.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI void convertToUTF8(StringRef Source, SmallVectorImpl< char > &Result)
constexpr StringLiteral CLASS_WSA
@ ESD_ST_ElementDefinition
@ ESD_ST_SectionDefinition
bool isRelocation(MCFixupKind FixupKind)
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
bool isPrint(char C)
Checks whether character C is printable.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
This struct is a compact representation of a valid (non-zero power of two) alignment.
GOFF::ESDLoadingBehavior LoadBehavior
GOFF::ESDLinkageType Linkage
GOFF::ESDBindingScope BindingScope
GOFF::ESDExecutable Executable
GOFF::ESDTaskingBehavior TaskingBehavior
Target independent information on a fixup kind.
const char * Name
A target specific name for the fixup kind.