Skip to content

Commit 7ac0418

Browse files
committed
Add clang patch
1 parent 6d7988c commit 7ac0418

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# eZ80 C/C++ Toolchain
2+
3+
1. C/C++ compiler: LLVM with Clang
4+
2. Assembler, linker, object tools: GNU binutils
5+
3. Standard library: patches from ZDS-II, fillers

clang/0001-Emit-GAS-sytax.patch

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
From 8974d48fac9e60a84315bffd3992904b24397575 Mon Sep 17 00:00:00 2001
2+
From: Byron Ellacott <[email protected]>
3+
Date: Mon, 1 Feb 2021 08:00:41 +1000
4+
Subject: [PATCH] Emit GAS sytax
5+
6+
---
7+
.../Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp | 64 ++++++++++---------
8+
.../Z80/MCTargetDesc/Z80TargetStreamer.cpp | 10 +--
9+
llvm/lib/Target/Z80/Z80InstrInfo.td | 4 +-
10+
3 files changed, 41 insertions(+), 37 deletions(-)
11+
12+
diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp
13+
index 9a8109b7b714..458fa87d5617 100644
14+
--- a/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp
15+
+++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80MCAsmInfo.cpp
16+
@@ -25,41 +25,45 @@ Z80MCAsmInfoELF::Z80MCAsmInfoELF(const Triple &T) {
17+
DollarIsPC = true;
18+
SeparatorString = nullptr;
19+
CommentString = ";";
20+
- PrivateGlobalPrefix = PrivateLabelPrefix = "";
21+
- Code16Directive = "assume\tadl = 0";
22+
- Code24Directive = "assume\tadl = 1";
23+
+ //PrivateGlobalPrefix = PrivateLabelPrefix = "";
24+
+ Code16Directive = ".assume\tadl = 0";
25+
+ Code24Directive = ".assume\tadl = 1";
26+
Code32Directive = Code64Directive = nullptr;
27+
AssemblerDialect = !Is16Bit;
28+
SupportsQuotedNames = false;
29+
- ZeroDirective = AscizDirective = nullptr;
30+
- BlockSeparator = " dup ";
31+
- AsciiDirective = ByteListDirective = Data8bitsDirective = "\tdb\t";
32+
+ ZeroDirective = "\tds\t";
33+
+ //ZeroDirective =
34+
+ AscizDirective = nullptr;
35+
+ //BlockSeparator = " dup ";
36+
+ AsciiDirective = nullptr;
37+
+ ByteListDirective = "\tdb\t";
38+
OctalLiteralSyntax = AOLS_TrailingO;
39+
- CharacterLiteralSyntax = ACLS_SingleQuotes;
40+
+ CharacterLiteralSyntax = ACLS_Unknown; //ACLS_SingleQuotePrefix; //ACLS_SingleQuotes;
41+
StringLiteralEscapeSyntax = ASLES_RepeatDelimiter;
42+
+ Data8bitsDirective = "\tdb\t";
43+
Data16bitsDirective = "\tdw\t";
44+
- Data24bitsDirective = "\tdl\t";
45+
- Data32bitsDirective = "\tdd\t";
46+
- Data64bitsDirective = "\tdq\t";
47+
- DataULEB128Directive = "\tuleb128\t";
48+
- DataSLEB128Directive = "\tsleb128\t";
49+
- SectionDirective = "\tsection\t";
50+
+ Data24bitsDirective = "\td24\t";
51+
+ Data32bitsDirective = "\td32\t";
52+
+ Data64bitsDirective = nullptr;//"\tdq\t";
53+
+ DataULEB128Directive = "\t.uleb128\t";
54+
+ DataSLEB128Directive = "\t.sleb128\t";
55+
+ SectionDirective = "\t.section\t";
56+
AlwaysChangeSection = true;
57+
- GlobalDirective = "\tpublic\t";
58+
- LGloblDirective = "\tprivate\t";
59+
- SetDirective = "\tlabel\t";
60+
- SetSeparator = " at ";
61+
- HasFunctionAlignment = false;
62+
- HasDotTypeDotSizeDirective = false;
63+
- IdentDirective = "\tident\t";
64+
- WeakDirective = "\tweak\t";
65+
+ GlobalDirective = "\t.global\t";
66+
+ LGloblDirective = "\t.local\t";
67+
+ //SetDirective = "\tlabel\t";
68+
+ //SetSeparator = " at ";
69+
+ //HasFunctionAlignment = false;
70+
+ //HasDotTypeDotSizeDirective = false;
71+
+ IdentDirective = "\t.ident\t";
72+
+ WeakDirective = "\t.weak\t";
73+
UseIntegratedAssembler = false;
74+
UseLogicalShr = false;
75+
- HasSingleParameterDotFile = false;
76+
+ //HasSingleParameterDotFile = false;
77+
SupportsDebugInformation = SupportsCFI = true;
78+
- ExceptionsType = ExceptionHandling::SjLj;
79+
- DwarfFileDirective = "\tfile\t";
80+
- DwarfLocDirective = "\tloc\t";
81+
+ //ExceptionsType = ExceptionHandling::SjLj;
82+
+ DwarfFileDirective = "\t.file\t";
83+
+ DwarfLocDirective = "\t.loc\t";
84+
DwarfCFIDirectivePrefix = "\tcfi_";
85+
}
86+
87+
@@ -68,7 +72,7 @@ MCSection *Z80MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
88+
}
89+
90+
bool Z80MCAsmInfoELF::isAcceptableChar(char C) const {
91+
- return MCAsmInfo::isAcceptableChar(C) || C == '%' || C == '^';
92+
+ return MCAsmInfo::isAcceptableChar(C);// || C == '%' || C == '^';
93+
}
94+
95+
bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
96+
@@ -78,9 +82,9 @@ bool Z80MCAsmInfoELF::shouldOmitSectionDirective(StringRef SectionName) const {
97+
const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
98+
switch (Size) {
99+
default: return nullptr;
100+
- case 1: return "\tdb\t";
101+
- case 2: return "\tdw\t";
102+
- case 3: return "\tdl\t";
103+
- case 4: return "\tdd\t";
104+
+ case 1: return Data8bitsDirective;
105+
+ case 2: return Data16bitsDirective;
106+
+ case 3: return Data24bitsDirective;
107+
+ case 4: return Data32bitsDirective;
108+
}
109+
}
110+
diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp
111+
index 4ca0d9c5fa0f..350e1a18dc56 100644
112+
--- a/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp
113+
+++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80TargetStreamer.cpp
114+
@@ -31,29 +31,29 @@ void Z80TargetAsmStreamer::emitLabel(MCSymbol *Symbol) {
115+
116+
void Z80TargetAsmStreamer::emitAlign(Align Alignment) {
117+
if (auto Mask = Alignment.value() - 1)
118+
- OS << "\trb\t" << Mask << " - ($ - $$ + " << Mask << ") and not " << Mask
119+
+ OS << "\tds\t" << Mask << " - ($ - $$ + " << Mask << ") and not " << Mask
120+
<< "\n";
121+
}
122+
123+
void Z80TargetAsmStreamer::emitBlock(uint64_t NumBytes) {
124+
if (NumBytes)
125+
- OS << "\trb\t" << NumBytes << '\n';
126+
+ OS << "\tds\t" << NumBytes << '\n';
127+
}
128+
129+
void Z80TargetAsmStreamer::emitLocal(MCSymbol *Symbol) {
130+
- OS << "\tprivate\t";
131+
+ OS << "\t.local\t";
132+
Symbol->print(OS, MAI);
133+
OS << '\n';
134+
}
135+
136+
void Z80TargetAsmStreamer::emitGlobal(MCSymbol *Symbol) {
137+
- OS << "\tpublic\t";
138+
+ OS << "\t.global\t";
139+
Symbol->print(OS, MAI);
140+
OS << '\n';
141+
}
142+
143+
void Z80TargetAsmStreamer::emitExtern(MCSymbol *Symbol) {
144+
- OS << "\textern\t";
145+
+ OS << "\t.extern\t";
146+
Symbol->print(OS, MAI);
147+
OS << '\n';
148+
}
149+
diff --git a/llvm/lib/Target/Z80/Z80InstrInfo.td b/llvm/lib/Target/Z80/Z80InstrInfo.td
150+
index ad26337c2fe4..02d111d2123a 100644
151+
--- a/llvm/lib/Target/Z80/Z80InstrInfo.td
152+
+++ b/llvm/lib/Target/Z80/Z80InstrInfo.td
153+
@@ -348,7 +348,7 @@ let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
154+
155+
let isBranch = 1, isTerminator = 1 in {
156+
let isBarrier = 1 in {
157+
- def JQ : Pseudo<"jq", "\t$tgt", "", (outs), (ins jmptarget:$tgt),
158+
+ def JQ : Pseudo<"jp", "\t$tgt", "", (outs), (ins jmptarget:$tgt),
159+
[(br bb:$tgt)]>;
160+
def JR : Io <NoPre, 0x18, "jr", "\t$tgt", "",
161+
(outs), (ins jmptargetoff:$tgt)>;
162+
@@ -364,7 +364,7 @@ let isBranch = 1, isTerminator = 1 in {
163+
}
164+
}
165+
let Uses = [F] in {
166+
- def JQCC : Pseudo<"jq", "\t$cc, $tgt", "",
167+
+ def JQCC : Pseudo<"jp", "\t$cc, $tgt", "",
168+
(outs), (ins jmptarget:$tgt, cc:$cc),
169+
[(Z80brcond bb:$tgt, imm:$cc, F)]>;
170+
def JRCC : Io <NoPre, 0x18, "jr", "\t$cc, $tgt", "",
171+
--
172+
2.28.0
173+

clang/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# eZ80 support for clang via the GNU assembler
2+
3+
Starting from https://github.com/jacobly0/llvm-project apply this patch and build using
4+
something along the lines of:
5+
6+
cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_INSTALL_PREFIX=/opt/local/z80-none-elf -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=Z80 -DLLVM_TARGETS_TO_BUILD="" -DLLVM_DEFAULT_TARGET_TRIPLE=ez80-none-elf ../llvm
7+
8+
Compilation will require a few flags to succeed:
9+
10+
- `-Wa,-march=ez80` will pass the approproate architecture flag to the GNU assembler
11+
- `-nostdinc` will prevent incorrect headers from being included
12+
13+

0 commit comments

Comments
 (0)