Skip to content

Commit

Permalink
ASR and LLVM: implement xor
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Dec 2, 2021
1 parent 1ec6095 commit f02b68a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grammar/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ ttype
| Class(symbol class_type, dimension* dims)
| Pointer(ttype type)

boolop = And | Or | NEqv | Eqv
boolop = And | Or | Xor | NEqv | Eqv

binop = Add | Sub | Mul | Div | Pow

Expand Down
4 changes: 4 additions & 0 deletions src/lfortran/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
tmp = builder->CreateOr(left_val, right_val);
break;
};
case ASR::boolopType::Xor: {
tmp = builder->CreateXor(left_val, right_val);
break;
};
case ASR::boolopType::NEqv: {
tmp = builder->CreateXor(left_val, right_val);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/lfortran/semantics/ast_common_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,17 @@ class CommonVisitorMethods {
case (AST::Or):
op = ASR::Or;
break;
case (AST::Xor):
op = ASR::Xor;
break;
case (AST::NEqv):
op = ASR::NEqv;
break;
case (AST::Eqv):
op = ASR::Eqv;
break;
default:
throw SemanticError(R"""(Only .and., .or., .neqv., .eqv.
throw SemanticError(R"""(Only .and., .or., .xor., .neqv., .eqv.
implemented for logical type operands.)""",
x.base.base.loc);
}
Expand Down

0 comments on commit f02b68a

Please sign in to comment.