From f18e5fe0fadac44f09526df3f9d3c24d94cd1542 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 5 Jul 2016 16:51:26 -0700 Subject: [PATCH] Parse select instructions. --- cranelift/src/libreader/parser.rs | 13 ++++++++++++- cranelift/tests/parser/tiny.cton | 6 ++++++ cranelift/tests/parser/tiny.cton.ref | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cranelift/src/libreader/parser.rs b/cranelift/src/libreader/parser.rs index eb57504a6f..82e17aea5f 100644 --- a/cranelift/src/libreader/parser.rs +++ b/cranelift/src/libreader/parser.rs @@ -791,6 +791,18 @@ impl<'a> Parser<'a> { args: [lhs, rhs], } } + InstructionFormat::Select => { + let ctrl_arg = try!(self.match_value("expected SSA value control operand")); + try!(self.match_token(Token::Comma, "expected ',' between operands")); + let true_arg = try!(self.match_value("expected SSA value true operand")); + try!(self.match_token(Token::Comma, "expected ',' between operands")); + let false_arg = try!(self.match_value("expected SSA value false operand")); + InstructionData::Select { + opcode: opcode, + ty: VOID, + args: [ctrl_arg, true_arg, false_arg], + } + } InstructionFormat::Jump => { // Parse the destination EBB number. Don't translate source to local numbers yet. let ebb_num = try!(self.match_ebb("expected jump destination EBB")); @@ -819,7 +831,6 @@ impl<'a> Parser<'a> { }), } } - InstructionFormat::Select | InstructionFormat::InsertLane | InstructionFormat::ExtractLane | InstructionFormat::BranchTable | diff --git a/cranelift/tests/parser/tiny.cton b/cranelift/tests/parser/tiny.cton index 9619147f6f..5e38d5efbb 100644 --- a/cranelift/tests/parser/tiny.cton +++ b/cranelift/tests/parser/tiny.cton @@ -12,3 +12,9 @@ ebb0: v1 = iconst.i8 6 v2 = ishl v0, v1 } + +; Polymorphic istruction controlled by second operand. +function select() { +ebb0(vx0: i32, vx1:i32, vx2: b1): + v0 = select vx2, vx0, vx1 +} diff --git a/cranelift/tests/parser/tiny.cton.ref b/cranelift/tests/parser/tiny.cton.ref index c8c28dd419..29b604f29d 100644 --- a/cranelift/tests/parser/tiny.cton.ref +++ b/cranelift/tests/parser/tiny.cton.ref @@ -9,3 +9,8 @@ ebb0: v1 = iconst.i8 6 v2 = ishl v0, v1 } + +function select() { +ebb0(vx0: i32, vx1: i32, vx2: b1): + v0 = select vx2, vx0, vx1 +}