MCPcopy Create free account
hub / github.com/Meridian59/Meridian59 / codegen_statement

Function codegen_statement

blakcomp/codegen.c:584–672  ·  view source on GitHub ↗

/ * 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. */

Source from the content-addressed store, hash-verified

582 * Returns highest # local variable used in code for statement.
583 */
584int 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);

Callers 4

codegen_ifFunction · 0.85
codegen_whileFunction · 0.85
codegen_forFunction · 0.85
codegen_messageFunction · 0.85

Calls 11

flatten_exprFunction · 0.85
codegen_callFunction · 0.85
OutputOpcodeFunction · 0.85
codegen_returnFunction · 0.85
codegen_ifFunction · 0.85
codegen_forFunction · 0.85
codegen_whileFunction · 0.85
OutputIntFunction · 0.85
OutputGotoOffsetFunction · 0.85
SafeMallocFunction · 0.70
list_add_itemFunction · 0.70

Tested by

no test coverage detected