Example #1
0
    // called from AST Foreign node constructor
    static Alg_bool<FR>
    compareOp(const CMP op, const AST_Node<Alg>& a, const AST_Node<Alg>& b)
    {
        // evaluate left and right hand side nodes
        EvalAST<Alg> A, B;
        a.accept(A);
        b.accept(B);

        // push left and right hand side results on stack
        EvalAST<Alg> C;
        C.push(A.result());
        C.push(B.result());

        // evaluate comparison operation
        C.compareOp(op);

        // convert comparison result of foreign algebraic type to predicate
        const bool result = bool(C.result());
        return Alg_bool<FR>(result,
                            boolTo<FR>(result),
                            valueBits(result),
                            C.result().r1Terms());
    }
Example #2
0
    static U xwordOp(const AST_Node<Alg>& src, const U& dummy)
    {
        // evaluate source node
        EvalAST<Alg> E;
        src.accept(E);

        const auto x = TL<R1C<FR>>::singleton()->argBits(E.result());
        typename U::ValueType uvalue;
        const auto returnSize = sizeBits(uvalue);

#ifdef USE_ASSERT
        // source must be: bool, 8-bit, 32-bit, 64-bit
        assert(x.size() <= 64);
#endif

        if (1 == x.size()) {
            // source is bool

            if (returnSize <= 64) {
                // replicate bit to unsigned integer word
                uvalue = E.result().value()
                    ? -1 // all bits set
                    : 0; // all bits clear

            } else {
                // convert bit to zero and one
                uvalue = typename U::ValueType(E.result().value()
                                               ? 1ul
                                               : 0ul);
            }

        } else {
            // source is 8-bit octet, 32-bit or 64-bit word
            uvalue = E.result().value();
        }

        // convert result of foreign algebraic source type to target type
        return U(uvalue,
                 valueToString(uvalue),
                 valueBits(uvalue),
                 rank1_xword(x, returnSize));
    }
Example #3
0
 // called from AST Variable overloaded assignment operator
 static Alg
 assignEval(const AST_Var<Alg>& lhs, const AST_Node<Alg>& rhs) {
     EvalAST<Alg> E;
     rhs.accept(E);
     return E.result();
 }
Example #4
0
int
AST_Imports::apply (AST_Node x)
{
  x->accept (this);
  return (0);
}