Index: src/IceInstMIPS32.cpp |
diff --git a/src/IceInstMIPS32.cpp b/src/IceInstMIPS32.cpp |
index 9ba87776c22526868634bb6c4b2bf51925f15d18..1dcc04f7bf503e0f66377f134b6cdceeea737434 100644 |
--- a/src/IceInstMIPS32.cpp |
+++ b/src/IceInstMIPS32.cpp |
@@ -25,6 +25,17 @@ |
namespace Ice { |
namespace MIPS32 { |
+const struct InstMIPS32CondAttributes_ { |
+ CondMIPS32::Cond Opposite; |
+ const char *EmitString; |
+} InstMIPS32CondAttributes[] = { |
+#define X(tag, encode, opp, emit) \ |
+ { CondMIPS32::opp, emit } \ |
+ , |
+ ICEINSTMIPS32COND_TABLE |
+#undef X |
+}; |
+ |
bool OperandMIPS32Mem::canHoldOffset(Type Ty, bool SignExt, int32_t Offset) { |
(void)SignExt; |
(void)Ty; |
@@ -111,10 +122,21 @@ template <> void InstMIPS32Multu::emit(const Cfg *Func) const { |
} |
InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue, |
+ const CfgNode *TargetFalse, Operand *Src0, |
+ Operand *Src1, const InstMIPS32Label *Label, |
Jim Stichnoth
2016/05/19 15:03:40
In ICE there's a pretty strong assumption/pattern
sagar.thakur
2016/05/23 18:30:25
Done.
|
+ CondMIPS32::Cond Cond) |
+ : InstMIPS32(Func, InstMIPS32::Br, 2, nullptr), TargetTrue(TargetTrue), |
+ TargetFalse(TargetFalse), Label(Label), Predicate(Cond) { |
+ addSource(Src0); |
+ if (Src1 != NULL) |
Jim Stichnoth
2016/05/19 15:03:40
nullptr
sagar.thakur
2016/05/23 18:30:25
Done.
|
+ addSource(Src1); |
+} |
+ |
+InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue, |
const CfgNode *TargetFalse, |
- const InstMIPS32Label *Label) |
+ const InstMIPS32Label *Label, CondMIPS32::Cond Cond) |
: InstMIPS32(Func, InstMIPS32::Br, 0, nullptr), TargetTrue(TargetTrue), |
- TargetFalse(TargetFalse), Label(Label) {} |
+ TargetFalse(TargetFalse), Label(Label), Predicate(Cond) {} |
InstMIPS32Label::InstMIPS32Label(Cfg *Func, TargetMIPS32 *Target) |
: InstMIPS32(Func, InstMIPS32::Label, 0, nullptr), |
@@ -271,17 +293,39 @@ void InstMIPS32Br::emit(const Cfg *Func) const { |
return; |
Ostream &Str = Func->getContext()->getStrEmit(); |
Str << "\t" |
- "b" |
- << "\t"; |
+ "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t"; |
if (Label) { |
Str << Label->getLabelName(); |
} else { |
if (isUnconditionalBranch()) { |
Str << getTargetFalse()->getAsmName(); |
} else { |
- // TODO(reed kotler): Finish implementing conditional branch. |
+ switch (Predicate) { |
+ default: |
+ break; |
+ case CondMIPS32::EQ: |
+ case CondMIPS32::NE: { |
+ getSrc(0)->emit(Func); |
+ Str << ", "; |
+ getSrc(1)->emit(Func); |
+ Str << ", "; |
+ break; |
+ } |
+ case CondMIPS32::EQZ: |
+ case CondMIPS32::NEZ: |
+ case CondMIPS32::LEZ: |
+ case CondMIPS32::LTZ: |
+ case CondMIPS32::GEZ: |
+ case CondMIPS32::GTZ: { |
+ getSrc(0)->emit(Func); |
+ Str << ", "; |
+ break; |
+ } |
+ } |
+ Str << getTargetFalse()->getAsmName(); |
} |
} |
+ return; |
Jim Stichnoth
2016/05/19 15:03:40
this "return" is unnecessary, remove
sagar.thakur
2016/05/23 18:30:25
Done.
|
} |
void InstMIPS32Call::emit(const Cfg *Func) const { |