Merge pull request #218 from saper/build-fixes
[envytools.git] / rnn / expand.c
blob04141836632061f95fea599dc3fdc69671844ab2
1 /*
2 * Copyright (C) 2010 Luca Barbieri <luca@luca-barbieri.com>
3 * Copyright (C) 2010 Marcelina Koƛcielnicka <mwk@0x04.net>
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "rnn.h"
27 #include "rnndec.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <inttypes.h>
33 void expand (const char* prefix, struct rnndelem *elem, uint64_t base, int width, struct rnndeccontext *vc) {
34 int i, j;
35 if(elem->length > 1024)
36 return;
37 if(!rnndec_varmatch(vc, &elem->varinfo))
38 return;
39 switch (elem->type) {
40 case RNN_ETYPE_REG:
41 for(i = 0; i < elem->length; ++i) {
42 if(elem->length >= 2)
43 printf("d %s %08"PRIx64" %s(%i)", prefix, base + elem->offset + i * elem->stride, elem->fullname, i);
44 else
45 printf("d %s %08"PRIx64" %s", prefix, base + elem->offset, elem->fullname);
47 printf(" %s\n", elem->typeinfo.name);
49 break;
50 case RNN_ETYPE_STRIPE:
51 case RNN_ETYPE_ARRAY:
52 for (i = 0; i < elem->length; i++)
53 for (j = 0; j < elem->subelemsnum; j++)
54 expand(prefix, elem->subelems[j], base + elem->offset + i * elem->stride, width, vc);
55 break;
56 default:
57 break;
61 int main(int argc, char **argv) {
62 char** argp;
63 rnn_init();
64 struct rnndb *db = rnn_newdb();
65 rnn_parsefile (db, argv[1]);
66 rnn_prepdb (db);
67 struct rnndeccontext *vc = rnndec_newcontext(db);
68 vc->colors = &rnndec_colorsterm;
69 argp = argv + 2;
70 while (*argp && !strcmp (*argp, "-v")) {
71 ++argp;
72 if(!argp[0] || !argp[1])
73 fprintf(stderr, "error: -v option lacking VARSET and VARIANT arguments following it\n");
74 else {
75 rnndec_varadd(vc, argp[0], argp[1]);
76 argp += 2;
79 int i, j;
80 for(i = 0; i < db->domainsnum; ++i)
81 for (j = 0; j < db->domains[i]->subelemsnum; ++j)
82 expand (db->domains[i]->name, db->domains[i]->subelems[j], 0, db->domains[i]->width, vc);
83 for(i = 0; i < db->enumsnum; ++i)
84 for (j = 0; j < db->enums[i]->valsnum; ++j)
85 if (db->enums[i]->vals[j]->valvalid)
86 printf("e %s %"PRIx64" %s\n", db->enums[i]->name, db->enums[i]->vals[j]->value, db->enums[i]->vals[j]->name);
88 rnndec_freecontext(vc);
89 rnn_freedb(db);
90 rnn_fini();
92 return 0;