Lines Matching +full:slice +full:- +full:per +full:- +full:line
1 //===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output ----------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
81 (asmbackend) ? asmbackend->createObjectWriter(NullStream) in MCAsmStreamer()
85 if (Assembler->getBackendPtr()) in MCAsmStreamer()
86 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding()); in MCAsmStreamer()
93 IsVerboseAsm = TO->AsmVerbose; in MCAsmStreamer()
95 InstPrinter->setCommentStream(CommentStream); in MCAsmStreamer()
96 ShowInst = TO->ShowMCInst; in MCAsmStreamer()
97 switch (TO->MCUseDwarfDirectory) { in MCAsmStreamer()
106 Context.getAsmInfo()->enableDwarfFileDirectoryDefault(); in MCAsmStreamer()
157 /// Emit a blank line to a .s file to pretty it up.
173 auto [Ptr, Bits] = InstPrinter->getMnemonic(&MI); in getMnemonic()
231 /// @param Symbol - The common symbol to emit.
232 /// @param Size - The size of the common symbol.
233 /// @param ByteAlignment - The alignment of the common symbol in bytes.
300 void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column,
313 void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
449 CommentToEmit.push_back('\n'); // Place comment in a new line. in AddComment()
463 // Emit a line of comments. in EmitCommentsAndEOL()
464 OS.PadToColumn(MAI->getCommentColumn()); in EmitCommentsAndEOL()
466 OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n'; in EmitCommentsAndEOL()
476 return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8)); in truncateToSize()
482 OS << MAI->getCommentString() << T; in emitRawComment()
488 if (c == MAI->getSeparatorString()) in addExplicitComment()
492 ExplicitCommentToEmit.append(MAI->getCommentString()); in addExplicitComment()
494 ExplicitCommentToEmit.append(c.slice(2, c.size()).str()); in addExplicitComment()
496 size_t p = 2, len = c.size() - 2; in addExplicitComment()
497 // emit each line in comment as separate newline. in addExplicitComment()
501 ExplicitCommentToEmit.append(MAI->getCommentString()); in addExplicitComment()
502 ExplicitCommentToEmit.append(c.slice(p, newp).str()); in addExplicitComment()
503 // If we have another line in this comment add line in addExplicitComment()
508 } else if (c.starts_with(StringRef(MAI->getCommentString()))) { in addExplicitComment()
514 ExplicitCommentToEmit.append(MAI->getCommentString()); in addExplicitComment()
515 ExplicitCommentToEmit.append(c.slice(1, c.size()).str()); in addExplicitComment()
518 // full line comments immediately output in addExplicitComment()
532 TS->changeSection(getCurrentSection().first, Section, Subsection, OS); in changeSection()
534 Section->printSwitchToSection(*MAI, getContext().getTargetTriple(), OS, in changeSection()
544 OriginalSym->print(OS, MAI); in emitELFSymverDirective()
554 Symbol->print(OS, MAI); in emitLabel()
555 OS << MAI->getLabelSuffix(); in emitLabel()
565 assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!"); in emitLOHDirective()
575 Arg->print(OS, MAI); in emitLOHDirective()
588 case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break; in emitAssemblerFlag()
589 case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break; in emitAssemblerFlag()
590 case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break; in emitAssemblerFlag()
604 if (!MAI->doesSupportDataRegionDirectives()) in emitDataRegion()
657 llvm_unreachable("Invalid Mach-O platform type"); in getPlatformName()
681 // Only Mach-O hasSubsectionsViaSymbols() in emitThumbFunc()
682 if (MAI->hasSubsectionsViaSymbols()) { in emitThumbFunc()
684 Func->print(OS, MAI); in emitThumbFunc()
693 if (E->inlineAssignedExpr()) in emitAssignment()
697 Symbol->print(OS, MAI); in emitAssignment()
699 Value->print(OS, MAI); in emitAssignment()
710 Symbol->print(OS, MAI); in emitConditionalAssignment()
712 Value->print(OS, MAI); in emitConditionalAssignment()
718 Alias->print(OS, MAI); in emitWeakReference()
720 Symbol->print(OS, MAI); in emitWeakReference()
735 if (!MAI->hasDotTypeDotSizeDirective()) in emitSymbolAttribute()
738 Symbol->print(OS, MAI); in emitSymbolAttribute()
739 OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%'); in emitSymbolAttribute()
753 OS << MAI->getGlobalDirective(); in emitSymbolAttribute()
762 if (!MAI->hasNoDeadStrip()) in emitSymbolAttribute()
776 case MCSA_Weak: OS << MAI->getWeakDirective(); break; in emitSymbolAttribute()
781 case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break; in emitSymbolAttribute()
786 // Non-AIX assemblers currently do not support exported visibility. in emitSymbolAttribute()
796 Symbol->print(OS, MAI); in emitSymbolAttribute()
804 Symbol->print(OS, MAI); in emitSymbolDesc()
810 if (MAI->getAssemblerDialect() == 1) { in emitSyntaxDirective()
821 Symbol->print(OS, MAI); in beginCOFFSymbolDef()
843 Symbol->print(OS, MAI); in emitCOFFSafeSEH()
849 Symbol->print(OS, MAI); in emitCOFFSymbolIndex()
855 Symbol->print(OS, MAI); in emitCOFFSectionIndex()
861 Symbol->print(OS, MAI); in emitCOFFSecRel32()
869 Symbol->print(OS, MAI); in emitCOFFImgRel32()
873 OS << '-' << -Offset; in emitCOFFImgRel32()
877 // We need an XCOFF-specific version of this directive as the AIX syntax
884 assert(MAI->getLCOMMDirectiveAlignmentType() == LCOMM::Log2Alignment && in emitXCOFFLocalCommonSymbol()
885 "We only support writing log base-2 alignment format with XCOFF."); in emitXCOFFLocalCommonSymbol()
888 LabelSym->print(OS, MAI); in emitXCOFFLocalCommonSymbol()
890 CsectSym->print(OS, MAI); in emitXCOFFLocalCommonSymbol()
898 if (XSym->hasRename()) in emitXCOFFLocalCommonSymbol()
899 emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName()); in emitXCOFFLocalCommonSymbol()
907 OS << MAI->getGlobalDirective(); in emitXCOFFSymbolLinkageWithVisibility()
910 OS << MAI->getWeakDirective(); in emitXCOFFSymbolLinkageWithVisibility()
922 Symbol->print(OS, MAI); in emitXCOFFSymbolLinkageWithVisibility()
944 if (cast<MCSymbolXCOFF>(Symbol)->hasRename()) in emitXCOFFSymbolLinkageWithVisibility()
946 cast<MCSymbolXCOFF>(Symbol)->getSymbolTableName()); in emitXCOFFSymbolLinkageWithVisibility()
952 Name->print(OS, MAI); in emitXCOFFRenameDirective()
967 Symbol->print(OS, MAI); in emitXCOFFRefDirective()
978 Symbol->print(OS, MAI); in emitXCOFFExceptDirective()
988 // Start by emitting the .info pseudo-op and C_INFO symbol name. in emitXCOFFCInfoSym()
995 // Emit the 4-byte length of the metadata. in emitXCOFFCInfoSym()
1005 // assembly because the .info pseudo-op can only generate words of data. We in emitXCOFFCInfoSym()
1010 uint32_t PaddingSize = PaddedSize - MetadataSize; in emitXCOFFCInfoSym()
1015 // so we need multiple .info pseudo-ops. We choose a small number of words in emitXCOFFCInfoSym()
1016 // per pseudo-op to keep the assembly readable. in emitXCOFFCInfoSym()
1022 if (WordsBeforeNextDirective-- == 0) { in emitXCOFFCInfoSym()
1039 assert(PaddedSize - Index == WordSize); in emitXCOFFCInfoSym()
1041 ::memcpy(LastWord.data(), Metadata.data() + Index, MetadataSize - Index); in emitXCOFFCInfoSym()
1048 assert(MAI->hasDotTypeDotSizeDirective()); in emitELFSize()
1050 Symbol->print(OS, MAI); in emitELFSize()
1052 Value->print(OS, MAI); in emitELFSize()
1059 Symbol->print(OS, MAI); in emitCommonSymbol()
1062 if (MAI->getCOMMDirectiveAlignmentIsInBytes()) in emitCommonSymbol()
1071 if (XSym && XSym->hasRename()) in emitCommonSymbol()
1072 emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName()); in emitCommonSymbol()
1078 Symbol->print(OS, MAI); in emitLocalCommonSymbol()
1082 switch (MAI->getLCOMMDirectiveAlignmentType()) { in emitLocalCommonSymbol()
1100 Symbol->setFragment(&Section->getDummyFragment()); in emitZerofill()
1105 assert(Section->getVariant() == MCSection::SV_MachO && in emitZerofill()
1106 ".zerofill is a Mach-O specific directive"); in emitZerofill()
1107 // This is a mach-o specific directive. in emitZerofill()
1110 OS << MOSection->getSegmentName() << "," << MOSection->getName(); in emitZerofill()
1114 Symbol->print(OS, MAI); in emitZerofill()
1126 Symbol->setFragment(&Section->getDummyFragment()); in emitTBSSSymbol()
1130 assert(Section->getVariant() == MCSection::SV_MachO && in emitTBSSSymbol()
1131 ".zerofill is a Mach-O specific directive"); in emitTBSSSymbol()
1132 // This is a mach-o specific directive and section. in emitTBSSSymbol()
1135 Symbol->print(OS, MAI); in emitTBSSSymbol()
1148 for (const unsigned char C : make_range(BeginPtr, EndPtr - 1)) { in isPrintableString()
1178 for (const unsigned char C : make_range(BeginPtr, EndPtr - 1)) { in PrintByteList()
1182 printOneCharacter(*(EndPtr - 1)); in PrintByteList()
1201 if (MAI->hasPairedDoubleQuoteStringConstants()) { in PrintQuotedString()
1256 // use .ascii or a byte-list directive in emitBytes()
1257 if (MAI->getAscizDirective() && Data.back() == 0) { in emitBytes()
1258 OS << MAI->getAscizDirective(); in emitBytes()
1259 Data = Data.substr(0, Data.size() - 1); in emitBytes()
1260 } else if (LLVM_LIKELY(MAI->getAsciiDirective())) { in emitBytes()
1261 OS << MAI->getAsciiDirective(); in emitBytes()
1262 } else if (MAI->hasPairedDoubleQuoteStringConstants() && in emitBytes()
1266 assert(MAI->getPlainStringDirective() && in emitBytes()
1269 assert(MAI->getByteListDirective() && in emitBytes()
1273 OS << MAI->getPlainStringDirective(); in emitBytes()
1274 Data = Data.substr(0, Data.size() - 1); in emitBytes()
1276 OS << MAI->getByteListDirective(); in emitBytes()
1278 } else if (MAI->getByteListDirective()) { in emitBytes()
1279 OS << MAI->getByteListDirective(); in emitBytes()
1280 PrintByteList(Data, OS, MAI->characterLiteralSyntax()); in emitBytes()
1295 // Only single byte is provided or no ascii, asciz, or byte-list directives in emitBytes()
1298 TS->emitRawBytes(Data); in emitBytes()
1301 const char *Directive = MAI->getData8bitsDirective(); in emitBytes()
1314 OS << MAI->getData8bitsDirective(); in emitBinaryData()
1315 for (; J < EJ - 1; ++J) in emitBinaryData()
1343 case 1: Directive = MAI->getData8bitsDirective(); break; in emitValueImpl()
1344 case 2: Directive = MAI->getData16bitsDirective(); break; in emitValueImpl()
1345 case 4: Directive = MAI->getData32bitsDirective(); break; in emitValueImpl()
1346 case 8: Directive = MAI->getData64bitsDirective(); break; in emitValueImpl()
1351 if (!Value->evaluateAsAbsolute(IntValue)) in emitValueImpl()
1358 bool IsLittleEndian = MAI->isLittleEndian(); in emitValueImpl()
1360 unsigned Remaining = Size - Emitted; in emitValueImpl()
1363 unsigned EmissionSize = llvm::bit_floor(std::min(Remaining, Size - 1)); in emitValueImpl()
1367 IsLittleEndian ? Emitted : (Remaining - EmissionSize); in emitValueImpl()
1372 uint64_t Shift = 64 - EmissionSize * 8; in emitValueImpl()
1386 TS->emitValue(Value); in emitValueImpl()
1388 Value->print(OS, MAI); in emitValueImpl()
1395 if (Value->evaluateAsAbsolute(IntValue)) { in emitULEB128Value()
1400 Value->print(OS, MAI); in emitULEB128Value()
1406 if (Value->evaluateAsAbsolute(IntValue)) { in emitSLEB128Value()
1411 Value->print(OS, MAI); in emitSLEB128Value()
1416 assert(MAI->getDTPRel64Directive() != nullptr); in emitDTPRel64Value()
1417 OS << MAI->getDTPRel64Directive(); in emitDTPRel64Value()
1418 Value->print(OS, MAI); in emitDTPRel64Value()
1423 assert(MAI->getDTPRel32Directive() != nullptr); in emitDTPRel32Value()
1424 OS << MAI->getDTPRel32Directive(); in emitDTPRel32Value()
1425 Value->print(OS, MAI); in emitDTPRel32Value()
1430 assert(MAI->getTPRel64Directive() != nullptr); in emitTPRel64Value()
1431 OS << MAI->getTPRel64Directive(); in emitTPRel64Value()
1432 Value->print(OS, MAI); in emitTPRel64Value()
1437 assert(MAI->getTPRel32Directive() != nullptr); in emitTPRel32Value()
1438 OS << MAI->getTPRel32Directive(); in emitTPRel32Value()
1439 Value->print(OS, MAI); in emitTPRel32Value()
1444 assert(MAI->getGPRel64Directive() != nullptr); in emitGPRel64Value()
1445 OS << MAI->getGPRel64Directive(); in emitGPRel64Value()
1446 Value->print(OS, MAI); in emitGPRel64Value()
1451 assert(MAI->getGPRel32Directive() != nullptr); in emitGPRel32Value()
1452 OS << MAI->getGPRel32Directive(); in emitGPRel32Value()
1453 Value->print(OS, MAI); in emitGPRel32Value()
1464 if (const char *ZeroDirective = MAI->getZeroDirective()) { in emitFill()
1465 if (MAI->doesZeroDirectiveSupportNonZeroValue() || FillValue == 0) { in emitFill()
1475 "Cannot emit non-absolute expression lengths of fill."); in emitFill()
1477 OS << MAI->getData8bitsDirective() << (int)FillValue; in emitFill()
1501 if (MAI->useDotAlignForAlignment()) { in emitAlignmentDirective()
1503 report_fatal_error("Only power-of-two alignments are supported " in emitAlignmentDirective()
1511 // Some assemblers don't support non-power of two alignments, so we always in emitAlignmentDirective()
1547 // Non-power of two alignment. This is not widely supported by assemblers. in emitAlignmentDirective()
1577 if (MAI->getTextAlignFillValue()) in emitCodeAlignment()
1578 emitAlignmentDirective(Alignment.value(), MAI->getTextAlignFillValue(), 1, in emitCodeAlignment()
1589 Offset->print(OS, MAI); in emitValueToOffset()
1595 assert(MAI->hasSingleParameterDotFile()); in emitFileDirective()
1605 assert(MAI->hasFourStringsDotFile()); in emitFileDirective()
1652 OS << " md5 0x" << Checksum->digest(); in printDwarfFileDirective()
1677 !MAI->usesDwarfFileAndLocDirectives()) in tryEmitDwarfFileDirective()
1686 TS->emitDwarfFileDirective(OS1.str()); in tryEmitDwarfFileDirective()
1706 if (!MAI->usesDwarfFileAndLocDirectives()) in emitDwarfFile0Directive()
1715 TS->emitDwarfFileDirective(OS1.str()); in emitDwarfFile0Directive()
1720 void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line, in emitDwarfLocDirective() argument
1726 if (!MAI->usesDwarfFileAndLocDirectives()) { in emitDwarfLocDirective()
1728 // first one gets a line entry. in emitDwarfLocDirective()
1730 this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa, in emitDwarfLocDirective()
1735 OS << "\t.loc\t" << FileNo << " " << Line << " " << Column; in emitDwarfLocDirective()
1736 if (MAI->supportsExtendedDwarfLocDirective()) { in emitDwarfLocDirective()
1761 OS.PadToColumn(MAI->getCommentColumn()); in emitDwarfLocDirective()
1762 OS << MAI->getCommentString() << ' ' << FileName << ':' in emitDwarfLocDirective()
1763 << Line << ':' << Column; in emitDwarfLocDirective()
1766 this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa, in emitDwarfLocDirective()
1771 // Always use the zeroth line table, since asm syntax only supports one line in getDwarfLineTableSymbol()
1816 unsigned Line, unsigned Column, in emitCVLocDirective() argument
1823 OS << "\t.cv_loc\t" << FunctionId << " " << FileNo << " " << Line << " " in emitCVLocDirective()
1832 OS.PadToColumn(MAI->getCommentColumn()); in emitCVLocDirective()
1833 OS << MAI->getCommentString() << ' ' << FileName << ':' << Line << ':' in emitCVLocDirective()
1843 FnStart->print(OS, MAI); in emitCVLinetableDirective()
1845 FnEnd->print(OS, MAI); in emitCVLinetableDirective()
1847 this->MCStreamer::emitCVLinetableDirective(FunctionId, FnStart, FnEnd); in emitCVLinetableDirective()
1857 FnStartSym->print(OS, MAI); in emitCVInlineLinetableDirective()
1859 FnEndSym->print(OS, MAI); in emitCVInlineLinetableDirective()
1861 this->MCStreamer::emitCVInlineLinetableDirective( in emitCVInlineLinetableDirective()
1870 Range.first->print(OS, MAI); in PrintCVDefRangePrefix()
1872 Range.second->print(OS, MAI); in PrintCVDefRangePrefix()
1930 ProcSym->print(OS, MAI); in emitCVFPOData()
1935 assert(MAI->hasIdentDirective() && ".ident directive not supported"); in emitIdent()
1969 if (!MAI->useDwarfRegNumForCFI()) { in EmitRegisterName()
1975 MRI->getLLVMRegNum(Register, true)) { in EmitRegisterName()
1976 InstPrinter->printRegName(OS, *LLVMRegister); in EmitRegisterName()
2010 size_t e = Values.size() - 1; in PrintCFIEscape()
2052 Sym->print(OS, MAI); in emitCFIPersonality()
2059 Sym->print(OS, MAI); in emitCFILsda()
2168 Symbol->print(OS, MAI); in emitWinCFIStartProc()
2205 Sym->print(OS, MAI); in emitWinEHHandler()
2231 MCSection *TextSec = &CurFrame->Function->getSection(); in emitWinEHHandlerData()
2243 InstPrinter->printRegName(OS, Register); in emitWinCFIPushReg()
2252 InstPrinter->printRegName(OS, Register); in emitWinCFISetFrame()
2269 InstPrinter->printRegName(OS, Register); in emitWinCFISaveReg()
2279 InstPrinter->printRegName(OS, Register); in emitWinCFISaveXMM()
2304 From->getSymbol().print(OS, MAI); in emitCGProfileEntry()
2306 To->getSymbol().print(OS, MAI); in emitCGProfileEntry()
2324 // representation. We do this by making a per-bit map to the fixup item index, in AddEncodingComment()
2343 // high order halfword of a 32-bit Thumb2 instruction is emitted first. in AddEncodingComment()
2366 << char('A' + MapEntry - 1) << '\''; in AddEncodingComment()
2368 OS << char('A' + MapEntry - 1); in AddEncodingComment()
2373 for (unsigned j = 8; j--;) { in AddEncodingComment()
2377 if (MAI->isLittleEndian()) in AddEncodingComment()
2380 FixupBit = i * 8 + (7-j); in AddEncodingComment()
2384 OS << char('A' + MapEntry - 1); in AddEncodingComment()
2396 OS << " fixup " << char('A' + i) << " - " in AddEncodingComment()
2398 F.getValue()->print(OS, MAI); in AddEncodingComment()
2408 if (!MAI->usesDwarfFileAndLocDirectives()) in emitInstruction()
2410 // a line entry for any .loc directive that has been seen. in emitInstruction()
2423 getTargetStreamer()->prettyPrintAsm(*InstPrinter, 0, Inst, STI, OS); in emitInstruction()
2425 InstPrinter->printInst(&Inst, 0, "", STI, OS); in emitInstruction()
2447 OS << " " << FnSym->getName(); in emitPseudoProbe()
2478 Expr->print(OS, MAI); in emitRelocDirective()
2491 Sym->print(OS, MAI); in emitAddrsigSym()
2495 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
2509 // Now it is time to emit debug line sections if target doesn't support .loc in finishImpl()
2510 // and .line directives. in finishImpl()
2511 if (!MAI->usesDwarfFileAndLocDirectives()) { in finishImpl()
2516 // Emit the label for the line table, if requested - since the rest of the in finishImpl()
2517 // line table will be defined by .loc/.file directives, and not emitted in finishImpl()
2521 assert(Tables.size() == 1 && "asm output only supports one line table"); in finishImpl()
2522 if (auto *Label = Tables.begin()->second.getLabel()) { in finishImpl()
2523 switchSection(getContext().getObjectFileInfo()->getDwarfLineSection()); in finishImpl()
2536 if (!MAI->needsDwarfSectionSizeInHeader()) in emitDwarfUnitLength()
2549 if (!MAI->needsDwarfSectionSizeInHeader()) in emitDwarfUnitLength()
2562 if (!MAI->needsDwarfSectionSizeInHeader()) { in emitDwarfLineStartLabel()
2583 // If the targets write the raw debug line data for assembly output (We can in emitDwarfLineEndEntry()
2588 assert(!MAI->usesDwarfFileAndLocDirectives() && in emitDwarfLineEndEntry()
2594 // the explicit sections and -ffunction-sections when we try to generate or in emitDwarfLineEndEntry()
2596 MCSection *TextSection = Ctx.getObjectFileInfo()->getTextSection(); in emitDwarfLineEndEntry()
2597 assert(TextSection->hasEnded() && ".text section is not end!"); in emitDwarfLineEndEntry()
2599 MCSymbol *SectionEnd = TextSection->getEndSymbol(Ctx); in emitDwarfLineEndEntry()
2602 AsmInfo->getCodePointerSize()); in emitDwarfLineEndEntry()
2605 // Generate DWARF line sections for assembly mode without .loc/.file
2610 assert(!MAI->usesDwarfFileAndLocDirectives() && in emitDwarfAdvanceLineAddr()
2611 ".loc/.file don't need raw data in debug line section!"); in emitDwarfAdvanceLineAddr()
2614 AddComment("Set address to " + Label->getName()); in emitDwarfAdvanceLineAddr()
2637 // Advance line. in emitDwarfAdvanceLineAddr()
2638 AddComment("Advance line " + Twine(LineDelta)); in emitDwarfAdvanceLineAddr()
2645 // Emit section end. This is used to tell the debug line section where the end in doFinalizationAtSectionEnd()
2646 // is for a text section if we don't use .loc to represent the debug line. in doFinalizationAtSectionEnd()
2647 if (MAI->usesDwarfFileAndLocDirectives()) in doFinalizationAtSectionEnd()
2652 MCSymbol *Sym = getCurrentSectionOnly()->getEndSymbol(getContext()); in doFinalizationAtSectionEnd()
2654 if (!Sym->isInSection()) in doFinalizationAtSectionEnd()