MKDIR_P = mkdir -p
OBJ_DIR = bin
-CPP_SOURCES := constraint.cc inc_solver.cc set.cc mutableset.cc element.cc function.cc order.cc table.cc predicate.cc boolean.cc csolver.cc
+CPP_SOURCES := set.cc mutableset.cc element.cc function.cc order.cc table.cc predicate.cc boolean.cc csolver.cc structs.c
OBJECTS := $(CPP_SOURCES:%.cc=$(OBJ_DIR)/%.o) $(C_SOURCES:%.c=$(OBJ_DIR)/%.o)
#include "classlist.h"
#include "mymemory.h"
-class Boolean {
- public:
- MEMALLOC;
- private:
+struct Boolean {
};
#endif
#ifndef CLASSLIST_H
#define CLASSLIST_H
-#include "hashset.h"
+//#include "hashset.h"
#include "mymemory.h"
#include <inttypes.h>
+#define bool int
+#define true 1
+#define false 0
+
+struct CSolver;
+typedef struct CSolver CSolver;
struct Constraint;
typedef struct Constraint Constraint;
typedef struct Boolean Boolean;
struct IncrementalSolver;
-typedef struct IncrementSolver IncrementalSolver;
+typedef struct IncrementalSolver IncrementalSolver;
struct Set;
typedef struct Set Set;
typedef struct Function Function;
struct Predicate;
-typedef struct Predicat Predicate;
+typedef struct Predicate Predicate;
struct Table;
typedef struct Table Table;
CSolver * allocCSolver() {
CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
- tmp->constraint=allocVector();
+ tmp->constraint=allocDefVectorBoolean();
return tmp;
}
-Set * createSet(CSolver * solver, Type type, uint64_t ** elements) {
-
+Set * createSet(CSolver * solver, VarType type, uint64_t ** elements) {
+ return NULL;
}
-Set * createSet(CSolver * solver, Type type, uint64_t lowrange, uint64_t highrange) {
+Set * createRangeSet(CSolver * solver, VarType type, uint64_t lowrange, uint64_t highrange) {
+ return NULL;
}
-MutableSet * createMutableSet(CSolver * solver, Type type) {
+MutableSet * createMutableSet(CSolver * solver, VarType type) {
+ return NULL;
}
-void CSolver::addItem(MutableSet * set, uint64_t element) {
+void addItem(CSolver *solver, MutableSet * set, uint64_t element) {
}
-int64_t CSolver::createUniqueItem(MutableSet * set) {
+int64_t createUniqueItem(CSolver *solver, MutableSet * set) {
+ return 0;
}
-Element * CSolver::getElementVar(Set * set) {
+Element * getElementVar(CSolver *solver, Set * set) {
+ return NULL;
}
-Boolean * CSolver::getBooleanVar() {
+Boolean * getBooleanVar(CSolver *solver) {
+ return NULL;
}
-Function * CSolver::createFunctionOperator(enum ArithOp op, Set ** domain, Set * range, enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus) {
+Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domain, Set * range, enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus) {
+ return NULL;
}
-Function * CSolver::createFunctionOperator(enum ArithOp op) {
+Function * createFunctionOperatorPure(CSolver *solver, enum ArithOp op) {
+ return NULL;
}
-Predicate * CSolver::createPredicateOperator(enum CompOp op, Set ** domain) {
+Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain) {
+ return NULL;
}
-Table * CSolver::createTable(Set **domains, Set * range) {
+Table * createTable(CSolver *solver, Set **domains, Set * range) {
+ return NULL;
}
-void CSolver::addTableEntry(Element ** inputs, Element *result) {
+void addTableEntry(CSolver *solver, Element ** inputs, Element *result) {
}
-Function * CSolver::completeTable(struct Table *) {
+Function * completeTable(CSolver *solver, Table * table) {
+ return NULL;
}
-Element * CSolver::applyFunction(Function * function, Element ** array) {
+Element * applyFunction(CSolver *solver, Function * function, Element ** array) {
+ return NULL;
}
-Boolean * CSolver::applyPredicate(Predicate * predicate, Element ** inputs) {
+Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs) {
+ return NULL;
}
-Boolean * CSolver::applyLogicalOperation(enum LogicOp op, Boolean ** array) {
+Boolean * applyLogicalOperation(CSolver *solver, enum LogicOp op, Boolean ** array) {
+ return NULL;
}
-void CSolver::addBoolean(Boolean * constraint) {
+void addBoolean(CSolver *solver, Boolean * constraint) {
}
-Order * CSolver::createOrder(enum OrderType type, Set * set) {
+Order * createOrder(CSolver *solver, enum OrderType type, Set * set) {
+ return NULL;
}
-Boolean * CSolver::orderedConstraint(Order * order, uint64_t first, uint64_t second) {
+Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) {
+ return NULL;
}
#define CSOLVER_H
#include "classlist.h"
#include "ops.h"
+#include "structs.h"
-class CSolver {
-public:
- CSolver();
- Set * createSet(Type type, uint64_t ** elements);
- Set * createSet(Type type, uint64_t lowrange, uint64_t highrange);
- MutableSet * createMutableSet(Type type);
+struct CSolver {
+ VectorBoolean * constraint;
+};
+
+CSolver * allocCSolver();
+Set * createSet(CSolver *, VarType type, uint64_t ** elements);
+Set * createRangeSet(CSolver *, VarType type, uint64_t lowrange, uint64_t highrange);
+MutableSet * createMutableSet(CSolver *, VarType type);
- void addItem(MutableSet * set, uint64_t element);
- int64_t createUniqueItem(MutableSet * set);
+void addItem(CSolver *, MutableSet * set, uint64_t element);
+int64_t createUniqueItem(CSolver *, MutableSet * set);
- Element * getElementVar(Set * set);
- Constraint * getBooleanVar();
+Element * getElementVar(CSolver *, Set * set);
+Boolean * getBooleanVar(CSolver *);
- Function * createFunctionOperator(enum ArithOp op, Set ** domain, Set * range, enum OverFlowBehavior overflowbehavior, Constraint * overflowstatus);
- //Does Not Overflow
- Function * createFunctionOperator(enum ArithOp op);
- Predicate * createPredicateOperator(enum CompOp op, Set ** domain);
+Function * createFunctionOperator(CSolver *, enum ArithOp op, Set ** domain, Set * range, enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus);
+//Does Not Overflow
+Function * createFunctionOperatorPure(CSolver *, enum ArithOp op);
+Predicate * createPredicateOperator(CSolver *, enum CompOp op, Set ** domain);
- Table * createTable(Set **domains, Set * range);
- void addTableEntry(Element ** inputs, Element *result);
- Function * completeTable(struct Table *);
+Table * createTable(CSolver *, Set **domains, Set * range);
+void addTableEntry(CSolver *, Element ** inputs, Element *result);
+Function * completeTable(CSolver *, struct Table *);
- Element * applyFunction(Function * function, Element ** array);
- Constraint * applyPredicate(Predicate * predicate, Element ** inputs);
- Constraint * applyLogicalOperation(enum LogicOp op, Constraint ** array);
+Element * applyFunction(CSolver *, Function * function, Element ** array);
+Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs);
+Boolean * applyLogicalOperation(CSolver *, enum LogicOp op, Boolean ** array);
- void addConstraint(Constraint * constraint);
+void addBoolean(CSolver *, Boolean * constraint);
- Order * createOrder(enum OrderType type, Set * set);
- Constraint * orderedConstraint(Order * order, uint64_t first, uint64_t second);
-private:
- ModelVector<Constraint *> constraints;
-};
+Order * createOrder(CSolver *, enum OrderType type, Set * set);
+Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second);
#endif
#include "element.h"
-Element::Element(Set * s) :
- set(s) {
+Element *allocElement(Set * s) {
+ Element * tmp=(Element *)ouralloc(sizeof(Element));
+ tmp->set=s;
+ return tmp;
}
#include "classlist.h"
#include "mymemory.h"
-class Element {
-public:
- Element(Set *s);
- MEMALLOC;
-private:
- Set *set;
+struct Element {
+ Set * set;
};
+
+Element * allocElement(Set *s);
#endif
#define FUNCTION_H
#include "classlist.h"
#include "mymemory.h"
-class Function {
-public:
- MEMALLOC;
-private:
+struct Function {
};
#endif
#include "mutableset.h"
+void addElementMSet(MutableSet * set, uint64_t element) { pushVectorInt(set->members, element); }
#define MUTABLESET_H
#include "set.h"
-class MutableSet : Set {
-public:
- void addElement(uint64_t element) { members->push_back(element); }
-};
+void addElementMSet(MutableSet * set, uint64_t element);
#endif
/** MEMALLOC declares the allocators for a class to allocate
* memory in the non-snapshotting heap. */
-#define MEMALLOC \
+/*
+#define MEMALLOC \
void * operator new(size_t size) { \
return model_malloc(size); \
} \
void * operator new(size_t size, void *p) { \
return p; \
}
+*/
+
+void * ourmalloc(size_t size);
+void ourfree(void *ptr);
+void * ourcalloc(size_t count, size_t size);
+void * ourrealloc(void *ptr, size_t size);
void *model_malloc(size_t size);
void *model_calloc(size_t count, size_t size);
void * model_realloc(void *ptr, size_t size);
void model_free(void *ptr);
-/** @brief Provides a non-snapshotting allocator for use in STL classes.
- *
- * The code was adapted from a code example from the book The C++
- * Standard Library - A Tutorial and Reference by Nicolai M. Josuttis,
- * Addison-Wesley, 1999 © Copyright Nicolai M. Josuttis 1999
- * Permission to copy, use, modify, sell and distribute this software
- * is granted provided this copyright notice appears in all copies.
- * This software is provided "as is" without express or implied
- * warranty, and with no claim as to its suitability for any purpose.
- */
-template <class T>
-class ModelAlloc {
-public:
- // type definitions
- typedef T value_type;
- typedef T* pointer;
- typedef const T* const_pointer;
- typedef T& reference;
- typedef const T& const_reference;
- typedef size_t size_type;
- typedef size_t difference_type;
-
- // rebind allocator to type U
- template <class U>
- struct rebind {
- typedef ModelAlloc<U> other;
- };
-
- // return address of values
- pointer address(reference value) const {
- return &value;
- }
- const_pointer address(const_reference value) const {
- return &value;
- }
-
- /* constructors and destructor
- * - nothing to do because the allocator has no state
- */
- ModelAlloc() throw() {
- }
- ModelAlloc(const ModelAlloc&) throw() {
- }
- template <class U>
- ModelAlloc(const ModelAlloc<U>&) throw() {
- }
- ~ModelAlloc() throw() {
- }
-
- // return maximum number of elements that can be allocated
- size_type max_size() const throw() {
- return std::numeric_limits<size_t>::max() / sizeof(T);
- }
-
- // allocate but don't initialize num elements of type T
- pointer allocate(size_type num, const void * = 0) {
- pointer p = (pointer)model_malloc(num * sizeof(T));
- return p;
- }
-
- // initialize elements of allocated storage p with value value
- void construct(pointer p, const T& value) {
- // initialize memory with placement new
- new((void*)p)T(value);
- }
-
- // destroy elements of initialized storage p
- void destroy(pointer p) {
- // destroy objects by calling their destructor
- p->~T();
- }
-
- // deallocate storage p of deleted elements
- void deallocate(pointer p, size_type num) {
- model_free((void*)p);
- }
-};
-
-/** Return that all specializations of this allocator are interchangeable. */
-template <class T1, class T2>
-bool operator ==(const ModelAlloc<T1>&,
- const ModelAlloc<T2>&) throw() {
- return true;
-}
-
-/** Return that all specializations of this allocator are interchangeable. */
-template <class T1, class T2>
-bool operator!= (const ModelAlloc<T1>&,
- const ModelAlloc<T2>&) throw() {
- return false;
-}
-
-
#endif/* _MY_MEMORY_H */
#include "classlist.h"
#include "mymemory.h"
-class Order {
-public:
- MEMALLOC;
-
-private:
+struct Order {
};
#endif
#include "classlist.h"
#include "mymemory.h"
-class Predicate {
-public:
+struct Predicate {
- MEMALLOC;
-private:
};
#endif
#include "set.h"
#include <stddef.h>
-#include <cassert>
-Set::Set(VarType t, uint64_t* elements, int num) :
- type (t),
- isRange(false),
- low(0),
- high(0),
- members(new ModelVector<uint64_t>()) {
- members->reserve(num);
- for(int i=0;i<num;i++)
- members->push_back(elements[i]);
+Set * allocSet(VarType t, uint64_t* elements, uint num) {
+ Set * tmp=(Set *)ourmalloc(sizeof(struct Set));
+ tmp->type=t;
+ tmp->isRange=false;
+ tmp->low=0;
+ tmp->high=0;
+ tmp->members=allocVectorArrayInt(elements, num);
+ return tmp;
}
-Set::Set(VarType t, uint64_t lowrange, uint64_t highrange) :
- type(t),
- isRange(true),
- low(lowrange),
- high(highrange),
- members(NULL) {
+Set * allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange) {
+ Set * tmp=(Set *)ourmalloc(sizeof(struct Set));
+ tmp->type=t;
+ tmp->isRange=true;
+ tmp->low=lowrange;
+ tmp->high=highrange;
+ tmp->members=NULL;
+ return tmp;
}
-Set::~Set() {
- if (isRange)
- delete members;
+void freeSet(Set * set) {
+ if (set->isRange)
+ freeVectorInt(set->members);
+ ourfree(set);
}
#define SET_H
#include "classlist.h"
-#include "stl-model.h"
+#include "structs.h"
#include "mymemory.h"
-class Set {
-public:
- Set(VarType t, uint64_t * elements, int num);
- Set(VarType t, uint64_t lowrange, uint64_t highrange);
- ~Set();
-
- MEMALLOC;
-private:
+struct Set {
VarType type;
bool isRange;
uint64_t low, high;
-
-protected:
- ModelVector<uint64_t> *members;
+ VectorInt * members;
};
+
+
+Set *allocSet(VarType t, uint64_t * elements, uint num);
+Set * allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange);
+void freeSet(Set *set);
#endif/* SET_H */
+++ /dev/null
-/* Copyright (c) 2015 Regents of the University of California
- *
- * Author: Brian Demsky <bdemsky@uci.edu>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- */
-
-#ifndef __STL_MODEL_H__
-#define __STL_MODEL_H__
-
-#include <vector>
-#include <list>
-#include "mymemory.h"
-
-template<typename _Tp>
-class ModelList : public std::list<_Tp, ModelAlloc<_Tp> >
-{
-public:
- typedef std::list< _Tp, ModelAlloc<_Tp> > list;
-
- ModelList() :
- list()
- { }
-
- ModelList(size_t n, const _Tp& val = _Tp()) :
- list(n, val)
- { }
-
- MEMALLOC;
-};
-
-template<typename _Tp>
-class ModelVector : public std::vector<_Tp, ModelAlloc<_Tp> >
-{
-public:
- typedef std::vector< _Tp, ModelAlloc<_Tp> > vector;
-
- ModelVector() :
- vector()
- { }
-
- ModelVector(size_t n, const _Tp& val = _Tp()) :
- vector(n, val)
- { }
-
- MEMALLOC;
-};
-
-#endif/* __STL_MODEL_H__ */
--- /dev/null
+#include "structs.h"
+#include "mymemory.h"
+
+VectorImpl(Int, uint64_t, 4);
+VectorImpl(Boolean, Boolean *, 4);
--- /dev/null
+#ifndef STRUCTS_H
+#define STRUCTS_H
+#include "vector.h"
+#include "classlist.h"
+
+VectorDef(Int, uint64_t, 4);
+VectorDef(Boolean, Boolean *, 4);
+#endif
#include "classlist.h"
#include "mymemory.h"
-class Table {
-public:
- MEMALLOC;
-private:
+struct Table {
+
};
+
+Table * allocTable();
#endif
--- /dev/null
+#ifndef VECTOR_H
+#define VECTOR_H
+#include <string.h>
+
+#define VectorDef(name, type, defcap) \
+ struct Vector ## name { \
+ uint size; \
+ uint capacity; \
+ type * array; \
+ }; \
+ typedef struct Vector ## name Vector ## name; \
+ Vector ## name * allocVector ## name(uint capacity); \
+ Vector ## name * allocDefVector ## name(); \
+ Vector ## name * allocVectorArray ## name(type * array, uint capacity); \
+ void pushVector ## name(Vector ## name *vector, type item); \
+ type getVector ## name(Vector ## name *vector, uint index); \
+ void setVector ## name(Vector ## name *vector, uint index, type item); \
+ uint getSize ##name(Vector ##name *vector); \
+ void freeVector ##name(Vector ##name *vector);
+
+#define VectorImpl(name, type, defcap) \
+ Vector ## name * allocDefVector ## name() { \
+ return allocVector ## name(defcap); \
+ } \
+ Vector ## name * allocVector ## name(uint capacity) { \
+ Vector ## name * tmp = (Vector ## name *) ourmalloc(sizeof(type)); \
+ tmp->size = 0; \
+ tmp->capacity = capacity; \
+ tmp->array = (type *) ourcalloc(1, sizeof(type) * capacity); \
+ return tmp; \
+ } \
+ Vector ## name * allocVectorArray ## name(uint capacity, type * array) { \
+ Vector ## name * tmp = allocVector ## name(capacity); \
+ memcpy(tmp->array, array, capacity * sizeof(type)); \
+ return tmp; \
+ } \
+ void pushVector ## name(Vector ## name *vector, type item) { \
+ if (vector->size >= vector->capacity) { \
+ uint newcap=vector->capacity * 2; \
+ vector->array=(type *)ourrealloc(vector->array, newcap); \
+ } \
+ vector->array[vector->size++] = item; \
+ } \
+ type getVector ## name(Vector ## name * vector, uint index) { \
+ return vector->array[index]; \
+ } \
+ void setVector ## name(Vector ## name * vector, uint index, type item) { \
+ vector->array[index]=item; \
+ } \
+ uint getSize ## name(Vector ## name *vector) { \
+ return vector->size; \
+ } \
+ void freeVector ##name(Vector ##name *vector) { \
+ ourfree(vector->array); \
+ ourfree(vector); \
+ }
+#endif