1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
//
//
//! @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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <rld.h>
#include "TargetFactory.h"
#include "Target_aarch64.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 "Target_riscv.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[] = {
{ "aarch64", Target_aarch64_Constructor },
{ "arm", Target_arm_Constructor },
{ "i386", Target_i386_Constructor },
{ "lm32", Target_lm32_Constructor },
{ "m68k", Target_m68k_Constructor },
{ "powerpc", Target_powerpc_Constructor },
{ "sparc", Target_sparc_Constructor },
{ "riscv", Target_riscv_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 );
}
std::ostringstream what;
what << cpu << "is not a known architecture!!! - fix me" << std::endl;
throw rld::error( what, "TargetFactory" );
return NULL;
}
}
|