Skip to content

Commit

Permalink
Add logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Drevanoorschot committed Jul 3, 2023
1 parent 372ab12 commit a736980
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parsers/antlr4/LangLLVMSpecLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ SUB: 'sub';
MUL: 'mul';
UDIV: 'udiv';
SDIV: 'sdiv';
// bitwise
AND: 'and';
OR: 'or';
XOR: 'xor';

// operators -> other
ICMP: 'icmp';
Expand Down
4 changes: 4 additions & 0 deletions src/parsers/antlr4/LangLLVMSpecParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expression
| constant
| identifier
| valExpr
| <assoc=right> expression valImpOp expression
;

instruction
Expand Down Expand Up @@ -52,6 +53,9 @@ binOp
| MUL # mul
| UDIV # udiv
| SDIV # sdiv
| AND # and
| OR # or
| XOR # xor
;


Expand Down
17 changes: 17 additions & 0 deletions src/parsers/vct/parsers/transform/LLVMContractToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ case class LLVMContractToCol[G](override val originProvider: OriginProvider,
case Expression1(constant) => convert(constant)
case Expression2(identifier) => convert(identifier)
case Expression3(valExpr) => convert(valExpr)
case Expression4(e1, impOp, e2) => impOp match {
case ValImpOp0(_) => ???
case ValImpOp1(_) => Implies(convert(e1), convert(e2))
}
}

def convert(implicit inst: InstructionContext): Expr[G] = inst match {
Expand Down Expand Up @@ -128,6 +132,19 @@ case class LLVMContractToCol[G](override val originProvider: OriginProvider,
case Sub(_) => Minus(left, right)
case Mul(_) => Mult(left, right)
case Udiv(_) | Sdiv(_) => FloorDiv(left, right)(blame(op))
// bitwise/boolean
case bitOp => left.t match {
case TBool() => bitOp match {
case LLVMSpecParserPatterns.And(_) => vct.col.ast.And(left, right)
case LLVMSpecParserPatterns.Or(_) => vct.col.ast.Or(left, right)
case Xor(_) => Neq(left, right)
}
case TInt() => bitOp match {
case LLVMSpecParserPatterns.And(_) => BitAnd(left, right)
case LLVMSpecParserPatterns.Or(_) => BitOr(left, right)
case Xor(_) => BitXor(left, right)
}
}
}
}

Expand Down

0 comments on commit a736980

Please sign in to comment.