Skip to content

Commit 5685f33

Browse files
mateoconlechugaSightem
authored andcommitted
[z80] fix gas output for string escape sequences
1 parent 5ea5cab commit 5685f33

1 file changed

Lines changed: 67 additions & 38 deletions

File tree

llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,69 +24,92 @@ static cl::opt<bool> EscapeNonPrint(
2424
"Avoid outputting non-printable ascii characters to assembly files."),
2525
cl::Hidden);
2626

27+
cl::opt<bool> Z80GasStyle(
28+
"z80-gas-style",
29+
cl::desc("Use GAS style assembly syntax instead of FASMG style."),
30+
cl::NotHidden);
31+
2732
void Z80MCAsmInfoELF::anchor() { }
2833

2934
Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) {
3035
bool Is16Bit = T.isArch16Bit() || T.getEnvironment() == Triple::CODE16;
3136
CodePointerSize = CalleeSaveStackSlotSize = Is16Bit ? 2 : 3;
3237
MaxInstLength = 6;
33-
DollarIsPC = true;
34-
SeparatorString = nullptr;
38+
39+
// Common to both GAS and fasmg
3540
CommentString = ";";
36-
PrivateGlobalPrefix = PrivateLabelPrefix = "";
37-
Code16Directive = "assume\tadl = 0";
38-
Code24Directive = "assume\tadl = 1";
41+
AscizDirective = nullptr;
3942
Code32Directive = Code64Directive = nullptr;
43+
UseIntegratedAssembler = false;
4044
AssemblerDialect = !Is16Bit;
41-
SupportsQuotedNames = false;
42-
ZeroDirective = AscizDirective = nullptr;
43-
BlockSeparator = " dup ";
44-
AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t";
45-
NumberLiteralSyntax = ANLS_PlainDecimal;
46-
CharacterLiteralSyntax = ACLS_SingleQuotes;
47-
HasPairedDoubleQuoteStringConstants = true;
48-
HasBackslashEscapesInStringConstants = false;
49-
StringConstantsEscapeNonPrint = EscapeNonPrint;
50-
StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null
51-
Data16bitsDirective = "\tdw\t";
52-
Data24bitsDirective = "\tdl\t";
53-
Data32bitsDirective = "\tdd\t";
54-
Data64bitsDirective = "\tdq\t";
55-
DataULEB128Directive = "\tuleb128\t";
56-
DataSLEB128Directive = "\tsleb128\t";
57-
SectionDirective = "\tsection\t";
58-
AlwaysChangeSection = true;
59-
GlobalDirective = "\tpublic\t";
60-
LGloblDirective = "\tprivate\t";
61-
SetDirective = "\tlabel\t";
62-
SetSeparator = " at ";
6345
HasFunctionAlignment = false;
64-
HasDotTypeDotSizeDirective = false;
65-
IdentDirective = "\tident\t";
66-
WeakDirective = "\tweak\t";
67-
UseIntegratedAssembler = false;
68-
UseLogicalShr = false;
69-
HasSingleParameterDotFile = false;
70-
SupportsDebugInformation = SupportsCFI = true;
7146
ExceptionsType = ExceptionHandling::SjLj;
72-
DwarfFileDirective = "\tfile\t";
73-
DwarfLocDirective = "\tloc\t";
74-
DwarfCFIDirectivePrefix = "\tcfi_";
47+
48+
if (Z80GasStyle) {
49+
Code16Directive = ".assume\tADL = 0";
50+
Code24Directive = ".assume\tADL = 1";
51+
AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t";
52+
Data16bitsDirective = "\tdw\t";
53+
Data24bitsDirective = "\td24\t";
54+
Data32bitsDirective = "\td32\t";
55+
StringConstantsEscapeNonPrint = true;
56+
StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null
57+
} else {
58+
Code16Directive = "assume\tadl = 0";
59+
Code24Directive = "assume\tadl = 1";
60+
DollarIsPC = true;
61+
SeparatorString = nullptr;
62+
PrivateGlobalPrefix = PrivateLabelPrefix = "";
63+
SupportsQuotedNames = false;
64+
ZeroDirective = nullptr;
65+
BlockSeparator = " dup ";
66+
AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t";
67+
NumberLiteralSyntax = ANLS_PlainDecimal;
68+
CharacterLiteralSyntax = ACLS_SingleQuotes;
69+
HasPairedDoubleQuoteStringConstants = true;
70+
HasBackslashEscapesInStringConstants = false;
71+
StringConstantsEscapeNonPrint = EscapeNonPrint;
72+
StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null
73+
Data16bitsDirective = "\tdw\t";
74+
Data24bitsDirective = "\tdl\t";
75+
Data32bitsDirective = "\tdd\t";
76+
Data64bitsDirective = "\tdq\t";
77+
DataULEB128Directive = "\tuleb128\t";
78+
DataSLEB128Directive = "\tsleb128\t";
79+
SectionDirective = "\tsection\t";
80+
AlwaysChangeSection = true;
81+
GlobalDirective = "\tpublic\t";
82+
LGloblDirective = "\tprivate\t";
83+
SetDirective = "\tlabel\t";
84+
SetSeparator = " at ";
85+
HasDotTypeDotSizeDirective = false;
86+
IdentDirective = "\tident\t";
87+
WeakDirective = "\tweak\t";
88+
UseLogicalShr = false;
89+
HasSingleParameterDotFile = false;
90+
SupportsDebugInformation = SupportsCFI = true;
91+
DwarfFileDirective = "\tfile\t";
92+
DwarfLocDirective = "\tloc\t";
93+
DwarfCFIDirectivePrefix = "\tcfi_";
94+
}
7595
}
7696

7797
MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
7898
return nullptr;
7999
}
80100

81101
bool Z80MCAsmInfoELF::isAcceptableChar(char C) const {
82-
return MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^';
102+
return Z80GasStyle ? MCAsmInfo::isAcceptableChar(C) : (MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^');
83103
}
84104

85105
bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
86106
return false;
87107
}
88108

89109
const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
110+
if (Z80GasStyle) {
111+
return MCAsmInfoELF::getBlockDirective(Size);
112+
}
90113
switch (Size) {
91114
default: return nullptr;
92115
case 1: return "\tdb\t";
@@ -97,6 +120,9 @@ const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
97120
}
98121

99122
const char *Z80MCAsmInfoELF::getUnaryOperator(unsigned Opc) const {
123+
if (Z80GasStyle) {
124+
return MCAsmInfoELF::getUnaryOperator(Opc);
125+
}
100126
switch (Opc) {
101127
default: llvm_unreachable("unknown opcode");
102128
case MCUnaryExpr::LNot: return "~";
@@ -107,6 +133,9 @@ const char *Z80MCAsmInfoELF::getUnaryOperator(unsigned Opc) const {
107133
}
108134

109135
const char *Z80MCAsmInfoELF::getBinaryOperator(unsigned Opc) const {
136+
if (Z80GasStyle) {
137+
return MCAsmInfoELF::getBinaryOperator(Opc);
138+
}
110139
switch (Opc) {
111140
default: llvm_unreachable("unknown opcode");
112141
case MCBinaryExpr::Add: return "+";

0 commit comments

Comments
 (0)