Search
lxdream.org :: lxdream/src/tools/mdparse.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/tools/mdparse.c
changeset 1298:d0eb2307b847
prev1296:30ecee61f811
author nkeynes
date Wed Feb 04 08:38:23 2015 +1000 (5 years ago)
permissions -rw-r--r--
last change Fix assorted compile warnings reported by Clang
file annotate diff log raw
1.1 --- a/src/tools/mdparse.c Sat Jan 26 14:00:48 2013 +1000
1.2 +++ b/src/tools/mdparse.c Wed Feb 04 08:38:23 2015 +1000
1.3 @@ -107,7 +107,7 @@
1.4 int yyline;
1.5 int yycol;
1.6 union {
1.7 - long i;
1.8 + uint64_t i;
1.9 char *s;
1.10 } v;
1.11 int slen;
1.12 @@ -126,7 +126,7 @@
1.13
1.14 #define YYPARSE_ERROR( msg, ... ) \
1.15 do { \
1.16 - fprintf( stderr, "Parse error in %s:%d:%d: " msg "\n", yystate.yyfilename, yytok.yyline, yytok.yycol, __VA_ARGS__ ); \
1.17 + fprintf( stderr, "Parse error in %s:%d:%d: " msg "\n", yystate.yyfilename, yytok.yyline, yytok.yycol, ## __VA_ARGS__ ); \
1.18 exit(2); \
1.19 } while(0)
1.20
1.21 @@ -159,14 +159,14 @@
1.22 return strncasecmp(yytok.yytext, cmp, yytok.yylength);
1.23 }
1.24
1.25 -static int yymatch( const char *arr[], unsigned numOptions )
1.26 +static int yymatch( const char *arr[], unsigned numOptions, const char *desc )
1.27 {
1.28 for( unsigned i=0; i<numOptions; i++ ) {
1.29 if( yystrcasecmp( arr[i] ) == 0 ) {
1.30 return i;
1.31 }
1.32 }
1.33 - return -1;
1.34 + YYPARSE_ERROR( "Unknown %s '%s'", desc, yystrdup() );
1.35 }
1.36
1.37 static gint register_block_sort_cb( gconstpointer a, gconstpointer b )
1.38 @@ -190,9 +190,9 @@
1.39 if( tok == TOK_INTEGER ) {
1.40 apv->i = yytok.v.i;
1.41 if( *numBytes == 0 ) {
1.42 - YYPARSE_ERROR( "Expected string initializer but was an integer (0x%x)", yytok.v.i );
1.43 + YYPARSE_ERROR( "Expected string initializer but was an integer (0x%llx)", yytok.v.i );
1.44 }
1.45 - } else if( tok = TOK_STRING ) {
1.46 + } else if( tok == TOK_STRING ) {
1.47 if( *numBytes == 0 ) {
1.48 *numBytes = yytok.slen;
1.49 apv->s = yytok.v.s;
1.50 @@ -224,10 +224,7 @@
1.51 case TOK_ACCESS:
1.52 READ(TOK_EQUALS);
1.53 READ(TOK_IDENTIFIER);
1.54 - flags->access = yymatch(ACCESS_NAMES,elementsof(ACCESS_NAMES));
1.55 - if( flags->access == -1 ) {
1.56 - YYPARSE_ERROR("Unknown access mode '%s'", yystrdup());
1.57 - }
1.58 + flags->access = yymatch(ACCESS_NAMES,elementsof(ACCESS_NAMES), "access mode");
1.59 break;
1.60 case TOK_MASK:
1.61 if( numBytes ) {
1.62 @@ -235,32 +232,23 @@
1.63 tok = iolex(TOK_INTEGER);
1.64 ioparse_apval( tok, &flags->maskValue, numBytes );
1.65 } else {
1.66 - YYPARSE_ERROR("mask is not valid on a register block",0);
1.67 + YYPARSE_ERROR("mask is not valid on a register block");
1.68 }
1.69 break;
1.70 case TOK_ENDIAN:
1.71 READ(TOK_EQUALS);
1.72 READ(TOK_IDENTIFIER);
1.73 - flags->endian = yymatch(ENDIAN_NAMES,elementsof(ENDIAN_NAMES));
1.74 - if( flags->endian == -1 ) {
1.75 - YYPARSE_ERROR("Unknown endianness '%s'", yystrdup());
1.76 - }
1.77 + flags->endian = yymatch(ENDIAN_NAMES,elementsof(ENDIAN_NAMES), "endianness");
1.78 break;
1.79 case TOK_TRACE:
1.80 READ(TOK_EQUALS);
1.81 READ(TOK_IDENTIFIER);
1.82 - flags->traceFlag = yymatch(TRACE_NAMES,elementsof(TRACE_NAMES));
1.83 - if( flags->traceFlag == -1 ) {
1.84 - YYPARSE_ERROR("Unknown trace flag '%s'", yystrdup());
1.85 - }
1.86 + flags->traceFlag = yymatch(TRACE_NAMES,elementsof(TRACE_NAMES), "trace flags");
1.87 break;
1.88 case TOK_TEST:
1.89 READ(TOK_EQUALS);
1.90 READ(TOK_IDENTIFIER);
1.91 - flags->testFlag = yymatch(TRACE_NAMES,elementsof(TRACE_NAMES));
1.92 - if( flags->testFlag == -1 ) {
1.93 - YYPARSE_ERROR("Unknown test flag '%s'", yystrdup());
1.94 - }
1.95 + flags->testFlag = yymatch(TRACE_NAMES,elementsof(TRACE_NAMES), "test flag");
1.96 break;
1.97 case TOK_COMMA:
1.98 break;
1.99 @@ -274,17 +262,17 @@
1.100
1.101 static void ioparse_regdef( struct regdef *reg )
1.102 {
1.103 - reg->offset = yytok.v.i;
1.104 + reg->offset = (uint32_t)yytok.v.i;
1.105 reg->numElements = 1;
1.106 reg->numBytes = 0;
1.107 reg->initValue.i = 0;
1.108 reg->flags.maskValue.i = -1;
1.109 - unsigned rangeOffset = reg->offset;
1.110 + uint32_t rangeOffset = reg->offset;
1.111
1.112 int tok = iolex(TOK_COLON);
1.113 if( tok == TOK_RANGE ) {
1.114 READ(TOK_INTEGER);
1.115 - rangeOffset = yytok.v.i;
1.116 + rangeOffset = (uint32_t)yytok.v.i;
1.117 if( rangeOffset < reg->offset ) {
1.118 YYPARSE_ERROR( "Range end (0x%x) must be greater than the range start (0x%x)", rangeOffset, reg->offset );
1.119 }
1.120 @@ -293,10 +281,7 @@
1.121 YYPARSE_ERROR( "Expected ':' but was %s\n", TOKEN_NAMES[tok] );
1.122 }
1.123 READ(TOK_IDENTIFIER);
1.124 - reg->mode = yymatch(MODE_NAMES, elementsof(MODE_NAMES));
1.125 - if( reg->mode == -1 ) {
1.126 - YYPARSE_ERROR( "Unknown register mode '%s'", yystrdup() );
1.127 - }
1.128 + reg->mode = yymatch(MODE_NAMES, elementsof(MODE_NAMES), "register mode");
1.129 if( reg->mode == REG_MIRROR ) {
1.130 /* Mirror regions have a target range only */
1.131 READ(TOK_INTEGER);
1.132 @@ -306,14 +291,14 @@
1.133 if( tok == TOK_RANGE ) {
1.134 READ(TOK_INTEGER);
1.135 if( yytok.v.i < reg->initValue.i ) {
1.136 - YYPARSE_ERROR( "Invalid mirror target range 0x%x..0x%x", reg->initValue.i, yytok.v.i );
1.137 + YYPARSE_ERROR( "Invalid mirror target range 0x%llx..0x%llx", reg->initValue.i, yytok.v.i );
1.138 }
1.139 - reg->numBytes = yytok.v.i - reg->initValue.i + 1;
1.140 + reg->numBytes = (uint32_t)(yytok.v.i - reg->initValue.i + 1);
1.141 tok = iolex(TOK_STRIDE);
1.142 }
1.143 if( tok == TOK_STRIDE ) {
1.144 READ(TOK_INTEGER);
1.145 - reg->stride = yytok.v.i;
1.146 + reg->stride = (uint32_t)yytok.v.i;
1.147 tok = iolex(TOK_ACTION);
1.148 } else {
1.149 reg->stride = reg->numBytes;
1.150 @@ -333,10 +318,7 @@
1.151
1.152 } else {
1.153 READ(TOK_IDENTIFIER);
1.154 - reg->type = yymatch(TYPE_NAMES, elementsof(TYPE_NAMES));
1.155 - if( reg->type == -1 ) {
1.156 - YYPARSE_ERROR( "Unknown register type '%s'", yystrdup() );
1.157 - }
1.158 + reg->type = yymatch(TYPE_NAMES, elementsof(TYPE_NAMES), "register type");
1.159 reg->numBytes = TYPE_SIZES[reg->type];
1.160 tok = iolex(TOK_IDENTIFIER);
1.161 if( tok == TOK_IDENTIFIER ) {
1.162 @@ -361,7 +343,7 @@
1.163 }
1.164 tok = iolex(TOK_ACTION);
1.165 } else if( reg->type == REG_STRING ) {
1.166 - YYPARSE_ERROR( "String declarations must have an initializer (ie = 'abcd')",0 );
1.167 + YYPARSE_ERROR( "String declarations must have an initializer (ie = 'abcd')" );
1.168 }
1.169 if( tok == TOK_ACTION ) {
1.170 // reg->action = yystrdup();
1.171 @@ -393,7 +375,7 @@
1.172 YYPARSE_ERROR("Expected AT but got %s\n", TOKEN_NAMES[tok] );
1.173 }
1.174 READ(TOK_INTEGER);
1.175 - block->address = yytok.v.i;
1.176 + block->address = (uint32_t)yytok.v.i;
1.177
1.178 tok = iolex(TOK_LBRACE);
1.179 if( tok == TOK_LPAREN) {
1.180 @@ -450,7 +432,7 @@
1.181 free(tmp);
1.182 } else if( tok == TOK_SPACE ) {
1.183 } else if( tok == TOK_REGISTERS ) {
1.184 - struct regblock *block = ioparse_regblock(block);
1.185 + struct regblock *block = ioparse_regblock();
1.186 count++;
1.187 blocks = g_list_insert_sorted(blocks, block, register_block_sort_cb);
1.188 } else {
1.189 @@ -638,7 +620,7 @@
1.190 while( yystate.yyposn < yystate.yyend && isdigit(*yystate.yyposn) )
1.191 yystate.yyposn++;
1.192 }
1.193 - yytok.v.i = strtol( yystart, NULL, 0 );
1.194 + yytok.v.i = strtoll( yystart, NULL, 0 );
1.195 YYRETURN(TOK_INTEGER);
1.196 } else if( isalpha(ch) || ch == '_' ) {
1.197 /* IDENTIFIER */
.