OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 * portable half of code generator. | 6 * portable half of code generator. |
7 * mainly statements and control flow. | 7 * mainly statements and control flow. |
8 */ | 8 */ |
9 | 9 |
10 #include <u.h> | 10 #include <u.h> |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 cgen_dcl(n->left); | 465 cgen_dcl(n->left); |
466 break; | 466 break; |
467 | 467 |
468 case OAS: | 468 case OAS: |
469 if(gen_as_init(n)) | 469 if(gen_as_init(n)) |
470 break; | 470 break; |
471 cgen_as(n->left, n->right); | 471 cgen_as(n->left, n->right); |
472 break; | 472 break; |
473 | 473 |
474 case OCALLMETH: | 474 case OCALLMETH: |
475 » » cgen_callmeth(n, 0); | 475 » » cgen_callmeth(n, nil, 0); |
476 break; | 476 break; |
477 | 477 |
478 case OCALLINTER: | 478 case OCALLINTER: |
479 » » cgen_callinter(n, N, 0); | 479 » » cgen_callinter(n, N, nil, 0); |
480 break; | 480 break; |
481 | 481 |
482 case OCALLFUNC: | 482 case OCALLFUNC: |
483 » » cgen_call(n, 0); | 483 » » cgen_call(n, nil, 0); |
484 break; | 484 break; |
485 | 485 |
486 case OPROC: | 486 case OPROC: |
487 cgen_proc(n, 1); | 487 cgen_proc(n, 1); |
488 break; | 488 break; |
489 | 489 |
490 case ODEFER: | 490 case ODEFER: |
491 cgen_proc(n, 2); | 491 cgen_proc(n, 2); |
492 break; | 492 break; |
493 | 493 |
(...skipping 20 matching lines...) Expand all Loading... |
514 lineno = lno; | 514 lineno = lno; |
515 } | 515 } |
516 | 516 |
517 /* | 517 /* |
518 * generate call to non-interface method | 518 * generate call to non-interface method |
519 * proc=0 normal call | 519 * proc=0 normal call |
520 * proc=1 goroutine run in new proc | 520 * proc=1 goroutine run in new proc |
521 * proc=2 defer call save away stack | 521 * proc=2 defer call save away stack |
522 */ | 522 */ |
523 void | 523 void |
524 cgen_callmeth(Node *n, int proc) | 524 cgen_callmeth(Node *n, Node *tmp, int proc) |
525 { | 525 { |
526 Node n2; | 526 Node n2; |
527 Node *l; | 527 Node *l; |
528 | 528 |
529 // generate a rewrite in n2 for the method call | 529 // generate a rewrite in n2 for the method call |
530 // (p.f)(...) goes to (f)(p,...) | 530 // (p.f)(...) goes to (f)(p,...) |
531 | 531 |
532 l = n->left; | 532 l = n->left; |
533 if(l->op != ODOTMETH) | 533 if(l->op != ODOTMETH) |
534 fatal("cgen_callmeth: not dotmethod: %N"); | 534 fatal("cgen_callmeth: not dotmethod: %N"); |
535 | 535 |
536 n2 = *n; | 536 n2 = *n; |
537 n2.op = OCALLFUNC; | 537 n2.op = OCALLFUNC; |
538 n2.left = l->right; | 538 n2.left = l->right; |
539 n2.left->type = l->type; | 539 n2.left->type = l->type; |
540 | 540 |
541 if(n2.left->op == ONAME) | 541 if(n2.left->op == ONAME) |
542 n2.left->class = PFUNC; | 542 n2.left->class = PFUNC; |
543 » cgen_call(&n2, proc); | 543 » cgen_call(&n2, tmp, proc); |
544 } | 544 } |
545 | 545 |
546 /* | 546 /* |
547 * generate code to start new proc running call n. | 547 * generate code to start new proc running call n. |
548 */ | 548 */ |
549 static void | 549 static void |
550 cgen_proc(Node *n, int proc) | 550 cgen_proc(Node *n, int proc) |
551 { | 551 { |
552 switch(n->left->op) { | 552 switch(n->left->op) { |
553 default: | 553 default: |
554 fatal("cgen_proc: unknown call %O", n->left->op); | 554 fatal("cgen_proc: unknown call %O", n->left->op); |
555 | 555 |
556 case OCALLMETH: | 556 case OCALLMETH: |
557 » » cgen_callmeth(n->left, proc); | 557 » » cgen_callmeth(n->left, n->alloc, proc); |
558 break; | 558 break; |
559 | 559 |
560 case OCALLINTER: | 560 case OCALLINTER: |
561 » » cgen_callinter(n->left, N, proc); | 561 » » cgen_callinter(n->left, N, n->alloc, proc); |
562 break; | 562 break; |
563 | 563 |
564 case OCALLFUNC: | 564 case OCALLFUNC: |
565 » » cgen_call(n->left, proc); | 565 » » cgen_call(n->left, n->alloc, proc); |
566 break; | 566 break; |
567 } | 567 } |
568 | 568 |
569 } | 569 } |
570 | 570 |
571 /* | 571 /* |
572 * generate declaration. | 572 * generate declaration. |
573 * have to allocate heap copy | 573 * have to allocate heap copy |
574 * for escaped variables. | 574 * for escaped variables. |
575 */ | 575 */ |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 Node* | 962 Node* |
963 temp(Type *t) | 963 temp(Type *t) |
964 { | 964 { |
965 Node *n; | 965 Node *n; |
966 ········ | 966 ········ |
967 n = nod(OXXX, N, N); | 967 n = nod(OXXX, N, N); |
968 tempname(n, t); | 968 tempname(n, t); |
969 n->sym->def->used = 1; | 969 n->sym->def->used = 1; |
970 return n->orig; | 970 return n->orig; |
971 } | 971 } |
OLD | NEW |