Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Bitblaster used to bitblast to Boolean Nodes. 11 : : */ 12 : : #include "cvc5_private.h" 13 : : 14 : : #ifndef CVC5__THEORY__BV__BITBLAST_NODE_BITBLASTER_H 15 : : #define CVC5__THEORY__BV__BITBLAST_NODE_BITBLASTER_H 16 : : 17 : : #include "theory/bv/bitblast/bitblaster.h" 18 : : 19 : : namespace cvc5::internal { 20 : : namespace theory { 21 : : namespace bv { 22 : : 23 : : /** 24 : : * Implementation of a simple Node-based bit-blaster. 25 : : * 26 : : * Implements the bare minimum to bit-blast bit-vector atoms/terms. 27 : : */ 28 : : class NodeBitblaster : public TBitblaster<Node>, protected EnvObj 29 : : { 30 : : using Bits = std::vector<Node>; 31 : : 32 : : public: 33 : : NodeBitblaster(Env& env, TheoryState* state); 34 : 117136 : ~NodeBitblaster() = default; 35 : : 36 : : /** Bit-blast term 'node' and return bit-blasted 'bits'. */ 37 : : void bbTerm(TNode node, Bits& bits) override; 38 : : /** Bit-blast atom 'node'. */ 39 : : void bbAtom(TNode node) override; 40 : : /** Get bit-blasted atom, returns 'atom' itself since it's Boolean. */ 41 : : Node getBBAtom(TNode atom) const override; 42 : : /** Store Boolean node representing the bit-blasted atom. */ 43 : : void storeBBAtom(TNode atom, Node atom_bb) override; 44 : : /** Store bits of bit-blasted term. */ 45 : : void storeBBTerm(TNode node, const Bits& bits) override; 46 : : /** Check if atom was already bit-blasted. */ 47 : : bool hasBBAtom(TNode atom) const override; 48 : : /** Get bit-blasted node stored for atom. */ 49 : : Node getStoredBBAtom(TNode node); 50 : : /** Create 'bits' for variable 'var'. */ 51 : : void makeVariable(TNode var, Bits& bits) override; 52 : : 53 : : /** Add d_variables to termSet. */ 54 : : void computeRelevantTerms(std::set<Node>& termSet); 55 : : /** Collect model values for all relevant terms given in 'relevantTerms'. */ 56 : : bool collectModelValues(TheoryModel* m, const std::set<Node>& relevantTerms); 57 : : 58 : 0 : prop::SatSolver* getSatSolver() override { Unreachable(); } 59 : : 60 : : /** Checks whether node is a variable introduced via `makeVariable`.*/ 61 : : bool isVariable(TNode node); 62 : : 63 : : /** 64 : : * Bit-blast `node` and return the result without applying any rewrites. 65 : : * 66 : : * This method is used by BBProof and does not cache the result for `node`. 67 : : */ 68 : : Node applyAtomBBStrategy(TNode node); 69 : : 70 : : private: 71 : : /** Query SAT solver for assignment of node 'a'. */ 72 : : Node getModelFromSatSolver(TNode a, bool fullModel) override; 73 : : 74 : : /** Caches variables for which we already created bits. */ 75 : : TNodeSet d_variables; 76 : : /** Stores bit-blasted atoms. */ 77 : : std::unordered_map<Node, Node> d_bbAtoms; 78 : : /** Theory state. */ 79 : : TheoryState* d_state; 80 : : }; 81 : : 82 : : } // namespace bv 83 : : } // namespace theory 84 : : } // namespace cvc5::internal 85 : : 86 : : #endif