Skip to content

Commit

Permalink
x86: fix issue keystone-engine#214
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jul 1, 2016
1 parent ce922a6 commit 2b0fc2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class X86AsmParser : public MCTargetAsmParser {
InfixOperatorStack.push_back(Op);
}

int64_t execute(unsigned int &KsError) { // qq
int64_t execute(unsigned int &KsError) {
// Push any remaining operators onto the postfix stack.
while (!InfixOperatorStack.empty()) {
InfixCalculatorTok StackOp = InfixOperatorStack.pop_back_val();
Expand Down Expand Up @@ -2584,8 +2584,14 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
Parser.eatToEndOfStatement();
return true;
}
// check for comma and eat it
if (getLexer().is(AsmToken::Comma))
// for LJMP, check for ':'. otherwise, check for comma and eat it
if (Name.startswith("ljmp") || Name.startswith("ljmp")) {
if (getLexer().is(AsmToken::Colon)) {
//Parser.Lex();
Operands.push_back(X86Operand::CreateToken(":", consumeToken()));
} else
break;
} else if (getLexer().is(AsmToken::Comma))
Parser.Lex();
else
break;
Expand Down
8 changes: 4 additions & 4 deletions suite/regress/x86_jmp_0x33_08.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python

# Test if "jmp 0x33, 08" throws an error.
# Test if "ljmp 0x33:08" throws an error.

# Github issue: #214
# Author: Duncan (mrexodia)
Expand All @@ -15,10 +15,10 @@ def runTest(self):
ks = Ks(KS_ARCH_X86, KS_MODE_32)
# Assemble with zero addr
try:
encoding, count = ks.asm("jmp 0x33, 08", 0)
self.fail()
encoding, count = ks.asm("ljmp 0x33:08", 0)
self.assertEqual(encoding, [ 0xea, 0x08, 0x00, 0x30, 0x00 ])
except KsError as e:
pass

if __name__ == '__main__':
regress.main()
regress.main()

0 comments on commit 2b0fc2e

Please sign in to comment.