diff options
author | Josh Blum | 2013-08-01 01:12:24 -0700 |
---|---|---|
committer | Josh Blum | 2013-08-01 01:12:24 -0700 |
commit | a23bf59c46dae7aa25c4763c6122d0822c88abc7 (patch) | |
tree | af37ea0c6b2872071938390c857e4efcb4975d86 /include | |
parent | 1897808616c91d277e24335a337bec92592fb87a (diff) | |
download | sandhi-a23bf59c46dae7aa25c4763c6122d0822c88abc7.tar.gz sandhi-a23bf59c46dae7aa25c4763c6122d0822c88abc7.tar.bz2 sandhi-a23bf59c46dae7aa25c4763c6122d0822c88abc7.zip |
gras: jit factory api + unit tests
Diffstat (limited to 'include')
-rw-r--r-- | include/gras/detail/factory.hpp | 44 | ||||
-rw-r--r-- | include/gras/factory.hpp | 32 |
2 files changed, 43 insertions, 33 deletions
diff --git a/include/gras/detail/factory.hpp b/include/gras/detail/factory.hpp index 551ba9e..36023de 100644 --- a/include/gras/detail/factory.hpp +++ b/include/gras/detail/factory.hpp @@ -40,7 +40,7 @@ template <typename ReturnType> void register_factory(const std::string &path, ReturnType(*fcn)()) { void *r = new FactoryRegistryEntryImpl0<ReturnType>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -64,7 +64,7 @@ template <typename ReturnType, typename A0> void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &)) { void *r = new FactoryRegistryEntryImpl1<ReturnType, A0>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -88,7 +88,7 @@ template <typename ReturnType, typename A0, typename A1> void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &)) { void *r = new FactoryRegistryEntryImpl2<ReturnType, A0, A1>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -112,7 +112,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2> void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)) { void *r = new FactoryRegistryEntryImpl3<ReturnType, A0, A1, A2>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -136,7 +136,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &)) { void *r = new FactoryRegistryEntryImpl4<ReturnType, A0, A1, A2, A3>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -160,7 +160,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &)) { void *r = new FactoryRegistryEntryImpl5<ReturnType, A0, A1, A2, A3, A4>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -184,7 +184,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &)) { void *r = new FactoryRegistryEntryImpl6<ReturnType, A0, A1, A2, A3, A4, A5>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -208,7 +208,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &)) { void *r = new FactoryRegistryEntryImpl7<ReturnType, A0, A1, A2, A3, A4, A5, A6>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -232,7 +232,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &)) { void *r = new FactoryRegistryEntryImpl8<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -256,7 +256,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &)) { void *r = new FactoryRegistryEntryImpl9<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7, A8>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -280,7 +280,7 @@ template <typename ReturnType, typename A0, typename A1, typename A2, typename A void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &)) { void *r = new FactoryRegistryEntryImpl10<ReturnType, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9>(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -290,7 +290,7 @@ inline Element *make(const std::string &path) { PMCList args(0); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0> @@ -298,7 +298,7 @@ Element *make(const std::string &path, const A0 &a0) { PMCList args(1); args[0] = PMC_M(a0); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1> @@ -307,7 +307,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1) PMCList args(2); args[0] = PMC_M(a0); args[1] = PMC_M(a1); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2> @@ -317,7 +317,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2) args[0] = PMC_M(a0); args[1] = PMC_M(a1); args[2] = PMC_M(a2); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3> @@ -328,7 +328,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[1] = PMC_M(a1); args[2] = PMC_M(a2); args[3] = PMC_M(a3); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4> @@ -340,7 +340,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[2] = PMC_M(a2); args[3] = PMC_M(a3); args[4] = PMC_M(a4); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> @@ -353,7 +353,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[3] = PMC_M(a3); args[4] = PMC_M(a4); args[5] = PMC_M(a5); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> @@ -367,7 +367,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[4] = PMC_M(a4); args[5] = PMC_M(a5); args[6] = PMC_M(a6); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> @@ -382,7 +382,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[5] = PMC_M(a5); args[6] = PMC_M(a6); args[7] = PMC_M(a7); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> @@ -398,7 +398,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[6] = PMC_M(a6); args[7] = PMC_M(a7); args[8] = PMC_M(a8); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> @@ -415,7 +415,7 @@ Element *make(const std::string &path, const A0 &a0, const A1 &a1, const A2 &a2, args[7] = PMC_M(a7); args[8] = PMC_M(a8); args[9] = PMC_M(a9); - return Factory::_handle_make(path, PMC_M(args)); + return _handle_make(path, PMC_M(args)); } } diff --git a/include/gras/factory.hpp b/include/gras/factory.hpp index fd03bb3..819877c 100644 --- a/include/gras/factory.hpp +++ b/include/gras/factory.hpp @@ -6,24 +6,28 @@ #include <gras/gras.hpp> #include <gras/element.hpp> #include <PMC/PMC.hpp> +#include <vector> #include <string> namespace gras { /*! - * Element factory: - * - Register factory functions into the global factory. - * - Call make() to create element from global factory. + * The just in time factory: + * Compile a C++ source and load it into the element factory. + * + * Flags are an optional list of compiler flags. + * See the man page for clang for possible options. + * Example: flags.push_back("-O3") + * + * Include directories control the header file search path. + * Users may leave this empty unless headers + * are installed into non-standard directories. + * + * \param source C++ source code in a string + * \param flags optional compiler flags */ -struct GRAS_API Factory -{ - /******************************************************************* - * Private registration hooks - ******************************************************************/ - static void _register_factory(const std::string &, void *); - static Element *_handle_make(const std::string &, const PMCC &); -}; +GRAS_API void jit_factory(const std::string &source, const std::vector<std::string> &flags); /*********************************************************************** * Register API - don't look here, template magic, not helpful @@ -101,6 +105,12 @@ static Element *make(const std::string &path, const A0 &, const A1 &, const A2 & template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> static Element *make(const std::string &path, const A0 &, const A1 &, const A2 &, const A3 &, const A4 &, const A5 &, const A6 &, const A7 &, const A8 &, const A9 &); + +//! Register factory functions into the global factory. +GRAS_API void _register_factory(const std::string &, void *); + +//! Call make() to create element from global factory. +GRAS_API Element *_handle_make(const std::string &, const PMCC &); } /*! |