@@ -665,6 +665,19 @@ impl<'a> Parser<'a> {
665
665
}
666
666
}
667
667
668
+ // Match and consume a signed 16-bit immediate.
669
+ fn match_imm16 ( & mut self , err_msg : & str ) -> ParseResult < i16 > {
670
+ if let Some ( Token :: Integer ( text) ) = self . token ( ) {
671
+ self . consume ( ) ;
672
+ // Lexer just gives us raw text that looks like an integer.
673
+ // Parse it as a i16 to check for overflow and other issues.
674
+ text. parse ( )
675
+ . map_err ( |_| self . error ( "expected i16 decimal immediate" ) )
676
+ } else {
677
+ err ! ( self . loc, err_msg)
678
+ }
679
+ }
680
+
668
681
// Match and consume an i32 immediate.
669
682
// This is used for stack argument byte offsets.
670
683
fn match_imm32 ( & mut self , err_msg : & str ) -> ParseResult < i32 > {
@@ -855,7 +868,7 @@ impl<'a> Parser<'a> {
855
868
} else {
856
869
let uimm128 = match ty. lane_type ( ) {
857
870
I8 => consume ! ( ty, self . match_uimm8( "Expected an 8-bit unsigned integer" ) ) ,
858
- I16 => unimplemented ! ( ) , // TODO no 16-bit match yet
871
+ I16 => consume ! ( ty , self . match_imm16 ( "Expected a 16-bit integer" ) ) ,
859
872
I32 => consume ! ( ty, self . match_imm32( "Expected a 32-bit integer" ) ) ,
860
873
I64 => consume ! ( ty, self . match_imm64( "Expected a 64-bit integer" ) ) ,
861
874
F32 => consume ! ( ty, self . match_ieee32( "Expected a 32-bit float..." ) ) ,
0 commit comments