Skip to content

Commit 8338aa8

Browse files
committed
Add fasmg operators.
1 parent 42c2ff8 commit 8338aa8

File tree

5 files changed

+82
-30
lines changed

5 files changed

+82
-30
lines changed

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ class MCAsmInfo {
942942
bool hasMipsExpressions() const { return HasMipsExpressions; }
943943
bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
944944
bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
945+
946+
virtual const char *getUnaryOperator(unsigned Opc) const;
947+
virtual const char *getBinaryOperator(unsigned Opc) const;
945948
};
946949

947950
} // end namespace llvm

llvm/lib/MC/MCAsmInfo.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,39 @@ bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
147147
return SectionName == ".text" || SectionName == ".data" ||
148148
(SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
149149
}
150+
151+
const char *MCAsmInfo::getUnaryOperator(unsigned Opc) const {
152+
switch (Opc) {
153+
default: llvm_unreachable("unknown opcode");
154+
case MCUnaryExpr::LNot: return "!";
155+
case MCUnaryExpr::Minus: return "-";
156+
case MCUnaryExpr::Not: return "~";
157+
case MCUnaryExpr::Plus: return "+";
158+
}
159+
}
160+
161+
const char *MCAsmInfo::getBinaryOperator(unsigned Opc) const {
162+
switch (Opc) {
163+
default: llvm_unreachable("unknown opcode");
164+
case MCBinaryExpr::Add: return "+";
165+
case MCBinaryExpr::AShr: return ">>";
166+
case MCBinaryExpr::And: return "&";
167+
case MCBinaryExpr::Div: return "/";
168+
case MCBinaryExpr::EQ: return "==";
169+
case MCBinaryExpr::GT: return ">";
170+
case MCBinaryExpr::GTE: return ">=";
171+
case MCBinaryExpr::LAnd: return "&&";
172+
case MCBinaryExpr::LOr: return "||";
173+
case MCBinaryExpr::LShr: return ">>";
174+
case MCBinaryExpr::LT: return "<";
175+
case MCBinaryExpr::LTE: return "<=";
176+
case MCBinaryExpr::Mod: return "%";
177+
case MCBinaryExpr::Mul: return "*";
178+
case MCBinaryExpr::NE: return "!=";
179+
case MCBinaryExpr::Or: return "|";
180+
case MCBinaryExpr::OrNot: return "!";
181+
case MCBinaryExpr::Shl: return "<<";
182+
case MCBinaryExpr::Sub: return "-";
183+
case MCBinaryExpr::Xor: return "^";
184+
}
185+
}

llvm/lib/MC/MCExpr.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
9898

9999
case MCExpr::Unary: {
100100
const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this);
101-
switch (UE.getOpcode()) {
102-
case MCUnaryExpr::LNot: OS << '!'; break;
103-
case MCUnaryExpr::Minus: OS << '-'; break;
104-
case MCUnaryExpr::Not: OS << '~'; break;
105-
case MCUnaryExpr::Plus: OS << '+'; break;
106-
}
101+
OS << MAI->getUnaryOperator(UE.getOpcode());
107102
bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary;
108103
if (Binary) OS << "(";
109104
UE.getSubExpr()->print(OS, MAI);
@@ -123,38 +118,16 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
123118
OS << ')';
124119
}
125120

126-
switch (BE.getOpcode()) {
127-
case MCBinaryExpr::Add:
121+
if (BE.getOpcode() == MCBinaryExpr::Add) {
128122
// Print "X-42" instead of "X+-42".
129123
if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) {
130124
if (RHSC->getValue() < 0) {
131125
OS << RHSC->getValue();
132126
return;
133127
}
134128
}
135-
136-
OS << '+';
137-
break;
138-
case MCBinaryExpr::AShr: OS << ">>"; break;
139-
case MCBinaryExpr::And: OS << '&'; break;
140-
case MCBinaryExpr::Div: OS << '/'; break;
141-
case MCBinaryExpr::EQ: OS << "=="; break;
142-
case MCBinaryExpr::GT: OS << '>'; break;
143-
case MCBinaryExpr::GTE: OS << ">="; break;
144-
case MCBinaryExpr::LAnd: OS << "&&"; break;
145-
case MCBinaryExpr::LOr: OS << "||"; break;
146-
case MCBinaryExpr::LShr: OS << ">>"; break;
147-
case MCBinaryExpr::LT: OS << '<'; break;
148-
case MCBinaryExpr::LTE: OS << "<="; break;
149-
case MCBinaryExpr::Mod: OS << '%'; break;
150-
case MCBinaryExpr::Mul: OS << '*'; break;
151-
case MCBinaryExpr::NE: OS << "!="; break;
152-
case MCBinaryExpr::Or: OS << '|'; break;
153-
case MCBinaryExpr::OrNot: OS << '!'; break;
154-
case MCBinaryExpr::Shl: OS << "<<"; break;
155-
case MCBinaryExpr::Sub: OS << '-'; break;
156-
case MCBinaryExpr::Xor: OS << '^'; break;
157129
}
130+
OS << MAI->getBinaryOperator(BE.getOpcode());
158131

159132
// Only print parens around the LHS if it is non-trivial.
160133
if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Z80MCAsmInfo.h"
1515
#include "llvm/ADT/StringSwitch.h"
1616
#include "llvm/ADT/Triple.h"
17+
#include "llvm/MC/MCExpr.h"
1718
using namespace llvm;
1819

1920
void Z80MCAsmInfoELF::anchor() { }
@@ -87,3 +88,39 @@ const char *Z80MCAsmInfoELF::getBlockDirective(int64_t Size) const {
8788
case 4: return "\tdd\t";
8889
}
8990
}
91+
92+
const char *Z80MCAsmInfoELF::getUnaryOperator(unsigned Opc) const {
93+
switch (Opc) {
94+
default: llvm_unreachable("unknown opcode");
95+
case MCUnaryExpr::LNot: return "~";
96+
case MCUnaryExpr::Minus: return "-";
97+
case MCUnaryExpr::Not: return "not ";
98+
case MCUnaryExpr::Plus: return "+";
99+
}
100+
}
101+
102+
const char *Z80MCAsmInfoELF::getBinaryOperator(unsigned Opc) const {
103+
switch (Opc) {
104+
default: llvm_unreachable("unknown opcode");
105+
case MCBinaryExpr::Add: return "+";
106+
case MCBinaryExpr::AShr: return " shr ";
107+
case MCBinaryExpr::And: return " and ";
108+
case MCBinaryExpr::Div: return "/";
109+
case MCBinaryExpr::EQ: return "=";
110+
case MCBinaryExpr::GT: return ">";
111+
case MCBinaryExpr::GTE: return ">=";
112+
case MCBinaryExpr::LAnd: return "&";
113+
case MCBinaryExpr::LOr: return "|";
114+
case MCBinaryExpr::LShr: return " shr ";
115+
case MCBinaryExpr::LT: return "<";
116+
case MCBinaryExpr::LTE: return "<=";
117+
case MCBinaryExpr::Mod: return " mod ";
118+
case MCBinaryExpr::Mul: return "*";
119+
case MCBinaryExpr::NE: return "<>";
120+
case MCBinaryExpr::Or: return " or ";
121+
case MCBinaryExpr::OrNot: return "~";
122+
case MCBinaryExpr::Shl: return " shl ";
123+
case MCBinaryExpr::Sub: return "-";
124+
case MCBinaryExpr::Xor: return " xor ";
125+
}
126+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Z80MCAsmInfoELF : public MCAsmInfoELF {
3232
bool shouldOmitSectionDirective(StringRef SectionName) const override;
3333

3434
const char *getBlockDirective(int64_t Size) const override;
35+
36+
const char *getUnaryOperator(unsigned Opc) const override;
37+
const char *getBinaryOperator(unsigned Opc) const override;
3538
};
3639
} // End llvm namespace
3740

0 commit comments

Comments
 (0)