#include "predicate.h"
Predicate::Predicate(FuncInst * func_inst) :
- func_inst(func_inst)
+ func_inst(func_inst),
+ predicates(),
+ children()
{}
-unsigned int pred_expr_hash(struct pred_expr * expr) {
+unsigned int pred_expr_hash(struct pred_expr * expr)
+{
return (unsigned int)((uintptr_t)expr);
}
void Predicate::add_predicate(token_t token, void * location, bool value)
{
- struct pred_expr predicate = {token, location, value};
- predicates.add(&predicate);
+ struct pred_expr *ptr = new pred_expr(token, location, value);
+ predicates.add(ptr);
+}
+
+void Predicate::add_child(Predicate * child)
+{
+ /* check duplication? */
+ children.push_back(child);
+}
+
+void Predicate::print_predicate()
+{
+ //model_print("self: %p ", this);
+ func_inst->print();
+ PredSetIter * it = predicates.iterator();
+
+ if (predicates.getSize() == 0)
+ model_print("no predicate\n");
+
+ while (it->hasNext()) {
+ struct pred_expr * expr = it->next();
+ model_print("token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value);
+ }
+}
+
+void Predicate::print_pred_subtree()
+{
+ print_predicate();
+ for (uint i = 0; i < children.size(); i++) {
+ Predicate * child = children[i];
+// model_print("parent: %p - ", this);
+ child->print_pred_subtree();
+ }
}
unsigned int pred_expr_hash (struct pred_expr *);
bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
-typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredicateSet;
+typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredSet;
+typedef HSIterator<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredSetIter;
typedef enum predicate_token {
EQUALITY, NULLITY
* read at memory location specified in predicate_expr.
*/
struct pred_expr {
+ pred_expr(token_t token, void * location, bool value) :
+ token(token),
+ location(location),
+ value(value)
+ {}
+
token_t token;
void * location;
bool value;
+
+ MEMALLOC
};
~Predicate();
FuncInst * get_func_inst() { return func_inst; }
- PredicateSet * get_predicates() { return &predicates; }
+ PredSet * get_predicates() { return &predicates; }
void add_predicate(token_t token, void * location, bool value);
+ void add_child(Predicate * child);
+
+ void print_predicate();
+ void print_pred_subtree();
MEMALLOC
private:
FuncInst * func_inst;
/* may have multiple precicates */
- PredicateSet predicates;
+ PredSet predicates;
ModelVector<Predicate *> children;
};