From 2b19d7a2dede80bfff87f157e48f8480936b6917 Mon Sep 17 00:00:00 2001 From: Atirut Wattanamongkol Date: Mon, 21 Apr 2025 22:30:23 +0700 Subject: [PATCH 1/5] Fix fixed-length character arrays producing invalid GAS syntax --- llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp index f2d0f6f8b32e2..4949474c38da7 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp @@ -38,20 +38,24 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { // Common to both GAS and fasmg CommentString = ";"; + ZeroDirective = AscizDirective = nullptr; Code32Directive = Code64Directive = nullptr; UseIntegratedAssembler = false; AssemblerDialect = !Is16Bit; HasFunctionAlignment = false; ExceptionsType = ExceptionHandling::SjLj; - if (!Z80GasStyle) { + if (Z80GasStyle) { + Code16Directive = ".assume ADL = 0"; + Code24Directive = ".assume ADL = 1"; + AsciiDirective = ByteListDirective = Data8bitsDirective = "\t.byte\t"; + } else { Code16Directive = "assume\tadl = 0"; Code24Directive = "assume\tadl = 1"; DollarIsPC = true; SeparatorString = nullptr; PrivateGlobalPrefix = PrivateLabelPrefix = ""; SupportsQuotedNames = false; - ZeroDirective = AscizDirective = nullptr; BlockSeparator = " dup "; AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t"; NumberLiteralSyntax = ANLS_PlainDecimal; From 61e493b6d8aea63ae891940803a92082ce7faabd Mon Sep 17 00:00:00 2001 From: Atirut Wattanamongkol Date: Mon, 21 Apr 2025 22:44:13 +0700 Subject: [PATCH 2/5] Correct alignment directive --- llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp index 6f63a3ed47817..388beede31684 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp @@ -34,8 +34,13 @@ void Z80TargetAsmStreamer::emitLabel(MCSymbol *Symbol) { } void Z80TargetAsmStreamer::emitAlign(Align Alignment) { - if (auto Mask = Alignment.value() - 1) - Z80GasStyle ? OS << "\t.skip\t($$ - $) and " << Mask << '\n' : OS << "\trb\t($$ - $) and " << Mask << '\n'; + if (auto Mask = Alignment.value() - 1) { + if (Z80GasStyle) { + OS << "\t.balign\t" << Alignment.value() << '\n'; + } else { + OS << "\trb\t($$ - $) and " << Mask << '\n'; + } + } } void Z80TargetAsmStreamer::emitBlock(uint64_t NumBytes) { From dd5731a798dccddda4dbda5d2e24fa810698deb1 Mon Sep 17 00:00:00 2001 From: Atirut Wattanamongkol Date: Mon, 21 Apr 2025 22:57:39 +0700 Subject: [PATCH 3/5] Use tabs for ADL directives Idk how to squash with commits inbetween --- llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp index 4949474c38da7..9a1b9f3e31342 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp @@ -46,8 +46,8 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { ExceptionsType = ExceptionHandling::SjLj; if (Z80GasStyle) { - Code16Directive = ".assume ADL = 0"; - Code24Directive = ".assume ADL = 1"; + Code16Directive = ".assume\tADL = 0"; + Code24Directive = ".assume\tADL = 1"; AsciiDirective = ByteListDirective = Data8bitsDirective = "\t.byte\t"; } else { Code16Directive = "assume\tadl = 0"; From c92783dcd857eb46a14a1fa8a3649ddef874ed5e Mon Sep 17 00:00:00 2001 From: Atirut Wattanamongkol Date: Mon, 21 Apr 2025 23:15:10 +0700 Subject: [PATCH 4/5] Do not null out zero directive for GAS --- llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp index 9a1b9f3e31342..9e938e5741244 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp @@ -38,7 +38,7 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { // Common to both GAS and fasmg CommentString = ";"; - ZeroDirective = AscizDirective = nullptr; + AscizDirective = nullptr; Code32Directive = Code64Directive = nullptr; UseIntegratedAssembler = false; AssemblerDialect = !Is16Bit; @@ -56,6 +56,7 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { SeparatorString = nullptr; PrivateGlobalPrefix = PrivateLabelPrefix = ""; SupportsQuotedNames = false; + ZeroDirective = nullptr; BlockSeparator = " dup "; AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t"; NumberLiteralSyntax = ANLS_PlainDecimal; From ab47d49b78e95733e188ee8c714303d840aca440 Mon Sep 17 00:00:00 2001 From: Atirut Wattanamongkol Date: Thu, 24 Apr 2025 00:54:38 +0700 Subject: [PATCH 5/5] String fix v2 --- llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp index 9e938e5741244..d389876208ad2 100644 --- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp +++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp @@ -48,7 +48,10 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) { if (Z80GasStyle) { Code16Directive = ".assume\tADL = 0"; Code24Directive = ".assume\tADL = 1"; - AsciiDirective = ByteListDirective = Data8bitsDirective = "\t.byte\t"; + AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t"; + Data16bitsDirective = "\tdw\t"; + Data24bitsDirective = "\td24\t"; + Data32bitsDirective = "\td32\t"; } else { Code16Directive = "assume\tadl = 0"; Code24Directive = "assume\tadl = 1";