Skip to content

Commit

Permalink
Fixed isnan, isinf, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 13, 2023
1 parent ac0e928 commit 365e5e3
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpRoundToIntegralExpr.of(FpRoundingMode.RTZ,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -138,7 +139,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpRoundToIntegralExpr.of(FpRoundingMode.RTP,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -153,8 +155,7 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val assign: AssignStmt<*> = Stmts.Assign(
TypeUtils.cast((expr as RefExpr<*>).decl as VarDecl<*>, type.smtType),
TypeUtils.cast(AbstractExprs.Ite<Type>(
FpIsInfiniteExpr.of(
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>),
FpIsInfiniteExpr.of(callStmt.params[1] as Expr<FpType?>),
type.unitValue, type.nullValue),
type.smtType))
parseContext.metadata.create(assign.expr, "cType", type)
Expand All @@ -170,8 +171,7 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val assign: AssignStmt<*> = Stmts.Assign(
TypeUtils.cast((expr as RefExpr<*>).decl as VarDecl<*>, type.smtType),
TypeUtils.cast(AbstractExprs.Ite<Type>(
FpIsInfiniteExpr.of(
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>),
FpIsInfiniteExpr.of(callStmt.params[1] as Expr<FpType?>),
type.nullValue, type.unitValue),
type.smtType))
parseContext.metadata.create(assign.expr, "cType", type)
Expand All @@ -197,8 +197,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val assign: AssignStmt<*> = Stmts.Assign(
TypeUtils.cast((expr as RefExpr<*>).decl as VarDecl<*>, type.smtType),
TypeUtils.cast(
AbstractExprs.Ite<Type>(FpIsNanExpr.of(
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>),
AbstractExprs.Ite<Type>(
FpIsNanExpr.of(callStmt.params[1] as Expr<FpType?>),
type.unitValue, type.nullValue), type.smtType))
parseContext.getMetadata().create(assign.expr, "cType", type)
return StmtLabel(assign, metadata = callStmt.metadata)
Expand All @@ -213,7 +213,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpRoundToIntegralExpr.of(FpRoundingMode.RNA,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -226,7 +227,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpSqrtExpr.of(FpRoundingMode.RNE,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -243,8 +245,10 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val expr = callStmt.params[0]
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpMinExpr.of(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]) as Expr<FpType?>))
FpMinExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>,
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -257,8 +261,10 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val expr = callStmt.params[0]
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpMaxExpr.of(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]) as Expr<FpType?>))
FpMaxExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>,
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[2]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -271,7 +277,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpRoundToIntegralExpr.of(FpRoundingMode.RTN,
CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand All @@ -283,7 +290,8 @@ class FpFunctionsToExprsPass(val parseContext: ParseContext) : ProcedurePass {
val expr = callStmt.params[0]
Preconditions.checkState(expr is RefExpr<*>)
val assign = Stmts.Assign((expr as RefExpr<*>).decl as VarDecl<FpType>,
FpAbsExpr.of(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]) as Expr<FpType?>))
FpAbsExpr.of(TypeUtils.cast(CComplexType.getType(expr, parseContext).castTo(callStmt.params[1]),
CComplexType.getType(expr, parseContext).smtType) as Expr<FpType?>))
if (parseContext.getMetadata().getMetadataValue(expr, "cType").isPresent) {
parseContext.getMetadata().create(assign.expr, "cType", CComplexType.getType(expr, parseContext))
}
Expand Down

0 comments on commit 365e5e3

Please sign in to comment.