From 56dc54d38ac6c1d47ea6dbae88b1e5f7fee9f3ec Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sun, 3 Apr 2016 22:32:14 +0100 Subject: 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 --- utils/regtools/include/soc_desc.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'utils/regtools') 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; typedef uint32_t soc_word_t; typedef int soc_id_t; +/** Default value for IDs */ +const soc_id_t DEFAULT_ID = 0xcafebabe; + /** Error class */ class error_t { @@ -81,6 +84,9 @@ struct enum_t std::string name; /** Name (must be unique among field enums) */ std::string desc; /** Optional description of the meaning of this value */ soc_word_t value; /** Value of the field */ + + /** Default constructor: default ID and value is 0 */ + enum_t():id(DEFAULT_ID), value(0) {} }; /** Register field information */ @@ -93,6 +99,9 @@ struct field_t size_t width; /** Width of the field in bits */ std::vector< enum_t > enum_; /** List of special values */ + /** Default constructor: default ID, position is 0, width is 1 */ + field_t():id(DEFAULT_ID), pos(0), width(1) {} + /** Returns the bit mask of the field within the register */ soc_word_t bitmask() const { @@ -140,6 +149,9 @@ struct variant_t soc_id_t id; /** ID (must be unique among register variants) */ std::string type; /** type of the variant */ soc_addr_t offset; /** offset of the variant */ + + /** Default constructor: default ID, offset is 0 */ + variant_t():id(DEFAULT_ID), offset(0) {} }; /** Register information */ @@ -149,6 +161,9 @@ struct register_t std::string desc; /** Optional description of the register */ std::vector< field_t > field; /** List of fields */ std::vector< variant_t > variant; /** List of variants */ + + /** Default constructor: width is 32 */ + register_t():width(32) {} }; /** Node address range information */ @@ -170,6 +185,9 @@ struct range_t std::string variable; /** Formula variable name (for FORMULA) */ std::vector< soc_word_t > list; /** Address list (for LIST) */ + /** Default constructor: empty stride */ + range_t():type(STRIDE), first(0), count(0), base(0), stride(0) {} + /** Return the number of indexes (based on count or list) */ size_t size() { @@ -193,6 +211,9 @@ struct instance_t type_t type; /** Instance type */ soc_word_t addr; /** Address (for SINGLE) */ range_t range; /** Range (for RANGE) */ + + /** Default constructor: single instance at 0 */ + instance_t():id(DEFAULT_ID), type(SINGLE), addr(0) {} }; /** Node information */ @@ -205,6 +226,9 @@ struct node_t std::vector< register_t> register_; /** Optional register */ std::vector< instance_t> instance; /** List of instances */ std::vector< node_t > node; /** List of sub-nodes */ + + /** Default constructor: default ID */ + node_t():id(DEFAULT_ID) {} }; /** System-on-chip information */ -- cgit v1.2.3