forked from OSchip/llvm-project
[XCOFF] handle string constants generation for AIX
This follows https://www.ibm.com/docs/en/aix/7.2?topic=constants-string Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D101280
This commit is contained in:
parent
26e916334e
commit
a95473c563
|
@ -357,9 +357,15 @@ protected:
|
|||
LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
|
||||
|
||||
/// True if the target only has basename for .file directive. False if the
|
||||
/// target also needs the directory along with the basename. Default to true.
|
||||
/// target also needs the directory along with the basename. Defaults to true.
|
||||
bool HasBasenameOnlyForFileDirective = true;
|
||||
|
||||
/// True if the target represents string constants as mostly raw characters in
|
||||
/// paired double quotation with paired double quotation marks as the escape
|
||||
/// mechanism to represent a double quotation mark within the string. Defaults
|
||||
/// to false.
|
||||
bool HasPairedDoubleQuoteStringConstants = false;
|
||||
|
||||
// True if the target allows .align directives on functions. This is true for
|
||||
// most targets, so defaults to true.
|
||||
bool HasFunctionAlignment = true;
|
||||
|
@ -697,6 +703,9 @@ public:
|
|||
bool hasBasenameOnlyForFileDirective() const {
|
||||
return HasBasenameOnlyForFileDirective;
|
||||
}
|
||||
bool hasPairedDoubleQuoteStringConstants() const {
|
||||
return HasPairedDoubleQuoteStringConstants;
|
||||
}
|
||||
bool hasFunctionAlignment() const { return HasFunctionAlignment; }
|
||||
bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
|
||||
bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
|
||||
|
|
|
@ -20,6 +20,11 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
|
|||
IsLittleEndian = false;
|
||||
HasVisibilityOnlyWithLinkage = true;
|
||||
HasBasenameOnlyForFileDirective = false;
|
||||
|
||||
// For XCOFF, string constant consists of any number of characters enclosed in
|
||||
// "" (double quotation marks).
|
||||
HasPairedDoubleQuoteStringConstants = true;
|
||||
|
||||
PrivateGlobalPrefix = "L..";
|
||||
PrivateLabelPrefix = "L..";
|
||||
SupportsQuotedNames = false;
|
||||
|
|
|
@ -60,6 +60,13 @@ class MCAsmStreamer final : public MCStreamer {
|
|||
unsigned UseDwarfDirectory : 1;
|
||||
|
||||
void EmitRegisterName(int64_t Register);
|
||||
void PrintQuotedString(StringRef Data, raw_ostream &OS) const;
|
||||
void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
||||
StringRef Filename,
|
||||
Optional<MD5::MD5Result> Checksum,
|
||||
Optional<StringRef> Source,
|
||||
bool UseDwarfDirectory,
|
||||
raw_svector_ostream &OS) const;
|
||||
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
|
||||
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
|
||||
|
||||
|
@ -1039,33 +1046,53 @@ static void PrintByteList(StringRef Data, raw_ostream &OS,
|
|||
llvm_unreachable("Invalid AsmCharLiteralSyntax value!");
|
||||
}
|
||||
|
||||
static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
|
||||
void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) const {
|
||||
OS << '"';
|
||||
|
||||
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
|
||||
unsigned char C = Data[i];
|
||||
if (C == '"' || C == '\\') {
|
||||
OS << '\\' << (char)C;
|
||||
continue;
|
||||
if (MAI->hasPairedDoubleQuoteStringConstants()) {
|
||||
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
|
||||
unsigned char C = Data[i];
|
||||
if (C == '"')
|
||||
OS << "\"\"";
|
||||
else
|
||||
OS << (char)C;
|
||||
}
|
||||
} else {
|
||||
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
|
||||
unsigned char C = Data[i];
|
||||
if (C == '"' || C == '\\') {
|
||||
OS << '\\' << (char)C;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isPrint((unsigned char)C)) {
|
||||
OS << (char)C;
|
||||
continue;
|
||||
}
|
||||
if (isPrint((unsigned char)C)) {
|
||||
OS << (char)C;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (C) {
|
||||
case '\b': OS << "\\b"; break;
|
||||
case '\f': OS << "\\f"; break;
|
||||
case '\n': OS << "\\n"; break;
|
||||
case '\r': OS << "\\r"; break;
|
||||
case '\t': OS << "\\t"; break;
|
||||
switch (C) {
|
||||
case '\b':
|
||||
OS << "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
OS << "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
OS << "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
OS << "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
OS << "\\t";
|
||||
break;
|
||||
default:
|
||||
OS << '\\';
|
||||
OS << toOctal(C >> 6);
|
||||
OS << toOctal(C >> 3);
|
||||
OS << toOctal(C >> 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1390,12 +1417,10 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename) {
|
|||
EmitEOL();
|
||||
}
|
||||
|
||||
static void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
|
||||
StringRef Filename,
|
||||
Optional<MD5::MD5Result> Checksum,
|
||||
Optional<StringRef> Source,
|
||||
bool UseDwarfDirectory,
|
||||
raw_svector_ostream &OS) {
|
||||
void MCAsmStreamer::printDwarfFileDirective(
|
||||
unsigned FileNo, StringRef Directory, StringRef Filename,
|
||||
Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source,
|
||||
bool UseDwarfDirectory, raw_svector_ostream &OS) const {
|
||||
SmallString<128> FullPathName;
|
||||
|
||||
if (!UseDwarfDirectory && !Directory.empty()) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
|
||||
; RUN: | FileCheck %s
|
||||
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
|
||||
; RUN: | FileCheck %s
|
||||
|
||||
; CHECK: .file "1""2.c"
|
||||
|
||||
source_filename = "1\222.c"
|
|
@ -0,0 +1,8 @@
|
|||
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
|
||||
; RUN: | FileCheck %s
|
||||
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
|
||||
; RUN: | FileCheck %s
|
||||
|
||||
; CHECK: .file "1'2.c"
|
||||
|
||||
source_filename = "1'2.c"
|
Loading…
Reference in New Issue