Changeset 258
- Timestamp:
- 11/21/09 10:55:39 (15 years ago)
- Files:
-
- trunk/src/e2ir.c (modified) (4 diffs)
- trunk/src/irstate.c (modified) (2 diffs)
- trunk/src/irstate.h (modified) (1 diff)
- trunk/src/mars.c (modified) (3 diffs)
- trunk/src/mars.h (modified) (1 diff)
- trunk/src/win32.mak (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/e2ir.c
r253 r258 2556 2556 printf("elwr\n"); 2557 2557 elem_print(elwr); 2558 2558 printf("eupr\n"); 2559 2559 elem_print(eupr); 2560 2560 printf("enbytes\n"); 2561 2561 elem_print(enbytes); 2562 2562 #endif 2563 2563 einit = el_combine(n1x, einit); 2564 2564 einit = el_combine(einit, elwrx); 2565 2565 einit = el_combine(einit, euprx); 2566 2566 2567 2567 evalue = this->e2->toElem(irs); 2568 2568 2569 2569 #if 0 2570 2570 printf("n1\n"); 2571 2571 elem_print(n1); 2572 2572 printf("enbytes\n"); 2573 2573 elem_print(enbytes); 2574 2574 #endif 2575 2575 2576 if ( global.params.useArrayBounds&& eupr && ta->ty != Tpointer)2576 if (irs->arrayBoundsCheck() && eupr && ta->ty != Tpointer) 2577 2577 { 2578 2578 elem *c1; 2579 2579 elem *c2; 2580 2580 elem *ea; 2581 2581 elem *eb; 2582 2582 elem *enbytesx; 2583 2583 2584 2584 assert(elwr); 2585 2585 enbytesx = enbytes; 2586 2586 enbytes = el_same(&enbytesx); 2587 2587 c1 = el_bin(OPle, TYint, el_copytree(eupr), enbytesx); 2588 2588 c2 = el_bin(OPle, TYint, el_copytree(elwr), el_copytree(eupr)); 2589 2589 c1 = el_bin(OPandand, TYint, c1, c2); 2590 2590 2591 2591 // Construct: (c1 || ModuleArray(line)) 2592 2592 Symbol *sassert; 2593 2593 2594 2594 sassert = irs->blx->module->toModuleArray(); 2595 2595 ea = el_bin(OPcall,TYvoid,el_var(sassert), el_long(TYint, loc.linnum)); 2596 2596 eb = el_bin(OPoror,TYvoid,c1,ea); … … 2661 2661 { 2662 2662 /* It's array1[]=array2[] 2663 2663 * which is a memcpy 2664 2664 */ 2665 2665 elem *ep; 2666 2666 2667 2667 elem *eto = e1->toElem(irs); 2668 2668 elem *efrom = e2->toElem(irs); 2669 2669 2670 2670 unsigned size = t1->nextOf()->size(); 2671 2671 elem *esize = el_long(TYint, size); 2672 2672 2673 2673 /* Determine if we need to do postblit 2674 2674 */ 2675 2675 int postblit = 0; 2676 2676 if (needsPostblit(t1)) 2677 2677 postblit = 1; 2678 2678 2679 2679 assert(e2->type->ty != Tpointer); 2680 2680 2681 if (!postblit && ! global.params.useArrayBounds)2681 if (!postblit && !irs->arrayBoundsCheck()) 2682 2682 { 2683 2683 elem *ex = el_same(&eto); 2684 2684 2685 2685 // Determine if elen is a constant 2686 2686 elem *elen; 2687 2687 if (eto->Eoper == OPpair && 2688 2688 eto->E1->Eoper == OPconst) 2689 2689 { 2690 2690 elen = el_copytree(eto->E1); 2691 2691 } 2692 2692 else 2693 2693 { 2694 2694 // It's not a constant, so pull it from the dynamic array 2695 2695 elen = el_una(OP64_32, TYint, el_copytree(ex)); 2696 2696 } 2697 2697 2698 2698 esize = el_bin(OPmul, TYint, elen, esize); 2699 2699 elem *epto = array_toPtr(e1->type, ex); 2700 2700 elem *epfr = array_toPtr(e2->type, efrom); 2701 2701 #if 1 … … 4211 4211 { 4212 4212 //printf("SliceExp::toElem()\n"); 4213 4213 Type *t1 = e1->type->toBasetype(); 4214 4214 elem *e = e1->toElem(irs); 4215 4215 if (lwr) 4216 4216 { 4217 4217 elem *einit = resolveLengthVar(lengthVar, &e, t1); 4218 4218 4219 4219 int sz = t1->nextOf()->size(); 4220 4220 4221 4221 elem *elwr = lwr->toElem(irs); 4222 4222 elem *eupr = upr->toElem(irs); 4223 4223 4224 4224 elem *elwr2 = el_same(&elwr); 4225 4225 4226 4226 // Create an array reference where: 4227 4227 // length is (upr - lwr) 4228 4228 // pointer is (ptr + lwr*sz) 4229 4229 // Combine as (length pair ptr) 4230 4230 4231 if ( global.params.useArrayBounds)4231 if (irs->arrayBoundsCheck()) 4232 4232 { 4233 4233 // Checks (unsigned compares): 4234 4234 // upr <= array.length 4235 4235 // lwr <= upr 4236 4236 4237 4237 elem *c1; 4238 4238 elem *c2; 4239 4239 elem *ea; 4240 4240 elem *eb; 4241 4241 elem *eupr2; 4242 4242 elem *elength; 4243 4243 4244 4244 if (t1->ty == Tpointer) 4245 4245 { 4246 4246 // Just do lwr <= upr check 4247 4247 4248 4248 eupr2 = el_same(&eupr); 4249 4249 eupr2->Ety = TYuint; // make sure unsigned comparison 4250 4250 c1 = el_bin(OPle, TYint, elwr2, eupr2); 4251 4251 c1 = el_combine(eupr, c1); … … 4340 4340 assert(n2->Enumbytes); 4341 4341 } 4342 4342 elem *valuesize = el_long(TYuint, vsize); // BUG: should be TYsize_t 4343 4343 //printf("valuesize: "); elem_print(valuesize); 4344 4344 if (modifiable) 4345 4345 { 4346 4346 n1 = el_una(OPaddr, TYnptr, n1); 4347 4347 s = taa->aaGetSymbol("Get", 1); 4348 4348 } 4349 4349 else 4350 4350 { 4351 4351 s = taa->aaGetSymbol("GetRvalue", 1); 4352 4352 } 4353 4353 //printf("taa->index = %s\n", taa->index->toChars()); 4354 4354 keyti = taa->index->getInternalTypeInfo(NULL)->toElem(irs); 4355 4355 //keyti = taa->index->getTypeInfo(NULL)->toElem(irs); 4356 4356 //printf("keyti:\n"); 4357 4357 //elem_print(keyti); 4358 4358 ep = el_params(n2, valuesize, keyti, n1, NULL); 4359 4359 e = el_bin(OPcall, TYnptr, el_var(s), ep); 4360 if ( global.params.useArrayBounds)4360 if (irs->arrayBoundsCheck()) 4361 4361 { 4362 4362 elem *ea; 4363 4363 4364 4364 elem *n = el_same(&e); 4365 4365 4366 4366 // Construct: ((e || ModuleAssert(line)),n) 4367 4367 Symbol *sassert = irs->blx->module->toModuleArray(); 4368 4368 ea = el_bin(OPcall,TYvoid,el_var(sassert), 4369 4369 el_long(TYint, loc.linnum)); 4370 4370 e = el_bin(OPoror,TYvoid,e,ea); 4371 4371 e = el_bin(OPcomma, TYnptr, e, n); 4372 4372 } 4373 4373 e = el_una(OPind, type->totym(), e); 4374 4374 if (tybasic(e->Ety) == TYstruct) 4375 4375 e->Enumbytes = type->size(); 4376 4376 } 4377 4377 else 4378 4378 { 4379 4379 elem *einit = resolveLengthVar(lengthVar, &n1, t1); 4380 4380 elem *n2 = e2->toElem(irs); 4381 4381 4382 if ( global.params.useArrayBounds)4382 if (irs->arrayBoundsCheck()) 4383 4383 { 4384 4384 elem *elength; 4385 4385 elem *n2x; 4386 4386 elem *ea; 4387 4387 4388 4388 if (t1->ty == Tsarray) 4389 4389 { TypeSArray *tsa = (TypeSArray *)t1; 4390 4390 dinteger_t length = tsa->dim->toInteger(); 4391 4391 4392 4392 elength = el_long(TYuint, length); 4393 4393 goto L1; 4394 4394 } 4395 4395 else if (t1->ty == Tarray) 4396 4396 { 4397 4397 elength = n1; 4398 4398 n1 = el_same(&elength); 4399 4399 elength = el_una(OP64_32, TYuint, elength); 4400 4400 L1: 4401 4401 n2x = n2; 4402 4402 n2 = el_same(&n2x); trunk/src/irstate.c
r189 r258 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 8by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright 6 6 // http://www.digitalmars.com 7 7 8 8 #include <stdio.h> 9 9 10 #include "mars.h" 11 #include "mtype.h" 12 #include "declaration.h" 10 13 #include "irstate.h" 11 14 12 15 IRState::IRState(IRState *irs, Statement *s) 13 16 { 14 17 prev = irs; 15 18 statement = s; 16 19 symbol = NULL; 17 20 breakBlock = NULL; 18 21 contBlock = NULL; 19 22 switchBlock = NULL; 20 23 defaultBlock = NULL; 21 24 ident = NULL; 22 25 ehidden = NULL; 23 26 startaddress = NULL; 24 27 if (irs) 25 28 { 26 29 m = irs->m; 27 30 shidden = irs->shidden; 28 31 sclosure = irs->sclosure; 29 32 sthis = irs->sthis; … … 145 148 146 149 for (bc = this; bc; bc = bc->prev) 147 150 { 148 151 if (bc->defaultBlock) 149 152 return bc->defaultBlock; 150 153 } 151 154 return NULL; 152 155 } 153 156 154 157 FuncDeclaration *IRState::getFunc() 155 158 { 156 159 IRState *bc; 157 160 158 161 for (bc = this; bc->prev; bc = bc->prev) 159 162 { 160 163 } 161 164 return (FuncDeclaration *)(bc->symbol); 162 165 } 163 166 164 167 168 /********************** 169 * Return !=0 if do array bounds checking 170 */ 171 int IRState::arrayBoundsCheck() 172 { 173 int result = global.params.useArrayBounds; 174 175 if (result == 1) 176 { // For safe functions only 177 result = 0; 178 FuncDeclaration *fd = getFunc(); 179 if (fd) 180 { Type *t = fd->type; 181 if (t->ty == Tfunction && ((TypeFunction *)t)->trust == TRUSTsafe) 182 result = 1; 183 } 184 } 185 return result; 186 } trunk/src/irstate.h
r189 r258 35 35 Symbol *sclosure; // pointer to closure instance 36 36 Blockx *blx; 37 37 Array *deferToObj; // array of Dsymbol's to run toObjFile(int multiobj) on later 38 38 elem *ehidden; // transmit hidden pointer to CallExp::toElem() 39 39 Symbol *startaddress; 40 40 41 41 block *breakBlock; 42 42 block *contBlock; 43 43 block *switchBlock; 44 44 block *defaultBlock; 45 45 46 46 IRState(IRState *irs, Statement *s); 47 47 IRState(IRState *irs, Dsymbol *s); 48 48 IRState(Module *m, Dsymbol *s); 49 49 50 50 block *getBreakBlock(Identifier *ident); 51 51 block *getContBlock(Identifier *ident); 52 52 block *getSwitchBlock(); 53 53 block *getDefaultBlock(); 54 54 FuncDeclaration *getFunc(); 55 int arrayBoundsCheck(); 55 56 }; 56 57 57 58 #endif /* DMD_CONTEXT_H */ trunk/src/mars.c
r242 r258 219 219 -d allow deprecated features\n\ 220 220 -debug compile in debug code\n\ 221 221 -debug=level compile in debug code <= level\n\ 222 222 -debug=ident compile in debug code identified by ident\n\ 223 223 -debuglib=name set symbolic debug library to name\n\ 224 224 -defaultlib=name set default library to name\n\ 225 225 -deps=filename write module dependencies to filename\n\ 226 226 -g add symbolic debug info\n\ 227 227 -gc add symbolic debug info, pretend to be C\n\ 228 228 -H generate 'header' file\n\ 229 229 -Hddirectory write 'header' file to directory\n\ 230 230 -Hffilename write 'header' file to filename\n\ 231 231 --help print help\n\ 232 232 -Ipath where to look for imports\n\ 233 233 -ignore ignore unsupported pragmas\n\ 234 234 -inline do function inlining\n\ 235 235 -Jpath where to look for string imports\n\ 236 236 -Llinkerflag pass linkerflag to link\n\ 237 237 -lib generate library rather than object files\n\ 238 238 -man open web browser on manual page\n\ 239 -noboundscheck turns off array bounds checking for all functions\n\ 239 240 -nofloat do not emit reference to floating point\n\ 240 241 -O optimize\n\ 241 242 -o- do not write object file\n\ 242 243 -odobjdir write object & library files to directory objdir\n\ 243 244 -offilename name output file to filename\n\ 244 245 -op do not strip paths from source file\n\ 245 246 -profile profile runtime performance of generated code\n\ 246 247 -quiet suppress unnecessary messages\n\ 247 248 -release compile release version\n\ 248 249 -run srcfile args... run resulting program, passing args\n\ 249 -safe safe memory model\n\250 250 -unittest compile in unit tests\n\ 251 251 -v verbose\n\ 252 252 -version=level compile in version code >= level\n\ 253 253 -version=ident compile in version code identified by ident\n\ 254 254 -vtls list all variables going into thread local storage\n\ 255 255 -w enable warnings\n\ 256 256 -X generate JSON file\n\ 257 257 -Xffilename write JSON file to filename\n\ 258 258 "); 259 259 } 260 260 261 261 int main(int argc, char *argv[]) 262 262 { 263 263 int i; 264 264 Array files; 265 265 Array libmodules; 266 266 char *p; 267 267 Module *m; 268 268 int status = EXIT_SUCCESS; 269 269 int argcstart = argc; 270 270 int setdebuglib = 0; 271 char noboundscheck = 0; 271 272 272 273 // Check for malformed input 273 274 if (argc < 1 || !argv) 274 275 { 275 276 Largs: 276 277 error("missing or null command line arguments"); 277 278 fatal(); 278 279 } 279 280 for (i = 0; i < argc; i++) 280 281 { 281 282 if (!argv[i]) 282 283 goto Largs; 283 284 } 284 285 285 286 if (response_expand(&argc,&argv)) // expand response files 286 287 error("can't open response file"); 287 288 288 289 files.reserve(argc - 1); 289 290 290 291 // Set default values 291 292 global.params.argv0 = argv[0]; 292 293 global.params.link = 1; 293 294 global.params.useAssert = 1; 294 295 global.params.useInvariants = 1; 295 296 global.params.useIn = 1; 296 297 global.params.useOut = 1; 297 global.params.useArrayBounds = 1;298 global.params.useArrayBounds = 2; // default to all functions 298 299 global.params.useSwitchError = 1; 299 300 global.params.useInline = 0; 300 301 global.params.obj = 1; 301 302 global.params.Dversion = 2; 302 303 global.params.quiet = 1; 303 304 304 305 global.params.linkswitches = new Array(); 305 306 global.params.libfiles = new Array(); 306 307 global.params.objfiles = new Array(); 307 308 global.params.ddocfiles = new Array(); 308 309 309 310 #if TARGET_WINDOS 310 311 global.params.defaultlibname = "phobos"; 311 312 #elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS 312 313 global.params.defaultlibname = "phobos2"; 313 314 #elif TARGET_NET 314 315 #else 315 316 #error "fix this" 316 317 #endif 317 318 … … 513 514 case 0: 514 515 break; 515 516 516 517 default: 517 518 goto Lerror; 518 519 } 519 520 } 520 521 else if (strcmp(p + 1, "ignore") == 0) 521 522 global.params.ignoreUnsupportedPragmas = 1; 522 523 else if (strcmp(p + 1, "inline") == 0) 523 524 global.params.useInline = 1; 524 525 else if (strcmp(p + 1, "lib") == 0) 525 526 global.params.lib = 1; 526 527 else if (strcmp(p + 1, "nofloat") == 0) 527 528 global.params.nofloat = 1; 528 529 else if (strcmp(p + 1, "quiet") == 0) 529 530 global.params.quiet = 1; 530 531 else if (strcmp(p + 1, "release") == 0) 531 532 global.params.release = 1; 532 533 #if DMDV2 533 else if (strcmp(p + 1, " safe") == 0)534 global.params.safe = 1; // now ignored534 else if (strcmp(p + 1, "noboundscheck") == 0) 535 noboundscheck = 1; 535 536 #endif 536 537 else if (strcmp(p + 1, "unittest") == 0) 537 538 global.params.useUnitTests = 1; 538 539 else if (p[1] == 'I') 539 540 { 540 541 if (!global.params.imppath) 541 542 global.params.imppath = new Array(); 542 543 global.params.imppath->push(p + 2); 543 544 } 544 545 else if (p[1] == 'J') 545 546 { 546 547 if (!global.params.fileImppath) 547 548 global.params.fileImppath = new Array(); 548 549 global.params.fileImppath->push(p + 2); 549 550 } 550 551 else if (memcmp(p + 1, "debug", 5) == 0 && p[6] != 'l') 551 552 { 552 553 // Parse: 553 554 // -debug 554 555 // -debug=number … … 709 710 { 710 711 fatal(); 711 712 } 712 713 if (files.dim == 0) 713 714 { usage(); 714 715 return EXIT_FAILURE; 715 716 } 716 717 717 718 if (!setdebuglib) 718 719 global.params.debuglibname = global.params.defaultlibname; 719 720 720 721 #if TARGET_OSX 721 722 global.params.pic = 1; 722 723 #endif 723 724 724 725 if (global.params.release) 725 726 { global.params.useInvariants = 0; 726 727 global.params.useIn = 0; 727 728 global.params.useOut = 0; 728 729 global.params.useAssert = 0; 730 global.params.useArrayBounds = 1; 731 global.params.useSwitchError = 0; 732 } 733 if (noboundscheck) 729 734 global.params.useArrayBounds = 0; 730 global.params.useSwitchError = 0;731 }732 735 733 736 if (global.params.run) 734 737 global.params.quiet = 1; 735 738 736 739 if (global.params.useUnitTests) 737 740 global.params.useAssert = 1; 738 741 739 742 if (!global.params.obj || global.params.lib) 740 743 global.params.link = 0; 741 744 742 745 if (global.params.link) 743 746 { 744 747 global.params.exefile = global.params.objname; 745 748 global.params.oneobj = 1; 746 749 if (global.params.objname) 747 750 { 748 751 /* Use this to name the one object file with the same 749 752 * name as the exe file. 750 753 */ 751 754 global.params.objname = FileName::forceExt(global.params.objname, global.obj_ext)->toChars(); trunk/src/mars.h
r242 r258 123 123 char oneobj; // write one object file instead of multiple ones 124 124 char trace; // insert profiling hooks 125 125 char quiet; // suppress non-error messages 126 126 char verbose; // verbose compile 127 127 char vtls; // identify thread local variables 128 128 char symdebug; // insert debug symbolic information 129 129 char optimize; // run optimizer 130 130 char cpu; // target CPU 131 131 char isX86_64; // generate X86_64 bit code 132 132 char isLinux; // generate code for linux 133 133 char isOSX; // generate code for Mac OSX 134 134 char isWindows; // generate code for Windows 135 135 char isFreeBSD; // generate code for FreeBSD 136 136 char isSolaris; // generate code for Solaris 137 137 char scheduler; // which scheduler to use 138 138 char useDeprecated; // allow use of deprecated features 139 139 char useAssert; // generate runtime code for assert()'s 140 140 char useInvariants; // generate class invariant checks 141 141 char useIn; // generate precondition checks 142 142 char useOut; // generate postcondition checks 143 char useArrayBounds; // generate array bounds checks 143 char useArrayBounds; // 0: no array bounds checks 144 // 1: array bounds checks for safe functions only 145 // 2: array bounds checks for all functions 146 char noboundscheck; // no array bounds checking at all 144 147 char useSwitchError; // check for switches without a default 145 148 char useUnitTests; // generate unittest code 146 149 char useInline; // inline expand functions 147 150 char release; // build release version 148 151 char preservePaths; // !=0 means don't strip path from source file 149 152 char warnings; // enable warnings 150 153 char pic; // generate position-independent-code for shared libs 151 154 char cov; // generate code coverage data 152 155 char nofloat; // code should not pull in floating point support 153 156 char Dversion; // D version number 154 157 char ignoreUnsupportedPragmas; // rather than error on them 155 char safe; // enforce safe memory model156 158 157 159 char *argv0; // program name 158 160 Array *imppath; // array of char*'s of where to look for import modules 159 161 Array *fileImppath; // array of char*'s of where to look for file import modules 160 162 char *objdir; // .obj/.lib file output directory 161 163 char *objname; // .obj file output name 162 164 char *libname; // .lib file output name 163 165 164 166 char doDocComments; // process embedded documentation comments 165 167 char *docdir; // write documentation file to docdir directory 166 168 char *docname; // write documentation file to docname 167 169 Array *ddocfiles; // macro include files for Ddoc 168 170 169 171 char doHdrGeneration; // process embedded documentation comments 170 172 char *hdrdir; // write 'header' file to docdir directory 171 173 char *hdrname; // write 'header' file to docname 172 174 173 175 char doXGeneration; // write JSON file 174 176 char *xfilename; // write JSON file to xfilename 175 177 trunk/src/win32.mak
r204 r258 244 244 245 245 cod1.obj : $C\rtlsym.h $C\cod1.c 246 246 $(CC) -c $(MFLAGS) $C\cod1 247 247 248 248 cod2.obj : $C\rtlsym.h $C\cod2.c 249 249 $(CC) -c $(MFLAGS) $C\cod2 250 250 251 251 cod3.obj : $C\rtlsym.h $C\cod3.c 252 252 $(CC) -c $(MFLAGS) $C\cod3 253 253 254 254 cod4.obj : $C\cod4.c 255 255 $(CC) -c $(MFLAGS) $C\cod4 256 256 257 257 cod5.obj : $C\cod5.c 258 258 $(CC) -c $(MFLAGS) $C\cod5 259 259 260 260 code.obj : $C\code.c 261 261 $(CC) -c $(MFLAGS) $C\code 262 262 263 263 irstate.obj : irstate.h irstate.c 264 $(CC) -c $(MFLAGS) irstate264 $(CC) -c $(MFLAGS) -I$(ROOT) irstate 265 265 266 266 csymbol.obj : $C\symbol.c 267 267 $(CC) -c $(MFLAGS) $C\symbol -ocsymbol.obj 268 268 269 269 debug.obj : $C\debug.c 270 270 $(CC) -c $(MFLAGS) -I. $C\debug 271 271 272 272 dt.obj : $C\dt.h $C\dt.c 273 273 $(CC) -c $(MFLAGS) $C\dt 274 274 275 275 ee.obj : $C\ee.c 276 276 $(CC) -c $(MFLAGS) $C\ee 277 277 278 278 eh.obj : $C\cc.h $C\code.h $C\type.h $C\dt.h eh.c 279 279 $(CC) -c $(MFLAGS) eh 280 280 281 281 el.obj : $C\rtlsym.h $C\el.h $C\el.c 282 282 $(CC) -c $(MFLAGS) $C\el 283 283 284 284 evalu8.obj : $C\evalu8.c
