PulkoMandy | 17fc759 | 2022-07-28 18:27:54 +0200 | [diff] [blame] | 1 | /* $VER: vbcc (main.c) $Revision: 1.67 $ */ |
| 2 | #include "vbcc_cpp.h" |
| 3 | #include "vbc.h" |
| 4 | #include "opt.h" |
| 5 | static char FILE_[]=__FILE__; |
| 6 | void do_function(Var *); |
| 7 | static function_info *current_fi; |
| 8 | token *ctok; |
| 9 | lexer_state ls; |
| 10 | int endok=1; |
| 11 | int line,errors; |
| 12 | bvtype task_preempt_regs[RSIZE/sizeof(bvtype)]; |
| 13 | bvtype task_schedule_regs[RSIZE/sizeof(bvtype)]; |
| 14 | char *multname[]={"","s"}; |
| 15 | |
| 16 | typedef struct deplist {char *name; struct deplist *next;} deplist; |
| 17 | deplist *deps; |
| 18 | FILE *depout; |
| 19 | void handle_deps(char *name,int string) |
| 20 | { |
| 21 | deplist *p=deps; |
| 22 | if(!depout||!name||!*name) return; |
| 23 | /* by default omit <...> includes */ |
| 24 | if(!string&&!(c_flags[51]&USEDFLAG)) return; |
| 25 | while(p){ |
| 26 | if(!strcmp(p->name,name)) return; |
| 27 | p=p->next; |
| 28 | } |
| 29 | p=mymalloc(sizeof(*p)); |
| 30 | p->name=mymalloc(strlen(name)+1); |
| 31 | strcpy(p->name,name); |
| 32 | p->next=deps; |
| 33 | deps=p; |
| 34 | fprintf(depout," %s",name); |
| 35 | } |
| 36 | |
| 37 | void raus(void) |
| 38 | /* Beendet das Programm */ |
| 39 | { |
| 40 | static int inraus; |
| 41 | if(inraus) return; |
| 42 | inraus = 1; |
| 43 | if(DEBUG) printf("raus()\n"); |
| 44 | if(!endok) fprintf(stderr,"unexpected end of file\n"); |
| 45 | if(errors) fprintf(stderr,"%d error%s found!\n",errors,multname[errors>1]); |
| 46 | if(debug_info&&out) |
| 47 | cleanup_db(out); |
| 48 | while(nesting>=0) leave_block(); |
| 49 | /*FIXME: do I have to close input-file? */ |
| 50 | if(!wpo) |
| 51 | cleanup_cg(out); |
| 52 | emit_flush(out); |
| 53 | if(cmdfile) fclose(cmdfile); |
| 54 | if(out) fclose(out); |
| 55 | if(ic1) fclose(ic1); |
| 56 | if(ic2) fclose(ic2); |
| 57 | /*FIXME: need to cleanup something for ucpp?*/; |
| 58 | if(endok&&!errors) exit(EXIT_SUCCESS); else exit(EXIT_FAILURE); |
| 59 | } |
| 60 | int eof; |
| 61 | void translation_unit(void) |
| 62 | /* bearbeitet translation_unit */ |
| 63 | /* hier z.Z. nur provisorisch */ |
| 64 | { |
| 65 | Var *p; |
| 66 | if(cross_module){ |
| 67 | for(p=first_ext;p;p=p->next) |
| 68 | if(!(p->flags&BUILTIN)) |
| 69 | p->flags|=NOTINTU; |
| 70 | } |
| 71 | while(1){ |
| 72 | killsp(); |
| 73 | if(eof||ctok->type!=NAME){ |
| 74 | if(!eof){ |
| 75 | error(369); |
| 76 | next_token(); |
| 77 | continue; |
| 78 | }else{ |
| 79 | if(cross_module){ |
| 80 | int n=0; |
| 81 | if(last_tunit){ |
| 82 | last_tunit->next=mymalloc(sizeof(*first_tunit)); |
| 83 | last_tunit=last_tunit->next; |
| 84 | }else{ |
| 85 | first_tunit=last_tunit=mymalloc(sizeof(*first_tunit)); |
| 86 | } |
| 87 | last_tunit->next=0; |
| 88 | for(p=first_var[0];p;p=p->next){ |
| 89 | if(p->storage_class==STATIC) n++; |
| 90 | } |
| 91 | last_tunit->statics=first_var[0]; |
| 92 | return; |
| 93 | }else{ |
| 94 | raus(); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | endok=0; |
| 99 | var_declaration(); |
| 100 | endok=1; |
| 101 | } |
| 102 | } |
| 103 | void reserve_reg(char *p) |
| 104 | /* reserviert ein Register */ |
| 105 | { |
| 106 | int i; |
| 107 | if(*p!='=') error(4,"-reserve-reg"); |
| 108 | for(i=1;i<=MAXR;i++){ |
| 109 | if(!strcmp(p+1,regnames[i])) |
| 110 | break; |
| 111 | } |
| 112 | if(i>MAXR){ |
| 113 | error(331,p+1); |
| 114 | }else{ |
| 115 | regsa[i]=1; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void dontwarn(char *p) |
| 120 | /* schaltet flags fuer Meldung auf DONTWARN */ |
| 121 | { |
| 122 | if(*p!='=') error(4,"-dontwarn"); |
| 123 | do{ |
| 124 | int i=atoi(p+1); |
| 125 | if(i>=err_num) error(159,i); |
| 126 | if(i<0){ |
| 127 | for(i=0;i<err_num;i++) |
| 128 | if(!(err_out[i].flags&(ANSIV|FATAL))) |
| 129 | err_out[i].flags|=DONTWARN; |
| 130 | return; |
| 131 | } |
| 132 | if(err_out[i].flags&(ANSIV|FATAL)) error(160,i); |
| 133 | err_out[i].flags|=DONTWARN; |
| 134 | p=strchr(p+1,','); |
| 135 | } while(p); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
| 140 | #define MISRA_98_RULE_NUMBER 127 |
| 141 | #define MISRA_04_CHAPTER 21 |
| 142 | #define MISRA_04_MAX_RULE_IN_CHAPTER 17 |
| 143 | |
| 144 | static int misra_98_warn_flag[MISRA_98_RULE_NUMBER] = { 0 }; |
| 145 | static int misra_04_warn_flag[MISRA_04_CHAPTER][MISRA_04_MAX_RULE_IN_CHAPTER] = { 0 }; |
| 146 | |
| 147 | void misrawarn(char *p) { |
| 148 | int rule,subrule,misraoldrule; |
| 149 | char* last; |
| 150 | int not_found; |
| 151 | tmisra_err_out* misr_err; |
| 152 | rule = 0; |
| 153 | subrule = 0; |
| 154 | misraoldrule = 0; |
| 155 | if(*p!='=') error(4,"-misrawarn"); |
| 156 | p++; |
| 157 | if (!(strncmp("chapter",p,6))) { |
| 158 | if (sscanf((p+7),"%d",&rule) != 1) { |
| 159 | error(327,"-misrawarn"); |
| 160 | } |
| 161 | } else if ( !(strncmp("misra98rule",p,11))) { |
| 162 | if (sscanf((p+12),"%d",&misraoldrule) != 1) { |
| 163 | error(327,"-misrawarn"); |
| 164 | } |
| 165 | } else { |
| 166 | if (last = strchr(p,'.')) { |
| 167 | *last = 0; |
| 168 | last++; |
| 169 | if (sscanf(last,"%d",&subrule) != 1) error(327,"-misrawarn"); |
| 170 | if (sscanf(p,"%d",&rule) != 1) error(327,"-misrawarn"); |
| 171 | last--; |
| 172 | *last='.'; |
| 173 | } else error(327,"-misrawarn"); |
| 174 | } |
| 175 | |
| 176 | p--; |
| 177 | if (!misracheck) misracheck = 1; |
| 178 | if (misraoldrule) { |
| 179 | if (misraversion==2004) error(328,misraversion,"-misrawarn",p); |
| 180 | if (!misraversion) misraversion=1998; |
| 181 | if ((misraoldrule < 1) || (misraoldrule>MISRA_98_RULE_NUMBER)) error(329,misraoldrule,"-misrawarn",p); |
| 182 | misra_98_warn_flag[misraoldrule-1] = 1; |
| 183 | } else { |
| 184 | if (misraversion==1998) error(328,misraversion,"-misrawarn",p); |
| 185 | if (!misraversion) misraversion=2004; |
| 186 | if (subrule) { |
| 187 | misr_err = misra_err_out; |
| 188 | not_found = 1; |
| 189 | while ( misr_err->text ) { |
| 190 | if ((misr_err->chapter == rule) && (misr_err->rule == subrule)) { |
| 191 | not_found = 0; |
| 192 | break; |
| 193 | } |
| 194 | misr_err++; |
| 195 | } |
| 196 | if (not_found) error(330,rule,subrule,"-misrawarn",p); |
| 197 | misra_04_warn_flag[rule-1][subrule-1] = 1; |
| 198 | } else { |
| 199 | misr_err = misra_err_out; |
| 200 | not_found = 1; |
| 201 | while ( misr_err->text ) { |
| 202 | if (misr_err->chapter == rule) { |
| 203 | not_found = 0; |
| 204 | misra_04_warn_flag[misr_err->chapter-1][misr_err->rule-1] = 1; |
| 205 | } |
| 206 | misr_err++; |
| 207 | } |
| 208 | if (not_found) error(330,rule,subrule,"-misrawarn",p); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | } |
| 213 | |
| 214 | |
| 215 | void misradontwarn(char *p) { |
| 216 | int rule,subrule,misraoldrule; |
| 217 | char* last; |
| 218 | int not_found; |
| 219 | tmisra_err_out* misr_err; |
| 220 | rule = 0; |
| 221 | subrule = 0; |
| 222 | misraoldrule = 0; |
| 223 | if(*p!='=') error(4,"-misradontwarn"); |
| 224 | p++; |
| 225 | if (!(strncmp("chapter",p,6))) { |
| 226 | if (sscanf((p+7),"%d",&rule) != 1) { |
| 227 | error(327,"-misradontwarn"); |
| 228 | } |
| 229 | } else if ( !(strncmp("misra98rule",p,11))) { |
| 230 | if (sscanf((p+12),"%d",&misraoldrule) != 1) { |
| 231 | error(327,"-misradontwarn"); |
| 232 | } |
| 233 | } else { |
| 234 | if (last = strchr(p,'.')) { |
| 235 | *last = 0; |
| 236 | last++; |
| 237 | if (sscanf(last,"%d",&subrule) != 1) error(327,"-misradontwarn"); |
| 238 | if (sscanf(p,"%d",&rule) != 1) error(327,"-misradontwarn"); |
| 239 | last--; |
| 240 | *last='.'; |
| 241 | } else error(327,"-misradontwarn"); |
| 242 | } |
| 243 | |
| 244 | p--; |
| 245 | if (misraoldrule) { |
| 246 | if (misraversion==2004) error(328,misraversion,"-misradontwarn",p); |
| 247 | if ((misraoldrule < 1) || (misraoldrule>MISRA_98_RULE_NUMBER)) error(329,misraoldrule,"-misradontwarn",p); |
| 248 | misra_98_warn_flag[misraoldrule-1] = -1; |
| 249 | } else { |
| 250 | if (misraversion==1998) error(328,misraversion,"-misradontwarn",p); |
| 251 | if (subrule) { |
| 252 | misr_err = misra_err_out; |
| 253 | not_found = 1; |
| 254 | while ( misr_err->text ) { |
| 255 | if ((misr_err->chapter == rule) && (misr_err->rule == subrule)) { |
| 256 | not_found = 0; |
| 257 | break; |
| 258 | } |
| 259 | misr_err++; |
| 260 | } |
| 261 | if (not_found) error(330,rule,subrule,"-misradontwarn",p); |
| 262 | misra_04_warn_flag[rule-1][subrule-1] = -1; |
| 263 | } else { |
| 264 | misr_err = misra_err_out; |
| 265 | not_found = 1; |
| 266 | while ( misr_err->text ) { |
| 267 | if (misr_err->chapter == rule) { |
| 268 | not_found = 0; |
| 269 | misra_04_warn_flag[misr_err->chapter-1][misr_err->rule-1] = -1; |
| 270 | } |
| 271 | misr_err++; |
| 272 | } |
| 273 | if (not_found) error(330,rule,subrule,"-misradontwarn",p); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | void warn(char *p) |
| 282 | /* schaltet Warnung fuer Meldung ein */ |
| 283 | /* wenn Nummer<0 sind alle Warnungen ein */ |
| 284 | { |
| 285 | int i; |
| 286 | if(*p!='=') error(4,"-warn"); |
| 287 | i=atoi(p+1); |
| 288 | if(i>=err_num) error(159,i); |
| 289 | if(i<0){ |
| 290 | for(i=0;i<err_num;i++) err_out[i].flags&=~DONTWARN; |
| 291 | return; |
| 292 | }else err_out[i].flags&=~DONTWARN; |
| 293 | } |
| 294 | void gen_function(FILE *f,Var *v,int real_gen) |
| 295 | { |
| 296 | IC *p,*new;int i,had_regs; |
| 297 | if(DEBUG&1) printf("gen_function <%s>,f=%p,real_gen=%d\n",v->identifier,(void*)f,real_gen); |
| 298 | if(!v->fi) ierror(0); |
| 299 | if(errors!=0) return; |
| 300 | first_ic=last_ic=0; |
| 301 | for(i=1;i<=MAXR;i++) {regs[i]=regused[i]=regsa[i];regsbuf[i]=0;} |
| 302 | function_calls=0;vlas=0; |
| 303 | if(!real_gen){ |
| 304 | for(p=v->fi->first_ic;p;p=p->next){ |
| 305 | new=new_IC(); |
| 306 | *new=*p; |
| 307 | p->copy=new; |
| 308 | add_IC(new); |
| 309 | new->file=p->file; |
| 310 | new->line=p->line; |
| 311 | if(p->code==CALL){ |
| 312 | int i; |
| 313 | function_calls++; |
| 314 | if((p->q1.flags&VAR)&&!strcmp(p->q1.v->identifier,"__allocvla")){ |
| 315 | vlas=1; |
| 316 | v->fi->flags|=USES_VLA; |
| 317 | } |
| 318 | new->arg_list=mymalloc(sizeof(*new->arg_list)*new->arg_cnt); |
| 319 | for(i=0;i<new->arg_cnt;i++) new->arg_list[i]=p->arg_list[i]->copy; |
| 320 | } |
| 321 | } |
| 322 | }else{ |
| 323 | for(i=1;i<=MAXR;i++) regused[i]=0; |
| 324 | for(p=v->fi->opt_ic;p;p=p->next){ |
| 325 | if(p->code==ALLOCREG){ |
| 326 | regused[p->q1.reg]=1; |
| 327 | if(reg_pair(p->q1.reg,&rp)){ |
| 328 | regused[rp.r1]=1; |
| 329 | regused[rp.r2]=1; |
| 330 | } |
| 331 | } |
| 332 | if(p->code==CALL){ |
| 333 | if((p->q1.flags&VAR)&&!strcmp(p->q1.v->identifier,"__allocvla")) vlas=1; |
| 334 | function_calls++; |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | if(vlas&&FPVLA_REG) regs[FPVLA_REG]=regused[FPVLA_REG]=regsa[FPVLA_REG]=regscratch[FPVLA_REG]=1; |
| 339 | |
| 340 | if(!real_gen&&(c_flags[2]&USEDFLAG)&&ic1){ |
| 341 | fprintf(ic1,"function %s\n",v->identifier); |
| 342 | pric(ic1,first_ic); |
| 343 | } |
| 344 | vl0=first_ext; |
| 345 | vl1=v->fi->statics; |
| 346 | vl2=0; |
| 347 | vl3=v->fi->vars; |
| 348 | nesting=1; |
| 349 | first_var[nesting]=last_var[nesting]=0; |
| 350 | cur_func=v->identifier; |
| 351 | if(!real_gen){ |
| 352 | optimize(optflags,v); |
| 353 | if((force_statics||prefer_statics)&&first_var[nesting]){ |
| 354 | |
| 355 | last_var[nesting]->next=v->fi->vars; |
| 356 | v->fi->vars=first_var[nesting]; |
| 357 | } |
| 358 | memset(regs_modified,0,RSIZE); |
| 359 | /* pseudeo generator pass to get regs_modified */ |
| 360 | v->fi->opt_ic=clone_ic(first_ic); |
| 361 | v->fi->max_offset=max_offset; |
| 362 | if(v->fi&&(v->fi->flags&ALL_REGS)) |
| 363 | had_regs=1; |
| 364 | else |
| 365 | had_regs=0; |
| 366 | gen_code(0,first_ic,v,max_offset); |
| 367 | #ifdef HAVE_REGS_MODIFIED |
| 368 | if(!v->fi) v->fi=new_fi(); |
| 369 | { |
| 370 | int i;IC *p; |
| 371 | for(i=1;i<=MAXR;i++){ |
| 372 | if(BTST(regs_modified,i)&®_pair(i,&rp)){ |
| 373 | BSET(regs_modified,rp.r1); |
| 374 | BSET(regs_modified,rp.r2); |
| 375 | } |
| 376 | } |
| 377 | #if 1 |
| 378 | for(i=1;i<=MAXR;i++){ |
| 379 | if(reg_pair(i,&rp)){ |
| 380 | if(BTST(regs_modified,rp.r1)||BTST(regs_modified,rp.r2)) |
| 381 | BSET(regs_modified,i); |
| 382 | } |
| 383 | } |
| 384 | #endif |
| 385 | if(had_regs){ |
| 386 | if(memcmp(regs_modified,v->fi->regs_modified,RSIZE)) |
| 387 | error(321,v->identifier); |
| 388 | }else |
| 389 | memcpy(v->fi->regs_modified,regs_modified,RSIZE); |
| 390 | #if 0 |
| 391 | printf("regs for %s (ALL_REGS=%d):\n",v->identifier,v->fi->flags&ALL_REGS); |
| 392 | for(i=1;i<MAXR;i++) if(BTST(regs_modified,i)) printf("%s ",regnames[i]); |
| 393 | printf("\n"); |
| 394 | #endif |
| 395 | } |
| 396 | #endif |
| 397 | v->flags|=GENERATED; |
| 398 | free_IC(first_ic); |
| 399 | first_ic=last_ic=0; |
| 400 | /*free_var(first_var[nesting]);*/ |
| 401 | nesting=0; |
| 402 | }else{ |
| 403 | if((c_flags[3]&USEDFLAG)&&ic2){ |
| 404 | fprintf(ic2,"function %s\n",v->identifier); |
| 405 | pric(ic2,v->fi->opt_ic); |
| 406 | } |
| 407 | gen_code(f,v->fi->opt_ic,v,v->fi->max_offset); |
| 408 | static_stack_check(v); |
| 409 | } |
| 410 | } |
| 411 | /* handle functions in a const list before caller */ |
| 412 | static void do_clist_calls(const_list *cl) |
| 413 | { |
| 414 | while(cl){ |
| 415 | if(cl->tree&&(cl->tree->o.flags&VARADR)){ |
| 416 | Var *v=cl->tree->o.v; |
| 417 | if(ISFUNC(v->vtyp->flags)){ |
| 418 | if(DEBUG&1) |
| 419 | printf(":: %s\n",v->identifier); |
| 420 | do_function(v); |
| 421 | } |
| 422 | } |
| 423 | if(cl->other) |
| 424 | do_clist_calls(cl->other); |
| 425 | cl=cl->next; |
| 426 | } |
| 427 | } |
| 428 | void do_function(Var *v) |
| 429 | { |
| 430 | int i;IC *p; |
| 431 | if((v->flags&(GENERATED|DEFINED))!=DEFINED) return; |
| 432 | v->flags|=GENERATED; |
| 433 | if(!v->fi) v->fi=new_fi(); |
| 434 | #if 0 |
| 435 | for(i=0;i<v->fi->call_cnt;i++){ |
| 436 | if(v->fi->call_list[i].v->flags&DEFINED) |
| 437 | do_function(v->fi->call_list[i].v); |
| 438 | } |
| 439 | #endif |
| 440 | /* handle callees before caller */ |
| 441 | for(p=v->fi->first_ic;p;p=p->next){ |
| 442 | /* direct call */ |
| 443 | if(p->code==CALL&&(p->q1.flags&(VAR|DREFOBJ))==VAR) |
| 444 | do_function(p->q1.v); |
| 445 | /* function address is also a candidate */ |
| 446 | if((p->q1.flags&(VAR|VARADR))&&ISFUNC(p->q1.v->vtyp->flags)) |
| 447 | do_function(p->q1.v); |
| 448 | if((p->q2.flags&(VAR|VARADR))&&ISFUNC(p->q2.v->vtyp->flags)) |
| 449 | do_function(p->q2.v); |
| 450 | if((p->z.flags&(VAR|VARADR))&&ISFUNC(p->z.v->vtyp->flags)) |
| 451 | do_function(p->z.v); |
| 452 | /* indirect call, handle special case */ |
| 453 | if(p->code==CALL&&(p->q1.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){ |
| 454 | Var *v=p->q1.v; |
| 455 | if(v->storage_class==AUTO||v->storage_class==REGISTER){ |
| 456 | IC *m=p->prev;Var *tmp=0; |
| 457 | while(m&&(m->code<LABEL||m->code>=BRA)){ |
| 458 | if(!tmp&&(m->z.flags&(VAR|DREFOBJ))==VAR&&m->z.v==v&& |
| 459 | (m->q1.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)) |
| 460 | tmp=m->q1.v; |
| 461 | if(tmp&&(m->z.flags&(VAR|DREFOBJ))==VAR&&m->z.v==tmp&& |
| 462 | (m->q1.flags&(VAR|VARADR))==(VAR|VARADR)&& |
| 463 | m->q1.v->clist&&is_const(m->q1.v->vtyp)){ |
| 464 | do_clist_calls(m->q1.v->clist); |
| 465 | } |
| 466 | m=m->prev; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | gen_function(0,v,0); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | |
| 476 | extern char *copyright; |
| 477 | int main(int argc,char *argv[]) |
| 478 | { |
| 479 | int i,j,*fname=malloc(argc*sizeof(int)),files=0; |
| 480 | unsigned long ucpp_flags=LEXER|WARN_TRIGRAPHS|WARN_STANDARD|WARN_ANNOYING/*|CCHARSET*/|HANDLE_PRAGMA|COPY_LINE|WARN_TRIGRAPHS_MORE|HANDLE_TRIGRAPHS; |
| 481 | if(!fname) ierror(0); |
| 482 | memset(fname,0,argc*sizeof(int)); |
| 483 | c_flags_val[9].f=dontwarn; |
| 484 | c_flags_val[10].f=warn; |
| 485 | c_flags_val[42].f=misrawarn; |
| 486 | c_flags_val[43].f=misradontwarn; |
| 487 | c_flags_val[44].f=reserve_reg; |
| 488 | for(i=1;i<argc;i++){ |
| 489 | if(*argv[i]!='-'){ /* kein Flag */ |
| 490 | fname[i]=1; |
| 491 | files++; |
| 492 | if(!inname) inname=argv[i]; |
| 493 | }else{ |
| 494 | int flag=0; |
| 495 | if(argv[i][1]=='D'||argv[i][1]=='I') flag=1; |
| 496 | for(j=0;j<MAXCF&&flag==0;j++){ |
| 497 | size_t l; |
| 498 | if(!c_flags_name[j]) continue; |
| 499 | l=strlen(c_flags_name[j]); |
| 500 | if(l>0&&!strncmp(argv[i]+1,c_flags_name[j],l)&&(argv[i][1+l]==0||argv[i][1+l]=='=')){ |
| 501 | flag=1; |
| 502 | if((c_flags[j]&(USEDFLAG|FUNCFLAG))==USEDFLAG){error(2,argv[i]);break;} |
| 503 | c_flags[j]|=USEDFLAG; |
| 504 | if(c_flags[j]&STRINGFLAG){ |
| 505 | if(argv[i][l+1]!='='){error(3,argv[i]);} |
| 506 | if(argv[i][l+2]||i>=argc-1) |
| 507 | c_flags_val[j].p=&argv[i][l+2]; |
| 508 | else |
| 509 | c_flags_val[j].p=&argv[++i][0]; |
| 510 | } |
| 511 | if(c_flags[j]&VALFLAG){ |
| 512 | if(argv[i][l+1]!='='){error(4,argv[i]);} |
| 513 | if(argv[i][l+2]||i>=argc-1) |
| 514 | c_flags_val[j].l=atol(&argv[i][l+2]); |
| 515 | else |
| 516 | c_flags_val[j].l=atol(&argv[++i][0]); |
| 517 | } |
| 518 | if(c_flags[j]&FUNCFLAG) c_flags_val[j].f(&argv[i][l+1]); |
| 519 | } |
| 520 | } |
| 521 | for(j=0;j<MAXGF&&flag==0;j++){ |
| 522 | size_t l; |
| 523 | if(!g_flags_name[j]) continue; |
| 524 | l=strlen(g_flags_name[j]); |
| 525 | if(l>0&&!strncmp(argv[i]+1,g_flags_name[j],l)){ |
| 526 | flag=1; |
| 527 | if((g_flags[j]&(USEDFLAG|FUNCFLAG))==USEDFLAG){error(2,argv[i]);break;} |
| 528 | g_flags[j]|=USEDFLAG; |
| 529 | if(g_flags[j]&STRINGFLAG){ |
| 530 | if(argv[i][l+1]!='='){error(3,argv[i]);} |
| 531 | if(argv[i][l+2]||i>=argc-1) |
| 532 | g_flags_val[j].p=&argv[i][l+2]; |
| 533 | else |
| 534 | g_flags_val[j].p=&argv[++i][0]; |
| 535 | } |
| 536 | if(g_flags[j]&VALFLAG){ |
| 537 | if(argv[i][l+1]!='='){error(4,argv[i]);} |
| 538 | if(argv[i][l+2]||i>=argc-1) |
| 539 | g_flags_val[j].l=atol(&argv[i][l+2]); |
| 540 | else |
| 541 | g_flags_val[j].l=atol(&argv[++i][0]); |
| 542 | } |
| 543 | if(g_flags[j]&FUNCFLAG) g_flags_val[j].f(&argv[i][l+1]); |
| 544 | } |
| 545 | } |
| 546 | if(!flag){error(5,argv[i]);} |
| 547 | } |
| 548 | } |
| 549 | if(!(c_flags[6]&USEDFLAG)){ |
| 550 | #ifdef SPECIAL_COPYRIGHT |
| 551 | printf("%s\n",SPECIAL_COPYRIGHT); |
| 552 | #else |
| 553 | printf("%s\n",copyright); |
| 554 | printf("%s\n",cg_copyright); |
| 555 | #endif |
| 556 | } |
| 557 | if(c_flags[4]&USEDFLAG) DEBUG=c_flags_val[4].l; else DEBUG=0; |
| 558 | if(c_flags[13]&USEDFLAG) ucpp_flags|=CPLUSPLUS_COMMENTS; |
| 559 | if(c_flags[14]&USEDFLAG) ucpp_flags|=CPLUSPLUS_COMMENTS; |
| 560 | if(c_flags[15]&USEDFLAG) ucpp_flags&=~HANDLE_TRIGRAPHS; |
| 561 | if(c_flags[52]&USEDFLAG) ucpp_flags&=~(WARN_STANDARD|WARN_ANNOYING); |
| 562 | if(c_flags[16]&USEDFLAG) no_inline_peephole=1; |
| 563 | if(c_flags[17]&USEDFLAG) final=1; |
| 564 | if(!(c_flags[8]&USEDFLAG)) c_flags_val[8].l=10; /* max. Fehlerzahl */ |
| 565 | if(c_flags[22]&USEDFLAG) c_flags[7]|=USEDFLAG; /* iso=ansi */ |
| 566 | if(c_flags[7]&USEDFLAG) error(209); |
| 567 | if(c_flags[0]&USEDFLAG) optflags=c_flags_val[0].l; |
| 568 | if(optflags&16384) cross_module=1; |
| 569 | if(c_flags[11]&USEDFLAG) maxoptpasses=c_flags_val[11].l; |
| 570 | if(c_flags[12]&USEDFLAG) inline_size=c_flags_val[12].l; |
| 571 | if(c_flags[21]&USEDFLAG) fp_assoc=1; |
| 572 | if(c_flags[25]&USEDFLAG) unroll_size=c_flags_val[25].l; |
| 573 | if(c_flags[23]&USEDFLAG) noaliasopt=1; |
| 574 | if(c_flags[27]&USEDFLAG) optspeed=1; |
| 575 | if(c_flags[28]&USEDFLAG) optsize=1; |
| 576 | if(c_flags[29]&USEDFLAG) unroll_all=1; |
| 577 | if(c_flags[30]&USEDFLAG) stack_check=1; |
| 578 | if(c_flags[31]&USEDFLAG) inline_depth=c_flags_val[31].l; |
| 579 | if(c_flags[32]&USEDFLAG) debug_info=1; |
| 580 | if(c_flags[33]&USEDFLAG) c99=1; |
| 581 | if(c_flags[60]&USEDFLAG) c99=0; |
| 582 | if(c_flags[34]&USEDFLAG) {wpo=1;no_emit=1;} |
| 583 | if(c_flags[36]&USEDFLAG) {noitra=1;} |
| 584 | if(c_flags[37]&USEDFLAG) { |
| 585 | misracheck=1; |
| 586 | if ((misraversion==1998) && (c_flags_val[37].l == 2004)) error(328,c_flags_val[37].l,"-misra",""); |
| 587 | if ((misraversion==2004) && (c_flags_val[37].l == 1998)) error(328,c_flags_val[37].l,"-misra",""); |
| 588 | misraversion=c_flags_val[37].l; |
| 589 | |
| 590 | if (!((misraversion==2004) || (misraversion==1998))) error(328,misraversion,"-misra",""); |
| 591 | if (misraversion==1998) { |
| 592 | int misra_set_iterator; |
| 593 | for (misra_set_iterator = 0; misra_set_iterator < MISRA_98_RULE_NUMBER; misra_set_iterator++ ) { |
| 594 | if (misra_98_warn_flag[misra_set_iterator] != -1) misra_98_warn_flag[misra_set_iterator] = 1; |
| 595 | } |
| 596 | } else { |
| 597 | int m1, m2; |
| 598 | for (m1 = 0; m1 < MISRA_04_CHAPTER; m1++) { |
| 599 | for (m2 = 0; m2 < MISRA_04_MAX_RULE_IN_CHAPTER; m2++) { |
| 600 | if (misra_04_warn_flag[m1][m2] != -1) misra_04_warn_flag[m1][m2] = 1; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | if(c_flags[38]&USEDFLAG) {coloring=c_flags_val[38].l;} |
| 606 | if(c_flags[39]&USEDFLAG) {dmalloc=1;} |
| 607 | if(c_flags[40]&USEDFLAG) {disable=c_flags_val[40].l;} |
| 608 | if(c_flags[41]&USEDFLAG) {softfloat=1;} |
| 609 | if(c_flags[45]&USEDFLAG) {ecpp=1;} |
| 610 | if(c_flags[46]&USEDFLAG) {short_push=1;} |
| 611 | if(c_flags[47]&USEDFLAG) {default_unsigned=1;} |
| 612 | if(c_flags[48]&USEDFLAG) {opencl=1;} |
| 613 | { |
| 614 | size_t hs=1000; |
| 615 | if(c_flags[53]&USEDFLAG) hs=c_flags_val[53].l; |
| 616 | if(hs!=0) hash_ext=new_hashtable(hs); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | if(wpo){ |
| 621 | cross_module=1; |
| 622 | optflags=-1; |
| 623 | } |
| 624 | if(optsize){ |
| 625 | if(!(c_flags[25]&USEDFLAG)) unroll_size=0; |
| 626 | clist_copy_pointer=clist_copy_stack; |
| 627 | } |
| 628 | |
| 629 | if(optspeed){ |
| 630 | clist_copy_pointer=256; |
| 631 | } |
| 632 | |
| 633 | if(ecpp&&c99){ |
| 634 | error(333, "c99", "ecpp"); |
| 635 | } |
| 636 | if(c99){ |
| 637 | ucpp_flags|=CPLUSPLUS_COMMENTS|MACRO_VAARG; |
| 638 | err_out[67].flags|=ANSIV; |
| 639 | err_out[67].flags&=~DONTWARN; |
| 640 | err_out[161].flags|=ANSIV; |
| 641 | err_out[161].flags&=~DONTWARN; |
| 642 | err_out[155].flags|=ANSIV; |
| 643 | err_out[155].flags&=~DONTWARN; |
| 644 | err_out[156].flags|=ANSIV; |
| 645 | err_out[156].flags&=~DONTWARN; |
| 646 | } |
| 647 | if(ecpp){ |
| 648 | #ifndef HAVE_ECPP |
| 649 | error(334, "EC++"); |
| 650 | #endif |
| 651 | ucpp_flags|=CPLUSPLUS_COMMENTS|MACRO_VAARG; |
| 652 | } |
| 653 | if(!cross_module&&files>1) error(1); |
| 654 | if(files<=0&&!(c_flags[35]&USEDFLAG)) error(6); |
| 655 | stackalign=l2zm(0L); |
| 656 | if(!init_cg()) exit(EXIT_FAILURE); |
| 657 | |
| 658 | if(c_flags[55]&USEDFLAG) {clist_copy_stack=c_flags_val[55].l;} |
| 659 | if(c_flags[56]&USEDFLAG) {clist_copy_static=c_flags_val[56].l;} |
| 660 | if(c_flags[57]&USEDFLAG) {clist_copy_pointer=c_flags_val[57].l;} |
| 661 | if(c_flags[58]&USEDFLAG) {inline_memcpy_sz=c_flags_val[58].l;} |
| 662 | if(c_flags[61]&USEDFLAG) {force_statics=1;} |
| 663 | if(c_flags[62]&USEDFLAG) {prefer_statics=1;} |
| 664 | if(c_flags[63]&USEDFLAG) {range_opt=1;} |
| 665 | if(c_flags[64]&USEDFLAG) {merge_strings=1;} |
| 666 | if(c_flags[65]&USEDFLAG) {sec_per_obj=1;} |
| 667 | if(c_flags[66]&USEDFLAG) {no_eff_ics=1;} |
| 668 | if(c_flags[67]&USEDFLAG) {early_eff_ics=1;} |
| 669 | if(c_flags[68]&USEDFLAG) {mask_opt=1;} |
| 670 | |
| 671 | |
| 672 | if(!(optflags&2)){ |
| 673 | for(i=1;i<=MAXR;i++){ |
| 674 | sregsa[i]=regsa[i]; |
| 675 | if(regsa[i]==REGSA_TEMPS) regsa[i]=0; |
| 676 | } |
| 677 | } |
| 678 | if(zmeqto(stackalign,l2zm(0L))) |
| 679 | stackalign=maxalign; |
| 680 | for(i=0;i<=MAX_TYPE;i++) |
| 681 | if(zmeqto(align[i],l2zm(0L))) |
| 682 | align[i]=l2zm(1L); |
| 683 | for(i=0;i<EMIT_BUF_DEPTH;i++) |
| 684 | emit_buffer[i]=mymalloc(EMIT_BUF_LEN); |
| 685 | emit_p=emit_buffer[0]; |
| 686 | /*FIXME: multiple-ccs don't work */ |
| 687 | if(c_flags[24]&USEDFLAG) multiple_ccs=0; |
| 688 | if(!(c_flags[5]&USEDFLAG)){ |
| 689 | if(c_flags[1]&USEDFLAG){ |
| 690 | out=open_out(c_flags_val[1].p,0); |
| 691 | }else{ |
| 692 | if(wpo) |
| 693 | out=open_out(inname,"o"); |
| 694 | else |
| 695 | out=open_out(inname,"asm"); |
| 696 | } |
| 697 | if(!out){ |
| 698 | exit(EXIT_FAILURE); |
| 699 | } |
| 700 | } |
| 701 | if(wpo){ |
| 702 | wpo_key=MAGIC_WPO; |
| 703 | fprintf(out,"%cVBCC",0); |
| 704 | } |
| 705 | if(debug_info) init_db(out); |
| 706 | if(c_flags[2]&USEDFLAG) ic1=open_out(inname,"ic1"); |
| 707 | if(c_flags[3]&USEDFLAG) ic2=open_out(inname,"ic2"); |
| 708 | c99_compliant=0; |
| 709 | init_cpp(); |
| 710 | if(c_flags[35]&USEDFLAG){ |
| 711 | /* we have a command file */ |
| 712 | cmdfile=fopen(c_flags_val[35].p,"r"); |
| 713 | if(!cmdfile) error(7,c_flags_val[35].p); |
| 714 | } |
| 715 | for(i=1;cmdfile||i<argc;i++){ |
| 716 | FILE *in; |
| 717 | int first_byte; |
| 718 | if(i<argc){ |
| 719 | if(!fname[i]) continue; |
| 720 | inname=argv[i]; |
| 721 | }else{ |
| 722 | static char nbuf[1024]; |
| 723 | if(!fgets(nbuf,1023,cmdfile)) break; |
| 724 | inname=nbuf; |
| 725 | while(isspace((unsigned char)*inname)) inname++; |
| 726 | if(*inname=='\"') inname++; |
| 727 | if(inname[strlen(inname)-1]=='\n') inname[strlen(inname)-1]=0; |
| 728 | if(inname[strlen(inname)-1]=='\"') inname[strlen(inname)-1]=0; |
| 729 | if(!*inname) break; |
| 730 | } |
| 731 | if(DEBUG&1) printf("starting translation-unit <%s>\n",inname); |
| 732 | in=fopen(inname,"r"); |
| 733 | if(!in) {error(7,inname);} |
| 734 | misratok=0; |
| 735 | first_byte=fgetc(in); |
| 736 | if(first_byte==0){ |
| 737 | input_wpo=in; |
| 738 | if(fgetc(in)!='V') error(300); |
| 739 | if(fgetc(in)!='B') error(300); |
| 740 | if(fgetc(in)!='C') error(300); |
| 741 | if(fgetc(in)!='C') error(300); |
| 742 | wpo_key=MAGIC_WPO; |
| 743 | }else{ |
| 744 | ungetc(first_byte,in); |
| 745 | input_wpo=0; |
| 746 | } |
| 747 | if(c_flags[50]&USEDFLAG){ |
| 748 | char *p; |
| 749 | depout=open_out(inname,"dep"); |
| 750 | /* nicht super schoen (besser letzten Punkt statt ersten), aber kurz.. */ |
| 751 | if(c_flags[59]&USEDFLAG){ |
| 752 | fprintf(depout,"%s: %s",c_flags_val[59].p,inname); |
| 753 | }else{ |
| 754 | for(p=inname;*p&&*p!='.';p++) fprintf(depout,"%c",*p); |
| 755 | fprintf(depout,".o: %s",inname); |
| 756 | } |
| 757 | } |
| 758 | if(c_flags[18]&USEDFLAG) ppout=open_out(inname,"i"); |
| 759 | if(!input_wpo){ |
| 760 | int mcmerk=misracheck; |
| 761 | misracheck=0; |
| 762 | init_tables(0); |
| 763 | init_include_path(0); |
| 764 | set_init_filename(inname,1); |
| 765 | init_lexer_state(&ls); |
| 766 | init_lexer_mode(&ls); |
| 767 | ls.flags=ucpp_flags; |
| 768 | ls.input=in; |
| 769 | for(j=1;j<argc;j++){ |
| 770 | if(argv[j][0]=='-'&&argv[j][1]=='I') |
| 771 | add_incpath(&argv[j][2]); |
| 772 | if(argv[j][0]=='-'&&argv[j][1]=='D') |
| 773 | define_macro(&ls,&argv[j][2]); |
| 774 | } |
| 775 | if(target_macros){ |
| 776 | char **m=target_macros; |
| 777 | while(*m) |
| 778 | define_macro(&ls,*m++); |
| 779 | } |
| 780 | define_macro(&ls,"__VBCC__"); |
| 781 | define_macro(&ls,"__entry=__vattr(\"entry\")"); |
| 782 | define_macro(&ls,"__str(x)=#x"); |
| 783 | define_macro(&ls,"__asm(x)=do{static void inline_assembly()=x;inline_assembly();}while(0)"); |
| 784 | define_macro(&ls,"__regsused(x)=__vattr(\"regused(\"x\")\")"); |
| 785 | define_macro(&ls,"__varsused(x)=__vattr(\"varused(\"x\")\")"); |
| 786 | define_macro(&ls,"__varsmodified(x)=__vattr(\"varchanged(\"x\")\")"); |
| 787 | define_macro(&ls,"__noreturn=__vattr(\"noreturn()\")"); |
| 788 | define_macro(&ls,"__alwaysreturn=__vattr(\"alwaysreturn()\")"); |
| 789 | define_macro(&ls,"__nosidefx=__vattr(\"nosidefx()\")"); |
| 790 | define_macro(&ls,"__stack(x)=__vattr(__str(stack1(x)))"); |
| 791 | define_macro(&ls,"__stack2(x)=__vattr(__str(stack2(x)))"); |
| 792 | define_macro(&ls,"__noinline=__vattr(\"noinline()\")"); |
| 793 | if(c99) |
| 794 | define_macro(&ls,"__STDC_VERSION__=199901L"); |
| 795 | if(optspeed) |
| 796 | define_macro(&ls,"__OPTSPEED__"); |
| 797 | if(optsize) |
| 798 | define_macro(&ls,"__OPTSIZE__"); |
| 799 | misracheck=mcmerk; |
| 800 | enter_file(&ls,ls.flags); |
| 801 | } |
| 802 | filename=current_filename; |
| 803 | switch_count=0;break_label=0; |
| 804 | line=0;eof=0; |
| 805 | next_token(); |
| 806 | killsp(); |
| 807 | nesting=-1;enter_block(); |
| 808 | translation_unit(); |
| 809 | fclose(in); /*FIXME: do I have to close??*/ |
| 810 | if((c_flags[18]&USEDFLAG)&&ppout) fclose(ppout); |
| 811 | if((c_flags[50]&USEDFLAG)&&depout){fprintf(depout,"\n");fclose(depout);} |
| 812 | if(!input_wpo) |
| 813 | free_lexer_state(&ls); |
| 814 | } |
| 815 | if(wpo) |
| 816 | raus(); |
| 817 | if(!cross_module){ |
| 818 | ierror(0); |
| 819 | }else{ |
| 820 | tunit *t; |
| 821 | Var *v,*sf; |
| 822 | #if HAVE_OSEK |
| 823 | /* removed */ |
| 824 | /* removed */ |
| 825 | /* removed */ |
| 826 | /* removed */ |
| 827 | /* removed */ |
| 828 | /* removed */ |
| 829 | /* removed */ |
| 830 | /* removed */ |
| 831 | /* removed */ |
| 832 | /* removed */ |
| 833 | /* removed */ |
| 834 | /* removed */ |
| 835 | /* removed */ |
| 836 | /* removed */ |
| 837 | /* removed */ |
| 838 | /* removed */ |
| 839 | /* removed */ |
| 840 | /* removed */ |
| 841 | /* removed */ |
| 842 | /* removed */ |
| 843 | /* removed */ |
| 844 | /* removed */ |
| 845 | /* removed */ |
| 846 | /* removed */ |
| 847 | /* removed */ |
| 848 | /* removed */ |
| 849 | /* removed */ |
| 850 | /* removed */ |
| 851 | /* removed */ |
| 852 | /* removed */ |
| 853 | /* removed */ |
| 854 | /* removed */ |
| 855 | /* removed */ |
| 856 | /* removed */ |
| 857 | /* removed */ |
| 858 | /* removed */ |
| 859 | /* removed */ |
| 860 | /* removed */ |
| 861 | /* removed */ |
| 862 | /* removed */ |
| 863 | /* removed */ |
| 864 | /* removed */ |
| 865 | /* removed */ |
| 866 | /* removed */ |
| 867 | /* removed */ |
| 868 | /* removed */ |
| 869 | /* removed */ |
| 870 | /* removed */ |
| 871 | /* removed */ |
| 872 | /* removed */ |
| 873 | /* removed */ |
| 874 | /* removed */ |
| 875 | /* removed */ |
| 876 | /* removed */ |
| 877 | /* removed */ |
| 878 | /* removed */ |
| 879 | /* removed */ |
| 880 | /* removed */ |
| 881 | /* removed */ |
| 882 | /* removed */ |
| 883 | /* removed */ |
| 884 | /* removed */ |
| 885 | /* removed */ |
| 886 | /* removed */ |
| 887 | /* removed */ |
| 888 | /* removed */ |
| 889 | /* removed */ |
| 890 | /* removed */ |
| 891 | /* removed */ |
| 892 | /* removed */ |
| 893 | /* removed */ |
| 894 | /* removed */ |
| 895 | /* removed */ |
| 896 | /* removed */ |
| 897 | /* removed */ |
| 898 | /* removed */ |
| 899 | /* removed */ |
| 900 | /* removed */ |
| 901 | /* removed */ |
| 902 | /* removed */ |
| 903 | /* removed */ |
| 904 | /* removed */ |
| 905 | /* removed */ |
| 906 | /* removed */ |
| 907 | /* removed */ |
| 908 | /* removed */ |
| 909 | /* removed */ |
| 910 | /* removed */ |
| 911 | /* removed */ |
| 912 | /* removed */ |
| 913 | /* removed */ |
| 914 | /* removed */ |
| 915 | /* removed */ |
| 916 | /* removed */ |
| 917 | /* removed */ |
| 918 | /* removed */ |
| 919 | /* removed */ |
| 920 | /* removed */ |
| 921 | /* removed */ |
| 922 | /* removed */ |
| 923 | /* removed */ |
| 924 | /* removed */ |
| 925 | /* removed */ |
| 926 | /* removed */ |
| 927 | /* removed */ |
| 928 | #endif |
| 929 | if(DEBUG&1) printf("first optimizing\n"); |
| 930 | for(v=first_ext;v;v=v->next){ |
| 931 | if(ISFUNC(v->vtyp->flags)&&(v->flags&DEFINED)&&(!v->vattr||!strstr(v->vattr,"taskprio("))){ |
| 932 | do_function(v); |
| 933 | } |
| 934 | } |
| 935 | for(t=first_tunit;t;t=t->next){ |
| 936 | for(v=t->statics;v;v=v->next){ |
| 937 | if(ISFUNC(v->vtyp->flags)&&(v->flags&DEFINED)){ |
| 938 | do_function(v); |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | if(DEBUG&1) printf("determining used objects\n"); |
| 943 | for(v=first_ext;v;v=v->next){ |
| 944 | if((v->flags&(DEFINED|TENTATIVE))&&(v->flags&(INLINEFUNC|INLINEEXT))!=INLINEFUNC){ |
| 945 | if(!final||!strcmp(v->identifier,"main")||(v->vattr&&strstr(v->vattr,"entry"))){ |
| 946 | #ifndef NO_OPTIMIZER |
| 947 | used_objects(v); |
| 948 | #endif |
| 949 | if(ISFUNC(v->vtyp->flags)) do_function(v); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | if(!(c_flags[5]&USEDFLAG)){ |
| 954 | if(DEBUG&1) printf("generating external functions:\n"); |
| 955 | for(v=first_ext;v;v=v->next){ |
| 956 | if(ISFUNC(v->vtyp->flags)&&(v->flags&(REFERENCED|DEFINED))==(REFERENCED|DEFINED)){ |
| 957 | gen_function(out,v,1); |
| 958 | } |
| 959 | } |
| 960 | if(DEBUG&1024) printf("generating static functions\n"); |
| 961 | i=0; |
| 962 | for(t=first_tunit;t;t=t->next){ |
| 963 | if(DEBUG&1) printf("translation-unit %d:\n",++i); |
| 964 | if(DEBUG&1) printf("generating statics:\n"); |
| 965 | for(v=t->statics;v;v=v->next){ |
| 966 | if(DEBUG&1) printf(" %s\n",v->identifier); |
| 967 | if(ISFUNC(v->vtyp->flags)&&(v->flags&(REFERENCED|DEFINED))==(REFERENCED|DEFINED)){ |
| 968 | gen_function(out,v,1); |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | if(DEBUG&1) printf("generating vars:\n"); |
| 974 | gen_vars(first_ext); |
| 975 | for(t=first_tunit;t;t=t->next) |
| 976 | gen_vars(t->statics); |
| 977 | for(v=first_ext;v;v=v->next){ |
| 978 | if(ISFUNC(v->vtyp->flags)&&(v->flags&DEFINED)) |
| 979 | gen_vars(v->fi->vars); |
| 980 | } |
| 981 | for(t=first_tunit;t;t=t->next){ |
| 982 | for(v=t->statics;v;v=v->next){ |
| 983 | if(ISFUNC(v->vtyp->flags)&&(v->flags&DEFINED)) |
| 984 | gen_vars(v->fi->vars); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | raus(); |
| 990 | } |
| 991 | int mcmp(const char *s1,const char *s2) |
| 992 | /* Einfachere strcmp-Variante. */ |
| 993 | { |
| 994 | char c; |
| 995 | do{ |
| 996 | c=*s1++; |
| 997 | if(c!=*s2++) return(1); |
| 998 | }while(c); |
| 999 | return 0; |
| 1000 | } |
| 1001 | int is_keyword(char *p) |
| 1002 | { |
| 1003 | char *n=p+1; |
| 1004 | switch(*p){ |
| 1005 | case 'a': |
| 1006 | if(!mcmp(n,"uto")) return 1; |
| 1007 | return 0; |
| 1008 | case 'b': |
| 1009 | if(ecpp&&!mcmp(n,"ool")) return 1; |
| 1010 | if(!mcmp(n,"reak")) return 1; |
| 1011 | return 0; |
| 1012 | case 'c': |
| 1013 | if(!mcmp(n,"ase")) return 1; |
| 1014 | if(ecpp&&!mcmp(n,"atch")) return 1; |
| 1015 | if(!mcmp(n,"har")) return 1; |
| 1016 | if(ecpp&&!mcmp(n,"lass")) return 1; |
| 1017 | if(!mcmp(n,"onst")) return 1; |
| 1018 | if(ecpp&&!mcmp(n,"ons_cast")) return 1; |
| 1019 | if(!mcmp(n,"ontinue")) return 1; |
| 1020 | return 0; |
| 1021 | case 'd': |
| 1022 | if(!mcmp(n,"efault")) return 1; |
| 1023 | if(ecpp&&!mcmp(n,"elete")) return 1; |
| 1024 | if(!mcmp(n,"o")) return 1; |
| 1025 | if(!mcmp(n,"ouble")) return 1; |
| 1026 | if(ecpp&&!mcmp(n,"ynamic_cast")) return 1; |
| 1027 | return 0; |
| 1028 | case 'e': |
| 1029 | if(!mcmp(n,"lse")) return 1; |
| 1030 | if(!mcmp(n,"num")) return 1; |
| 1031 | if(ecpp&&!mcmp(n,"xplicit")) return 1; |
| 1032 | if(ecpp&&!mcmp(n,"xport")) return 1; |
| 1033 | if(!mcmp(n,"xtern")) return 1; |
| 1034 | return 0; |
| 1035 | case 'f': |
| 1036 | if(ecpp&&!mcmp(n,"alse")) return 1; |
| 1037 | if(!mcmp(n,"loat")) return 1; |
| 1038 | if(!mcmp(n,"or")) return 1; |
| 1039 | if(ecpp&&!mcmp(n,"riend")) return 1; |
| 1040 | return 0; |
| 1041 | case 'g': |
| 1042 | if(!mcmp(n,"oto")) return 1; |
| 1043 | return 0; |
| 1044 | case 'i': |
| 1045 | if(!mcmp(n,"f")) return 1; |
| 1046 | if(c99&&!mcmp(n,"nline")) return 1; |
| 1047 | if(!mcmp(n,"nt")) return 1; |
| 1048 | return 0; |
| 1049 | case 'l': |
| 1050 | if(!mcmp(n,"ong")) return 1; |
| 1051 | return 0; |
| 1052 | case 'm': |
| 1053 | if(ecpp&&!mcmp(n,"utable")) return 1; |
| 1054 | return 0; |
| 1055 | case 'n': |
| 1056 | if(ecpp&&!mcmp(n,"amespace")) return 1; |
| 1057 | if(ecpp&&!mcmp(n,"ew")) return 1; |
| 1058 | return 0; |
| 1059 | case 'o': |
| 1060 | if(ecpp&&!mcmp(n,"perator")) return 1; |
| 1061 | return 0; |
| 1062 | case 'p': |
| 1063 | if(ecpp&&!mcmp(n,"rivate")) return 1; |
| 1064 | if(ecpp&&!mcmp(n,"rotected")) return 1; |
| 1065 | if(ecpp&&!mcmp(n,"ublic")) return 1; |
| 1066 | return 0; |
| 1067 | case 'r': |
| 1068 | if(!mcmp(n,"egister")) return 1; |
| 1069 | if(ecpp&&!mcmp(n,"einterpret_cast")) return 1; |
| 1070 | if(c99&&!mcmp(n,"estrict")) return 1; |
| 1071 | if(!mcmp(n,"eturn")) return 1; |
| 1072 | return 0; |
| 1073 | case 's': |
| 1074 | if(!mcmp(n,"hort")) return 1; |
| 1075 | if(!mcmp(n,"igned")) return 1; |
| 1076 | if(!mcmp(n,"izeof")) return 1; |
| 1077 | if(!mcmp(n,"tatic")) return 1; |
| 1078 | if(ecpp&&!mcmp(n,"tatic_cast")) return 1; |
| 1079 | if(!mcmp(n,"truct")) return 1; |
| 1080 | if(!mcmp(n,"witch")) return 1; |
| 1081 | return 0; |
| 1082 | case 't': |
| 1083 | if(ecpp&&!mcmp(n,"emplate")) return 1; |
| 1084 | /* if(ecpp&&!mcmp(n,"his")) return 1;*/ |
| 1085 | if(ecpp&&!mcmp(n,"hrow")) return 1; |
| 1086 | if(ecpp&&!mcmp(n,"rue")) return 1; |
| 1087 | if(ecpp&&!mcmp(n,"ry")) return 1; |
| 1088 | if(!mcmp(n,"ypedef")) return 1; |
| 1089 | if(ecpp&&!mcmp(n,"ypeid")) return 1; |
| 1090 | if(ecpp&&!mcmp(n,"ypename")) return 1; |
| 1091 | return 0; |
| 1092 | case 'u': |
| 1093 | if(!mcmp(n,"nion")) return 1; |
| 1094 | if(!mcmp(n,"nsigned")) return 1; |
| 1095 | if(ecpp&&!mcmp(n,"sing")) return 1; |
| 1096 | return 0; |
| 1097 | case 'v': |
| 1098 | if(ecpp&&!mcmp(n,"irtual")) return 1; |
| 1099 | if(!mcmp(n,"oid")) return 1; |
| 1100 | if(!mcmp(n,"olatile")) return 1; |
| 1101 | return 0; |
| 1102 | case 'w': |
| 1103 | if(ecpp&&!mcmp(n,"char_t")) return 1; |
| 1104 | if(!mcmp(n,"hile")) return 1; |
| 1105 | return 0; |
| 1106 | case '_': |
| 1107 | if(c99&&!mcmp(n,"Bool")) return 1; |
| 1108 | if(c99&&!mcmp(n,"Complex")) return 1; |
| 1109 | if(c99&&!mcmp(n,"Imaginary")) return 1; |
| 1110 | default: |
| 1111 | return 0; |
| 1112 | } |
| 1113 | } |
| 1114 | void cpbez(char *m,int check_keyword) |
| 1115 | /* Kopiert den naechsten Bezeichner von s nach m. Wenn check_keyord!=0 */ |
| 1116 | /* wird eine Fehlermeldung ausgegeben, falls das Ergebnis ein */ |
| 1117 | /* reserviertes Keyword von C ist. */ |
| 1118 | { |
| 1119 | if(ctok->type!=NAME){ |
| 1120 | *m=0; |
| 1121 | return; |
| 1122 | } |
| 1123 | if(strlen(ctok->name)>=MAXI){ |
| 1124 | error(206,MAXI-1); |
| 1125 | strncpy(m,ctok->name,MAXI-1); |
| 1126 | m[MAXI-1]=0; |
| 1127 | }else{ |
| 1128 | strcpy(m,ctok->name); |
| 1129 | } |
| 1130 | if(check_keyword&&is_keyword(m)) |
| 1131 | error(216,m); |
| 1132 | } |
| 1133 | void cpnum(char *m) |
| 1134 | /* kopiert die naechste int-Zahl von s nach m */ |
| 1135 | /* muss noch erheblich erweiter werden */ |
| 1136 | { |
| 1137 | if(ctok->type!=NUMBER){ |
| 1138 | *m=0; |
| 1139 | return; |
| 1140 | } |
| 1141 | strcpy(m,ctok->name); |
| 1142 | } |
| 1143 | void copy_token(token *d,token *s) |
| 1144 | { |
| 1145 | size_t l; |
| 1146 | *d=*s; |
| 1147 | if(S_TOKEN(s->type)){ |
| 1148 | l=strlen(s->name)+1; |
| 1149 | d->name=mymalloc(l); |
| 1150 | memcpy(d->name,s->name,l); |
| 1151 | }else |
| 1152 | d->name=0; |
| 1153 | } |
| 1154 | static token back_token; |
| 1155 | static int have_back_token; |
| 1156 | void push_token(token *t) |
| 1157 | { |
| 1158 | static char back_name[MAXI+1]; |
| 1159 | if(have_back_token) ierror(0); |
| 1160 | back_token=*t; |
| 1161 | if(S_TOKEN(t->type)){ |
| 1162 | strcpy(back_name,t->name); |
| 1163 | back_token.name=back_name; |
| 1164 | }else |
| 1165 | back_token.name=0; |
| 1166 | have_back_token=1; |
| 1167 | ctok=&back_token; |
| 1168 | } |
| 1169 | void next_token(void) |
| 1170 | { |
| 1171 | if(eof){ |
| 1172 | if(!endok) |
| 1173 | raus(); |
| 1174 | else |
| 1175 | return; |
| 1176 | } |
| 1177 | if(input_wpo){ |
| 1178 | int c; |
| 1179 | static token wpo_tok; |
| 1180 | static size_t sz; |
| 1181 | char *p;size_t cs; |
| 1182 | |
| 1183 | if(have_back_token){ |
| 1184 | have_back_token=0; |
| 1185 | ctok=&wpo_tok; |
| 1186 | return; |
| 1187 | } |
| 1188 | ctok=&wpo_tok; |
| 1189 | c=fgetc(input_wpo); |
| 1190 | if(c==EOF){ |
| 1191 | eof=1; |
| 1192 | return; |
| 1193 | }else |
| 1194 | c^=wpo_key++; |
| 1195 | wpo_tok.type=(unsigned char)c; |
| 1196 | /*printf("wpoget: %d (%s)\n",ctok->type,operators_name[ctok->type]);*/ |
| 1197 | if(S_TOKEN(wpo_tok.type)){ |
| 1198 | p=wpo_tok.name; |
| 1199 | cs=0; |
| 1200 | do{ |
| 1201 | if(cs>=sz){ |
| 1202 | sz+=1000; |
| 1203 | wpo_tok.name=myrealloc(wpo_tok.name,sz); |
| 1204 | p=wpo_tok.name+cs; |
| 1205 | } |
| 1206 | c=fgetc(input_wpo); |
| 1207 | if(c!=EOF){ |
| 1208 | c^=wpo_key++; |
| 1209 | *p++=c; |
| 1210 | cs++; |
| 1211 | }else |
| 1212 | eof=1; |
| 1213 | }while(((unsigned char)c)!=0&&c!=EOF); |
| 1214 | *p=0; |
| 1215 | /*printf("name=%s\n",ctok->name);*/ |
| 1216 | } |
| 1217 | return; |
| 1218 | } |
| 1219 | if(have_back_token){ |
| 1220 | have_back_token=0; |
| 1221 | if(S_TOKEN(ctok->type)&&!ctok->name) |
| 1222 | ierror(0); |
| 1223 | }else{ |
| 1224 | static int last_line=1,last_token=NONE; |
| 1225 | static char *last_fname;static size_t last_size; |
| 1226 | eof=lex(&ls); |
| 1227 | if(ctok&&S_TOKEN(ls.ctok->type)&&!ls.ctok->name) |
| 1228 | ierror(0); |
| 1229 | if(wpo){ |
| 1230 | fprintf(out,"%c",ls.ctok->type^wpo_key++); |
| 1231 | if(S_TOKEN(ls.ctok->type)){ |
| 1232 | char *p=ls.ctok->name; |
| 1233 | while(*p){ |
| 1234 | fprintf(out,"%c",*p^wpo_key++); |
| 1235 | p++; |
| 1236 | } |
| 1237 | fprintf(out,"%c",0^wpo_key++); |
| 1238 | } |
| 1239 | } |
| 1240 | if((c_flags[18]&USEDFLAG)&&ppout&&!input_wpo){ |
| 1241 | if(!last_fname){ |
| 1242 | last_fname=mymalloc(1); |
| 1243 | *last_fname=0; |
| 1244 | } |
| 1245 | if(strcmp(last_fname,current_filename)){ |
| 1246 | fprintf(ppout,"\n#line %d \"%s\"\n",(int)ls.ctok->line,current_filename); |
| 1247 | last_line=ls.ctok->line; |
| 1248 | if(strlen(current_filename)>=last_size) |
| 1249 | last_fname=myrealloc(last_fname,strlen(current_filename)+1); |
| 1250 | strcpy(last_fname,current_filename); |
| 1251 | }else{ |
| 1252 | for(;last_line<ls.ctok->line;last_line++) |
| 1253 | fprintf(ppout,"\n"); |
| 1254 | } |
| 1255 | if(S_TOKEN(ls.ctok->type)){ |
| 1256 | if(ls.ctok->type==PRAGMA) |
| 1257 | fprintf(ppout,"#pragma"); |
| 1258 | fprintf(ppout," %s",ls.ctok->name); |
| 1259 | }else |
| 1260 | fprintf(ppout," %s",operators_name[ls.ctok->type]); |
| 1261 | last_token=ls.ctok->type; |
| 1262 | } |
| 1263 | } |
| 1264 | ctok=ls.ctok; |
| 1265 | line=ctok->line; |
| 1266 | if(misracheck&&ctok->type!=PRAGMA&&ctok->type!=NONE&&ctok->type!=NEWLINE&&ctok->type!=COMMENT) |
| 1267 | misratok=1; |
| 1268 | /*FIXME: do not store multiple */ |
| 1269 | if(filename!=current_filename&&strcmp(filename,current_filename)){ |
| 1270 | filename=mymalloc(strlen(current_filename)+1); |
| 1271 | strcpy(filename,current_filename); |
| 1272 | } |
| 1273 | /*filename=current_filename;*/ |
| 1274 | if(DEBUG&2) printf("current token (type %d): %s\n",(int)ctok->type,ucpp_token_name(ctok)); |
| 1275 | } |
| 1276 | char *pragma_cpbez(char *buff,char *s); |
| 1277 | /* calculate fi entries (regs_modifed,uses,changes,flags etc.) from |
| 1278 | attributes */ |
| 1279 | void fi_from_attr(Var *v) |
| 1280 | { |
| 1281 | char *attr; |
| 1282 | attr=v->vattr; |
| 1283 | if(!attr) return; |
| 1284 | while(attr=strstr(attr,"readmem(")){ |
| 1285 | int f; |
| 1286 | attr+=8; |
| 1287 | if(sscanf(attr,"%d",&f)!=1) ierror(0); |
| 1288 | if(!v->fi) v->fi=new_fi(); |
| 1289 | v->fi->flags|=ALL_USES; |
| 1290 | v->fi->use_cnt++; |
| 1291 | v->fi->use_list=myrealloc(v->fi->use_list,v->fi->use_cnt*sizeof(varlist)); |
| 1292 | v->fi->use_list[v->fi->use_cnt-1].v=0; |
| 1293 | v->fi->use_list[v->fi->use_cnt-1].flags=f; |
| 1294 | } |
| 1295 | attr=v->vattr; |
| 1296 | while(attr=strstr(attr,"writemem(")){ |
| 1297 | int f; |
| 1298 | attr+=9; |
| 1299 | if(sscanf(attr,"%d",&f)!=1) ierror(0); |
| 1300 | if(!v->fi) v->fi=new_fi(); |
| 1301 | v->fi->flags|=ALL_MODS; |
| 1302 | v->fi->change_cnt++; |
| 1303 | v->fi->change_list=myrealloc(v->fi->change_list,v->fi->change_cnt*sizeof(varlist)); |
| 1304 | v->fi->change_list[v->fi->change_cnt-1].v=0; |
| 1305 | v->fi->change_list[v->fi->change_cnt-1].flags=f; |
| 1306 | } |
| 1307 | attr=v->vattr; |
| 1308 | while(attr=strstr(attr,"varused(")){ |
| 1309 | Var *n; |
| 1310 | attr+=8; |
| 1311 | if(!v->fi) v->fi=new_fi(); |
| 1312 | v->fi->flags|=ALL_USES; |
| 1313 | while(1){ |
| 1314 | while(isspace((unsigned char)*attr)) attr++; |
| 1315 | if(*attr==')') break; |
| 1316 | attr=pragma_cpbez(buff,attr); |
| 1317 | if(buff[0]==0){ |
| 1318 | error(76); |
| 1319 | break; |
| 1320 | } |
| 1321 | n=find_ext_var(buff); |
| 1322 | if(!n){ |
| 1323 | error(82,buff); |
| 1324 | break; |
| 1325 | } |
| 1326 | v->fi->use_cnt++; |
| 1327 | v->fi->use_list=myrealloc(v->fi->use_list,v->fi->use_cnt*sizeof(varlist)); |
| 1328 | v->fi->use_list[v->fi->use_cnt-1].v=n; |
| 1329 | v->fi->use_list[v->fi->use_cnt-1].flags=n->vtyp->flags; |
| 1330 | while(isspace((unsigned char)*attr)) attr++; |
| 1331 | if(*attr==','||*attr=='/') attr++; |
| 1332 | } |
| 1333 | } |
| 1334 | attr=v->vattr; |
| 1335 | while(attr=strstr(attr,"varchanged(")){ |
| 1336 | Var *n; |
| 1337 | attr+=11; |
| 1338 | if(!v->fi) v->fi=new_fi(); |
| 1339 | v->fi->flags|=ALL_MODS; |
| 1340 | while(1){ |
| 1341 | while(isspace((unsigned char)*attr)) attr++; |
| 1342 | if(*attr==')') break; |
| 1343 | attr=pragma_cpbez(buff,attr); |
| 1344 | if(buff[0]==0){ |
| 1345 | error(76); |
| 1346 | break; |
| 1347 | } |
| 1348 | n=find_ext_var(buff); |
| 1349 | if(!n){ |
| 1350 | error(82,buff); |
| 1351 | break; |
| 1352 | } |
| 1353 | v->fi->change_cnt++; |
| 1354 | v->fi->change_list=myrealloc(v->fi->change_list,v->fi->change_cnt*sizeof(varlist)); |
| 1355 | v->fi->change_list[v->fi->change_cnt-1].v=n; |
| 1356 | v->fi->change_list[v->fi->change_cnt-1].flags=n->vtyp->flags; |
| 1357 | while(isspace((unsigned char)*attr)) attr++; |
| 1358 | if(*attr==','||*attr=='/') attr++; |
| 1359 | } |
| 1360 | } |
| 1361 | attr=v->vattr; |
| 1362 | while(attr=strstr(attr,"regused(")){ |
| 1363 | int r,i; |
| 1364 | static char rname[MAXI]; |
| 1365 | attr+=8; |
| 1366 | if(!v->fi) v->fi=new_fi(); |
| 1367 | v->fi->flags|=ALL_REGS; |
| 1368 | while(1){ |
| 1369 | while(isspace((unsigned char)*attr)) attr++; |
| 1370 | for(i=0;i<MAXI-1&&*attr&&!isspace((unsigned char)*attr)&&*attr!=','&&*attr!=')'&&*attr!='/';i++) |
| 1371 | rname[i]=*attr++; |
| 1372 | rname[i]=0; |
| 1373 | for(r=1;r<=MAXR;r++){ |
| 1374 | if(!reg_pair(r,&rp)&&!strcmp(rname,regnames[r])){ |
| 1375 | BSET(v->fi->regs_modified,r); |
| 1376 | while(isspace((unsigned char)*attr)) attr++; |
| 1377 | if(*attr==','||*attr=='/') attr++; |
| 1378 | break; |
| 1379 | } |
| 1380 | } |
| 1381 | if(r>MAXR){ |
| 1382 | if(rname[0]) error(220,rname); |
| 1383 | break; |
| 1384 | } |
| 1385 | } |
| 1386 | } |
| 1387 | attr=v->vattr; |
| 1388 | while(attr=strstr(attr,"stack1(")){ |
| 1389 | unsigned long sz; |
| 1390 | if(!v->fi) v->fi=new_fi(); |
| 1391 | v->fi->flags|=ALL_STACK; |
| 1392 | attr+=7; |
| 1393 | if(sscanf(attr,"%lu",&sz)!=1) ierror(0); /*FIXME*/ |
| 1394 | v->fi->stack1=ul2zum(sz); |
| 1395 | } |
| 1396 | attr=v->vattr; |
| 1397 | while(attr=strstr(attr,"stack2(")){ |
| 1398 | unsigned long sz; |
| 1399 | if(!v->fi) v->fi=new_fi(); |
| 1400 | v->fi->flags|=ALL_STACK; |
| 1401 | attr+=7; |
| 1402 | if(sscanf(attr,"%lu",&sz)!=1) ierror(0); /*FIXME*/ |
| 1403 | v->fi->stack2=ul2zum(sz); |
| 1404 | } |
| 1405 | if(strstr(v->vattr,"noreturn()")){ |
| 1406 | if(!v->fi) v->fi=new_fi(); |
| 1407 | v->fi->flags|=NEVER_RETURNS; |
| 1408 | } |
| 1409 | if(strstr(v->vattr,"alwaysreturn()")){ |
| 1410 | if(!v->fi) v->fi=new_fi(); |
| 1411 | v->fi->flags|=ALWAYS_RETURNS; |
| 1412 | } |
| 1413 | if(strstr(v->vattr,"nosidefx()")){ |
| 1414 | if(!v->fi) v->fi=new_fi(); |
| 1415 | v->fi->flags|=NOSIDEFX; |
| 1416 | } |
| 1417 | if(strstr(v->vattr,"noinline()")){ |
| 1418 | if(!v->fi) v->fi=new_fi(); |
| 1419 | v->fi->flags|=NO_INLINE; |
| 1420 | } |
| 1421 | } |
| 1422 | #define pragma_killsp() while(isspace((unsigned char)*s)) s++; |
| 1423 | char *pragma_cpbez(char *buff,char *s) |
| 1424 | { |
| 1425 | int cnt=0; |
| 1426 | if(*s=='_'||isalpha((unsigned char)*s)){ |
| 1427 | *buff++=*s++; |
| 1428 | cnt++; |
| 1429 | while(cnt<MAXI-1&&(*s=='_'||isalnum((unsigned char)*s))){ |
| 1430 | *buff++=*s++; |
| 1431 | cnt++; |
| 1432 | } |
| 1433 | } |
| 1434 | *buff++=0; |
| 1435 | return s; |
| 1436 | } |
| 1437 | #define WARNSTACKSIZE 128 |
| 1438 | static int widx,warn_num[WARNSTACKSIZE],warn_flags[WARNSTACKSIZE]; |
| 1439 | #define PACKSTACKSIZE 128 |
| 1440 | static int pidx,pack[PACKSTACKSIZE]; |
| 1441 | void do_pragma(char *s) |
| 1442 | { |
| 1443 | error(163); |
| 1444 | pragma_killsp(); |
| 1445 | if(!strncmp("opt",s,3)){ |
| 1446 | s+=3;pragma_killsp(); |
| 1447 | c_flags_val[0].l=optflags=atol(s); |
| 1448 | if(DEBUG&1) printf("#pragma opt %ld\n",c_flags_val[0].l); |
| 1449 | }else if(!strncmp("dontwarn",s,8)){ |
| 1450 | int i; |
| 1451 | s+=8;pragma_killsp(); |
| 1452 | if(widx>=WARNSTACKSIZE) ierror(0); |
| 1453 | if(sscanf(s,"%d",&i)==1){ |
| 1454 | if(i>=err_num) error(159,i); |
| 1455 | warn_num[widx]=i; |
| 1456 | warn_flags[widx]=err_out[i].flags; |
| 1457 | widx++; |
| 1458 | err_out[i].flags|=DONTWARN; |
| 1459 | } |
| 1460 | }else if(!strncmp("warn",s,4)){ |
| 1461 | int i; |
| 1462 | s+=4;pragma_killsp(); |
| 1463 | if(widx>=WARNSTACKSIZE) ierror(0); |
| 1464 | if(sscanf(s,"%d",&i)==1){ |
| 1465 | if(i>=err_num) error(159,i); |
| 1466 | warn_num[widx]=i; |
| 1467 | warn_flags[widx]=err_out[i].flags; |
| 1468 | widx++; |
| 1469 | err_out[i].flags&=~DONTWARN; |
| 1470 | } |
| 1471 | }else if(!strncmp("popwarn",s,7)){ |
| 1472 | if(widx<=0) error(303); |
| 1473 | widx--; |
| 1474 | err_out[warn_num[widx]].flags=warn_flags[widx]; |
| 1475 | }else if(!strncmp("begin_header",s,12)){ |
| 1476 | header_cnt++; |
| 1477 | }else if(!strncmp("end_header",s,10)){ |
| 1478 | header_cnt--; |
| 1479 | }else if(!strncmp("pfi",s,3)){ |
| 1480 | Var *v; |
| 1481 | s+=3;pragma_killsp(); |
| 1482 | pragma_cpbez(buff,s); |
| 1483 | if(DEBUG&1) printf("print function_info %s\n",buff); |
| 1484 | v=find_var(buff,0); |
| 1485 | if(v&&v->fi) print_fi(stdout,v->fi); |
| 1486 | }else if(!strncmp("finfo",s,5)){ |
| 1487 | Var *v; |
| 1488 | s+=5;pragma_killsp(); |
| 1489 | pragma_cpbez(buff,s); |
| 1490 | if(DEBUG&1) printf("new function_info %s\n",buff); |
| 1491 | v=find_var(buff,0); |
| 1492 | if(v){ |
| 1493 | if(!v->fi) v->fi=new_fi(); |
| 1494 | current_fi=v->fi; |
| 1495 | } |
| 1496 | }else if(!strncmp("fi_flags",s,8)){ |
| 1497 | unsigned long flags; |
| 1498 | s+=8;pragma_killsp(); |
| 1499 | sscanf(s,"%lu",&flags); |
| 1500 | if(DEBUG&1) printf("fi_flags %lu\n",flags); |
| 1501 | if(current_fi) current_fi->flags=flags; |
| 1502 | }else if(!strncmp("fi_uses",s,7)){ |
| 1503 | int t;Var *v; |
| 1504 | s+=7;pragma_killsp(); |
| 1505 | s=pragma_cpbez(buff,s); |
| 1506 | t=nesting;nesting=0; |
| 1507 | v=find_var(buff,0); |
| 1508 | nesting=t; |
| 1509 | sscanf(s,"%d",&t); |
| 1510 | if(DEBUG&1) printf("new fi_use %s,%d\n",buff,t); |
| 1511 | if(current_fi){ |
| 1512 | current_fi->use_cnt++; |
| 1513 | current_fi->use_list=myrealloc(current_fi->use_list,current_fi->use_cnt*sizeof(varlist)); |
| 1514 | current_fi->use_list[current_fi->use_cnt-1].v=v; |
| 1515 | current_fi->use_list[current_fi->use_cnt-1].flags=t; |
| 1516 | } |
| 1517 | }else if(!strncmp("fi_changes",s,10)){ |
| 1518 | int t;Var *v; |
| 1519 | s+=10;pragma_killsp(); |
| 1520 | s=pragma_cpbez(buff,s); |
| 1521 | t=nesting;nesting=0; |
| 1522 | v=find_var(buff,0); |
| 1523 | nesting=t; |
| 1524 | sscanf(s,"%d",&t); |
| 1525 | if(DEBUG&1) printf("new fi_change %s,%d\n",buff,t); |
| 1526 | if(current_fi){ |
| 1527 | current_fi->change_cnt++; |
| 1528 | current_fi->change_list=myrealloc(current_fi->change_list,current_fi->change_cnt*sizeof(varlist)); |
| 1529 | current_fi->change_list[current_fi->change_cnt-1].v=v; |
| 1530 | current_fi->change_list[current_fi->change_cnt-1].flags=t; |
| 1531 | } |
| 1532 | }else if(!strncmp("fi_calls",s,8)){ |
| 1533 | int t;Var *v; |
| 1534 | s+=8;pragma_killsp(); |
| 1535 | s=pragma_cpbez(buff,s); |
| 1536 | t=nesting;nesting=0; |
| 1537 | v=find_var(buff,0); |
| 1538 | nesting=t; |
| 1539 | sscanf(s,"%d",&t); |
| 1540 | if(DEBUG&1) printf("new fi_call %s,%d\n",buff,t); |
| 1541 | if(current_fi){ |
| 1542 | current_fi->call_cnt++; |
| 1543 | current_fi->call_list=myrealloc(current_fi->call_list,current_fi->call_cnt*sizeof(varlist)); |
| 1544 | current_fi->call_list[current_fi->call_cnt-1].v=v; |
| 1545 | current_fi->call_list[current_fi->call_cnt-1].flags=t; |
| 1546 | } |
| 1547 | }else if(!strncmp("fi_regs",s,7)){ |
| 1548 | int r; |
| 1549 | s+=7;pragma_killsp(); |
| 1550 | pragma_cpbez(buff,s); |
| 1551 | for(r=1;r<=MAXR;r++) |
| 1552 | if(!strcmp(buff,regnames[r])) break; |
| 1553 | if(r<=MAXR&¤t_fi) |
| 1554 | BSET(current_fi->regs_modified,r); |
| 1555 | }else if(!strncmp("printflike",s,10)){ |
| 1556 | Var *v; |
| 1557 | s+=10;pragma_killsp(); |
| 1558 | pragma_cpbez(buff,s); |
| 1559 | if(DEBUG&1) printf("printflike %s\n",buff); |
| 1560 | v=find_var(buff,0); |
| 1561 | if(v){ |
| 1562 | v->flags|=PRINTFLIKE; |
| 1563 | if(DEBUG&1) printf("succeeded\n"); |
| 1564 | } |
| 1565 | }else if(!strncmp("scanflike",s,9)){ |
| 1566 | Var *v; |
| 1567 | s+=9;pragma_killsp(); |
| 1568 | pragma_cpbez(buff,s); |
| 1569 | if(DEBUG&1) printf("scanflike %s\n",buff); |
| 1570 | v=find_var(buff,0); |
| 1571 | if(v){ |
| 1572 | v->flags|=SCANFLIKE; |
| 1573 | if(DEBUG&1) printf("succeeded\n"); |
| 1574 | } |
| 1575 | }else if(!strncmp("only-inline",s,11)){ |
| 1576 | s+=11;pragma_killsp(); |
| 1577 | if(!strncmp("on",s,2)){ |
| 1578 | if(DEBUG&1) printf("only-inline on\n"); |
| 1579 | only_inline=1; |
| 1580 | }else{ |
| 1581 | if(DEBUG&1) printf("only-inline off\n"); |
| 1582 | only_inline=2; |
| 1583 | } |
| 1584 | }else if(!strncmp("pack",s,4)){ |
| 1585 | /* packing of structures */ |
| 1586 | s+=4;pragma_killsp(); |
| 1587 | if(*s=='(') { s++;pragma_killsp();} |
| 1588 | if(!strncmp("push",s,4)){ |
| 1589 | if(pidx==PACKSTACKSIZE){ |
| 1590 | memmove(pack,pack+1,(PACKSTACKSIZE-1)*sizeof(pack[0])); |
| 1591 | pidx--; |
| 1592 | } |
| 1593 | pack[pidx++]=pack_align; |
| 1594 | s+=4;pragma_killsp(); |
| 1595 | if(*s==','){ |
| 1596 | s++;pragma_killsp(); |
| 1597 | sscanf(s,"%i",&pack_align); |
| 1598 | } |
| 1599 | }else if(!strncmp("pop",s,3)){ |
| 1600 | if(pidx>0) pack_align=pack[--pidx]; |
| 1601 | else pack_align=0; |
| 1602 | }else if(*s==')') |
| 1603 | pack_align=0; |
| 1604 | else |
| 1605 | sscanf(s,"%i",&pack_align); |
| 1606 | #if 0 |
| 1607 | }else if(!strncmp("type",s,4)){ |
| 1608 | /* Typ eines Ausdrucks im Klartext ausgeben */ |
| 1609 | np tree; |
| 1610 | s+=4;strcat(s,";"); |
| 1611 | tree=expression(); |
| 1612 | if(tree&&type_expression(tree)){ |
| 1613 | printf("type of %s is:\n",string+7); |
| 1614 | prd(stdout,tree->ntyp);printf("\n"); |
| 1615 | } |
| 1616 | if(tree) free_expression(tree); |
| 1617 | }else if(!strncmp("tree",s,4)){ |
| 1618 | /* gibt eine expression aus */ |
| 1619 | np tree; |
| 1620 | s+=4;strcat(s,";"); |
| 1621 | tree=expression(); |
| 1622 | if(tree&&type_expression(tree)){ |
| 1623 | printf("tree of %s is:\n",string+7); |
| 1624 | pre(stdout,tree);printf("\n"); |
| 1625 | } |
| 1626 | if(tree) free_expression(tree); |
| 1627 | #endif |
| 1628 | #ifdef HAVE_ECPP |
| 1629 | /* removed */ |
| 1630 | /* removed */ |
| 1631 | /* removed */ |
| 1632 | /* removed */ |
| 1633 | /* removed */ |
| 1634 | /* removed */ |
| 1635 | /* removed */ |
| 1636 | /* removed */ |
| 1637 | /* removed */ |
| 1638 | /* removed */ |
| 1639 | /* removed */ |
| 1640 | /* removed */ |
| 1641 | /* removed */ |
| 1642 | /* removed */ |
| 1643 | /* removed */ |
| 1644 | /* removed */ |
| 1645 | /* removed */ |
| 1646 | /* removed */ |
| 1647 | /* removed */ |
| 1648 | /* removed */ |
| 1649 | /* removed */ |
| 1650 | /* removed */ |
| 1651 | /* removed */ |
| 1652 | /* removed */ |
| 1653 | /* removed */ |
| 1654 | /* removed */ |
| 1655 | #endif |
| 1656 | }else{ |
| 1657 | #ifdef HAVE_TARGET_PRAGMAS |
| 1658 | handle_pragma(s); |
| 1659 | #endif |
| 1660 | } |
| 1661 | } |
| 1662 | void killsp(void) |
| 1663 | /* Ueberspringt Fuellzeichen */ |
| 1664 | /* noch einige unschoene Dinge drin */ |
| 1665 | { |
| 1666 | /*FIXME: #pragma etc. */ |
| 1667 | while(!eof&&(ttWHI(ctok->type)||ctok->type==PRAGMA||(!input_wpo&&!ls.condcomp))){ |
| 1668 | if(ctok->type==PRAGMA) |
| 1669 | do_pragma(ctok->name); |
| 1670 | next_token(); |
| 1671 | } |
| 1672 | } |
| 1673 | void enter_block(void) |
| 1674 | /* Setzt Zeiger/Struckturen bei Eintritt in neuen Block */ |
| 1675 | { |
| 1676 | if(nesting>=MAXN){error(9,nesting);return;} |
| 1677 | nesting++; |
| 1678 | if(DEBUG&1) printf("enter block %d\n",nesting); |
| 1679 | first_ilist[nesting]=last_ilist[nesting]=0; |
| 1680 | first_sd[nesting]=last_sd[nesting]=0; |
| 1681 | first_si[nesting]=last_si[nesting]=0; |
| 1682 | first_var[nesting]=last_var[nesting]=0; |
| 1683 | if(nesting==1){ |
| 1684 | first_llist=last_llist=0; |
| 1685 | first_clist=last_clist=0; |
| 1686 | merk_varf=merk_varl=0; |
| 1687 | merk_ilistf=merk_ilistl=0; |
| 1688 | merk_sif=merk_sil=0; |
| 1689 | /* struct-declarations erst ganz am Schluss loeschen. Um zu vermeiden, */ |
| 1690 | /* dass struct-declarations in Prototypen frei werden und dann eine */ |
| 1691 | /* spaetere struct, dieselbe Adresse bekommt und dadurch gleich wird. */ |
| 1692 | /* Nicht sehr schoen - wenn moeglich noch mal aendern. */ |
| 1693 | /* merk_sdf=merk_sdl=0;*/ |
| 1694 | afterlabel=0; |
| 1695 | } |
| 1696 | #ifdef HAVE_ECPP |
| 1697 | /* removed */ |
| 1698 | /* removed */ |
| 1699 | /* removed */ |
| 1700 | #endif |
| 1701 | } |
| 1702 | void leave_block(void) |
| 1703 | /* Setzt Zeiger/Struckturen bei Verlassen eines Blocks */ |
| 1704 | { |
| 1705 | static int inleave; |
| 1706 | int i; |
| 1707 | if(inleave) return; |
| 1708 | inleave=1; |
| 1709 | #ifdef HAVE_ECPP |
| 1710 | /* removed */ |
| 1711 | /* removed */ |
| 1712 | /* removed */ |
| 1713 | #endif |
| 1714 | for(i=1;i<=MAXR;i++) |
| 1715 | if(regbnesting[i]==nesting) regsbuf[i]=0; |
| 1716 | if(nesting<0){error(10);inleave=0;return;} |
| 1717 | if(DEBUG&1) printf("leave block %d vla=%p\n",nesting,(void *)block_vla[nesting]); |
| 1718 | if(block_vla[nesting]) clearvl(); |
| 1719 | if(nesting>0){ |
| 1720 | if(merk_varl) merk_varl->next=first_var[nesting]; else merk_varf=first_var[nesting]; |
| 1721 | if(last_var[nesting]) merk_varl=last_var[nesting]; |
| 1722 | if(merk_sil) merk_sil->next=first_si[nesting]; else merk_sif=first_si[nesting]; |
| 1723 | if(last_si[nesting]) merk_sil=last_si[nesting]; |
| 1724 | if(merk_sdl) merk_sdl->next=first_sd[nesting]; else merk_sdf=first_sd[nesting]; |
| 1725 | if(last_sd[nesting]) merk_sdl=last_sd[nesting]; |
| 1726 | if(merk_ilistl) merk_ilistl->next=first_ilist[nesting]; else merk_ilistf=first_ilist[nesting]; |
| 1727 | if(last_ilist[nesting]) merk_ilistl=last_ilist[nesting]; |
| 1728 | } |
| 1729 | if(nesting==1){ |
| 1730 | if(cross_module){ |
| 1731 | /* anything to do? */ |
| 1732 | }else{ |
| 1733 | if(merk_varf) gen_vars(merk_varf); |
| 1734 | if(first_llist) free_llist(first_llist); |
| 1735 | first_llist=0; |
| 1736 | if(first_clist) free_clist(first_clist); |
| 1737 | first_clist=0; |
| 1738 | if(merk_varf) free_var(merk_varf); |
| 1739 | merk_varf=0; |
| 1740 | if(merk_sif) free_si(merk_sif); |
| 1741 | merk_sif=0; |
| 1742 | /* struct-declarations erst ganz am Schluss loeschen. Um zu vermeiden, */ |
| 1743 | /* dass struct-declarations in Prototypen frei werden und dann eine */ |
| 1744 | /* spaetere struct, dieselbe Adresse bekommt und dadurch gleich wird. */ |
| 1745 | /* Nicht sehr schoen - wenn moeglich noch mal aendern. */ |
| 1746 | /* if(merk_sdf) free_sd(merk_sdf);*/ |
| 1747 | if(merk_ilistf) free_ilist(merk_ilistf); |
| 1748 | merk_ilistf=0; |
| 1749 | } |
| 1750 | } |
| 1751 | if(nesting==0){ |
| 1752 | if(/*ecpp||*/cross_module){ |
| 1753 | /* don't free struct_declarations in EC++ for now, since they can be */ |
| 1754 | /* referenced even when they are not in scope */ |
| 1755 | /* anything to do? */ |
| 1756 | }else{ |
| 1757 | /* struct-declarations erst ganz am Schluss loeschen. Um zu vermeiden, */ |
| 1758 | /* dass struct-declarations in Prototypen frei werden und dann eine */ |
| 1759 | /* spaetere struct, dieselbe Adresse bekommt und dadurch gleich wird. */ |
| 1760 | /* Nicht sehr schoen - wenn moeglich noch mal aendern. */ |
| 1761 | if(first_si[0]) free_si(first_si[0]); |
| 1762 | if(first_ext) |
| 1763 | gen_vars(first_ext); |
| 1764 | if(first_var[0]) |
| 1765 | gen_vars(first_var[0]); |
| 1766 | if(first_ext) |
| 1767 | free_var(first_ext); |
| 1768 | if(first_var[0]) |
| 1769 | free_var(first_var[0]); |
| 1770 | if(merk_sdf) free_sd(merk_sdf); |
| 1771 | if(first_sd[0]) free_sd(first_sd[0]); |
| 1772 | if(first_ilist[0]) free_ilist(first_ilist[0]); |
| 1773 | } |
| 1774 | } |
| 1775 | nesting--; |
| 1776 | inleave=0; |
| 1777 | } |
| 1778 | void pra(FILE *f,argument_list *p) |
| 1779 | /* Gibt argument_list umgekehrt auf Bildschirm aus */ |
| 1780 | { |
| 1781 | if(p->next){ pra(f,p->next);fprintf(f,",");} |
| 1782 | if(p->arg) pre(f,p->arg); |
| 1783 | } |
| 1784 | void pre(FILE *f,np p) |
| 1785 | /* Gibt expression auf Bildschirm aus */ |
| 1786 | { |
| 1787 | int c; |
| 1788 | c=p->flags; |
| 1789 | if(p->sidefx) fprintf(f,"/"); |
| 1790 | if(p->lvalue) fprintf(f,"|"); |
| 1791 | if(c==CALL){fprintf(f,"call-function(");pre(f,p->left);fprintf(f,")("); |
| 1792 | if(p->alist) pra(f,p->alist); |
| 1793 | fprintf(f,")");return;} |
| 1794 | if(c==CAST){fprintf(f,"cast(");pre(f,p->left); |
| 1795 | fprintf(f,"->");prd(f,p->ntyp); |
| 1796 | fprintf(f,")");return;} |
| 1797 | if(c==MEMBER){if(p->identifier) fprintf(f,".%s",p->identifier);return;} |
| 1798 | if(c==IDENTIFIER){if(p->identifier) fprintf(f,"%s",p->identifier); |
| 1799 | fprintf(f,"+");printval(f,&p->val,LONG); return;} |
| 1800 | fprintf(f,"%s(",ename[c]); |
| 1801 | if(p->left) pre(f,p->left); |
| 1802 | if(p->right){ |
| 1803 | fprintf(f,","); |
| 1804 | pre(f,p->right); |
| 1805 | } |
| 1806 | fprintf(f,")"); |
| 1807 | if(c==CEXPR||c==PCEXPR){fprintf(f,"(value="); printval(f,&p->val,p->ntyp->flags); fprintf(f,")");} |
| 1808 | } |
| 1809 | static int pp_line; |
| 1810 | void do_error(int errn,va_list vl) |
| 1811 | /* Behandelt Ausgaben wie Fehler und Meldungen */ |
| 1812 | { |
| 1813 | int type,have_stack=0; |
| 1814 | int treat_warning_as_error=0; |
| 1815 | char *errstr="",*txt=filename; |
| 1816 | if(c_flags_val[8].l&&c_flags_val[8].l<=errors) |
| 1817 | return; |
| 1818 | if(errn==-1) errn=158; |
| 1819 | type=err_out[errn].flags; |
| 1820 | treat_warning_as_error=(type&WARNING)&&(c_flags[54]&USEDFLAG); |
| 1821 | #ifdef HAVE_MISRA |
| 1822 | /* removed */ |
| 1823 | #endif |
| 1824 | if(type&DONTWARN) return; |
| 1825 | if(type&WARNING) errstr="warning"; |
| 1826 | if(type&ERROR) errstr="error"; |
| 1827 | if(input_wpo){ |
| 1828 | fprintf(stderr,"%s %d: ",errstr,errn); |
| 1829 | }else if((type&NOLINE)/*||((type&PREPROC)&&pp_line<=0)*/){ |
| 1830 | fprintf(stderr,"%s %d: ",errstr,errn); |
| 1831 | }else if(type&(INFUNC|INIC)){ |
| 1832 | if((type&INIC)&&err_ic&&err_ic->line){ |
| 1833 | fprintf(stderr,"%s %d in line %d of \"%s\": ",errstr,errn,err_ic->line,err_ic->file); |
| 1834 | |
| 1835 | |
| 1836 | }else{ |
| 1837 | fprintf(stderr,"%s %d in function \"%s\": ",errstr,errn,cur_func); |
| 1838 | } |
| 1839 | }else if(!input_wpo){ |
| 1840 | int n; |
| 1841 | if(eof){ |
| 1842 | fprintf(stderr,">EOF\n"); |
| 1843 | }else{ |
| 1844 | if(ls.cli!=0) ls.copy_line[ls.cli]=0; |
| 1845 | fprintf(stderr,">%s\n",ls.copy_line); |
| 1846 | } |
| 1847 | if(type&PREPROC){ |
| 1848 | txt=current_filename; |
| 1849 | n=pp_line; |
| 1850 | }else{ |
| 1851 | if(ctok) |
| 1852 | n=ctok->line; |
| 1853 | else |
| 1854 | n=-1; |
| 1855 | } |
| 1856 | if(c_flags[20]&USEDFLAG){ /* strip-path from filename */ |
| 1857 | char *p=txt,c; |
| 1858 | while(c=*p++) |
| 1859 | if(c==':'||c=='/'||c=='\\') txt=p; |
| 1860 | } |
| 1861 | fprintf(stderr,"%s %d in line %d of \"%s\": ",errstr,errn,n,txt); |
| 1862 | have_stack=1; /* we can report the include stack */ |
| 1863 | } |
| 1864 | vfprintf(stderr,err_out[errn].text,vl); |
| 1865 | fprintf(stderr,"\n"); |
| 1866 | if(have_stack&&(!(c_flags[49]&USEDFLAG))){ |
| 1867 | int i; |
| 1868 | stack_context *sc = report_context(); |
| 1869 | for(i=0;;i++){ |
| 1870 | if(sc[i].line==-1) break; |
| 1871 | fprintf(stderr,"\tincluded from file \"%s\":%ld\n",sc[i].long_name?sc[i].long_name:sc[i].name,sc[i].line); |
| 1872 | } |
| 1873 | } |
| 1874 | if(treat_warning_as_error){fprintf(stderr,"warning %d treated as error [-warnings-as-errors]\n",errn);} |
| 1875 | if(type&ERROR||treat_warning_as_error){ |
| 1876 | errors++; |
| 1877 | if(c_flags_val[8].l&&c_flags_val[8].l<=errors&&!(type&NORAUS)) |
| 1878 | {fprintf(stderr,"Maximum number of errors reached!\n");raus();} |
| 1879 | } |
| 1880 | if(type&FATAL){fprintf(stderr,"aborting...\n");raus();} |
| 1881 | } |
| 1882 | void error(int errn,...) |
| 1883 | { |
| 1884 | va_list vl; |
| 1885 | va_start(vl,errn); |
| 1886 | do_error(errn,vl); |
| 1887 | va_end(vl); |
| 1888 | } |
| 1889 | void ucpp_ouch(char *fmt, ...) |
| 1890 | { |
| 1891 | ierror(0); |
| 1892 | } |
| 1893 | void do_ucpp_error(char *fmt,va_list vl) |
| 1894 | { |
| 1895 | int i; |
| 1896 | for(i=0;i<err_num;i++){ |
| 1897 | if(!strcmp(fmt,err_out[i].text)) |
| 1898 | break; |
| 1899 | } |
| 1900 | if(*fmt=='#'){ |
| 1901 | /* #error/#warning-directive */ |
| 1902 | i=*(fmt+1)=='w'?325:292; |
| 1903 | } |
| 1904 | if(i>=err_num){ |
| 1905 | puts(fmt); |
| 1906 | ierror(0); |
| 1907 | } |
| 1908 | do_error(i,vl); |
| 1909 | } |
| 1910 | void ucpp_error(long line, char *fmt, ...) |
| 1911 | { |
| 1912 | va_list ap; |
| 1913 | pp_line=line; |
| 1914 | va_start(ap, fmt); |
| 1915 | do_ucpp_error(fmt,ap); |
| 1916 | va_end(ap); |
| 1917 | } |
| 1918 | void ucpp_warning(long line, char *fmt, ...) |
| 1919 | { |
| 1920 | va_list ap; |
| 1921 | pp_line=line; |
| 1922 | va_start(ap, fmt); |
| 1923 | do_ucpp_error(fmt,ap); |
| 1924 | va_end(ap); |
| 1925 | } |
| 1926 | |
| 1927 | void misra(int n,...) |
| 1928 | { |
| 1929 | va_list vl; |
| 1930 | if(!misracheck) return; |
| 1931 | va_start(vl,n); |
| 1932 | fprintf(stderr,"MISRA error %d\n",n); |
| 1933 | va_end(vl); |
| 1934 | } |
| 1935 | |
| 1936 | void misra_error(int n, int rule, int subrule, int line, ...) { |
| 1937 | va_list vl; |
| 1938 | tmisra_err_out* misr_err; |
| 1939 | char* mis_vers_string; |
| 1940 | char mis_numb_string[100]; |
| 1941 | char* rule_text; |
| 1942 | int not_found; |
| 1943 | if (!misracheck) return; |
| 1944 | mis_vers_string = 0; |
| 1945 | va_start(vl,line); |
| 1946 | |
| 1947 | if (line == 0) line = ctok->line; |
| 1948 | |
| 1949 | if ((n) && (misraversion==1998)) { |
| 1950 | if (misra_98_warn_flag[n-1] != 1) return; /* TODO: Zhler setzen wenn nur ein paar nicht ausgegeben werden sollen */ |
| 1951 | mis_vers_string = mystrdup("1998"); |
| 1952 | sprintf(mis_numb_string,"%d",n); |
| 1953 | misr_err = NULL; |
| 1954 | } else if ((rule) && (misraversion==2004)) { |
| 1955 | if (misra_04_warn_flag[rule-1][subrule-1] != 1) return;/* TODO: Zhler setzen wenn nur ein paar nicht ausgegeben werden sollen */ |
| 1956 | mis_vers_string = mystrdup("2004"); |
| 1957 | sprintf(mis_numb_string,"Chapter %d, Rule %d",rule,subrule); |
| 1958 | if (subrule) { |
| 1959 | misr_err = misra_err_out; |
| 1960 | not_found = 1; |
| 1961 | while ( not_found ) { |
| 1962 | if ((misr_err->chapter == rule) && (misr_err->rule == subrule)) { |
| 1963 | not_found = 0; |
| 1964 | break; |
| 1965 | } |
| 1966 | misr_err++; |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | if (!mis_vers_string) return; |
| 1971 | if (misr_err) fprintf(stderr,"MISRA(%s) Rule violation (%s) in line <%d>\n%s\n",mis_vers_string,mis_numb_string,line,misr_err->text); |
| 1972 | else fprintf(stderr,"MISRA(%s) Rule violation (%s) in line <%d>: No description found\n",mis_vers_string,mis_numb_string,line); |
| 1973 | |
| 1974 | if (mis_vers_string) free(mis_vers_string); |
| 1975 | |
| 1976 | va_end(vl); |
| 1977 | } |
| 1978 | |
| 1979 | void misra_neu(int n,int rule,int subrule, int line, ...) |
| 1980 | { |
| 1981 | va_list vl; |
| 1982 | int mis_warn = 0; |
| 1983 | misra_error(n,rule,subrule,line); |
| 1984 | return; |
| 1985 | va_start(vl,line); |
| 1986 | va_end(vl); |
| 1987 | |
| 1988 | } |
| 1989 | |
| 1990 | FILE *open_out(char *name,char *ext) |
| 1991 | /* Haengt ext an name an und versucht diese File als output zu oeffnen */ |
| 1992 | { |
| 1993 | char *s,*p;FILE *f; |
| 1994 | if(ext){ |
| 1995 | s=mymalloc(strlen(name)+strlen(ext)+2); |
| 1996 | strcpy(s,name); |
| 1997 | p=s+strlen(s); |
| 1998 | while(p>=s){ |
| 1999 | if(*p=='.'){*p=0;break;} |
| 2000 | p--; |
| 2001 | } |
| 2002 | strcat(s,"."); |
| 2003 | strcat(s,ext); |
| 2004 | }else |
| 2005 | s=name; |
| 2006 | f=fopen(s,"w"); |
| 2007 | if(!f) fprintf(stderr,"Couldn't open <%s> for output!\n",s); |
| 2008 | if(ext) free(s); |
| 2009 | return(f); |
| 2010 | } |