From a23bf59c46dae7aa25c4763c6122d0822c88abc7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 1 Aug 2013 01:12:24 -0700 Subject: gras: jit factory api + unit tests --- include/gras/detail/factory.hpp | 44 ++++++++++++++++++++--------------------- include/gras/factory.hpp | 32 +++++++++++++++++++----------- 2 files changed, 43 insertions(+), 33 deletions(-) (limited to 'include') 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 void register_factory(const std::string &path, ReturnType(*fcn)()) { void *r = new FactoryRegistryEntryImpl0(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -64,7 +64,7 @@ template void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &)) { void *r = new FactoryRegistryEntryImpl1(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -88,7 +88,7 @@ template void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &)) { void *r = new FactoryRegistryEntryImpl2(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -112,7 +112,7 @@ template void register_factory(const std::string &path, ReturnType(*fcn)(const A0 &, const A1 &, const A2 &)) { void *r = new FactoryRegistryEntryImpl3(fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -136,7 +136,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -160,7 +160,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -184,7 +184,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -208,7 +208,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -232,7 +232,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -256,7 +256,7 @@ template (fcn); - Factory::_register_factory(path, r); + _register_factory(path, r); } /*********************************************************************** @@ -280,7 +280,7 @@ template (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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 #include #include +#include #include 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 &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 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 &); } /*! -- cgit