diff --git a/llvm/lib/Target/Z80/GISel/Z80CallLowering.cpp b/llvm/lib/Target/Z80/GISel/Z80CallLowering.cpp index f3c86443548f1..c65862c094013 100644 --- a/llvm/lib/Target/Z80/GISel/Z80CallLowering.cpp +++ b/llvm/lib/Target/Z80/GISel/Z80CallLowering.cpp @@ -29,8 +29,8 @@ using namespace llvm; using namespace MIPatternMatch; -cl::opt ReturnSRet("z80-return-sret", cl::desc("Return sret pointers"), - cl::init(true), cl::Hidden); +static cl::opt ReturnSRet("z80-return-sret", cl::desc("Return sret pointers"), + cl::init(true), cl::Hidden); #define DEBUG_TYPE "z80-call-lowering" diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp index f47c4d8fa7e4f..d9f1684bd8cfc 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp @@ -24,54 +24,66 @@ static cl::opt EscapeNonPrint( "Avoid outputting non-printable ascii characters to assembly files."), cl::Hidden); +cl::opt Z80GasStyle( + "z80-gas-style", + cl::desc("Use GAS style assembly syntax instead of FASMG style."), + cl::NotHidden); + void Z80MCAsmInfoELF::anchor() { } Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { bool Is16Bit = T.isArch16Bit() || T.getEnvironment() == Triple::CODE16; CodePointerSize = CalleeSaveStackSlotSize = Is16Bit ? 2 : 3; MaxInstLength = 6; - DollarIsPC = true; - SeparatorString = nullptr; - CommentString = ";"; - PrivateGlobalPrefix = PrivateLabelPrefix = ""; - Code16Directive = "assume\tadl = 0"; - Code24Directive = "assume\tadl = 1"; - Code32Directive = Code64Directive = nullptr; - AssemblerDialect = !Is16Bit; - SupportsQuotedNames = false; - ZeroDirective = AscizDirective = nullptr; - BlockSeparator = " dup "; - AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t"; - NumberLiteralSyntax = ANLS_PlainDecimal; - CharacterLiteralSyntax = ACLS_SingleQuotes; - HasPairedDoubleQuoteStringConstants = true; - HasBackslashEscapesInStringConstants = false; - StringConstantsEscapeNonPrint = EscapeNonPrint; - StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null - Data16bitsDirective = "\tdw\t"; - Data24bitsDirective = "\tdl\t"; - Data32bitsDirective = "\tdd\t"; - Data64bitsDirective = "\tdq\t"; - DataULEB128Directive = "\tuleb128\t"; - DataSLEB128Directive = "\tsleb128\t"; - SectionDirective = "\tsection\t"; - AlwaysChangeSection = true; - GlobalDirective = "\tpublic\t"; - LGloblDirective = "\tprivate\t"; - SetDirective = "\tlabel\t"; - SetSeparator = " at "; - HasFunctionAlignment = false; - HasDotTypeDotSizeDirective = false; - IdentDirective = "\tident\t"; - WeakDirective = "\tweak\t"; - UseIntegratedAssembler = false; - UseLogicalShr = false; - HasSingleParameterDotFile = false; - SupportsDebugInformation = SupportsCFI = true; - ExceptionsType = ExceptionHandling::SjLj; - DwarfFileDirective = "\tfile\t"; - DwarfLocDirective = "\tloc\t"; - DwarfCFIDirectivePrefix = "\tcfi_"; + + if (!Z80GasStyle) { + DollarIsPC = true; + SeparatorString = nullptr; + CommentString = ";"; + PrivateGlobalPrefix = PrivateLabelPrefix = ""; + Code16Directive = "assume\tadl = 0"; + Code24Directive = "assume\tadl = 1"; + Code32Directive = Code64Directive = nullptr; + AssemblerDialect = !Is16Bit; + SupportsQuotedNames = false; + ZeroDirective = AscizDirective = nullptr; + BlockSeparator = " dup "; + AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t"; + NumberLiteralSyntax = ANLS_PlainDecimal; + CharacterLiteralSyntax = ACLS_SingleQuotes; + HasPairedDoubleQuoteStringConstants = true; + HasBackslashEscapesInStringConstants = false; + StringConstantsEscapeNonPrint = EscapeNonPrint; + StringConstantsRequiredEscapes = {"\n\r\32", 4}; // include null + Data16bitsDirective = "\tdw\t"; + Data24bitsDirective = "\tdl\t"; + Data32bitsDirective = "\tdd\t"; + Data64bitsDirective = "\tdq\t"; + DataULEB128Directive = "\tuleb128\t"; + DataSLEB128Directive = "\tsleb128\t"; + SectionDirective = "\tsection\t"; + AlwaysChangeSection = true; + GlobalDirective = "\tpublic\t"; + LGloblDirective = "\tprivate\t"; + SetDirective = "\tlabel\t"; + SetSeparator = " at "; + HasFunctionAlignment = false; + HasDotTypeDotSizeDirective = false; + IdentDirective = "\tident\t"; + WeakDirective = "\tweak\t"; + UseIntegratedAssembler = false; + UseLogicalShr = false; + HasSingleParameterDotFile = false; + SupportsDebugInformation = SupportsCFI = true; + ExceptionsType = ExceptionHandling::SjLj; + DwarfFileDirective = "\tfile\t"; + DwarfLocDirective = "\tloc\t"; + DwarfCFIDirectivePrefix = "\tcfi_"; + } else { + CommentString = ";"; + Code16Directive = Code24Directive = Code32Directive = Code64Directive = nullptr; + UseIntegratedAssembler = false; + } } MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const { @@ -79,7 +91,7 @@ MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const { } bool Z80MCAsmInfoELF::isAcceptableChar(char C) const { - return MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^'; + return Z80GasStyle ? MCAsmInfo::isAcceptableChar(C) : (MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^'); } bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const { @@ -89,10 +101,10 @@ bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const { const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const { switch (Size) { default: return nullptr; - case 1: return "\tdb\t"; - case 2: return "\tdw\t"; - case 3: return "\tdl\t"; - case 4: return "\tdd\t"; + case 1: return Z80GasStyle ? "\t.byte" : "\tdb\t"; + case 2: return Z80GasStyle ? "\t.short" : "\tdw\t"; + case 3: return Z80GasStyle ? "\t.long" : "\tdl\t"; + case 4: return Z80GasStyle ? "\t.quad" : "\tdd\t"; } } diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp index ce2c3f3ea8c2c..6f63a3ed47817 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp @@ -14,10 +14,13 @@ #include "Z80TargetStreamer.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" using namespace llvm; +extern cl::opt Z80GasStyle; + Z80TargetStreamer::Z80TargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} @@ -32,34 +35,34 @@ void Z80TargetAsmStreamer::emitLabel(MCSymbol *Symbol) { void Z80TargetAsmStreamer::emitAlign(Align Alignment) { if (auto Mask = Alignment.value() - 1) - OS << "\trb\t($$ - $) and " << Mask << '\n'; + Z80GasStyle ? OS << "\t.skip\t($$ - $) and " << Mask << '\n' : OS << "\trb\t($$ - $) and " << Mask << '\n'; } void Z80TargetAsmStreamer::emitBlock(uint64_t NumBytes) { if (NumBytes) - OS << "\trb\t" << NumBytes << '\n'; + Z80GasStyle ? OS << "\t.skip\t" << NumBytes << '\n' : OS << "\trb\t" << NumBytes << '\n'; } void Z80TargetAsmStreamer::emitLocal(MCSymbol *Symbol) { - OS << "\tprivate\t"; + Z80GasStyle ? OS << "\t.local\t" : OS << "\tprivate\t"; Symbol->print(OS, MAI); OS << '\n'; } void Z80TargetAsmStreamer::emitWeakGlobal(MCSymbol *Symbol) { - OS << "\tweak\t"; + Z80GasStyle ? OS << "\t.weak\t" : OS << "\tweak\t"; Symbol->print(OS, MAI); OS << '\n'; } void Z80TargetAsmStreamer::emitGlobal(MCSymbol *Symbol) { - OS << "\tpublic\t"; + Z80GasStyle ? OS << "\t.global\t" : OS << "\tpublic\t"; Symbol->print(OS, MAI); OS << '\n'; } void Z80TargetAsmStreamer::emitExtern(MCSymbol *Symbol) { - OS << "\textern\t"; + Z80GasStyle ? OS << "\t.extern\t" : OS << "\textern\t"; Symbol->print(OS, MAI); OS << '\n'; }