[Compbench-devel] CompBenchmarks++/Compiler Compiler.cpp, NONE, 1.1 Compiler.h, NONE, 1.1 Compiler-
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2006-11-01 11:31:48
|
Update of /cvsroot/compbench/CompBenchmarks++/Compiler In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8489 Added Files: Compiler.cpp Compiler.h Compiler-Options.cpp Compiler-Options.h Log Message: Class name changed. --- NEW FILE: Compiler-Options.h --- /* ---------------------------------------------------------------------------- $Id: Compiler-Options.h,v 1.1 2006/11/01 11:31:39 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMCOMPILER_OPTIONS #define H_CBMCOMPILER_OPTIONS #include <string> class CBMCompiler; /** \brief Abstraction layer for handling compilers' options. * * This class defines the base object for all options to supported compilers. * It only stores options (std::string, or char*) into an object and allows * querying them. */ class CBMCompilerOptions { private: /** Stores options. Initialised by constructor. * \sa Options() */ std::string options; /** Stores compiler using options. Initialised by constructor. * \sa Compiler() */ class CBMCompiler *compiler; protected: public: /** Constructor \param _compiler Compiler object related to given options \param _options Options to manage in current object. */ CBMCompilerOptions(class CBMCompiler *_compiler, char *_options); /** Retrives compiler \return Compiler instance declared in constructor */ virtual class CBMCompiler *Compiler(void); /** Retrives options \return Options (to compiler instance) declared in constructor */ virtual std::string Options(void); virtual ~CBMCompilerOptions(); }; #endif --- NEW FILE: Compiler.h --- /* ---------------------------------------------------------------------------- $Id: Compiler.h,v 1.1 2006/11/01 11:31:39 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMCOMPILER #define H_CBMCOMPILER #include <string> class CBMSystem; /** \brief Abstraction layer for handling compilers. * * This class defines the base abstract (pure) object for all supported compilers. */ class CBMCompiler { private: /** Internal usage * Speeds up compilerName(). */ std::string cacheCompilerName; /** Internal usage * Speeds up compilerVersion(). */ std::string cacheCompilerVersion; protected: /** Used internally to get information on compiler's binary */ class CBMSystem *system; /** Initialised by constructor. \sa CBMCompiler() */ char *compilerBinary; /** Constructor \param _system the CBMSystem to use internaly. \param _compilerBinary absolute or relative path to the compiler program */ CBMCompiler(class CBMSystem *_system, char *_compilerBinary); /** Gets compiler's name * \return std::string containing the name of the compiler * \sa getCompilerName() */ virtual std::string getCompilerName(void) = 0; /** Gets compiler's version * \return std::string containing the version of the compiler * \sa getCompilerVersion() */ virtual std::string getCompilerVersion(void) = 0; public: /** Display compiler's information. * Format is strict. This output is used by compbenchmark-config. */ virtual void display(void); /** Internal compiler id. \return std::string like 'gcc' or 'g++'. */ virtual std::string compiler(void) = 0; /** Gets compiler's name. Do not overload. \sa getCompilerName() \return The compiler name. */ virtual std::string compilerName(void); /** Gets compiler's version. Do not overload. \sa getCompilerVersion() \return The compiler version. */ virtual std::string compilerVersion(void); /** Gets compiler's program (as specified in constructor). \return The compiler program (absolute or relative, depending on method used in instanciation). */ virtual std::string Binary(void); /** Gets compiler's language. \return C or C++. */ virtual char *language(void) = 0; /** Virtual destructor */ virtual ~CBMCompiler(); }; /** \brief Gives a compiler object according to a binary (or executable) program. * * This class creates CBMCompiler objects. It is only instancied once, and I currently see no need to derivate it. */ class CBMCompilerSelector { private: protected: class CBMSystem *system; public: /** Constructor */ CBMCompilerSelector(class CBMSystem *_system); /** Main method. * Returns a CBMCompiler object. * \param compilerBinary Absolute or relative name of the compiler program */ CBMCompiler *select(char *compilerBinary); /** Virtual destructor */ ~CBMCompilerSelector(); }; #endif --- NEW FILE: Compiler.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler.cpp,v 1.1 2006/11/01 11:31:39 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Compiler/Compiler.h> #include <Compiler/Compiler-GCC/Compiler-GCC.h> #include <Compiler/Compiler-TCC/Compiler-TCC.h> #include <System/System.h> #include <iostream> CBMCompiler::CBMCompiler(CBMSystem *_system, char *_compilerBinary) { system=_system; compilerBinary=_compilerBinary; } std::string CBMCompiler::compilerName(void) { if (cacheCompilerName!="") return(cacheCompilerName); cacheCompilerName=getCompilerName(); system->Chomp(cacheCompilerName); return(cacheCompilerName); } std::string CBMCompiler::compilerVersion(void) { if (cacheCompilerVersion!="") return(cacheCompilerVersion); cacheCompilerVersion=getCompilerVersion(); system->Chomp(cacheCompilerVersion); return(cacheCompilerVersion); } std::string CBMCompiler::Binary(void) { return(compilerBinary); } void CBMCompiler::display(void) { std::cout << "compiler::id=" << compiler() << std::endl << "compiler::name=" << compilerName() << std::endl << "compiler::version=" << compilerVersion() << std::endl << "compiler::language=" << language() << std::endl << "compiler::binary=" << Binary() << std::endl; } CBMCompiler::~CBMCompiler() { } CBMCompilerSelector::CBMCompilerSelector(CBMSystem *_system) { system=_system; } CBMCompiler *CBMCompilerSelector::select(char *compilerBinary) { std::string cmd; std::string raw; cmd="("; cmd+=compilerBinary; cmd+=" --version) 2> /dev/null"; system->exec(cmd, raw); if (raw!="") { if (((int) raw.find("(GCC)")>0) && ((int) raw.find("Free Software Foundation")>0)) { if ((int) raw.find("g++")>=0) { return(new CBMCompilerGCC_cpp(system, compilerBinary)); } else return(new CBMCompilerGCC(system, compilerBinary)); } raw=compilerBinary; if (((int) raw.find("g++")>0) || (raw=="g++")) { return(new CBMCompilerGCC_cpp(system, compilerBinary)); } if (((int) raw.find("gcc")>0) || (raw=="gcc")) { return(new CBMCompilerGCC(system, compilerBinary)); } } cmd="("; cmd+=compilerBinary; cmd+=" -h) 2> /dev/null"; system->exec(cmd, raw); /* !!! */ if (raw!="") { if ((int) raw.find("Tiny C Compiler">0)) { return(new CBMCompilerTCC(system, compilerBinary)); } } /* !!! */ return(0); } CBMCompilerSelector::~CBMCompilerSelector() { } --- NEW FILE: Compiler-Options.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler-Options.cpp,v 1.1 2006/11/01 11:31:39 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Compiler/Compiler-Options.h> #include <Compiler/Compiler.h> CBMCompilerOptions::CBMCompilerOptions(CBMCompiler *_compiler, char *_options) { compiler=_compiler; options=_options; } CBMCompiler *CBMCompilerOptions::Compiler(void) { return(compiler); } std::string CBMCompilerOptions::Options(void) { return(options); } CBMCompilerOptions::~CBMCompilerOptions() { } |