comparison gen/statements.cpp @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents 5825d48b27d1
children 44a95ac7368a
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "gen/llvm.h" 9 #include "gen/llvm.h"
10 #include "llvm/InlineAsm.h" 10 #include "llvm/InlineAsm.h"
11 11
12 #include "mars.h"
12 #include "total.h" 13 #include "total.h"
13 #include "init.h" 14 #include "init.h"
14 #include "mtype.h" 15 #include "mtype.h"
15 #include "hdrgen.h" 16 #include "hdrgen.h"
16 #include "port.h" 17 #include "port.h"
25 26
26 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
27 28
28 void CompoundStatement::toIR(IRState* p) 29 void CompoundStatement::toIR(IRState* p)
29 { 30 {
30 Logger::println("CompoundStatement::toIR()"); 31 Logger::println("CompoundStatement::toIR(): %s", loc.toChars());
31 LOG_SCOPE; 32 LOG_SCOPE;
32 33
33 for (int i=0; i<statements->dim; i++) 34 for (int i=0; i<statements->dim; i++)
34 { 35 {
35 Statement* s = (Statement*)statements->data[i]; 36 Statement* s = (Statement*)statements->data[i];
36 if (s) 37 if (s) {
37 s->toIR(p); 38 s->toIR(p);
38 else {
39 Logger::println("??? null statement found in CompoundStatement");
40 } 39 }
41 } 40 }
42 } 41 }
43 42
44 ////////////////////////////////////////////////////////////////////////////// 43 //////////////////////////////////////////////////////////////////////////////
45 44
46 void ReturnStatement::toIR(IRState* p) 45 void ReturnStatement::toIR(IRState* p)
47 { 46 {
48 static int rsi = 0; 47 Logger::println("ReturnStatement::toIR(): %s", loc.toChars());
49 Logger::println("ReturnStatement::toIR(%d): %s", rsi++, toChars());
50 LOG_SCOPE; 48 LOG_SCOPE;
51 49
52 if (exp) 50 if (exp)
53 { 51 {
54 Logger::println("return type is: %s", exp->type->toChars()); 52 Logger::println("return type is: %s", exp->type->toChars());
124 122
125 ////////////////////////////////////////////////////////////////////////////// 123 //////////////////////////////////////////////////////////////////////////////
126 124
127 void ExpStatement::toIR(IRState* p) 125 void ExpStatement::toIR(IRState* p)
128 { 126 {
129 static int esi = 0; 127 Logger::println("ExpStatement::toIR(): %s", loc.toChars());
130 Logger::println("ExpStatement::toIR(%d): %s", esi++, toChars());
131 LOG_SCOPE; 128 LOG_SCOPE;
132 129
133 if (global.params.llvmAnnotate) 130 if (global.params.llvmAnnotate)
134 DtoAnnotation(exp->toChars()); 131 DtoAnnotation(exp->toChars());
135 132
148 145
149 ////////////////////////////////////////////////////////////////////////////// 146 //////////////////////////////////////////////////////////////////////////////
150 147
151 void IfStatement::toIR(IRState* p) 148 void IfStatement::toIR(IRState* p)
152 { 149 {
153 Logger::println("IfStatement::toIR()"); 150 Logger::println("IfStatement::toIR(): %s", loc.toChars());
154 LOG_SCOPE; 151 LOG_SCOPE;
155 152
156 DValue* cond_e = condition->toElem(p); 153 DValue* cond_e = condition->toElem(p);
157 llvm::Value* cond_val = cond_e->getRVal(); 154 llvm::Value* cond_val = cond_e->getRVal();
158 delete cond_e; 155 delete cond_e;
193 190
194 ////////////////////////////////////////////////////////////////////////////// 191 //////////////////////////////////////////////////////////////////////////////
195 192
196 void ScopeStatement::toIR(IRState* p) 193 void ScopeStatement::toIR(IRState* p)
197 { 194 {
198 Logger::println("ScopeStatement::toIR()"); 195 Logger::println("ScopeStatement::toIR(): %s", loc.toChars());
199 LOG_SCOPE; 196 LOG_SCOPE;
200 197
201 llvm::BasicBlock* oldend = p->scopeend(); 198 llvm::BasicBlock* oldend = p->scopeend();
202 199
203 llvm::BasicBlock* beginbb = 0; 200 llvm::BasicBlock* beginbb = 0;
224 221
225 ////////////////////////////////////////////////////////////////////////////// 222 //////////////////////////////////////////////////////////////////////////////
226 223
227 void WhileStatement::toIR(IRState* p) 224 void WhileStatement::toIR(IRState* p)
228 { 225 {
229 static int wsi = 0; 226 Logger::println("WhileStatement::toIR(): %s", loc.toChars());
230 Logger::println("WhileStatement::toIR(%d): %s", wsi++, toChars());
231 LOG_SCOPE; 227 LOG_SCOPE;
232 228
233 // create while blocks 229 // create while blocks
234 llvm::BasicBlock* oldend = gIR->scopeend(); 230 llvm::BasicBlock* oldend = gIR->scopeend();
235 llvm::BasicBlock* whilebb = new llvm::BasicBlock("whilecond", gIR->topfunc(), oldend); 231 llvm::BasicBlock* whilebb = new llvm::BasicBlock("whilecond", gIR->topfunc(), oldend);
269 265
270 ////////////////////////////////////////////////////////////////////////////// 266 //////////////////////////////////////////////////////////////////////////////
271 267
272 void DoStatement::toIR(IRState* p) 268 void DoStatement::toIR(IRState* p)
273 { 269 {
274 static int wsi = 0; 270 Logger::println("DoStatement::toIR(): %s", loc.toChars());
275 Logger::println("DoStatement::toIR(%d): %s", wsi++, toChars());
276 LOG_SCOPE; 271 LOG_SCOPE;
277 272
278 // create while blocks 273 // create while blocks
279 llvm::BasicBlock* oldend = gIR->scopeend(); 274 llvm::BasicBlock* oldend = gIR->scopeend();
280 llvm::BasicBlock* dowhilebb = new llvm::BasicBlock("dowhile", gIR->topfunc(), oldend); 275 llvm::BasicBlock* dowhilebb = new llvm::BasicBlock("dowhile", gIR->topfunc(), oldend);
306 301
307 ////////////////////////////////////////////////////////////////////////////// 302 //////////////////////////////////////////////////////////////////////////////
308 303
309 void ForStatement::toIR(IRState* p) 304 void ForStatement::toIR(IRState* p)
310 { 305 {
311 static int wsi = 0; 306 Logger::println("ForStatement::toIR(): %s", loc.toChars());
312 Logger::println("ForStatement::toIR(%d): %s", wsi++, toChars());
313 LOG_SCOPE; 307 LOG_SCOPE;
314 308
315 // create for blocks 309 // create for blocks
316 llvm::BasicBlock* oldend = gIR->scopeend(); 310 llvm::BasicBlock* oldend = gIR->scopeend();
317 llvm::BasicBlock* forbb = new llvm::BasicBlock("forcond", gIR->topfunc(), oldend); 311 llvm::BasicBlock* forbb = new llvm::BasicBlock("forcond", gIR->topfunc(), oldend);
368 362
369 ////////////////////////////////////////////////////////////////////////////// 363 //////////////////////////////////////////////////////////////////////////////
370 364
371 void BreakStatement::toIR(IRState* p) 365 void BreakStatement::toIR(IRState* p)
372 { 366 {
373 Logger::println("BreakStatement::toIR(): %s", toChars()); 367 Logger::println("BreakStatement::toIR(): %s", loc.toChars());
374 LOG_SCOPE; 368 LOG_SCOPE;
375 369
376 if (ident != 0) { 370 if (ident != 0) {
377 Logger::println("ident = %s", ident->toChars()); 371 Logger::println("ident = %s", ident->toChars());
378 assert(0); 372 assert(0);
384 378
385 ////////////////////////////////////////////////////////////////////////////// 379 //////////////////////////////////////////////////////////////////////////////
386 380
387 void ContinueStatement::toIR(IRState* p) 381 void ContinueStatement::toIR(IRState* p)
388 { 382 {
389 Logger::println("ContinueStatement::toIR(): %s", toChars()); 383 Logger::println("ContinueStatement::toIR(): %s", loc.toChars());
390 LOG_SCOPE; 384 LOG_SCOPE;
391 385
392 if (ident != 0) { 386 if (ident != 0) {
393 Logger::println("ident = %s", ident->toChars()); 387 Logger::println("ident = %s", ident->toChars());
394 assert(0); 388 assert(0);
400 394
401 ////////////////////////////////////////////////////////////////////////////// 395 //////////////////////////////////////////////////////////////////////////////
402 396
403 void OnScopeStatement::toIR(IRState* p) 397 void OnScopeStatement::toIR(IRState* p)
404 { 398 {
405 Logger::println("OnScopeStatement::toIR(): %s", toChars()); 399 Logger::println("OnScopeStatement::toIR(): %s", loc.toChars());
406 LOG_SCOPE; 400 LOG_SCOPE;
407 401
408 assert(statement); 402 assert(statement);
409 //statement->toIR(p); // this seems to be redundant 403 //statement->toIR(p); // this seems to be redundant
410 } 404 }
411 405
412 ////////////////////////////////////////////////////////////////////////////// 406 //////////////////////////////////////////////////////////////////////////////
413 407
414 void TryFinallyStatement::toIR(IRState* p) 408 void TryFinallyStatement::toIR(IRState* p)
415 { 409 {
416 Logger::println("TryFinallyStatement::toIR(): %s", toChars()); 410 Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars());
417 LOG_SCOPE; 411 LOG_SCOPE;
418 412
419 // create basic blocks 413 // create basic blocks
420 llvm::BasicBlock* oldend = p->scopeend(); 414 llvm::BasicBlock* oldend = p->scopeend();
421 415
489 483
490 ////////////////////////////////////////////////////////////////////////////// 484 //////////////////////////////////////////////////////////////////////////////
491 485
492 void TryCatchStatement::toIR(IRState* p) 486 void TryCatchStatement::toIR(IRState* p)
493 { 487 {
494 static int wsi = 0; 488 Logger::println("TryCatchStatement::toIR(): %s", loc.toChars());
495 Logger::println("TryCatchStatement::toIR(%d): %s", wsi++, toChars()); 489 LOG_SCOPE;
496 LOG_SCOPE; 490
497 491 Logger::attention(loc, "try-catch is not yet fully implemented, only the try block will be emitted.");
498 Logger::attention("try-catch is not yet fully implemented, only the try block will be emitted.");
499 492
500 assert(body); 493 assert(body);
501 body->toIR(p); 494 body->toIR(p);
502 495
503 /*assert(catches); 496 /*assert(catches);
510 503
511 ////////////////////////////////////////////////////////////////////////////// 504 //////////////////////////////////////////////////////////////////////////////
512 505
513 void ThrowStatement::toIR(IRState* p) 506 void ThrowStatement::toIR(IRState* p)
514 { 507 {
515 static int wsi = 0; 508 Logger::println("ThrowStatement::toIR(): %s", loc.toChars());
516 Logger::println("ThrowStatement::toIR(%d): %s", wsi++, toChars()); 509 LOG_SCOPE;
517 LOG_SCOPE; 510
518 511 Logger::attention(loc, "throw is not yet implemented, replacing expression with assert(0);");
519 Logger::attention("throw is not yet implemented, replacing expression with assert(0);");
520 512
521 DtoAssert(NULL, &loc, NULL); 513 DtoAssert(NULL, &loc, NULL);
522 514
523 /* 515 /*
524 assert(exp); 516 assert(exp);
572 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp"); 564 return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
573 } 565 }
574 566
575 void SwitchStatement::toIR(IRState* p) 567 void SwitchStatement::toIR(IRState* p)
576 { 568 {
577 Logger::println("SwitchStatement::toIR()"); 569 Logger::println("SwitchStatement::toIR(): %s", loc.toChars());
578 LOG_SCOPE; 570 LOG_SCOPE;
579 571
580 llvm::BasicBlock* oldend = gIR->scopeend(); 572 llvm::BasicBlock* oldend = gIR->scopeend();
581 573
582 // collect the needed cases 574 // collect the needed cases
723 } 715 }
724 716
725 ////////////////////////////////////////////////////////////////////////////// 717 //////////////////////////////////////////////////////////////////////////////
726 void CaseStatement::toIR(IRState* p) 718 void CaseStatement::toIR(IRState* p)
727 { 719 {
728 Logger::println("CaseStatement::toIR(): %s", toChars()); 720 Logger::println("CaseStatement::toIR(): %s", loc.toChars());
729 LOG_SCOPE; 721 LOG_SCOPE;
730 722
731 assert(0); 723 assert(0);
732 } 724 }
733 725
734 ////////////////////////////////////////////////////////////////////////////// 726 //////////////////////////////////////////////////////////////////////////////
735 727
736 void UnrolledLoopStatement::toIR(IRState* p) 728 void UnrolledLoopStatement::toIR(IRState* p)
737 { 729 {
738 Logger::println("UnrolledLoopStatement::toIR(): %s", toChars()); 730 Logger::println("UnrolledLoopStatement::toIR(): %s", loc.toChars());
739 LOG_SCOPE; 731 LOG_SCOPE;
740 732
741 llvm::BasicBlock* oldend = gIR->scopeend(); 733 llvm::BasicBlock* oldend = gIR->scopeend();
742 llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend); 734 llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend);
743 735
758 750
759 ////////////////////////////////////////////////////////////////////////////// 751 //////////////////////////////////////////////////////////////////////////////
760 752
761 void ForeachStatement::toIR(IRState* p) 753 void ForeachStatement::toIR(IRState* p)
762 { 754 {
763 Logger::println("ForeachStatement::toIR(): %s", toChars()); 755 Logger::println("ForeachStatement::toIR(): %s", loc.toChars());
764 LOG_SCOPE; 756 LOG_SCOPE;
765 757
766 //assert(arguments->dim == 1); 758 //assert(arguments->dim == 1);
767 assert(value != 0); 759 assert(value != 0);
768 assert(body != 0); 760 assert(body != 0);
914 906
915 ////////////////////////////////////////////////////////////////////////////// 907 //////////////////////////////////////////////////////////////////////////////
916 908
917 void LabelStatement::toIR(IRState* p) 909 void LabelStatement::toIR(IRState* p)
918 { 910 {
919 Logger::println("LabelStatement::toIR(): %s", toChars()); 911 Logger::println("LabelStatement::toIR(): %s", loc.toChars());
920 LOG_SCOPE; 912 LOG_SCOPE;
921 913
922 assert(tf == NULL); 914 assert(tf == NULL);
923 assert(!isReturnLabel); 915 assert(!isReturnLabel);
924 916
938 930
939 ////////////////////////////////////////////////////////////////////////////// 931 //////////////////////////////////////////////////////////////////////////////
940 932
941 void GotoStatement::toIR(IRState* p) 933 void GotoStatement::toIR(IRState* p)
942 { 934 {
943 Logger::println("GotoStatement::toIR(): %s", toChars()); 935 Logger::println("GotoStatement::toIR(): %s", loc.toChars());
944 LOG_SCOPE; 936 LOG_SCOPE;
945 937
946 assert(tf == NULL); 938 assert(tf == NULL);
947 939
948 llvm::BasicBlock* oldend = gIR->scopeend(); 940 llvm::BasicBlock* oldend = gIR->scopeend();
957 949
958 ////////////////////////////////////////////////////////////////////////////// 950 //////////////////////////////////////////////////////////////////////////////
959 951
960 void WithStatement::toIR(IRState* p) 952 void WithStatement::toIR(IRState* p)
961 { 953 {
962 Logger::println("WithStatement::toIR(): %s", toChars()); 954 Logger::println("WithStatement::toIR(): %s", loc.toChars());
963 LOG_SCOPE; 955 LOG_SCOPE;
964 956
965 assert(exp); 957 assert(exp);
966 assert(body); 958 assert(body);
967 959
974 966
975 ////////////////////////////////////////////////////////////////////////////// 967 //////////////////////////////////////////////////////////////////////////////
976 968
977 void SynchronizedStatement::toIR(IRState* p) 969 void SynchronizedStatement::toIR(IRState* p)
978 { 970 {
979 Logger::println("SynchronizedStatement::toIR(): %s", toChars()); 971 Logger::println("SynchronizedStatement::toIR(): %s", loc.toChars());
980 LOG_SCOPE; 972 LOG_SCOPE;
981 973
982 Logger::attention("synchronized is currently ignored. only the body will be emitted"); 974 Logger::attention(loc, "synchronized is currently ignored. only the body will be emitted");
983 975
984 body->toIR(p); 976 body->toIR(p);
985 } 977 }
986 978
987 ////////////////////////////////////////////////////////////////////////////// 979 //////////////////////////////////////////////////////////////////////////////
988 980
989 void AsmStatement::toIR(IRState* p) 981 void AsmStatement::toIR(IRState* p)
990 { 982 {
991 Logger::println("AsmStatement::toIR(): %s", toChars()); 983 Logger::println("AsmStatement::toIR(): %s", loc.toChars());
992 LOG_SCOPE; 984 LOG_SCOPE;
993 error("%s: inline asm is not yet implemented", loc.toChars()); 985 error("%s: inline asm is not yet implemented", loc.toChars());
994 fatal(); 986 fatal();
995 987
996 assert(!asmcode && !asmalign && !refparam && !naked && !regs); 988 assert(!asmcode && !asmalign && !refparam && !naked && !regs);
1014 1006
1015 // create inline asm callee 1007 // create inline asm callee
1016 llvm::InlineAsm* inasm = llvm::InlineAsm::get(fty, asmstr, "r,r", false); 1008 llvm::InlineAsm* inasm = llvm::InlineAsm::get(fty, asmstr, "r,r", false);
1017 1009
1018 assert(0); 1010 assert(0);
1011 }
1012
1013 //////////////////////////////////////////////////////////////////////////////
1014
1015 void VolatileStatement::toIR(IRState* p)
1016 {
1017 Logger::println("VolatileStatement::toIR(): %s", loc.toChars());
1018 LOG_SCOPE;
1019
1020 Logger::attention(loc, "volatile is currently ignored. only the body will be emitted");
1021
1022 statement->toIR(p);
1019 } 1023 }
1020 1024
1021 ////////////////////////////////////////////////////////////////////////////// 1025 //////////////////////////////////////////////////////////////////////////////
1022 1026
1023 ////////////////////////////////////////////////////////////////////////////// 1027 //////////////////////////////////////////////////////////////////////////////
1042 //STUBST(CompoundStatement); 1046 //STUBST(CompoundStatement);
1043 //STUBST(ScopeStatement); 1047 //STUBST(ScopeStatement);
1044 //STUBST(AsmStatement); 1048 //STUBST(AsmStatement);
1045 //STUBST(TryCatchStatement); 1049 //STUBST(TryCatchStatement);
1046 //STUBST(TryFinallyStatement); 1050 //STUBST(TryFinallyStatement);
1047 STUBST(VolatileStatement); 1051 //STUBST(VolatileStatement);
1048 //STUBST(LabelStatement); 1052 //STUBST(LabelStatement);
1049 //STUBST(ThrowStatement); 1053 //STUBST(ThrowStatement);
1050 STUBST(GotoCaseStatement); 1054 STUBST(GotoCaseStatement);
1051 STUBST(GotoDefaultStatement); 1055 STUBST(GotoDefaultStatement);
1052 //STUBST(GotoStatement); 1056 //STUBST(GotoStatement);