Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 2710772

Browse files
author
Matheus Almeida
committed
[mips] Small update to the logic behind the expansion of assembly pseudo instructions.
Summary: The functions that do the expansion now return false on success and true otherwise. This is so we can catch some errors during the expansion (e.g.: immediate too large). The next patch adds some test cases. Reviewers: vmedic Reviewed By: vmedic Differential Revision: http://reviews.llvm.org/D4214 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211269 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent dc9bdcc commit 2710772

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,20 @@ class MipsAsmParser : public MCTargetAsmParser {
116116

117117
bool needsExpansion(MCInst &Inst);
118118

119-
void expandInstruction(MCInst &Inst, SMLoc IDLoc,
119+
// Expands assembly pseudo instructions.
120+
// Returns false on success, true otherwise.
121+
bool expandInstruction(MCInst &Inst, SMLoc IDLoc,
120122
SmallVectorImpl<MCInst> &Instructions);
121-
void expandLoadImm(MCInst &Inst, SMLoc IDLoc,
123+
124+
bool expandLoadImm(MCInst &Inst, SMLoc IDLoc,
122125
SmallVectorImpl<MCInst> &Instructions);
123-
void expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
126+
127+
bool expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
124128
SmallVectorImpl<MCInst> &Instructions);
125-
void expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
129+
130+
bool expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
126131
SmallVectorImpl<MCInst> &Instructions);
132+
127133
void expandMemInst(MCInst &Inst, SMLoc IDLoc,
128134
SmallVectorImpl<MCInst> &Instructions, bool isLoad,
129135
bool isImmOpnd);
@@ -965,7 +971,7 @@ bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
965971
} // if load/store
966972

967973
if (needsExpansion(Inst))
968-
expandInstruction(Inst, IDLoc, Instructions);
974+
return expandInstruction(Inst, IDLoc, Instructions);
969975
else
970976
Instructions.push_back(Inst);
971977

@@ -984,9 +990,11 @@ bool MipsAsmParser::needsExpansion(MCInst &Inst) {
984990
}
985991
}
986992

987-
void MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
993+
bool MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
988994
SmallVectorImpl<MCInst> &Instructions) {
989995
switch (Inst.getOpcode()) {
996+
default: assert(0 && "unimplemented expansion");
997+
return true;
990998
case Mips::LoadImm32Reg:
991999
return expandLoadImm(Inst, IDLoc, Instructions);
9921000
case Mips::LoadAddr32Imm:
@@ -996,7 +1004,7 @@ void MipsAsmParser::expandInstruction(MCInst &Inst, SMLoc IDLoc,
9961004
}
9971005
}
9981006

999-
void MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
1007+
bool MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
10001008
SmallVectorImpl<MCInst> &Instructions) {
10011009
MCInst tmpInst;
10021010
const MCOperand &ImmOp = Inst.getOperand(1);
@@ -1038,9 +1046,10 @@ void MipsAsmParser::expandLoadImm(MCInst &Inst, SMLoc IDLoc,
10381046
tmpInst.setLoc(IDLoc);
10391047
Instructions.push_back(tmpInst);
10401048
}
1049+
return false;
10411050
}
10421051

1043-
void
1052+
bool
10441053
MipsAsmParser::expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
10451054
SmallVectorImpl<MCInst> &Instructions) {
10461055
MCInst tmpInst;
@@ -1081,9 +1090,10 @@ MipsAsmParser::expandLoadAddressReg(MCInst &Inst, SMLoc IDLoc,
10811090
tmpInst.addOperand(MCOperand::CreateReg(SrcRegOp.getReg()));
10821091
Instructions.push_back(tmpInst);
10831092
}
1093+
return false;
10841094
}
10851095

1086-
void
1096+
bool
10871097
MipsAsmParser::expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
10881098
SmallVectorImpl<MCInst> &Instructions) {
10891099
MCInst tmpInst;
@@ -1115,6 +1125,7 @@ MipsAsmParser::expandLoadAddressImm(MCInst &Inst, SMLoc IDLoc,
11151125
tmpInst.addOperand(MCOperand::CreateImm(ImmValue & 0xffff));
11161126
Instructions.push_back(tmpInst);
11171127
}
1128+
return false;
11181129
}
11191130

11201131
void MipsAsmParser::expandMemInst(MCInst &Inst, SMLoc IDLoc,

0 commit comments

Comments
 (0)