Home | History | Annotate | Line # | Download | only in rnn
      1 /*
      2  * Copyright (C) 2010 Marcin Kocielnicki <koriakin (at) 0x04.net>
      3  * Copyright (C) 2010 Luca Barbieri <luca (at) luca-barbieri.com>
      4  * All Rights Reserved.
      5  *
      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:
     12  *
     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.
     16  *
     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.
     24  */
     25 
     26 #ifndef RNN_H
     27 #define RNN_H
     28 
     29 #include <stdint.h>
     30 #include <stdlib.h>
     31 
     32 struct rnnauthor {
     33 	char* name;
     34 	char* email;
     35 	char* contributions;
     36 	char* license;
     37 	char** nicknames;
     38 	int nicknamesnum;
     39 	int nicknamesmax;
     40 };
     41 
     42 struct rnncopyright {
     43 	unsigned firstyear;
     44 	char* license;
     45 	struct rnnauthor **authors;
     46 	int authorsnum;
     47 	int authorsmax;
     48 };
     49 
     50 struct rnndb {
     51 	struct rnncopyright copyright;
     52 	struct rnnenum **enums;
     53 	int enumsnum;
     54 	int enumsmax;
     55 	struct rnnbitset **bitsets;
     56 	int bitsetsnum;
     57 	int bitsetsmax;
     58 	struct rnndomain **domains;
     59 	int domainsnum;
     60 	int domainsmax;
     61 	struct rnngroup **groups;
     62 	int groupsnum;
     63 	int groupsmax;
     64 	struct rnnspectype **spectypes;
     65 	int spectypesnum;
     66 	int spectypesmax;
     67 	char **files;
     68 	int filesnum;
     69 	int filesmax;
     70 	int estatus;
     71 };
     72 
     73 struct rnnvarset {
     74 	struct rnnenum *venum;
     75 	int *variants;
     76 };
     77 
     78 struct rnnvarinfo {
     79 	char *prefixstr;
     80 	char *varsetstr;
     81 	char *variantsstr;
     82 	int dead;
     83 	struct rnnenum *prefenum;
     84 	char *prefix;
     85 	struct rnnvarset **varsets;
     86 	int varsetsnum;
     87 	int varsetsmax;
     88 };
     89 
     90 struct rnnenum {
     91 	char *name;
     92 	int bare;
     93 	int isinline;
     94 	struct rnnvarinfo varinfo;
     95 	struct rnnvalue **vals;
     96 	int valsnum;
     97 	int valsmax;
     98 	char *fullname;
     99 	int prepared;
    100 	char *file;
    101 };
    102 
    103 struct rnnvalue {
    104 	char *name;
    105 	int valvalid;
    106 	uint64_t value;
    107 	struct rnnvarinfo varinfo;
    108 	char *fullname;
    109 	char *file;
    110 };
    111 
    112 struct rnntypeinfo {
    113 	char *name;
    114 	enum rnnttype {
    115 		RNN_TTYPE_INVALID,
    116 		RNN_TTYPE_INLINE_ENUM,
    117 		RNN_TTYPE_INLINE_BITSET,
    118 		RNN_TTYPE_ENUM,
    119 		RNN_TTYPE_BITSET,
    120 		RNN_TTYPE_SPECTYPE,
    121 		RNN_TTYPE_HEX,
    122 		RNN_TTYPE_INT,
    123 		RNN_TTYPE_UINT,
    124 		RNN_TTYPE_FLOAT,
    125 		RNN_TTYPE_BOOLEAN,
    126 		RNN_TTYPE_FIXED,
    127 		RNN_TTYPE_UFIXED,
    128 		RNN_TTYPE_A3XX_REGID,
    129 	} type;
    130 	struct rnnenum *eenum;
    131 	struct rnnbitset *ebitset;
    132 	struct rnnspectype *spectype;
    133 	struct rnnbitfield **bitfields;
    134 	int bitfieldsnum;
    135 	int bitfieldsmax;
    136 	struct rnnvalue **vals;
    137 	int valsnum;
    138 	int valsmax;
    139 	int shr, low, high;
    140 	uint64_t min, max, align, radix;
    141 	int addvariant;
    142 	int minvalid, maxvalid, alignvalid, radixvalid;
    143 };
    144 
    145 static inline uint64_t typeinfo_mask(struct rnntypeinfo *ti)
    146 {
    147 	if (ti->high == 63)
    148 		return -(1ULL << ti->low);
    149 	else
    150 		return (1ULL << (ti->high + 1)) - (1ULL << ti->low);
    151 }
    152 
    153 struct rnnbitset {
    154 	char *name;
    155 	int bare;
    156 	int isinline;
    157 	struct rnnvarinfo varinfo;
    158 	struct rnnbitfield **bitfields;
    159 	int bitfieldsnum;
    160 	int bitfieldsmax;
    161 	char *fullname;
    162 	char *file;
    163 };
    164 
    165 struct rnnbitfield {
    166 	char *name;
    167 	struct rnnvarinfo varinfo;
    168 	struct rnntypeinfo typeinfo;
    169 	char *fullname;
    170 	char *file;
    171 };
    172 
    173 struct rnndomain {
    174 	char *name;
    175 	int bare;
    176 	int width;
    177 	uint64_t size;
    178 	int sizevalid;
    179 	struct rnnvarinfo varinfo;
    180 	struct rnndelem **subelems;
    181 	int subelemsnum;
    182 	int subelemsmax;
    183 	char *fullname;
    184 	char *file;
    185 };
    186 
    187 struct rnngroup {
    188 	char *name;
    189 	struct rnndelem **subelems;
    190 	int subelemsnum;
    191 	int subelemsmax;
    192 };
    193 
    194 struct rnndelem {
    195 	enum rnnetype {
    196 		RNN_ETYPE_REG,
    197 		RNN_ETYPE_ARRAY,
    198 		RNN_ETYPE_STRIPE,
    199 		RNN_ETYPE_USE_GROUP,
    200 	} type;
    201 	char *name;
    202 	int width;
    203 	enum rnnaccess {
    204 		RNN_ACCESS_R,
    205 		RNN_ACCESS_W,
    206 		RNN_ACCESS_RW,
    207 	} access;
    208 	uint64_t offset;
    209 	uint64_t *offsets;       /* for "array" with irregular offsets */
    210 	int offsetsnum;
    211 	int offsetsmax;
    212 	char *doffset;
    213 	char **doffsets;
    214 	int doffsetsnum;
    215 	int doffsetsmax;
    216 	uint64_t length;
    217 	uint64_t stride;
    218 	struct rnndelem **subelems;
    219 	int subelemsnum;
    220 	int subelemsmax;
    221 	struct rnnvarinfo varinfo;
    222 	struct rnntypeinfo typeinfo;
    223 	struct rnnenum *index;   /* for arrays, for symbolic idx values */
    224 	char *fullname;
    225 	char *file;
    226 };
    227 
    228 struct rnnspectype {
    229 	char *name;
    230 	struct rnntypeinfo typeinfo;
    231 	char *file;
    232 };
    233 
    234 void rnn_init(void);
    235 struct rnndb *rnn_newdb(void);
    236 void rnn_parsefile (struct rnndb *db, char *file);
    237 void rnn_prepdb (struct rnndb *db);
    238 struct rnnenum *rnn_findenum (struct rnndb *db, const char *name);
    239 struct rnnbitset *rnn_findbitset (struct rnndb *db, const char *name);
    240 struct rnndomain *rnn_finddomain (struct rnndb *db, const char *name);
    241 struct rnnspectype *rnn_findspectype (struct rnndb *db, const char *name);
    242 
    243 #endif
    244