Skip to content

Commit 53d816d

Browse files
Merge pull request #1 from atirut-w/gas-directives
Add option for GAS-style directives
2 parents b5164b3 + fae9438 commit 53d816d

File tree

3 files changed

+70
-55
lines changed

3 files changed

+70
-55
lines changed

llvm/lib/Target/Z80/GISel/Z80CallLowering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
using namespace llvm;
3030
using namespace MIPatternMatch;
3131

32-
cl::opt<bool> ReturnSRet("z80-return-sret", cl::desc("Return sret pointers"),
33-
cl::init(true), cl::Hidden);
32+
static cl::opt<bool> ReturnSRet("z80-return-sret", cl::desc("Return sret pointers"),
33+
cl::init(true), cl::Hidden);
3434

3535
#define DEBUG_TYPE "z80-call-lowering"
3636

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

+59-47
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,74 @@ 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;
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_";
38+
39+
if (!Z80GasStyle) {
40+
DollarIsPC = true;
41+
SeparatorString = nullptr;
42+
CommentString = ";";
43+
PrivateGlobalPrefix = PrivateLabelPrefix = "";
44+
Code16Directive = "assume\tadl = 0";
45+
Code24Directive = "assume\tadl = 1";
46+
Code32Directive = Code64Directive = nullptr;
47+
AssemblerDialect = !Is16Bit;
48+
SupportsQuotedNames = false;
49+
ZeroDirective = AscizDirective = nullptr;
50+
BlockSeparator = " dup ";
51+
AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t";
52+
NumberLiteralSyntax = ANLS_PlainDecimal;
53+
CharacterLiteralSyntax = ACLS_SingleQuotes;
54+
HasPairedDoubleQuoteStringConstants = true;
55+
HasBackslashEscapesInStringConstants = false;
56+
StringConstantsEscapeNonPrint = EscapeNonPrint;
57+
StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null
58+
Data16bitsDirective = "\tdw\t";
59+
Data24bitsDirective = "\tdl\t";
60+
Data32bitsDirective = "\tdd\t";
61+
Data64bitsDirective = "\tdq\t";
62+
DataULEB128Directive = "\tuleb128\t";
63+
DataSLEB128Directive = "\tsleb128\t";
64+
SectionDirective = "\tsection\t";
65+
AlwaysChangeSection = true;
66+
GlobalDirective = "\tpublic\t";
67+
LGloblDirective = "\tprivate\t";
68+
SetDirective = "\tlabel\t";
69+
SetSeparator = " at ";
70+
HasFunctionAlignment = false;
71+
HasDotTypeDotSizeDirective = false;
72+
IdentDirective = "\tident\t";
73+
WeakDirective = "\tweak\t";
74+
UseIntegratedAssembler = false;
75+
UseLogicalShr = false;
76+
HasSingleParameterDotFile = false;
77+
SupportsDebugInformation = SupportsCFI = true;
78+
ExceptionsType = ExceptionHandling::SjLj;
79+
DwarfFileDirective = "\tfile\t";
80+
DwarfLocDirective = "\tloc\t";
81+
DwarfCFIDirectivePrefix = "\tcfi_";
82+
} else {
83+
CommentString = ";";
84+
Code16Directive = Code24Directive = Code32Directive = Code64Directive = nullptr;
85+
UseIntegratedAssembler = false;
86+
}
7587
}
7688

7789
MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
7890
return nullptr;
7991
}
8092

8193
bool Z80MCAsmInfoELF::isAcceptableChar(char C) const {
82-
return MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^';
94+
return Z80GasStyle ? MCAsmInfo::isAcceptableChar(C) : (MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^');
8395
}
8496

8597
bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
@@ -89,10 +101,10 @@ bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
89101
const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
90102
switch (Size) {
91103
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";
104+
case 1: return Z80GasStyle ? "\t.byte" : "\tdb\t";
105+
case 2: return Z80GasStyle ? "\t.short" : "\tdw\t";
106+
case 3: return Z80GasStyle ? "\t.long" : "\tdl\t";
107+
case 4: return Z80GasStyle ? "\t.quad" : "\tdd\t";
96108
}
97109
}
98110

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

+9-6
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> Z80GasStyle;
23+
2124
Z80TargetStreamer::Z80TargetStreamer(MCStreamer &S)
2225
: MCTargetStreamer(S) {}
2326

@@ -32,34 +35,34 @@ 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+
Z80GasStyle ? 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+
Z80GasStyle ? OS << "\t.skip\t" << NumBytes << '\n' : OS << "\trb\t" << NumBytes << '\n';
4144
}
4245

4346
void Z80TargetAsmStreamer::emitLocal(MCSymbol *Symbol) {
44-
OS << "\tprivate\t";
47+
Z80GasStyle ? OS << "\t.local\t" : OS << "\tprivate\t";
4548
Symbol->print(OS, MAI);
4649
OS << '\n';
4750
}
4851

4952
void Z80TargetAsmStreamer::emitWeakGlobal(MCSymbol *Symbol) {
50-
OS << "\tweak\t";
53+
Z80GasStyle ? OS << "\t.weak\t" : OS << "\tweak\t";
5154
Symbol->print(OS, MAI);
5255
OS << '\n';
5356
}
5457

5558
void Z80TargetAsmStreamer::emitGlobal(MCSymbol *Symbol) {
56-
OS << "\tpublic\t";
59+
Z80GasStyle ? OS << "\t.global\t" : OS << "\tpublic\t";
5760
Symbol->print(OS, MAI);
5861
OS << '\n';
5962
}
6063

6164
void Z80TargetAsmStreamer::emitExtern(MCSymbol *Symbol) {
62-
OS << "\textern\t";
65+
Z80GasStyle ? OS << "\t.extern\t" : OS << "\textern\t";
6366
Symbol->print(OS, MAI);
6467
OS << '\n';
6568
}

0 commit comments

Comments
 (0)