717 |
717 |
718 /***********************************/ |
718 /***********************************/ |
719 /* B 2.1 Instructions and Operands */ |
719 /* B 2.1 Instructions and Operands */ |
720 /***********************************/ |
720 /***********************************/ |
721 |
721 |
722 /* please see the comment before the RET_operator_c visitor for details... */ |
|
723 #define END_LABEL VAR_LEADER "end" |
|
724 |
|
725 /*| instruction_list il_instruction */ |
722 /*| instruction_list il_instruction */ |
726 void *visit(instruction_list_c *symbol) { |
723 void *visit(instruction_list_c *symbol) { |
727 |
724 |
728 /* Declare the backup to the default variable, that will store the result |
725 /* Declare the backup to the default variable, that will store the result |
729 * of the IL operations executed inside a parenthesis... |
726 * of the IL operations executed inside a parenthesis... |
739 s4o.print(s4o.indent_spaces); |
736 s4o.print(s4o.indent_spaces); |
740 print_backup_variable(); |
737 print_backup_variable(); |
741 s4o.print(".INTvar = 0;\n\n"); |
738 s4o.print(".INTvar = 0;\n\n"); |
742 |
739 |
743 print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
740 print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
744 |
|
745 /* label not used by at least one goto result in a warning. |
|
746 * To work around this we introduce the useless goto |
|
747 * to humour the compiler... |
|
748 */ |
|
749 s4o.print("\n"); |
|
750 s4o.print(s4o.indent_spaces); |
|
751 s4o.print("/* to humour the compiler, we insert a goto */\n"); |
|
752 s4o.print(s4o.indent_spaces); |
|
753 s4o.print("goto "); |
|
754 s4o.print(END_LABEL); |
|
755 s4o.print(";\n"); |
|
756 |
|
757 /* write the label marking the end of the code block */ |
|
758 /* please see the comment before the RET_operator_c visitor for details... */ |
|
759 s4o.print("\n"); |
|
760 s4o.print(s4o.indent_spaces); |
|
761 s4o.print(END_LABEL); |
|
762 s4o.print(":\n"); |
|
763 s4o.indent_right(); |
|
764 /* since every label must be followed by at least one statement, and |
|
765 * only the functions will introduce the return statement after this label, |
|
766 * function blocks written in IL would result in invalid C++ code. |
|
767 * To work around this we introduce the equivalent of a 'nop' operation |
|
768 * to humour the compiler... |
|
769 */ |
|
770 s4o.print(s4o.indent_spaces); |
|
771 s4o.print("/* to humour the compiler, we insert a nop */\n"); |
|
772 s4o.print(s4o.indent_spaces); |
|
773 this->default_variable_name.accept(*this); |
|
774 s4o.print(" = "); |
|
775 this->default_variable_name.accept(*this); |
|
776 s4o.print(";\n"); |
|
777 s4o.indent_left(); |
|
778 |
741 |
779 return NULL; |
742 return NULL; |
780 } |
743 } |
781 |
744 |
782 |
745 |