summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-04-03 22:32:14 +0100
committerGerrit Rockbox <gerrit@rockbox.org>2016-04-08 18:06:27 +0200
commit56dc54d38ac6c1d47ea6dbae88b1e5f7fee9f3ec (patch)
tree7f44562caba6a6152b0137489db3888a7f1f4bca
parent45a02dcf818ca2f7513863cda2a56a8929c6d20e (diff)
downloadrockbox-56dc54d38ac6c1d47ea6dbae88b1e5f7fee9f3ec.tar.gz
rockbox-56dc54d38ac6c1d47ea6dbae88b1e5f7fee9f3ec.zip
soc_desc: add default constructors to most structures
After being caught by several bugs of the type "let's forgot to initialize a field to default value", I'm finally fixing this. Change-Id: I01c33e0611d4f697f767db66465e4fb30858cdab
-rw-r--r--utils/regtools/include/soc_desc.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/utils/regtools/include/soc_desc.hpp b/utils/regtools/include/soc_desc.hpp
index f6c5cca28f..66562f80d9 100644
--- a/utils/regtools/include/soc_desc.hpp
+++ b/utils/regtools/include/soc_desc.hpp
@@ -39,6 +39,9 @@ typedef uint32_t soc_addr_t;
39typedef uint32_t soc_word_t; 39typedef uint32_t soc_word_t;
40typedef int soc_id_t; 40typedef int soc_id_t;
41 41
42/** Default value for IDs */
43const soc_id_t DEFAULT_ID = 0xcafebabe;
44
42/** Error class */ 45/** Error class */
43class error_t 46class error_t
44{ 47{
@@ -81,6 +84,9 @@ struct enum_t
81 std::string name; /** Name (must be unique among field enums) */ 84 std::string name; /** Name (must be unique among field enums) */
82 std::string desc; /** Optional description of the meaning of this value */ 85 std::string desc; /** Optional description of the meaning of this value */
83 soc_word_t value; /** Value of the field */ 86 soc_word_t value; /** Value of the field */
87
88 /** Default constructor: default ID and value is 0 */
89 enum_t():id(DEFAULT_ID), value(0) {}
84}; 90};
85 91
86/** Register field information */ 92/** Register field information */
@@ -93,6 +99,9 @@ struct field_t
93 size_t width; /** Width of the field in bits */ 99 size_t width; /** Width of the field in bits */
94 std::vector< enum_t > enum_; /** List of special values */ 100 std::vector< enum_t > enum_; /** List of special values */
95 101
102 /** Default constructor: default ID, position is 0, width is 1 */
103 field_t():id(DEFAULT_ID), pos(0), width(1) {}
104
96 /** Returns the bit mask of the field within the register */ 105 /** Returns the bit mask of the field within the register */
97 soc_word_t bitmask() const 106 soc_word_t bitmask() const
98 { 107 {
@@ -140,6 +149,9 @@ struct variant_t
140 soc_id_t id; /** ID (must be unique among register variants) */ 149 soc_id_t id; /** ID (must be unique among register variants) */
141 std::string type; /** type of the variant */ 150 std::string type; /** type of the variant */
142 soc_addr_t offset; /** offset of the variant */ 151 soc_addr_t offset; /** offset of the variant */
152
153 /** Default constructor: default ID, offset is 0 */
154 variant_t():id(DEFAULT_ID), offset(0) {}
143}; 155};
144 156
145/** Register information */ 157/** Register information */
@@ -149,6 +161,9 @@ struct register_t
149 std::string desc; /** Optional description of the register */ 161 std::string desc; /** Optional description of the register */
150 std::vector< field_t > field; /** List of fields */ 162 std::vector< field_t > field; /** List of fields */
151 std::vector< variant_t > variant; /** List of variants */ 163 std::vector< variant_t > variant; /** List of variants */
164
165 /** Default constructor: width is 32 */
166 register_t():width(32) {}
152}; 167};
153 168
154/** Node address range information */ 169/** Node address range information */
@@ -170,6 +185,9 @@ struct range_t
170 std::string variable; /** Formula variable name (for FORMULA) */ 185 std::string variable; /** Formula variable name (for FORMULA) */
171 std::vector< soc_word_t > list; /** Address list (for LIST) */ 186 std::vector< soc_word_t > list; /** Address list (for LIST) */
172 187
188 /** Default constructor: empty stride */
189 range_t():type(STRIDE), first(0), count(0), base(0), stride(0) {}
190
173 /** Return the number of indexes (based on count or list) */ 191 /** Return the number of indexes (based on count or list) */
174 size_t size() 192 size_t size()
175 { 193 {
@@ -193,6 +211,9 @@ struct instance_t
193 type_t type; /** Instance type */ 211 type_t type; /** Instance type */
194 soc_word_t addr; /** Address (for SINGLE) */ 212 soc_word_t addr; /** Address (for SINGLE) */
195 range_t range; /** Range (for RANGE) */ 213 range_t range; /** Range (for RANGE) */
214
215 /** Default constructor: single instance at 0 */
216 instance_t():id(DEFAULT_ID), type(SINGLE), addr(0) {}
196}; 217};
197 218
198/** Node information */ 219/** Node information */
@@ -205,6 +226,9 @@ struct node_t
205 std::vector< register_t> register_; /** Optional register */ 226 std::vector< register_t> register_; /** Optional register */
206 std::vector< instance_t> instance; /** List of instances */ 227 std::vector< instance_t> instance; /** List of instances */
207 std::vector< node_t > node; /** List of sub-nodes */ 228 std::vector< node_t > node; /** List of sub-nodes */
229
230 /** Default constructor: default ID */
231 node_t():id(DEFAULT_ID) {}
208}; 232};
209 233
210/** System-on-chip information */ 234/** System-on-chip information */