diff options
author | Chris Johns <chrisj@rtems.org> | 2014-05-09 21:50:37 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2014-06-18 16:48:08 +1200 |
commit | 100f517ab37265acdf067e36b6860020ec8b2184 (patch) | |
tree | 2316c8b888e11dcbcfbfc66a0c1e31991ea20656 /tester/covoar/TargetFactory.cc | |
parent | 4.11: Add ntp patch. (diff) | |
download | rtems-tools-100f517ab37265acdf067e36b6860020ec8b2184.tar.bz2 |
covoar: Merger the covoar source from rtems-testing.git.
Use waf to build covoar.
Diffstat (limited to 'tester/covoar/TargetFactory.cc')
-rw-r--r-- | tester/covoar/TargetFactory.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tester/covoar/TargetFactory.cc b/tester/covoar/TargetFactory.cc new file mode 100644 index 0000000..27b0bc1 --- /dev/null +++ b/tester/covoar/TargetFactory.cc @@ -0,0 +1,89 @@ +// +// + +//! @file TargetFactory.cc +//! @brief TargetFactory Implementation +//! +//! This file contains the implementation of a factory for a +//! instances of a family of classes derived from TargetBase. +//! + +#include "TargetFactory.h" + +#include "Target_arm.h" +#include "Target_i386.h" +#include "Target_m68k.h" +#include "Target_powerpc.h" +#include "Target_lm32.h" +#include "Target_sparc.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +namespace Target { + + //! + //! @brief TargetBase Factory Table Entry + //! + //! This structure contains the @a name associated with the target + //! in the configuration structures. The table of names is scanned + //! to find a constructor helper. + //! + typedef struct { + //! This is the string found in configuration to match. + const char *theTarget; + //! This is the static wrapper for the constructor. + TargetBase *(*theCtor)( + std::string + ); + } FactoryEntry_t; + + //! + //! @brief TargetBase Factory Table + //! + //! This is the table of possible types we can construct + //! dynamically based upon user specified configuration information. + //! All must be derived from TargetBase. + //! + static FactoryEntry_t FactoryTable[] = { + { "arm", Target_arm_Constructor }, + { "i386", Target_i386_Constructor }, + { "lm32", Target_lm32_Constructor }, + { "m68k", Target_m68k_Constructor }, + { "powerpc", Target_powerpc_Constructor }, + { "sparc", Target_sparc_Constructor }, + { "TBD", NULL }, + }; + + TargetBase* TargetFactory( + std::string targetName + ) + { + size_t i; + std::string cpu; + + i = targetName.find( '-' ); + if ( i == targetName.npos ) + cpu = targetName; + else + cpu = targetName.substr( 0, i ); + + // fprintf( stderr, "%s --> %s\n", targetName.c_str(), cpu.c_str()); + // Iterate over the table trying to find an entry with a matching name + for ( i=0 ; i < sizeof(FactoryTable) / sizeof(FactoryEntry_t); i++ ) { + if ( !strcmp(FactoryTable[i].theTarget, cpu.c_str() ) ) + return FactoryTable[i].theCtor( targetName ); + } + + fprintf( + stderr, + "ERROR!!! %s is not a known architecture!!!\n", + cpu.c_str() + ); + fprintf( stderr, "-- fix me\n" ); + exit( 1 ); + + return NULL; + } +} |