@@ -68,6 +68,17 @@ Expression FormulaGenerator::divToFraction(
6868 return wrapper;
6969}
7070
71+ bool FormulaGenerator::bitfunc (const std::string& name, const Expression& a,
72+ const Expression& b, Expression& res) const {
73+ if (ExpressionUtil::canBeNegative (a, offset) ||
74+ ExpressionUtil::canBeNegative (b, offset)) {
75+ // TODO: remove this limitation
76+ return false ;
77+ }
78+ res = Expression (Expression::Type::FUNCTION, name, {a, b});
79+ return true ;
80+ }
81+
7182bool FormulaGenerator::update (const Operation& op) {
7283 auto source = operandToExpression (op.source );
7384 auto target = operandToExpression (op.target );
@@ -162,6 +173,18 @@ bool FormulaGenerator::update(const Operation& op) {
162173 res = Expression (Expression::Type::FUNCTION, " max" , {prevTarget, source});
163174 break ;
164175 }
176+ case Operation::Type::BAN: {
177+ okay = bitfunc (" bitand" , prevTarget, source, res);
178+ break ;
179+ }
180+ case Operation::Type::BOR: {
181+ okay = bitfunc (" bitor" , prevTarget, source, res);
182+ break ;
183+ }
184+ case Operation::Type::BXO: {
185+ okay = bitfunc (" bitxor" , prevTarget, source, res);
186+ break ;
187+ }
165188 case Operation::Type::SEQ: {
166189 res = Expression (Expression::Type::FUNCTION,
167190 ProgramUtil::idStr (source.value .asInt ()), {prevTarget});
0 commit comments