/// Measure the specified inline asm to determine an approximation of its /// length. /// Comments (which run till the next SeparatorString or newline) do not /// count as an instruction. /// Any other non-whitespace text is considered an instruction, with /// multiple instructions separated by SeparatorString or newlines. /// Variable-length instructions are not handled here; this function /// may be overloaded in the target code to do that. /// We implement the special case of the .space directive taking only an /// integer argument, which is the size in bytes. This is used for creating /// inline code spacing for testing purposes using inline assembly. /// unsigned Mips16InstrInfo::getInlineAsmLength(const char *Str, const MCAsmInfo &MAI) const { // Count the number of instructions in the asm. bool atInsnStart = true; unsigned Length = 0; for (; *Str; ++Str) { if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), strlen(MAI.getSeparatorString())) == 0) atInsnStart = true; if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) { if (strncmp(Str, ".space", 6)==0) { char *EStr; int Sz; Sz = strtol(Str+6, &EStr, 10); while (isspace(*EStr)) ++EStr; if (*EStr=='\0') { DEBUG(dbgs() << "parsed .space " << Sz << '\n'); return Sz; } } Length += MAI.getMaxInstLength(); atInsnStart = false; } if (atInsnStart && strncmp(Str, MAI.getCommentString(), strlen(MAI.getCommentString())) == 0) atInsnStart = false; } return Length; }
/// Measure the specified inline asm to determine an approximation of its /// length. /// Comments (which run till the next SeparatorString or newline) do not /// count as an instruction. /// Any other non-whitespace text is considered an instruction, with /// multiple instructions separated by SeparatorString or newlines. /// Variable-length instructions are not handled here; this function /// may be overloaded in the target code to do that. unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, const MCAsmInfo &MAI) const { // Count the number of instructions in the asm. bool atInsnStart = true; unsigned Length = 0; for (; *Str; ++Str) { if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), strlen(MAI.getSeparatorString())) == 0) atInsnStart = true; if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) { Length += MAI.getMaxInstLength(); atInsnStart = false; } if (atInsnStart && strncmp(Str, MAI.getCommentString(), strlen(MAI.getCommentString())) == 0) atInsnStart = false; } return Length; }
/// Measure the specified inline asm to determine an approximation of its /// length. /// Comments (which run till the next SeparatorString or newline) do not /// count as an instruction. /// Any other non-whitespace text is considered an instruction, with /// multiple instructions separated by SeparatorString or newlines. /// Variable-length instructions are not handled here; this function /// may be overloaded in the target code to do that. unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, const MCAsmInfo &MAI) const { // Count the number of instructions in the asm. bool atInsnStart = true; unsigned InstCount = 0; for (; *Str; ++Str) { if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), strlen(MAI.getSeparatorString())) == 0) { atInsnStart = true; } else if (strncmp(Str, MAI.getCommentString(), strlen(MAI.getCommentString())) == 0) { // Stop counting as an instruction after a comment until the next // separator. atInsnStart = false; } if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) { ++InstCount; atInsnStart = false; } } return InstCount * MAI.getMaxInstLength(); }
AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) { AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); }
AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) { CurPtr = nullptr; isAtStartOfLine = true; AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); }
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const { if (ShouldOmitSectionDirective(SectionName, MAI)) { OS << '\t' << getSectionName(); if (Subsection) { OS << '\t'; Subsection->print(OS, &MAI); } OS << '\n'; return; } OS << "\t.section\t"; printName(OS, getSectionName()); // Handle the weird solaris syntax if desired. if (MAI.usesSunStyleELFSectionSwitchSyntax() && !(Flags & ELF::SHF_MERGE)) { if (Flags & ELF::SHF_ALLOC) OS << ",#alloc"; if (Flags & ELF::SHF_EXECINSTR) OS << ",#execinstr"; if (Flags & ELF::SHF_WRITE) OS << ",#write"; if (Flags & ELF::SHF_EXCLUDE) OS << ",#exclude"; if (Flags & ELF::SHF_TLS) OS << ",#tls"; OS << '\n'; return; } OS << ",\""; if (Flags & ELF::SHF_ALLOC) OS << 'a'; if (Flags & ELF::SHF_EXCLUDE) OS << 'e'; if (Flags & ELF::SHF_EXECINSTR) OS << 'x'; if (Flags & ELF::SHF_GROUP) OS << 'G'; if (Flags & ELF::SHF_WRITE) OS << 'w'; if (Flags & ELF::SHF_MERGE) OS << 'M'; if (Flags & ELF::SHF_STRINGS) OS << 'S'; if (Flags & ELF::SHF_TLS) OS << 'T'; // If there are target-specific flags, print them. if (Flags & ELF::XCORE_SHF_CP_SECTION) OS << 'c'; if (Flags & ELF::XCORE_SHF_DP_SECTION) OS << 'd'; OS << '"'; OS << ','; // If comment string is '@', e.g. as on ARM - use '%' instead if (MAI.getCommentString()[0] == '@') OS << '%'; else OS << '@'; if (Type == ELF::SHT_INIT_ARRAY) OS << "init_array"; else if (Type == ELF::SHT_FINI_ARRAY) OS << "fini_array"; else if (Type == ELF::SHT_PREINIT_ARRAY) OS << "preinit_array"; else if (Type == ELF::SHT_NOBITS) OS << "nobits"; else if (Type == ELF::SHT_NOTE) OS << "note"; else if (Type == ELF::SHT_PROGBITS) OS << "progbits"; if (EntrySize) { assert(Flags & ELF::SHF_MERGE); OS << "," << EntrySize; } if (Flags & ELF::SHF_GROUP) { OS << ","; printName(OS, Group->getName()); OS << ",comdat"; } if (isUnique()) OS << ",unique," << UniqueID; OS << '\n'; if (Subsection) { OS << "\t.subsection\t"; Subsection->print(OS, &MAI); OS << '\n'; } }
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const { if (ShouldOmitSectionDirective(SectionName, MAI)) { OS << '\t' << getSectionName() << '\n'; return; } StringRef name = getSectionName(); OS << "\t.section\t\""; for (const char *b = name.begin(), *e = name.end(); b < e; ++b) { if (*b == '"') // Unquoted " OS << "\\\""; else if (*b != '\\') // Neither " or backslash OS << *b; else if (b + 1 == e) // Trailing backslash OS << "\\\\"; else { OS << b[0] << b[1]; // Quoted character ++b; } } OS << '"'; // Handle the weird solaris syntax if desired. if (MAI.usesSunStyleELFSectionSwitchSyntax() && !(Flags & ELF::SHF_MERGE)) { if (Flags & ELF::SHF_ALLOC) OS << ",#alloc"; if (Flags & ELF::SHF_EXECINSTR) OS << ",#execinstr"; if (Flags & ELF::SHF_WRITE) OS << ",#write"; if (Flags & ELF::SHF_TLS) OS << ",#tls"; OS << '\n'; return; } OS << ",\""; if (Flags & ELF::SHF_ALLOC) OS << 'a'; if (Flags & ELF::SHF_EXECINSTR) OS << 'x'; if (Flags & ELF::SHF_GROUP) OS << 'G'; if (Flags & ELF::SHF_WRITE) OS << 'w'; if (Flags & ELF::SHF_MERGE) OS << 'M'; if (Flags & ELF::SHF_STRINGS) OS << 'S'; if (Flags & ELF::SHF_TLS) OS << 'T'; // If there are target-specific flags, print them. if (Flags & ELF::XCORE_SHF_CP_SECTION) OS << 'c'; if (Flags & ELF::XCORE_SHF_DP_SECTION) OS << 'd'; OS << '"'; OS << ','; // If comment string is '@', e.g. as on ARM - use '%' instead if (MAI.getCommentString()[0] == '@') OS << '%'; else OS << '@'; if (Type == ELF::SHT_INIT_ARRAY) OS << "init_array"; else if (Type == ELF::SHT_FINI_ARRAY) OS << "fini_array"; else if (Type == ELF::SHT_PREINIT_ARRAY) OS << "preinit_array"; else if (Type == ELF::SHT_NOBITS) OS << "nobits"; else if (Type == ELF::SHT_NOTE) OS << "note"; else if (Type == ELF::SHT_PROGBITS) OS << "progbits"; if (EntrySize) { assert(Flags & ELF::SHF_MERGE); OS << "," << EntrySize; } if (Flags & ELF::SHF_GROUP) OS << "," << Group->getName() << ",comdat"; OS << '\n'; }
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const { if (ShouldOmitSectionDirective(SectionName, MAI)) { OS << '\t' << getSectionName(); if (Subsection) { OS << '\t'; Subsection->print(OS, &MAI); } OS << '\n'; return; } OS << "\t.section\t"; printName(OS, getSectionName()); // Handle the weird solaris syntax if desired. if (MAI.usesSunStyleELFSectionSwitchSyntax() && !(Flags & ELF::SHF_MERGE)) { if (Flags & ELF::SHF_ALLOC) OS << ",#alloc"; if (Flags & ELF::SHF_EXECINSTR) OS << ",#execinstr"; if (Flags & ELF::SHF_WRITE) OS << ",#write"; if (Flags & ELF::SHF_EXCLUDE) OS << ",#exclude"; if (Flags & ELF::SHF_TLS) OS << ",#tls"; OS << '\n'; return; } OS << ",\""; if (Flags & ELF::SHF_ALLOC) OS << 'a'; if (Flags & ELF::SHF_EXCLUDE) OS << 'e'; if (Flags & ELF::SHF_EXECINSTR) OS << 'x'; if (Flags & ELF::SHF_GROUP) OS << 'G'; if (Flags & ELF::SHF_WRITE) OS << 'w'; if (Flags & ELF::SHF_MERGE) OS << 'M'; if (Flags & ELF::SHF_STRINGS) OS << 'S'; if (Flags & ELF::SHF_TLS) OS << 'T'; if (Flags & ELF::SHF_LINK_ORDER) OS << 'o'; // If there are target-specific flags, print them. Triple::ArchType Arch = T.getArch(); if (Arch == Triple::xcore) { if (Flags & ELF::XCORE_SHF_CP_SECTION) OS << 'c'; if (Flags & ELF::XCORE_SHF_DP_SECTION) OS << 'd'; } else if (T.isARM() || T.isThumb()) { if (Flags & ELF::SHF_ARM_PURECODE) OS << 'y'; } OS << '"'; OS << ','; // If comment string is '@', e.g. as on ARM - use '%' instead if (MAI.getCommentString()[0] == '@') OS << '%'; else OS << '@'; if (Type == ELF::SHT_INIT_ARRAY) OS << "init_array"; else if (Type == ELF::SHT_FINI_ARRAY) OS << "fini_array"; else if (Type == ELF::SHT_PREINIT_ARRAY) OS << "preinit_array"; else if (Type == ELF::SHT_NOBITS) OS << "nobits"; else if (Type == ELF::SHT_NOTE) OS << "note"; else if (Type == ELF::SHT_PROGBITS) OS << "progbits"; else if (Type == ELF::SHT_X86_64_UNWIND) OS << "unwind"; else if (Type == ELF::SHT_MIPS_DWARF) // Print hex value of the flag while we do not have // any standard symbolic representation of the flag. OS << "0x7000001e"; else if (Type == ELF::SHT_LLVM_ODRTAB) OS << "llvm_odrtab"; else if (Type == ELF::SHT_LLVM_LINKER_OPTIONS) OS << "llvm_linker_options"; else if (Type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE) OS << "llvm_call_graph_profile"; else report_fatal_error("unsupported type 0x" + Twine::utohexstr(Type) + " for section " + getSectionName()); if (EntrySize) { assert(Flags & ELF::SHF_MERGE); OS << "," << EntrySize; } if (Flags & ELF::SHF_GROUP) { OS << ","; printName(OS, Group->getName()); OS << ",comdat"; } if (Flags & ELF::SHF_LINK_ORDER) { assert(AssociatedSymbol); OS << ","; printName(OS, AssociatedSymbol->getName()); } if (isUnique()) OS << ",unique," << UniqueID; OS << '\n'; if (Subsection) { OS << "\t.subsection\t"; Subsection->print(OS, &MAI); OS << '\n'; } }
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const { if (ShouldOmitSectionDirective(SectionName.c_str(), MAI)) { OS << '\t' << getSectionName() << '\n'; return; } OS << "\t.section\t" << getSectionName(); // Handle the weird solaris syntax if desired. if (MAI.usesSunStyleELFSectionSwitchSyntax() && !(Flags & MCSectionELF::SHF_MERGE)) { if (Flags & MCSectionELF::SHF_ALLOC) OS << ",#alloc"; if (Flags & MCSectionELF::SHF_EXECINSTR) OS << ",#execinstr"; if (Flags & MCSectionELF::SHF_WRITE) OS << ",#write"; if (Flags & MCSectionELF::SHF_TLS) OS << ",#tls"; } else { OS << ",\""; if (Flags & MCSectionELF::SHF_ALLOC) OS << 'a'; if (Flags & MCSectionELF::SHF_EXECINSTR) OS << 'x'; if (Flags & MCSectionELF::SHF_WRITE) OS << 'w'; if (Flags & MCSectionELF::SHF_MERGE) OS << 'M'; if (Flags & MCSectionELF::SHF_STRINGS) OS << 'S'; if (Flags & MCSectionELF::SHF_TLS) OS << 'T'; // If there are target-specific flags, print them. if (Flags & ~MCSectionELF::TARGET_INDEP_SHF) PrintTargetSpecificSectionFlags(MAI, OS); OS << '"'; if (ShouldPrintSectionType(Type)) { OS << ','; // If comment string is '@', e.g. as on ARM - use '%' instead if (MAI.getCommentString()[0] == '@') OS << '%'; else OS << '@'; if (Type == MCSectionELF::SHT_INIT_ARRAY) OS << "init_array"; else if (Type == MCSectionELF::SHT_FINI_ARRAY) OS << "fini_array"; else if (Type == MCSectionELF::SHT_PREINIT_ARRAY) OS << "preinit_array"; else if (Type == MCSectionELF::SHT_NOBITS) OS << "nobits"; else if (Type == MCSectionELF::SHT_PROGBITS) OS << "progbits"; if (getKind().isMergeable1ByteCString()) { OS << ",1"; } else if (getKind().isMergeable2ByteCString()) { OS << ",2"; } else if (getKind().isMergeable4ByteCString() || getKind().isMergeableConst4()) { OS << ",4"; } else if (getKind().isMergeableConst8()) { OS << ",8"; } else if (getKind().isMergeableConst16()) { OS << ",16"; } } } OS << '\n'; }
static bool isAsmComment(const char *Str, const MCAsmInfo &MAI) { return strncmp(Str, MAI.getCommentString().data(), MAI.getCommentString().size()) == 0; }