32 std::istringstream Stream(Str);
35 while (std::getline(Stream, Line,
'\n'))
36 Lines.push_back(Line);
38 for (
auto S : Lines) {
39 if (
LLVM_LIKELY(S.length() < ContIndicatorColumn)) {
42 FOS.PadToColumn(InstLimit);
51 std::string TmpSubStr = S.substr(0, ContIndicatorColumn);
52 if (!TmpSubStr.compare(ContIndicatorColumn - 1, 1,
" "))
53 TmpSubStr.replace(ContIndicatorColumn - 1, 1,
"X");
56 FOS.PadToColumn(InstLimit);
59 size_t Emitted = ContIndicatorColumn - 1;
61 while (Emitted < S.length()) {
62 if ((S.length() - Emitted) < ContLen)
63 TmpSubStr = S.substr(Emitted, S.length());
65 TmpSubStr = S.substr(Emitted, ContLen);
66 if (!TmpSubStr.compare(ContLen - 1, 1,
" "))
67 TmpSubStr.replace(ContLen - 1, 1,
"X");
69 FOS.PadToColumn(ContStartColumn);
71 FOS.PadToColumn(InstLimit);
73 Emitted += ContLen - 1;
85 OS << Name <<
" XATTR ";
90 if (NotUnspecified || IsIndirectReference) {
91 OS << Sep <<
"REFERENCE(";
97 if (IsIndirectReference)
98 OS << SepRef <<
"INDIRECT";
104 OS << Sep <<
"PSECT(" << ADA->
getName() <<
")";
106 OS << Sep <<
"SCOPE(";
107 switch (BindingScope) {
133 OS << Name <<
" CATTR ";
134 OS <<
"ALIGN(" <<
static_cast<unsigned>(Alignment) <<
"),"
135 <<
"FILL(" <<
static_cast<unsigned>(FillByteValue) <<
")";
136 switch (LoadBehavior) {
146 switch (Executable) {
151 OS <<
",NOTEXECUTABLE";
177 OS <<
",PRIORITY(" << SortKey <<
")";
178 if (!PartName.
empty())
179 OS <<
",PART(" << PartName <<
")";
186 auto EmitExternalName = [&Sec,
this]() {
187 if (Sec.hasExternalName())
188 OS << Sec.getName() <<
" ALIAS C'" << Sec.getExternalName() <<
"'\n";
190 switch (Sec.getSymbolType()) {
192 OS << Sec.getName() <<
" CSECT\n";
199 if (!Sec.isEmitted()) {
204 if (
auto *BeginSym =
static_cast<MCSymbolGOFF *
>(Sec.getBeginSymbol())) {
205 if (BeginSym->getADA()) {
206 emitXATTR(OS, BeginSym->getName(), BeginSym->getADA(),
215 OS << Sec.getName() <<
" CATTR\n";
221 if (!Sec.isEmitted()) {
238 OS << ED->
getName() <<
" CATTR PART(" << Sec.getName() <<
")\n";
249 std::optional<int64_t>
Value,
251 unsigned MaxBytesToEmit) {
280 OS << MAI->getCommentString() <<
T;
300 assert(Comments.
back() ==
'\n' &&
"Comment array not newline terminated");
303 size_t Position = std::min(InstLimit - 2, Comments.
find(
'\n'));
304 FOS << MAI->getCommentString() <<
' ' << Comments.
substr(0, Position)
307 if (Comments[Position] ==
'\n')
309 Comments = Comments.
substr(Position);
310 }
while (!Comments.
empty());
318 unsigned MaxBytesToEmit) {
324 unsigned MaxBytesToEmit) {
326 if (MAI->getTextAlignFillValue())
335 "Cannot emit contents before setting section!");
340 size_t Len =
Data.size();
350 OS <<
'\'' <<
toHex(Chars) <<
'\'';
371 FixupMap.
resize(Code.size() * 8);
372 for (
unsigned I = 0, E = Code.size() * 8;
I != E; ++
I)
375 for (
unsigned I = 0, E = Fixups.size();
I != E; ++
I) {
379 for (
unsigned J = 0; J != Info.TargetSize; ++J) {
380 unsigned Index =
F.getOffset() * 8 + Info.TargetOffset + J;
381 assert(Index < Code.size() * 8 &&
"Invalid offset in fixup!");
382 FixupMap[Index] = 1 +
I;
387 for (
unsigned I = 0, E = Code.size();
I != E; ++
I) {
392 uint8_t MapEntry = FixupMap[
I * 8 + 0];
393 for (
unsigned J = 1; J != 8; ++J) {
394 if (FixupMap[
I * 8 + J] == MapEntry)
401 if (MapEntry !=
uint8_t(~0U)) {
408 <<
char(
'A' + MapEntry - 1) <<
'\'';
410 OS <<
char(
'A' + MapEntry - 1);
415 for (
unsigned J = 8; J--;) {
416 unsigned Bit = (Code[
I] >> J) & 1;
417 unsigned FixupBit =
I * 8 + (7 - J);
418 if (
uint8_t MapEntry = FixupMap[FixupBit]) {
419 assert(Bit == 0 &&
"Encoder wrote into fixed up bit!");
420 OS <<
char(
'A' + MapEntry - 1);
428 for (
unsigned I = 0, E = Fixups.size();
I != E; ++
I) {
430 OS <<
" fixup " <<
char(
'A' +
I) <<
" - "
431 <<
"offset: " <<
F.getOffset() <<
", value: ";
432 MAI->printExpr(OS, *
F.getValue());
433 auto Kind =
F.getKind();
435 OS <<
", relocation type: " << Kind;
440 OS <<
"FK_PCRel_" << (Info.TargetSize / 8);
454 InstPrinter->printInst(&Inst, 0,
"", STI, OS);
465 bool EmitLabelAndEntry =
471 if (EmitLabelAndEntry) {
472 OS <<
" ENTRY " << Sym->
getName();
483 if (EmitLabelAndEntry) {
484 OS << Sym->
getName() <<
" DS 0H";
495 String.consume_back(
"\n");
503 unsigned Size,
bool Parens) {
504 switch (
Value->getKind()) {
506 OS <<
"XL" <<
Size <<
'\'';
507 MAI->printExpr(OS, *
Value);
529 OS <<
'/' << (1 << Const);
548 "Unrecognized HLASM arithmetic expression!");
556 MAI->printExpr(OS, *
Value);
562 MAI->printExpr(OS, *
Value);
573 "Cannot emit contents before setting section!");
583 if (Symbol.isTemporary() || !Symbol.isRegistered() || Symbol.isDefined())
587 OS << Sym.getADA()->getParent()->getExternalName() <<
" CATTR PART("
588 << Sym.getName() <<
")";
591 OS <<
" " << (Sym.isWeak() ?
"WXTRN" :
"EXTRN") <<
" " << Sym.getName();
594 emitXATTR(OS, Sym.getName(), Sym.getADA(), Sym.isIndirect(),
595 Sym.getLinkage(), Sym.getCodeData(), Sym.getBindingScope());
597 if (Sym.hasExternalName())
598 OS << Sym.getName() <<
" ALIAS C'" << Sym.getExternalName() <<
"'\n";
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 declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
This file contains the MCSymbolGOFF class.
static void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment, GOFF::ESDLoadingBehavior LoadBehavior, GOFF::ESDExecutable Executable, bool IsReadOnly, uint32_t SortKey, uint8_t FillByteValue, StringRef PartName)
static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA, bool IsIndirectReference, GOFF::ESDLinkageType Linkage, GOFF::ESDExecutable Executable, GOFF::ESDBindingScope BindingScope)
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::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()
MCContext & getContext() const
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current 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.
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.
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.
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 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 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 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.
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.
@ ESD_ST_ElementDefinition
@ ESD_ST_SectionDefinition
bool isRelocation(MCFixupKind FixupKind)
This is an optimization pass for GlobalISel generic memory operations.
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 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.
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...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
GOFF::ESDLoadingBehavior LoadBehavior
GOFF::ESDLinkageType Linkage
GOFF::ESDBindingScope BindingScope
GOFF::ESDExecutable Executable
Target independent information on a fixup kind.
const char * Name
A target specific name for the fixup kind.