Skip to content

Commit d52e445

Browse files
committed
Add option for GAS-style directives
1 parent c74f71c commit d52e445

File tree

2 files changed

+72
-54
lines changed

2 files changed

+72
-54
lines changed

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

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

27+
// TODO: Put this somewhere more appropriate for a global
28+
cl::opt<bool> GasStyle(
29+
"z80-gas-style",
30+
cl::desc("Use GAS style assembly syntax instead of FASMG style."),
31+
cl::NotHidden);
32+
2733
void Z80MCAsmInfoELF::anchor() { }
2834

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

7790
MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
@@ -89,10 +102,10 @@ bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
89102
const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
90103
switch (Size) {
91104
default: return nullptr;
92-
case 1: return "\tdb\t";
93-
case 2: return "\tdw\t";
94-
case 3: return "\tdl\t";
95-
case 4: return "\tdd\t";
105+
case 1: return GasStyle ? "\t.byte" : "\tdb\t";
106+
case 2: return GasStyle ? "\t.short" : "\tdw\t";
107+
case 3: return GasStyle ? "\t.long" : "\tdl\t";
108+
case 4: return GasStyle ? "\t.quad" : "\tdd\t";
96109
}
97110
}
98111

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include "Z80TargetStreamer.h"
1515
#include "llvm/MC/MCContext.h"
1616
#include "llvm/MC/MCSymbol.h"
17+
#include "llvm/Support/CommandLine.h"
1718
#include "llvm/Support/FormattedStream.h"
1819

1920
using namespace llvm;
2021

22+
extern cl::opt<bool> GasStyle;
23+
2124
Z80TargetStreamer::Z80TargetStreamer(MCStreamer &S)
2225
: MCTargetStreamer(S) {}
2326

@@ -32,34 +35,36 @@ void Z80TargetAsmStreamer::emitLabel(MCSymbol *Symbol) {
3235

3336
void Z80TargetAsmStreamer::emitAlign(Align Alignment) {
3437
if (auto Mask = Alignment.value() - 1)
35-
OS << "\trb\t($$ - $) and " << Mask << '\n';
38+
GasStyle ? OS << "\t.skip\t($$ - $) and " << Mask << '\n' : OS << "\trb\t($$ - $) and " << Mask << '\n';
3639
}
3740

3841
void Z80TargetAsmStreamer::emitBlock(uint64_t NumBytes) {
3942
if (NumBytes)
40-
OS << "\trb\t" << NumBytes << '\n';
43+
GasStyle ? OS << "\t.skip\t" << NumBytes << '\n' : OS << "\trb\t" << NumBytes << '\n';
4144
}
4245

4346
void Z80TargetAsmStreamer::emitLocal(MCSymbol *Symbol) {
44-
OS << "\tprivate\t";
45-
Symbol->print(OS, MAI);
46-
OS << '\n';
47+
if (!GasStyle) {
48+
OS << "\tprivate\t";
49+
Symbol->print(OS, MAI);
50+
OS << '\n';
51+
}
4752
}
4853

4954
void Z80TargetAsmStreamer::emitWeakGlobal(MCSymbol *Symbol) {
50-
OS << "\tweak\t";
55+
GasStyle ? OS << "\t.weak\t" : OS << "\tweak\t";
5156
Symbol->print(OS, MAI);
5257
OS << '\n';
5358
}
5459

5560
void Z80TargetAsmStreamer::emitGlobal(MCSymbol *Symbol) {
56-
OS << "\tpublic\t";
61+
GasStyle ? OS << "\t.globl\t" : OS << "\tpublic\t";
5762
Symbol->print(OS, MAI);
5863
OS << '\n';
5964
}
6065

6166
void Z80TargetAsmStreamer::emitExtern(MCSymbol *Symbol) {
62-
OS << "\textern\t";
67+
GasStyle ? OS << "\t.extern\t" : OS << "\textern\t";
6368
Symbol->print(OS, MAI);
6469
OS << '\n';
6570
}

0 commit comments

Comments
 (0)