@@ -151,6 +151,7 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
151
151
case IntegerType () => Ints .IntSort ()
152
152
case RealType () => Reals .RealSort ()
153
153
case BVType (_,l) => FixedSizeBitVectors .BitVectorSort (l)
154
+ case FPType (e, s) => FloatingPoint .FloatingPointSort (e, s)
154
155
case CharType () => FixedSizeBitVectors .BitVectorSort (16 )
155
156
case StringType () => Strings .StringSort ()
156
157
@@ -277,6 +278,14 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
277
278
278
279
case IntegerLiteral (i) => intToTerm(i)
279
280
case BVLiteral (_, bits, size) => FixedSizeBitVectors .BitVectorLit (List .range(1 , size + 1 ).map(i => bits(size + 1 - i)))
281
+ case FPLiteral (e, s, bits) =>
282
+ val size = e + s
283
+ FloatingPoint .FPLit (
284
+ FixedSizeBitVectors .BitVectorLit (List .range(1 , 2 ).map(i => bits(size + 1 - i))),
285
+ FixedSizeBitVectors .BitVectorLit (List .range(2 , e + 2 ).map(i => bits(size + 1 - i))),
286
+ FixedSizeBitVectors .BitVectorLit (List .range(e + 2 , size + 1 ).map(i => bits(size + 1 - i)))
287
+ )
288
+
280
289
case FractionLiteral (n, d) => Reals .Div (realToTerm(n), realToTerm(d))
281
290
case CharLiteral (c) => FixedSizeBitVectors .BitVectorLit (Hexadecimal .fromShort(c.toShort))
282
291
case BooleanLiteral (v) => Core .BoolConst (v)
@@ -372,35 +381,40 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
372
381
373
382
case UMinus (u) => u.getType match {
374
383
case BVType (_,_) => FixedSizeBitVectors .Neg (toSMT(u))
384
+ case FPType (_, _) => FloatingPoint .Neg (toSMT(u))
375
385
case IntegerType () => Ints .Neg (toSMT(u))
376
386
case RealType () => Reals .Neg (toSMT(u))
377
387
}
378
388
379
389
case Equals (a, b) => Core .Equals (toSMT(a), toSMT(b))
380
390
case Implies (a, b) => Core .Implies (toSMT(a), toSMT(b))
381
- case pl @ Plus (a, _ ) =>
391
+ case pl @ Plus (a, b ) =>
382
392
val rec = flattenPlus(pl).map(toSMT)
383
393
a.getType match {
384
394
case BVType (_,_) => FixedSizeBitVectors .Add (rec)
395
+ case FPType (_, _) => FloatingPoint .Add (FloatingPoint .RNE (), toSMT(a), toSMT(b))
385
396
case IntegerType () => Ints .Add (rec)
386
397
case RealType () => Reals .Add (rec)
387
398
}
388
399
case Minus (a, b) => a.getType match {
389
400
case BVType (_,_) => FixedSizeBitVectors .Sub (toSMT(a), toSMT(b))
401
+ case FPType (_,_) => FloatingPoint .Sub (FloatingPoint .RNE (), toSMT(a), toSMT(b))
390
402
case IntegerType () => Ints .Sub (toSMT(a), toSMT(b))
391
403
case RealType () => Reals .Sub (toSMT(a), toSMT(b))
392
404
}
393
- case tms @ Times (a, _ ) =>
405
+ case tms @ Times (a, b ) =>
394
406
val rec = flattenTimes(tms).map(toSMT)
395
407
a.getType match {
396
408
case BVType (_,_) => FixedSizeBitVectors .Mul (rec)
409
+ case FPType (_,_) => FloatingPoint .Mul (FloatingPoint .RNE (), toSMT(a), toSMT(b))
397
410
case IntegerType () => Ints .Mul (rec)
398
411
case RealType () => Reals .Mul (rec)
399
412
}
400
413
401
414
case Division (a, b) => a.getType match {
402
415
case BVType (true , _) => FixedSizeBitVectors .SDiv (toSMT(a), toSMT(b))
403
416
case BVType (false , _) => FixedSizeBitVectors .UDiv (toSMT(a), toSMT(b))
417
+ case FPType (_,_) => FloatingPoint .Div (FloatingPoint .RNE (), toSMT(a), toSMT(b))
404
418
case IntegerType () =>
405
419
val ar = toSMT(a)
406
420
val br = toSMT(b)
@@ -415,6 +429,7 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
415
429
case Remainder (a, b) => a.getType match {
416
430
case BVType (true , _) => FixedSizeBitVectors .SRem (toSMT(a), toSMT(b))
417
431
case BVType (false , _) => FixedSizeBitVectors .URem (toSMT(a), toSMT(b))
432
+ case FPType (_, _) => FloatingPoint .Rem (toSMT(a), toSMT(b))
418
433
case IntegerType () =>
419
434
val q = toSMT(Division (a, b))
420
435
Ints .Sub (toSMT(a), Ints .Mul (toSMT(b), q))
@@ -440,27 +455,31 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
440
455
case LessThan (a, b) => a.getType match {
441
456
case BVType (true , _) => FixedSizeBitVectors .SLessThan (toSMT(a), toSMT(b))
442
457
case BVType (false , _) => FixedSizeBitVectors .ULessThan (toSMT(a), toSMT(b))
458
+ case FPType (_,_) => FloatingPoint .LessThan (toSMT(a), toSMT(b))
443
459
case IntegerType () => Ints .LessThan (toSMT(a), toSMT(b))
444
460
case RealType () => Reals .LessThan (toSMT(a), toSMT(b))
445
461
case CharType () => FixedSizeBitVectors .ULessThan (toSMT(a), toSMT(b))
446
462
}
447
463
case LessEquals (a, b) => a.getType match {
448
464
case BVType (true , _) => FixedSizeBitVectors .SLessEquals (toSMT(a), toSMT(b))
449
465
case BVType (false , _) => FixedSizeBitVectors .ULessEquals (toSMT(a), toSMT(b))
466
+ case FPType (_,_) => FloatingPoint .LessEquals (toSMT(a), toSMT(b))
450
467
case IntegerType () => Ints .LessEquals (toSMT(a), toSMT(b))
451
468
case RealType () => Reals .LessEquals (toSMT(a), toSMT(b))
452
469
case CharType () => FixedSizeBitVectors .ULessEquals (toSMT(a), toSMT(b))
453
470
}
454
471
case GreaterThan (a, b) => a.getType match {
455
472
case BVType (true , _) => FixedSizeBitVectors .SGreaterThan (toSMT(a), toSMT(b))
456
473
case BVType (false , _) => FixedSizeBitVectors .UGreaterThan (toSMT(a), toSMT(b))
474
+ case FPType (_,_) => FloatingPoint .GreaterThan (toSMT(a), toSMT(b))
457
475
case IntegerType () => Ints .GreaterThan (toSMT(a), toSMT(b))
458
476
case RealType () => Reals .GreaterThan (toSMT(a), toSMT(b))
459
477
case CharType () => FixedSizeBitVectors .UGreaterThan (toSMT(a), toSMT(b))
460
478
}
461
479
case GreaterEquals (a, b) => a.getType match {
462
480
case BVType (true , _) => FixedSizeBitVectors .SGreaterEquals (toSMT(a), toSMT(b))
463
481
case BVType (false , _) => FixedSizeBitVectors .UGreaterEquals (toSMT(a), toSMT(b))
482
+ case FPType (_,_) => FloatingPoint .GreaterEquals (toSMT(a), toSMT(b))
464
483
case IntegerType () => Ints .GreaterEquals (toSMT(a), toSMT(b))
465
484
case RealType () => Reals .GreaterEquals (toSMT(a), toSMT(b))
466
485
case CharType () => FixedSizeBitVectors .UGreaterEquals (toSMT(a), toSMT(b))
@@ -487,6 +506,8 @@ trait SMTLIBTarget extends SMTLIBParser with Interruptible with ADTManagers {
487
506
case BVUnsignedToSigned (e) => toSMT(e)
488
507
case BVSignedToUnsigned (e) => toSMT(e)
489
508
509
+ case FPEquals (a, b) => FloatingPoint .Eq (toSMT(a), toSMT(b))
510
+
490
511
case And (sub) => SmtLibConstructors .and(sub.map(toSMT))
491
512
case Or (sub) => SmtLibConstructors .or(sub.map(toSMT))
492
513
case IfExpr (cond, thenn, elze) => Core .ITE (toSMT(cond), toSMT(thenn), toSMT(elze))
0 commit comments