Skip to content

Commit

Permalink
f64 constants
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 21, 2024
1 parent eae1daf commit 0634a8b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bril-rs/rs2bril/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,33 @@ fn from_expr_to_bril(expr: Expr, state: &mut State) -> (Option<String>, Vec<Code
}) if attrs.is_empty() && path.get_ident().is_some() => {
(Some(path.get_ident().unwrap().to_string()), Vec::new())
}
// f64 constants
Expr::Path(ExprPath {
attrs,
qself: None,
path,
}) if attrs.is_empty() && path.segments[0].ident == "f64" => {
let dest = state.fresh_var(Type::Float);
let float = if path.segments.len() == 2 && path.segments[1].ident == "INFINITY" {
f64::INFINITY
} else if path.segments.len() == 2 && path.segments[1].ident == "NEG_INFINITY" {
f64::NEG_INFINITY
} else if path.segments.len() == 2 && path.segments[1].ident == "NAN" {
f64::NAN
} else {
panic!("can't handle f64 path: {path:?}");
};
(
Some(dest.clone()),
vec![Code::Instruction(Instruction::Constant {
dest,
op: ConstOps::Const,
pos,
const_type: Type::Float,
value: Literal::Float(float),
})],
)
}
Expr::Reference(ExprReference {
attrs,
and_token: _,
Expand Down

0 comments on commit 0634a8b

Please sign in to comment.