]> git.tdb.fi Git - builder.git/blob - source/architecture.h
Allow architecture specifications to be refined after creation
[builder.git] / source / 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
24 private:
25         Builder &builder;
26         std::string type;
27         std::string cpu;
28         std::string fpu;
29         std::string system;
30         unsigned bits = 0;
31         std::string toolchain;
32         std::string name;
33         bool native = false;
34         std::string cross_prefix;
35         std::map<std::string, std::vector<Pattern>> filename_patterns;
36
37 public:
38         Architecture(Builder &b, const std::string &spec);
39
40         void refine(const std::string &);
41 private:
42         void update();
43
44 public:
45         const std::string &get_type() const { return type; }
46         const std::string &get_name() const { return name; }
47         const std::string &get_system() const { return system; }
48         unsigned get_bits() const { return bits; }
49         const std::string &get_cpu() const { return cpu; }
50         const std::string &get_fpu() const { return fpu; }
51         const std::string &get_toolchain() const { return toolchain; }
52         bool match_name(const std::string &, unsigned * = 0) const;
53         std::string best_match(const std::vector<std::string> &) const;
54         bool is_native() const { return native; }
55         bool is_cross() const { return !cross_prefix.empty(); }
56
57         const std::string &get_cross_prefix() const { return cross_prefix; }
58
59         template<typename T>
60         const std::vector<Pattern> &get_patterns() const;
61
62         template<typename T>
63         std::string create_filename(const std::string &) const;
64
65 private:
66         template<typename T>
67         void add_pattern(const std::string &);
68
69 private:
70         static void resolve_aliases(std::vector<std::string> &);
71         void parse_specification(const std::string &);
72 };
73
74 template<typename T>
75 inline const std::vector<Pattern> &Architecture::get_patterns() const
76 {
77         auto i = filename_patterns.find(typeid(T).name());
78         if(i!=filename_patterns.end())
79                 return i->second;
80
81         static std::vector<Pattern> empty;
82         return empty;
83 }
84
85 template<typename T>
86 inline std::string Architecture::create_filename(const std::string &base) const
87 {
88         const std::vector<Pattern> &patterns = get_patterns<T>();
89         return patterns.empty() ? base : patterns.front().apply(base);
90 }
91
92 #endif