Thread: [Compbench-devel] CompBenchmarks++/libcompbenchmarks/Compiler Compiler-Options.cpp, NONE, 1.1 Compi
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-22 18:24:27
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Compiler In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv20703 Added Files: Compiler-Options.cpp Compiler-Options.h Compiler.cpp Compiler.h Makefile.am Log Message: libcompbenchmarks moved in a separate directory. --- NEW FILE: Compiler.h --- /* ---------------------------------------------------------------------------- $Id: Compiler.h,v 1.1 2007/01/22 18:24:21 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> namespace CBM { // class CBM::System; /** \brief Abstraction layer for handling compilers. * * This class defines the base abstract (pure) object for all supported compilers. */ class Compiler { 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 System *system; /** Initialised by constructor. \sa Compiler() */ char *compilerBinary; /** Constructor \param _system the System to use internaly. \param _compilerBinary absolute or relative path to the compiler program */ Compiler(class System *_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 ~Compiler(); }; /** \brief Gives a compiler object according to a binary (or executable) program. * * This class creates Compiler objects. It is only instancied once, and I currently see no need to derivate it. */ class CompilerSelector { private: protected: class System *system; public: /** Constructor */ CompilerSelector(class System *_system); /** Main method. * Returns a Compiler object. * \param compilerBinary Absolute or relative name of the compiler program */ Compiler *select(char *compilerBinary); /** Virtual destructor */ ~CompilerSelector(); }; } #endif --- NEW FILE: Makefile.am --- # ----------------------------------------------------------------------------- # $Id: Makefile.am,v 1.1 2007/01/22 18:24:21 xfred Exp $ # $Source: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Compiler/Makefile.am,v $ # # This is free software. # For details, see the GNU Public License in the COPYING file, or # Look http://www.fsf.org # ----------------------------------------------------------------------------- noinst_LTLIBRARIES = libCompiler.la SUBDIRS = Compiler-TCC Compiler-GCC libCompiler_la_LIBADD = Compiler-TCC/libCompilerTCC.la \ Compiler-GCC/libCompilerGCC.la sources = Compiler.cpp \ Compiler-Options.cpp libCompiler_la_SOURCES = $(sources) libCompilerinclude_HEADERS = $(sources:.cpp=.h) libCompilerincludedir = $(includedir)/compbenchmarks/Compiler INCLUDES = -I $(top_srcdir)/libcompbenchmarks --- NEW FILE: Compiler-Options.h --- /* ---------------------------------------------------------------------------- $Id: Compiler-Options.h,v 1.1 2007/01/22 18:24:21 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> namespace CBM { 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 CompilerOptions { private: /** Stores options. Initialised by constructor. * \sa Options() */ std::string options; /** Stores compiler using options. Initialised by constructor. * \sa Compiler() */ class Compiler *compiler; protected: public: /** Constructor \param _compiler Compiler object related to given options \param _options Options to manage in current object. */ CompilerOptions(class Compiler *_compiler, char *_options); /** Retrives compiler \return Compiler instance declared in constructor */ virtual class Compiler *Compiler(void); /** Retrives options \return Options (to compiler instance) declared in constructor */ virtual std::string Options(void); virtual ~CompilerOptions(); }; } #endif --- NEW FILE: Compiler.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler.cpp,v 1.1 2007/01/22 18:24:21 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> using namespace CBM; Compiler::Compiler(System *_system, char *_compilerBinary) { system=_system; compilerBinary=_compilerBinary; } std::string Compiler::compilerName(void) { if (cacheCompilerName!="") return(cacheCompilerName); cacheCompilerName=getCompilerName(); system->Chomp(cacheCompilerName); return(cacheCompilerName); } std::string Compiler::compilerVersion(void) { if (cacheCompilerVersion!="") return(cacheCompilerVersion); cacheCompilerVersion=getCompilerVersion(); system->Chomp(cacheCompilerVersion); return(cacheCompilerVersion); } std::string Compiler::Binary(void) { return(compilerBinary); } void Compiler::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; } Compiler::~Compiler() { } CompilerSelector::CompilerSelector(CBM::System *_system) { system=_system; } Compiler *CompilerSelector::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 CompilerGCC_cpp(system, compilerBinary)); } else return(new CompilerGCC(system, compilerBinary)); } raw=compilerBinary; if (((int) raw.find("g++")>0) || (raw=="g++")) { return(new CompilerGCC_cpp(system, compilerBinary)); } if (((int) raw.find("gcc")>0) || (raw=="gcc")) { return(new CompilerGCC(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 CompilerTCC(system, compilerBinary)); } } /* !!! */ return(0); } CompilerSelector::~CompilerSelector() { } --- NEW FILE: Compiler-Options.cpp --- /* ---------------------------------------------------------------------------- $Id: Compiler-Options.cpp,v 1.1 2007/01/22 18:24:21 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> using namespace CBM; CompilerOptions::CompilerOptions(CBM::Compiler *_compiler, char *_options) { compiler=_compiler; options=_options; } Compiler *CompilerOptions::Compiler(void) { return(compiler); } std::string CompilerOptions::Options(void) { return(options); } CompilerOptions::~CompilerOptions() { } |