Skip to content

Commit 8eb28cb

Browse files
authored
* removed quoted string case in label identifier (for sha256sum) * not generate block when isConc has IntV * implement IEEE floating point visitor * added floating point test * minor fix * added fp80 benchmark
1 parent e8bfa0c commit 8eb28cb

File tree

9 files changed

+1504
-1481
lines changed

9 files changed

+1504
-1481
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int main()
2+
{
3+
long double a = 0x1e1;
4+
long double b = 0x1e2;
5+
long double c = 0x1e3;
6+
sym_print(a);
7+
sym_print(b);
8+
sym_print(c);
9+
return 0;
10+
}

dev-clean/grammar/LLVMLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,5 +649,5 @@ LOCAL_ID
649649

650650
LABEL_IDENT
651651
: ( LETTER | DECIMAL_DIGIT ) ( LETTER | DECIMAL_DIGIT ) * ':'
652-
| QUOTED_STRING ':'
652+
/* | QUOTED_STRING ':' */
653653
;

dev-clean/grammar/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ all:
22
./generate.sh
33

44
clean:
5-
rm *.java
6-
rm *.interp
7-
rm *.tokens
5+
rm -f *.java
6+
rm -f *.interp
7+
rm -f *.tokens

dev-clean/src/main/java/LLVMLexer.java

Lines changed: 1466 additions & 1470 deletions
Large diffs are not rendered by default.

dev-clean/src/main/scala/sai/lang/LLVM.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ package IR {
179179

180180
abstract class FloatKind extends LAST
181181
case object FK_Half extends FloatKind
182+
case object FK_BFloat extends FloatKind
182183
case object FK_Float extends FloatKind
183184
case object FK_Double extends FloatKind
184185
case object FK_X86_FP80 extends FloatKind
@@ -792,10 +793,9 @@ class MyVisitor extends LLVMParserBaseVisitor[LAST] {
792793
val floatStr = ctx.FLOAT_LIT.getText
793794
if (floatStr.contains('.')) FloatConst(floatStr.toFloat)
794795
else if (floatStr.startsWith("0x")) {
795-
// Does not work, need to parse "0x3FF4CCCCC0000000" as 1.3
796-
// val i = java.lang.Long.parseLong(floatStr.substring(2), 16)
797-
// FloatConst(java.lang.Float.intBitsToFloat(i.intValue()))
798-
???
796+
val hexString = floatStr.substring(2)
797+
val longBits = java.lang.Long.parseUnsignedLong(hexString, 16)
798+
FloatConst(java.lang.Double.longBitsToDouble(longBits).asInstanceOf[Float])
799799
}
800800
else ???
801801
}

dev-clean/src/main/scala/sai/llsc/EngineBase.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ trait EngineBase extends SAIOps { self: BasicDefs with ValueDefs =>
9191
(size + BYTE_SIZE - 1) / BYTE_SIZE
9292
case PtrType(ty, addrSpace) =>
9393
ARCH_WORD_SIZE / BYTE_SIZE
94+
case FloatType(fk) => {
95+
val rawSize = fk match {
96+
case FK_Half => 16
97+
case FK_BFloat => 16
98+
case FK_Float => 32
99+
case FK_Double => 64
100+
case FK_X86_FP80 => 80
101+
case FK_FP128 => 128
102+
case FK_PPC_FP1289 => 128
103+
}
104+
(rawSize + BYTE_SIZE - 1) / BYTE_SIZE
105+
}
94106
case _ => ???
95107
}
96108

dev-clean/src/main/scala/sai/llsc/states/GenericDefs.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ trait ValueDefs { self: SAIOps with BasicDefs =>
212212
def bv_sext(bw: Rep[Int]): Rep[Value] = "bv_sext".reflectWith[Value](v, bw)
213213
def bv_zext(bw: Rep[Int]): Rep[Value] = "bv_zext".reflectWith[Value](v, bw)
214214

215-
def isConc: Rep[Boolean] = "is-conc".reflectWith[Boolean](v)
215+
def isConc: Rep[Boolean] = v match {
216+
case IntV(_, _) => unit(true)
217+
case _ => "is-conc".reflectWith[Boolean](v)
218+
}
216219
def toSMTBool: Rep[SMTBool] = "to-SMT".reflectWith[SMTBool](v)
217220
def toSMTBoolNeg: Rep[SMTBool] = "to-SMTNeg".reflectWith[SMTBool](v)
218221

dev-clean/src/main/scala/sai/prototypes/llvm/Benchmarks.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ object Benchmarks {
4141
lazy val varArgInt = parseFile("benchmarks/llvm/varArgInt.ll")
4242
lazy val trunc = parseFile("benchmarks/llvm/trunc.ll")
4343
lazy val floatArith = parseFile("benchmarks/llvm/floatArith.ll")
44+
lazy val floatFp80 = parseFile("benchmarks/llvm/floatFp80.ll")
4445

4546
lazy val runCommandLine = parseFile("benchmarks/llvm/runCommandLine.ll")
4647

dev-clean/src/test/scala/sai/llsc/TestLLSC.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ object TestCases {
3131
TestPrg(ptrpred, "ptrPredTest", "@main", 0, 1),
3232
TestPrg(switchTestConc, "switchConcreteTest", "@main", 0, 1),
3333
TestPrg(trunc, "truncTest", "@main", 0, 1),
34+
TestPrg(floatArith, "floatArithTest", "@main", 0, 1),
35+
// FIXME: Support parsing fp80 literals <2022-01-12, David Deng> //
36+
// TestPrg(floatFp80, "floatFp80Test", "@main", 0, 1),
3437

3538
TestPrg(arrayAccess, "arrayAccTest", "@main", 0, 1),
3639
TestPrg(arrayAccessLocal, "arrayAccLocalTest", "@main", 0, 1),
@@ -84,8 +87,6 @@ object TestCases {
8487
// TestPrg(largeStackArray, "largeStackArrayTest", "@main", 0, 1),
8588
// TestPrg(makeSymbolicArray, "makeSymbolicArrayTest", "@main", 0, 1),
8689
// TestPrg(ptrtoint, "ptrToIntTest", "@main", 0, 1)
87-
// FIXME: parsing error
88-
// TestPrg(floatArith, "floatArithTest", "@main", 0, 1),
8990
}
9091

9192
import TestCases._

0 commit comments

Comments
 (0)