Skip to content

Commit

Permalink
Gravel Symbols and Module headers now print correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBayliss committed May 13, 2013
0 parents commit df25033
Show file tree
Hide file tree
Showing 30 changed files with 1,549 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


set (GRAVEL_SRC Context Module Object Symbol)
set (CODEGEN_SRC codegen/Generator
codegen/Definitions
codegen/SequentialModule
codegen/AssignmentModule
codegen/GuardModule
codegen/ForModule
codegen/CodegenModule)


add_library(gravel ${GRAVEL_SRC} ${CODEGEN_SRC})
target_link_libraries(gravel ${CLOOG_LIBRARY})
target_link_libraries(gravel ${OSL_LIBRARY})
target_link_libraries(gravel ${GMP_LIBRARY})
98 changes: 98 additions & 0 deletions src/Context.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <gravel/Context.h>
#include <boost/bind.hpp>
#include <stdlib.h>

#include <algorithm>
#include <functional>
#include <string>

Gravel::Context * Gravel::Context::pInstance = NULL;

Gravel::Context * Gravel::Context::getInstance()
{
if (Gravel::Context::pInstance == NULL) {
Gravel::Context::pInstance = new Gravel::Context();
}
return pInstance;
}

Gravel::Context::Context() {

}
struct name_matches : public std::binary_function<Gravel::Module, std::string, bool> {
bool operator()(const Gravel::Module& m, const std::string name) const {
return m.getName() == name;
}
};

Gravel::Module Gravel::Context::getModule(const std::string& name) const {
// This should increment module reference counter when return does a copy
std::binder2nd<name_matches> match_object(name_matches(), name);
Gravel::ModuleList::iterator mlit = std::find_if(ml.begin(), ml.end(), match_object);

if (mlit == ml.end()) {
throw Gravel::ModuleNotFound(name);
} else {
return *mlit;
}

}

void Gravel::Context::insert(const Gravel::Module& module) {
ml.insert(module);
}

bool Gravel::Context::exists(const Gravel::Module& module) {
// lookup in module
return (ml.find(module) != ml.end());

}

void Gravel::Context::insert(const Gravel::Module& module, const Gravel::Symbol symbol, const Gravel::SymbolInterface::Direction& direction) {
SymbolKey key(module, direction);
sm.insert(std::pair<SymbolKey, Symbol>(key, symbol));
}

struct symbol_matches : public std::binary_function<std::pair<const Gravel::SymbolKey, Gravel::Symbol>, Gravel::Symbol, bool> {
bool operator()(const std::pair<const Gravel::SymbolKey, Gravel::Symbol>& p, const Gravel::Symbol & n) const {
return (p.second) == n;
}
};


bool Gravel::Context::exists(const Gravel::Module& module, const Gravel::Symbol symbol, const Gravel::SymbolInterface::Direction& direction) {
SymbolKey key(module, direction);
ConstSymbolRange sr = sm.equal_range(key);

std::binder2nd<symbol_matches> match_object((symbol_matches()), symbol);
// Gravel::ModuleList::iterator mlit = std::find_if(ml.begin(), ml.end(), match_object);

return (std::find_if(sr.first, sr.second, match_object) == sr.second);//std::bind2nd<std::equal_to<Gravel::Symbol>, Gravel::Symbol>(eq,symbol)) != sr.second);
}

Gravel::ConstModuleList Gravel::Context::getModules() const {
return ml;
}

Gravel::ConstSymbolRange Gravel::Context::getSymbols(Gravel::Module module, Symbol::Direction direction) const {
SymbolKey key(module, direction);
return sm.equal_range(key);

}

void Gravel::Context::emit(std::ostream& os) {
// emit to file

os << ml.size() << std::endl;

}

bool Gravel::Context::elaborate() {
// create .gravel folder if it doesn't exist
// emit files to temporary file

// call iverilog and elaborate design (capturing output)
// report success / failure and output / error messages

return true;
}
165 changes: 165 additions & 0 deletions src/Module.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@

#include <gravel/Module.h>

#include <gravel/private/Module.h>

#include <cassert>

#include "gravel/Context.h"
#include <sstream>
#include <set>

#include <boost/static_assert.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_integral.hpp>
/*
Module Definition
*/


Gravel::ModuleNotFound::ModuleNotFound(std::string _name) : name(_name) {};

const char * Gravel::ModuleNotFound::what() const throw() {
std::stringstream ss;
ss << "Module (\"" << name << "\") Not Found ";
return ss.str().c_str();
}

Gravel::ModuleNotFound::~ModuleNotFound() throw() {

}



Gravel::Module::Module(){

}

Gravel::Module::Module(const std::string& name) : module(ModulePtr(new ModuleImplementation(name))) {


}



/* template<class T>
class FormattedBuffer : public std::streambuf, SeparatorInterface {
public :
explicit FormattedBuffer(std::ostream& sink, std::size_t buff_sz = 1);
private:
int_type overflow(int_type ch);
int sync();
FormattedBuffer(const FormattedBuffer &);
FormattedBuffer & operator= (const FormattedBuffer &);
std::ostream &sink_;
std::vector<char> buffer_;
};
*/




/*template < class T, class S >
class FormattedStream {
FormattedStream();
};*/


//openformattedstream -> ostream << formattedlist

//openformattedstream -> openformattedstream << formattedlist

//closedformattedstream

/* template <class T, class S >
FormattedStream<T,S> operator<< (std::ostream& os, FormattedList<T, S> fl) {
return FormattedStream<T,S>(os, fl);
}
*/
/*
template <class T, class S >
FormattedStream<T,S> operator<< (const FormattedStream<T, S> & fs, const FormattedList<T, S> & fr) {
std::cout << "concatenated streams" << std::endl;
return fs;
}
*/
// OpenFormattedList operator<<(std::ostream&,const FormattedList) {

// }

//operator<<()

std::ostream& Gravel::Module::emit(std::ostream& os) const {
os << "module " << this->getName();
Gravel::Context * ctx = Gravel::Context::getInstance();

Gravel::ConstSymbolRange si = ctx->getSymbols(*this, Gravel::Symbol::Input);
Gravel::ConstSymbolRange so = ctx->getSymbols(*this, Gravel::Symbol::Output);


os << "(" << FormattedList<Comma>(si.first, si.second) << FormattedList<Comma>(so.first, so.second) << ");" << "\n";

os << "endmodule" << "\n";
return os;
}

const std::string Gravel::Module::getName() const {
return module->getName();
}

void Gravel::Module::operator>>(Symbol& gs) {

// lookup context
Gravel::Context * context = Gravel::Context::getInstance();
// register a copy of the shared_ptr
if (!context->exists(*this)) {
context->insert(*this);
}
context->insert(*this, gs, Gravel::SymbolInterface::Output);

}
void Gravel::Module::operator<<(Symbol& gs){
Gravel::Context * context = Gravel::Context::getInstance();
// register a copy of the shared_ptr
if (!context->exists(*this)) {
context->insert(*this);
}
context->insert(*this, gs, Gravel::SymbolInterface::Input);
}

bool Gravel::Module::operator<(const Module & rhs) const {
if (this->getName() < rhs.getName()) {
return true;
} else if (this->getName() == rhs.getName()) {
return (module.get() < rhs.module.get());
}
return false;

}


/*
Module Implementation
*/


Gravel::ModuleImplementation::ModuleImplementation() {
assert(false);
}

Gravel::ModuleImplementation::ModuleImplementation(const std::string& name_) : name(name_) {

}

const std::string Gravel::ModuleImplementation::getName() {
return name;
}

1 change: 1 addition & 0 deletions src/Object.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <gravel/Object.h>
7 changes: 7 additions & 0 deletions src/Ranges.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include <utility>





14 changes: 14 additions & 0 deletions src/StateMachine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class StateMachine : SynthesizableModule{

};
addTransition

StateMachine sm;

Symbol x;
Symbol y;

sm.addTransition( "S1" >> "S2" ) -> ( y > x );

sm.addAction ( "S1") -> ( x2 += x + 1);

32 changes: 32 additions & 0 deletions src/Symbol.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#include <gravel/Symbol.h>
#include <gravel/private/Symbol.h>

Gravel::Symbol::Symbol() {

}

Gravel::Symbol::Symbol(const std::string& name_) : symbol(new Gravel::SymbolImplementation(name_)) {

}
const std::string Gravel::Symbol::getName() const {
return symbol->getName();
}


Gravel::SymbolImplementation::SymbolImplementation(const std::string& name_) : name(name_) {

}

const std::string Gravel::SymbolImplementation::getName() const {
return name;
}

bool Gravel::Symbol::operator==(const Gravel::Symbol& sm) const {
return (getName() == sm.getName());

}

std::ostream& Gravel::operator<< (std::ostream& os, const Gravel::Symbol& s) {
os << s.getName();
}
19 changes: 19 additions & 0 deletions src/cmake/FindCloog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FIND_PATH(CLOOG_INCLUDE_DIR cloog/isl/cloog.h)

FIND_LIBRARY(CLOOG_LIBRARY NAMES cloog-isl)

IF (CLOOG_INCLUDE_DIR AND CLOOG_LIBRARY)
SET(CLOOG_FOUND TRUE)
ENDIF (CLOOG_INCLUDE_DIR AND CLOOG_LIBRARY)


IF (CLOOG_FOUND)
IF (NOT CLOOG_FIND_QUIETLY)
MESSAGE(STATUS "Found Cloog: ${CLOOG_LIBRARY}")
ENDIF (NOT CLOOG_FIND_QUIETLY)
ELSE (CLOOG_FOUND)
IF (CLOOG_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Cloog")
ENDIF (CLOOG_FIND_REQUIRED)
ENDIF (CLOOG_FOUND)

19 changes: 19 additions & 0 deletions src/cmake/FindGmp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FIND_PATH(GMP_INCLUDE_DIR gmp.h)

FIND_LIBRARY(GMP_LIBRARY NAMES gmp)

IF (GMP_INCLUDE_DIR AND GMP_LIBRARY)
SET(GMP_FOUND TRUE)
ENDIF (GMP_INCLUDE_DIR AND GMP_LIBRARY)


IF (GMP_FOUND)
IF (NOT GMP_FIND_QUIETLY)
MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
ENDIF (NOT GMP_FIND_QUIETLY)
ELSE (GMP_FOUND)
IF (GMP_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find GMP")
ENDIF (GMP_FIND_REQUIRED)
ENDIF (GMP_FOUND)

Loading

0 comments on commit df25033

Please sign in to comment.