Parse VCD header to get values for context structure. * The context structure should be zeroed before calling this. */
| 211 | * The context structure should be zeroed before calling this. |
| 212 | */ |
| 213 | static gboolean parse_header(FILE *file, struct context *ctx) |
| 214 | { |
| 215 | uint64_t p, q; |
| 216 | gchar *name = NULL, *contents = NULL; |
| 217 | gboolean status = FALSE; |
| 218 | struct probe *probe; |
| 219 | |
| 220 | while (parse_section(file, &name, &contents)) |
| 221 | { |
| 222 | sr_dbg("Section '%s', contents '%s'.", name, contents); |
| 223 | |
| 224 | if (g_strcmp0(name, "enddefinitions") == 0) |
| 225 | { |
| 226 | status = TRUE; |
| 227 | break; |
| 228 | } |
| 229 | else if (g_strcmp0(name, "timescale") == 0) |
| 230 | { |
| 231 | /* The standard allows for values 1, 10 or 100 |
| 232 | * and units s, ms, us, ns, ps and fs. */ |
| 233 | if (sr_parse_period(contents, &p, &q) == SR_OK) |
| 234 | { |
| 235 | ctx->samplerate = q / p; |
| 236 | if (q % p != 0) |
| 237 | { |
| 238 | /* Does not happen unless time value is non-standard */ |
| 239 | sr_warn("Inexact rounding of samplerate, %llu / %llu to %llu Hz.", |
| 240 | (u64_t)q, (u64_t)p, (u64_t)ctx->samplerate); |
| 241 | } |
| 242 | |
| 243 | sr_dbg("Samplerate: %llu", (u64_t)ctx->samplerate); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | sr_err("Parsing timescale failed."); |
| 248 | } |
| 249 | } |
| 250 | else if (g_strcmp0(name, "var") == 0) |
| 251 | { |
| 252 | /* Format: $var type size identifier reference $end */ |
| 253 | gchar **parts = g_strsplit_set(contents, " \r\n\t", 0); |
| 254 | remove_empty_parts(parts); |
| 255 | |
| 256 | if (g_strv_length(parts) != 4) |
| 257 | { |
| 258 | sr_warn("$var section should have 4 items"); |
| 259 | } |
| 260 | else if (g_strcmp0(parts[0], "reg") != 0 && g_strcmp0(parts[0], "wire") != 0) |
| 261 | { |
| 262 | sr_info("Unsupported signal type: '%s'", parts[0]); |
| 263 | } |
| 264 | else if (strtol(parts[1], NULL, 10) != 1) |
| 265 | { |
| 266 | sr_info("Unsupported signal size: '%s'", parts[1]); |
| 267 | } |
| 268 | else if (ctx->probecount >= ctx->maxprobes) |
| 269 | { |
| 270 | sr_warn("Skipping '%s' because only %d probes requested.", parts[3], ctx->maxprobes); |
no test coverage detected