LEFT | RIGHT |
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 scontin = continpc; | 387 scontin = continpc; |
388 continpc = pc; | 388 continpc = pc; |
389 | 389 |
390 // define break and continue labels | 390 // define break and continue labels |
391 if((lab = stmtlabel(n)) != L) { | 391 if((lab = stmtlabel(n)) != L) { |
392 lab->breakpc = breakpc; | 392 lab->breakpc = breakpc; |
393 lab->continpc = continpc; | 393 lab->continpc = continpc; |
394 } | 394 } |
395 gen(n->nincr); // contin: incr | 395 gen(n->nincr); // contin: incr |
396 patch(p1, pc); // test: | 396 patch(p1, pc); // test: |
397 » » bgen(n->ntest, 0, breakpc, -1);»» //» » if(!test
) goto break | 397 » » bgen(n->ntest, 0, -1, breakpc);»» //» » if(!test
) goto break |
398 genlist(n->nbody); //
body | 398 genlist(n->nbody); //
body |
399 gjmp(continpc); | 399 gjmp(continpc); |
400 patch(breakpc, pc); // done: | 400 patch(breakpc, pc); // done: |
401 continpc = scontin; | 401 continpc = scontin; |
402 breakpc = sbreak; | 402 breakpc = sbreak; |
403 if(lab) { | 403 if(lab) { |
404 lab->breakpc = P; | 404 lab->breakpc = P; |
405 lab->continpc = P; | 405 lab->continpc = P; |
406 } | 406 } |
407 break; | 407 break; |
408 | 408 |
409 case OIF: | 409 case OIF: |
410 p1 = gjmp(P); // goto test | 410 p1 = gjmp(P); // goto test |
411 p2 = gjmp(P); // p2: goto else | 411 p2 = gjmp(P); // p2: goto else |
412 patch(p1, pc); // test: | 412 patch(p1, pc); // test: |
413 » » bgen(n->ntest, 0, p2, 0);» » » //» »
if(!test) goto p2 | 413 » » bgen(n->ntest, 0, 0, p2);» » » //» »
if(!test) goto p2 |
414 genlist(n->nbody); //
then | 414 genlist(n->nbody); //
then |
415 p3 = gjmp(P); // goto done | 415 p3 = gjmp(P); // goto done |
416 patch(p2, pc); // else: | 416 patch(p2, pc); // else: |
417 genlist(n->nelse); //
else | 417 genlist(n->nelse); //
else |
418 patch(p3, pc); // done: | 418 patch(p3, pc); // done: |
419 break; | 419 break; |
420 | 420 |
421 case OSWITCH: | 421 case OSWITCH: |
422 sbreak = breakpc; | 422 sbreak = breakpc; |
423 p1 = gjmp(P); // goto test | 423 p1 = gjmp(P); // goto test |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 Node* | 822 Node* |
823 temp(Type *t) | 823 temp(Type *t) |
824 { | 824 { |
825 Node *n; | 825 Node *n; |
826 ········ | 826 ········ |
827 n = nod(OXXX, N, N); | 827 n = nod(OXXX, N, N); |
828 tempname(n, t); | 828 tempname(n, t); |
829 n->sym->def->used = 1; | 829 n->sym->def->used = 1; |
830 return n; | 830 return n; |
831 } | 831 } |
LEFT | RIGHT |