diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/regtools/headergen.cpp | 108 | ||||
-rw-r--r-- | utils/regtools/lib/soc_desc.hpp | 4 |
2 files changed, 108 insertions, 4 deletions
diff --git a/utils/regtools/headergen.cpp b/utils/regtools/headergen.cpp index b4ade5f186..804f7e0a3a 100644 --- a/utils/regtools/headergen.cpp +++ b/utils/regtools/headergen.cpp | |||
@@ -137,6 +137,68 @@ void fprint_include_guard(FILE *f, bool begin) | |||
137 | fprint_include_guard_ex(f, begin, name); | 137 | fprint_include_guard_ex(f, begin, name); |
138 | } | 138 | } |
139 | 139 | ||
140 | struct limited_column_context_t | ||
141 | { | ||
142 | limited_column_context_t(size_t nr_col = 80) | ||
143 | :m_nr_col(nr_col), m_prevent_wordcut(true) {} | ||
144 | void set_prefix(const std::string& prefix) { m_prefix = prefix; } | ||
145 | void add(const std::string& text) | ||
146 | { | ||
147 | for(size_t i = 0; i < text.size();) | ||
148 | { | ||
149 | size_t offset = 0; | ||
150 | if(m_cur_line.size() == 0) | ||
151 | m_cur_line = m_prefix; | ||
152 | size_t len = std::min(text.size() - i, m_nr_col - m_cur_line.size()); | ||
153 | // prevent word cut | ||
154 | if(m_prevent_wordcut && !isspace(text[i + len - 1]) && | ||
155 | i + len < text.size() && !isspace(text[i + len])) | ||
156 | { | ||
157 | size_t pos = text.find_last_of(" \t\n\v\r\f", i + len - 1); | ||
158 | if(pos == std::string::npos || pos < i) | ||
159 | len = 0; | ||
160 | else | ||
161 | len = pos - i + 1; | ||
162 | } | ||
163 | size_t pos = text.find('\n', i); | ||
164 | if(pos != std::string::npos && pos <= i + len) | ||
165 | { | ||
166 | offset = 1; | ||
167 | len = pos - i; | ||
168 | } | ||
169 | m_cur_line += text.substr(i, len); | ||
170 | // len == 0 means we need a new line | ||
171 | if(m_cur_line.size() == m_nr_col || len == 0) | ||
172 | { | ||
173 | m_lines.push_back(m_cur_line); | ||
174 | m_cur_line = ""; | ||
175 | } | ||
176 | i += len + offset; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | std::string to_string() | ||
181 | { | ||
182 | std::string str; | ||
183 | for(size_t i = 0; i < m_lines.size(); i++) | ||
184 | str += m_lines[i] + "\n"; | ||
185 | if(m_cur_line.size() != 0) | ||
186 | str += m_cur_line + "\n"; | ||
187 | return str; | ||
188 | } | ||
189 | |||
190 | void print(FILE *f) | ||
191 | { | ||
192 | fprintf(f, "%s", to_string().c_str()); | ||
193 | } | ||
194 | |||
195 | std::vector< std::string > m_lines; | ||
196 | std::string m_cur_line; | ||
197 | std::string m_prefix; | ||
198 | size_t m_nr_col; | ||
199 | bool m_prevent_wordcut; | ||
200 | }; | ||
201 | |||
140 | struct define_align_context_t | 202 | struct define_align_context_t |
141 | { | 203 | { |
142 | define_align_context_t():m_max_name(0) {} | 204 | define_align_context_t():m_max_name(0) {} |
@@ -146,6 +208,11 @@ struct define_align_context_t | |||
146 | m_max_name = std::max(m_max_name, name.size()); | 208 | m_max_name = std::max(m_max_name, name.size()); |
147 | } | 209 | } |
148 | 210 | ||
211 | void add_raw(const std::string& line) | ||
212 | { | ||
213 | m_lines.push_back(std::make_pair("", line)); | ||
214 | } | ||
215 | |||
149 | void print(FILE *f) | 216 | void print(FILE *f) |
150 | { | 217 | { |
151 | std::string define = "#define "; | 218 | std::string define = "#define "; |
@@ -155,6 +222,12 @@ struct define_align_context_t | |||
155 | for(size_t i = 0; i < m_lines.size(); i++) | 222 | for(size_t i = 0; i < m_lines.size(); i++) |
156 | { | 223 | { |
157 | std::string name = m_lines[i].first; | 224 | std::string name = m_lines[i].first; |
225 | // raw entry ? | ||
226 | if(name.size() == 0) | ||
227 | { | ||
228 | fprintf(f, "%s", m_lines[i].second.c_str()); | ||
229 | continue; | ||
230 | } | ||
158 | name.insert(name.end(), align - define.size() - name.size(), ' '); | 231 | name.insert(name.end(), align - define.size() - name.size(), ' '); |
159 | fprintf(f, "%s%s%s\n", define.c_str(), name.c_str(), m_lines[i].second.c_str()); | 232 | fprintf(f, "%s%s%s\n", define.c_str(), name.c_str(), m_lines[i].second.c_str()); |
160 | } | 233 | } |
@@ -164,8 +237,36 @@ struct define_align_context_t | |||
164 | std::vector< std::pair< std::string, std::string > > m_lines; | 237 | std::vector< std::pair< std::string, std::string > > m_lines; |
165 | }; | 238 | }; |
166 | 239 | ||
240 | limited_column_context_t print_description(const std::string& desc, const std::string& prefix) | ||
241 | { | ||
242 | limited_column_context_t ctx; | ||
243 | if(desc.size() == 0) | ||
244 | return ctx; | ||
245 | ctx.set_prefix(prefix); | ||
246 | ctx.add(desc); | ||
247 | return ctx; | ||
248 | } | ||
249 | |||
250 | void fprint_description(FILE *f, const std::string& desc, const std::string& prefix) | ||
251 | { | ||
252 | limited_column_context_t ctx = print_description(desc, prefix); | ||
253 | ctx.print(f); | ||
254 | } | ||
255 | |||
256 | void fprint_description(define_align_context_t& ctx, const std::string& desc, const std::string& prefix) | ||
257 | { | ||
258 | limited_column_context_t ctx2 = print_description(desc, prefix); | ||
259 | ctx.add_raw(ctx2.to_string()); | ||
260 | } | ||
261 | |||
167 | void gen_soc_field(define_align_context_t& ctx, bool multidev, bool multireg, const soc_reg_field_t& field) | 262 | void gen_soc_field(define_align_context_t& ctx, bool multidev, bool multireg, const soc_reg_field_t& field) |
168 | { | 263 | { |
264 | if(field.desc.size() != 0) | ||
265 | { | ||
266 | ctx.add_raw("/* Field: " + field.name + "\n"); | ||
267 | fprint_description(ctx, "Description: " + field.desc + " */\n", " * "); | ||
268 | } | ||
269 | |||
169 | std::string prefix = g_soc_dev + "_" + g_soc_reg + "_" + g_soc_field; | 270 | std::string prefix = g_soc_dev + "_" + g_soc_reg + "_" + g_soc_field; |
170 | ctx.add("BP_" + prefix, to_str(field.first_bit)); | 271 | ctx.add("BP_" + prefix, to_str(field.first_bit)); |
171 | ctx.add("BM_" + prefix, "0x" + to_hex(field.bitmask())); | 272 | ctx.add("BM_" + prefix, "0x" + to_hex(field.bitmask())); |
@@ -200,8 +301,9 @@ void gen_soc_reg(FILE *f, bool multidev, const soc_reg_t& reg) | |||
200 | fprintf(f, "\n"); | 301 | fprintf(f, "\n"); |
201 | } | 302 | } |
202 | fprintf(f, " * SCT: %s\n", sct ? "yes" : "no"); | 303 | fprintf(f, " * SCT: %s\n", sct ? "yes" : "no"); |
203 | 304 | if(reg.desc.size() != 0) | |
204 | fprintf(f, "*/\n"); | 305 | fprint_description(f, "Description: " + reg.desc, " * "); |
306 | fprintf(f, " */\n"); | ||
205 | 307 | ||
206 | define_align_context_t ctx; | 308 | define_align_context_t ctx; |
207 | 309 | ||
@@ -307,7 +409,7 @@ void gen_soc_dev_header(const std::string& filename, const xml_ver_t& ver, const | |||
307 | 409 | ||
308 | void gen_soc_headers(const std::string& prefix, const soc_t& soc) | 410 | void gen_soc_headers(const std::string& prefix, const soc_t& soc) |
309 | { | 411 | { |
310 | printf("Generate headers for soc %s: use directory %s\n", soc.desc.c_str(), | 412 | printf("Generate headers for soc %s: use directory %s\n", soc.name.c_str(), |
311 | prefix.c_str()); | 413 | prefix.c_str()); |
312 | mkdir(prefix.c_str(), 0770); | 414 | mkdir(prefix.c_str(), 0770); |
313 | 415 | ||
diff --git a/utils/regtools/lib/soc_desc.hpp b/utils/regtools/lib/soc_desc.hpp index 4aa8c975ac..1b4985529c 100644 --- a/utils/regtools/lib/soc_desc.hpp +++ b/utils/regtools/lib/soc_desc.hpp | |||
@@ -47,7 +47,7 @@ | |||
47 | 47 | ||
48 | #define SOCDESC_VERSION_MAJOR 1 | 48 | #define SOCDESC_VERSION_MAJOR 1 |
49 | #define SOCDESC_VERSION_MINOR 1 | 49 | #define SOCDESC_VERSION_MINOR 1 |
50 | #define SOCDESC_VERSION_REV 0 | 50 | #define SOCDESC_VERSION_REV 1 |
51 | 51 | ||
52 | #define SOCDESC_VERSION__(maj,min,rev) #maj"."#min"."#rev | 52 | #define SOCDESC_VERSION__(maj,min,rev) #maj"."#min"."#rev |
53 | #define SOCDESC_VERSION_(maj,min,rev) SOCDESC_VERSION__(maj,min,rev) | 53 | #define SOCDESC_VERSION_(maj,min,rev) SOCDESC_VERSION__(maj,min,rev) |
@@ -101,6 +101,8 @@ struct soc_reg_field_t | |||
101 | std::string desc; /// human description | 101 | std::string desc; /// human description |
102 | unsigned first_bit, last_bit; /// bit range of the field | 102 | unsigned first_bit, last_bit; /// bit range of the field |
103 | 103 | ||
104 | soc_reg_field_t():first_bit(0), last_bit(31) {} | ||
105 | |||
104 | soc_word_t bitmask() const | 106 | soc_word_t bitmask() const |
105 | { | 107 | { |
106 | // WARNING beware of the case where first_bit=0 and last_bit=31 | 108 | // WARNING beware of the case where first_bit=0 and last_bit=31 |