Add operand kind and format for unsigned 128-bit immediates

This commit is contained in:
Andrew Brown
2019-07-23 11:02:52 -07:00
committed by Dan Gohman
parent 5ded38ce3e
commit 407d24c013
7 changed files with 71 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ use crate::testfile::{Comment, Details, TestFile};
use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir;
use cranelift_codegen::ir::entities::AnyEntity;
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64, Imm64, Offset32, Uimm32, Uimm64};
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64, Imm64, Offset32, Uimm128, Uimm32, Uimm64};
use cranelift_codegen::ir::instructions::{InstructionData, InstructionFormat, VariableArgs};
use cranelift_codegen::ir::types::INVALID;
use cranelift_codegen::ir::{
@@ -546,6 +546,23 @@ impl<'a> Parser<'a> {
}
}
// Match and consume a Uimm128 immediate; due to size restrictions on InstructionData, Uimm128 is boxed in cranelift-codegen/meta/src/shared/immediates.rs
fn match_uimm128(&mut self, err_msg: &str) -> ParseResult<Uimm128> {
if let Some(Token::Integer(text)) = self.token() {
self.consume();
// Lexer just gives us raw text that looks like hex code.
// Parse it as an Uimm128 to check for overflow and other issues.
text.parse().map_err(|e| {
self.error(&format!(
"expected u128 hexadecimal immediate, failed to parse: {}",
e
))
})
} else {
err!(self.loc, err_msg)
}
}
// Match and consume a Uimm64 immediate.
fn match_uimm64(&mut self, err_msg: &str) -> ParseResult<Uimm64> {
if let Some(Token::Integer(text)) = self.token() {
@@ -2109,6 +2126,14 @@ impl<'a> Parser<'a> {
opcode,
imm: self.match_imm64("expected immediate integer operand")?,
},
InstructionFormat::UnaryImm128 => {
let uimm128 = self.match_uimm128("expected immediate hexadecimal operand")?;
let constant_handle = ctx.function.dfg.constants.insert(uimm128.0.to_vec());
InstructionData::UnaryImm128 {
opcode,
imm: constant_handle,
}
}
InstructionFormat::UnaryIeee32 => InstructionData::UnaryIeee32 {
opcode,
imm: self.match_ieee32("expected immediate 32-bit float operand")?,