forked from Kitware/CMake
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmAvrGccOptimizationOption.h
165 lines (143 loc) · 6.33 KB
/
cmAvrGccOptimizationOption.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3.0 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "cmAvrGccCompilerOption.h"
namespace compiler {
/**
* @brief Provides services to identify optimizations opions passed to avr-gcc using the "-O" flag.
* An AtmelStudio7 compatible representation for those options which could be used while generating
* AtmelStudio7's projet files.
*/
struct OptimizationOption : public CompilerOption
{
/**
* @brief packs all optimization levels available in avr-gcc.
* Note that options are ordered in a way which allows sorting of many
* OptimizationOptions later on.
* When multiples OptimizationOptions are given to the compiler, the highest ranking one
* will be retrieved. For instance, if "-O3 -O0" are given, the maximum element in this sequence
* is "-O0" based on gcc precedence rules.
*/
enum class Level : uint8_t
{
O1, /**< Optimization for code size and execution time */
O, /**< Equivalent of O1 */
O2, /**< Optimize more for code size and execution time */
O3, /**< Optimize more for code size and execution time */
Og, /**< Optimize but keep enough information to help debugging */
Os, /**< Optimize for code size */
Ofast, /**< O3 with fast none accurate math calculations */
O0, /**< No Optimizations whatsoever, prevails on other options */
};
/**
* @brief Returns the default optimization settings for atmelstudio
*/
static std::pair<Level, AS7OptionRepresentation> get_default();
/**
* @brief determines whether the given token is part of the static map of available optimizations flags or not
* @param[in] _token : string representation of current flag being parsed
* @return true : token exist in collection ; false : token is not part of the collection, thus it is not part of the available set of optimizations.
*/
static bool can_create(const std::string& _token);
/**
* @brief Standard default constructor.
*/
OptimizationOption();
/**
* @brief Builds an OptimizationOption using given token to resolve the right
* Optimization representation.
* @param _token : raw token as parsed from command line input
*/
OptimizationOption(const std::string& _token);
/**
* @brief > operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is > other.optLevel
* false : this->optLevel is <= other.optLevel
*/
bool operator>(const OptimizationOption& other) const;
/**
* @brief < operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is < other.optLevel
* false : this->optLevel is >= other.optLevel
*/
bool operator<(const OptimizationOption& other) const;
/**
* @brief <= operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is <= other.optLevel
* false : this->optLevel is > other.optLevel
*/
bool operator<=(const OptimizationOption& other) const;
/**
* @brief >= operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is >= other.optLevel
* false : this->optLevel is < other.optLevel
*/
bool operator>=(const OptimizationOption& other) const;
/**
* @brief == operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is == other.optLevel
* false : this->optLevel is != other.optLevel
*/
bool operator==(const OptimizationOption& other) const;
/**
* @brief != operator is overloaded to allow sorting of OptimizationOption(s) based on
* their inner debugging level. Comparison is operated on the optLevel member.
*
* @param other : other OptimizationOption object
* @return true : this->optLevel is != other.optLevel
* false : this->optLevel is == other.optLevel
*/
bool operator!=(const OptimizationOption& other) const;
/**
* @brief Retrieves internally stored Optimization level.
* @return Level
*/
Level get_level() const;
/**
* @brief generates a string representation of this option using (or not) an
* AS7 compatible formalism.
*
* @param atmel_studio_compat : activates AS7 compatibility or not
*/
std::string generate(const bool atmel_studio_compat = true) override;
private:
static std::unordered_map<Level, AS7OptionRepresentation> available_opt; /**< List of all available options */
/**
* @brief Use raw input token to resolve the right pair of Level/AS7OptionRepresentation located
* within the available_opt map.
*
* @param token : raw token as parsed from command line input
*/
std::pair<Level, AS7OptionRepresentation*> resolve(const std::string& token) const;
Level optLevel = Level::O0; /**< Each instance embeds its own optimization Level representation*/
};
}