From: Hamed Date: Fri, 16 Jun 2017 23:40:03 +0000 (-0700) Subject: adding TableEntries and ... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=d4e365ab7ea6d97d8ad65c1f230871254ce36737 adding TableEntries and ... --- diff --git a/src/AST/table.c b/src/AST/table.c index e89d72a..48bd532 100644 --- a/src/AST/table.c +++ b/src/AST/table.c @@ -1 +1,20 @@ #include "table.h" +#include "common.h" +#include "structs.h" +#include "tableentry.h" + + +Table * allocTable(Set **domains, uint numDomain, Set * range){ + Table* table = (Table*) ourmalloc(sizeof(Table)); + table->domains = allocDefVectorSet(); + for(int i=0; idomains, domains[i]); + } + table->range =range; +} + +void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result){ + ASSERT(getSizeVectorSet( table->domains) == inputSize); + pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result)); +} + diff --git a/src/AST/table.h b/src/AST/table.h index 2bb9805..8027f88 100644 --- a/src/AST/table.h +++ b/src/AST/table.h @@ -2,10 +2,15 @@ #define TABLE_H #include "classlist.h" #include "mymemory.h" +#include "structs.h" struct Table { - + VectorSet* domains; + Set * range; + VectorTableEntry* entries; }; -Table * allocTable(); +Table * allocTable(Set **domains, uint numDomain, Set * range); +void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result); + #endif diff --git a/src/AST/tableentry.c b/src/AST/tableentry.c new file mode 100644 index 0000000..216a2b5 --- /dev/null +++ b/src/AST/tableentry.c @@ -0,0 +1,10 @@ +#include "tableentry.h" + +TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result){ + TableEntry* te = (TableEntry*) ourmalloc(sizeof(TableEntry)+inputSize*sizeof(uint64_t)); + te->output=result; + for(int i=0; iinputs[i]=inputs[i]; + } + return te; +} \ No newline at end of file diff --git a/src/AST/tableentry.h b/src/AST/tableentry.h new file mode 100644 index 0000000..fae0a3b --- /dev/null +++ b/src/AST/tableentry.h @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: tableentry.h + * Author: hamed + * + * Created on June 16, 2017, 3:54 PM + */ + +#ifndef TABLEENTRY_H +#define TABLEENTRY_H + +#include "classlist.h"; +#include "mymemory.h"; +struct TableEntry{ + uint64_t output; + uint64_t inputs[]; +}; + +TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result); + +#endif /* TABLEENTRY_H */ + diff --git a/src/Collections/structs.h b/src/Collections/structs.h index 888f359..3e08e97 100644 --- a/src/Collections/structs.h +++ b/src/Collections/structs.h @@ -11,6 +11,9 @@ VectorDef(Boolean, Boolean *, 4); VectorDef(Constraint, Constraint *, 4); VectorDef(Set, Set *, 4); VectorDef(Element, Element *, 4); +VectorDef(TableEntry, TableEntry *, 4); +VectorDef(Predicate, Predicate *, 4); +VectorDef(Table, Table *, 4); inline unsigned int Ptr_hash_function(void * hash) { return (unsigned int)((uint64_t)hash >> 4); diff --git a/src/classlist.h b/src/classlist.h index 361dcb6..fc265b5 100644 --- a/src/classlist.h +++ b/src/classlist.h @@ -54,6 +54,9 @@ typedef struct ElementEncoding ElementEncoding; struct FunctionEncoding; typedef struct FunctionEncoding FunctionEncoding; +struct TableEntry; +typedef struct TableEntry TableEntry; + typedef unsigned int uint; typedef uint64_t VarType; #endif diff --git a/src/csolver.c b/src/csolver.c index 8835fbf..68bbb46 100644 --- a/src/csolver.c +++ b/src/csolver.c @@ -5,6 +5,7 @@ #include "AST/boolean.h" #include "AST/predicate.h" #include "AST/order.h" +#include "table.h" CSolver * allocCSolver() { CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver)); @@ -12,6 +13,8 @@ CSolver * allocCSolver() { tmp->allBooleans=allocDefVectorBoolean(); tmp->allSets=allocDefVectorSet(); tmp->allElements=allocDefVectorElement(); + tmp->allPredicates = allocDefVectorPredicate(); + tmp->allTables = allocDefVectorTable(); return tmp; } @@ -38,7 +41,7 @@ void deleteSolver(CSolver *this) { for(uint i=0;iallElements, i)); } - + //FIXME: Freeing alltables and allpredicates deleteVectorElement(this->allElements); ourfree(this); } @@ -89,14 +92,19 @@ Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domai } Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain, uint numDomain) { - return allocPredicate(op, domain,numDomain); + Predicate* predicate= allocPredicate(op, domain,numDomain); + pushVectorPredicate(solver->allPredicates, predicate); + return predicate; } Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) { - return NULL; + Table* table= allocTable(domains,numDomain,range); + pushVectorTable(solver->allTables, table); + return table; } -void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result) { +void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) { + addNewTableEntry(table,inputs, inputSize,result); } Function * completeTable(CSolver *solver, Table * table) { diff --git a/src/csolver.h b/src/csolver.h index 15d3f47..0093586 100644 --- a/src/csolver.h +++ b/src/csolver.h @@ -9,6 +9,8 @@ struct CSolver { VectorBoolean * allBooleans; VectorSet * allSets; VectorElement * allElements; + VectorPredicate * allPredicates; + VectorTable * allTables; }; /** Create a new solver instance. */ @@ -60,7 +62,7 @@ Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) /** This function adds an input output relation to a table. */ -void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result); +void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result); /** This function converts a completed table into a function. */ @@ -86,6 +88,6 @@ void addBoolean(CSolver *, Boolean * constraint); /** This function instantiates an order of type type over the set set. */ Order * createOrder(CSolver *, enum OrderType type, Set * set); -/** This function instantiates a predicate on two items in an order. */ +/** This function instantiates a boolean on two items in an order. */ Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second); #endif