]> git.tdb.fi Git - builder.git/blob - source/lib/architecture.h
2cf4fa2fdff88bd9014e7cd800aa4754b1d9f3a0
[builder.git] / source / lib / architecture.h
1 #ifndef ARCHITECTURE_H_
2 #define ARCHITECTURE_H_
3
4 #include <typeinfo>
5 #include <msp/datafile/loader.h>
6 #include "buildinfo.h"
7 #include "pattern.h"
8
9 class Builder;
10
11 /**
12 Stores information about an architecture.  This includes CPU type, model and
13 bitness and operating system.
14 */
15 class Architecture
16 {
17 public:
18         class Loader: public Msp::DataFile::ObjectLoader<Architecture>
19         {
20         public:
21                 Loader(Architecture &);
22
23         private:
24                 void cross_prefix(const std::string &);
25         };
26
27 private:
28         Builder &builder;
29         std::string type;
30         std::string cpu;
31         std::string fpu;
32         std::string system;
33         unsigned bits = 0;
34         std::string toolchain;
35         std::string name;
36         bool native = false;
37         std::string cross_prefix;
38         std::map<std::string, std::vector<Pattern>> filename_patterns;
39
40 public:
41         Architecture(Builder &b, const std::string &spec);
42
43         void refine(const std::string &);
44 private:
45         void update();
46
47 public:
48         const std::string &get_type() const { return type; }
49         const std::string &get_name() const { return name; }
50         const std::string &get_system() const { return system; }
51         unsigned get_bits() const { return bits; }
52         const std::string &get_cpu() const { return cpu; }
53         const std::string &get_fpu() const { return fpu; }
54         const std::string &get_toolchain() const { return toolchain; }
55         bool match_name(const std::string &, unsigned * = 0) const;
56         std::string best_match(const std::vector<std::string> &) const;
57         bool is_native() const { return native; }
58         bool is_cross() const { return !cross_prefix.empty(); }
59
60         const std::string &get_cross_prefix() const { return cross_prefix; }
61
62         template<typename T>
63         const std::vector<Pattern> &get_patterns() const;
64
65         template<typename T>
66         std::string create_filename(const std::string &) const;
67
68 private:
69         template<typename T>
70         void add_pattern(const std::string &);
71
72 private:
73         static void resolve_aliases(std::vector<std::string> &);
74         void parse_specification(const std::string &);
75 };
76
77 template<typename T>
78 inline const std::vector<Pattern> &Architecture::get_patterns() const
79 {
80         auto i = filename_patterns.find(typeid(T).name());
81         if(i!=filename_patterns.end())
82                 return i->second;
83
84         static std::vector<Pattern> empty;
85         return empty;
86 }
87
88 template<typename T>
89 inline std::string Architecture::create_filename(const std::string &base) const
90 {
91         const std::vector<Pattern> &patterns = get_patterns<T>();
92         return patterns.empty() ? base : patterns.front().apply(base);
93 }
94
95 #endif