mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
d4257740dd
This CL changes the asm syntax for section flags, making them more like ELF (previously "passive" was the only option). Now we also allow "G" to designate COMDAT group sections. In these sections we set the appropriate comdat flag on function symbols, and also avoid auto-creating a new section for them. This also adds asm-based tests for the changes D92691 to go along with the direct-to-object tests. Differential Revision: https://reviews.llvm.org/D92952 This is a reland of rG4564553b8d8a with a fix to the lit pipeline in llvm/test/MC/WebAssembly/comdat.ll
104 lines
2.6 KiB
C++
104 lines
2.6 KiB
C++
//===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/MC/MCSectionWasm.h"
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
#include "llvm/MC/MCExpr.h"
|
|
#include "llvm/MC/MCSymbol.h"
|
|
#include "llvm/MC/MCSymbolWasm.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
// Decides whether a '.section' directive
|
|
// should be printed before the section name.
|
|
bool MCSectionWasm::shouldOmitSectionDirective(StringRef Name,
|
|
const MCAsmInfo &MAI) const {
|
|
return MAI.shouldOmitSectionDirective(Name);
|
|
}
|
|
|
|
static void printName(raw_ostream &OS, StringRef Name) {
|
|
if (Name.find_first_not_of("0123456789_."
|
|
"abcdefghijklmnopqrstuvwxyz"
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
|
|
OS << Name;
|
|
return;
|
|
}
|
|
OS << '"';
|
|
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 << '"';
|
|
}
|
|
|
|
void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
|
|
raw_ostream &OS,
|
|
const MCExpr *Subsection) const {
|
|
|
|
if (shouldOmitSectionDirective(getName(), MAI)) {
|
|
OS << '\t' << getName();
|
|
if (Subsection) {
|
|
OS << '\t';
|
|
Subsection->print(OS, &MAI);
|
|
}
|
|
OS << '\n';
|
|
return;
|
|
}
|
|
|
|
OS << "\t.section\t";
|
|
printName(OS, getName());
|
|
OS << ",\"";
|
|
|
|
if (IsPassive)
|
|
OS << "p";
|
|
if (Group)
|
|
OS << "G";
|
|
|
|
OS << '"';
|
|
|
|
OS << ',';
|
|
|
|
// If comment string is '@', e.g. as on ARM - use '%' instead
|
|
if (MAI.getCommentString()[0] == '@')
|
|
OS << '%';
|
|
else
|
|
OS << '@';
|
|
|
|
// TODO: Print section type.
|
|
|
|
if (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';
|
|
}
|
|
}
|
|
|
|
bool MCSectionWasm::UseCodeAlign() const { return false; }
|
|
|
|
bool MCSectionWasm::isVirtualSection() const { return false; }
|