/ * codegen_statement: Generate code for a single statement. * numlocals should be # of local variables for message excluding temps. * Returns highest # local variable used in code for statement. */
| 582 | * Returns highest # local variable used in code for statement. |
| 583 | */ |
| 584 | int codegen_statement(stmt_type s, int numlocals) |
| 585 | { |
| 586 | opcode_type opcode; |
| 587 | int our_maxtemp = numlocals; /* highest numbered temporary required for this statement alone */ |
| 588 | |
| 589 | /* Save line # debugging information */ |
| 590 | if (debug_bof && s->lineno != 0) |
| 591 | { |
| 592 | DebugLine *d = (DebugLine *) SafeMalloc(sizeof(DebugLine)); |
| 593 | d->lineno = s->lineno; |
| 594 | d->offset = FileCurPos(outfile); |
| 595 | debug_lines = list_add_item(debug_lines, d); |
| 596 | } |
| 597 | |
| 598 | memset(&opcode, 0, sizeof(opcode)); /* Set opcode to all zeros */ |
| 599 | switch (s->type) |
| 600 | { |
| 601 | case S_ASSIGN: |
| 602 | { |
| 603 | assign_stmt_type stmt = s->value.assign_stmt_val; |
| 604 | |
| 605 | /* Place result directly in lhs */ |
| 606 | our_maxtemp = flatten_expr(stmt->rhs, stmt->lhs, numlocals); |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | case S_CALL: |
| 611 | our_maxtemp = codegen_call(s->value.call_stmt_val, NULL, numlocals); |
| 612 | break; |
| 613 | |
| 614 | case S_PROP: |
| 615 | opcode.command = RETURN; |
| 616 | opcode.dest = PROPAGATE; |
| 617 | OutputOpcode(outfile, opcode); |
| 618 | break; |
| 619 | |
| 620 | case S_RETURN: |
| 621 | our_maxtemp = codegen_return(s->value.return_stmt_val, numlocals); |
| 622 | break; |
| 623 | |
| 624 | case S_IF: |
| 625 | our_maxtemp = codegen_if(s->value.if_stmt_val, numlocals); |
| 626 | break; |
| 627 | |
| 628 | case S_FOR: |
| 629 | our_maxtemp = codegen_for(s->value.for_stmt_val, numlocals); |
| 630 | break; |
| 631 | |
| 632 | case S_WHILE: |
| 633 | our_maxtemp = codegen_while(s->value.while_stmt_val, numlocals); |
| 634 | break; |
| 635 | |
| 636 | case S_BREAK: |
| 637 | /* Goto end of loop */ |
| 638 | opcode.command = GOTO; |
| 639 | opcode.source1 = 0; |
| 640 | opcode.source2 = GOTO_UNCONDITIONAL; |
| 641 | OutputOpcode(outfile, opcode); |
no test coverage detected