From 0b8262a167efb94ecdd056b90830cd58bdad36fc Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 6 Aug 1987 09:55:00 +0000 Subject: [PATCH] handle returns better --- lang/cem/cemcom/Makefile | 2 +- lang/cem/cemcom/code.c | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lang/cem/cemcom/Makefile b/lang/cem/cemcom/Makefile index a2c508a34..334fc6396 100644 --- a/lang/cem/cemcom/Makefile +++ b/lang/cem/cemcom/Makefile @@ -97,7 +97,7 @@ HFILES = $(HSRC) $(GHSRC) $(GHSTRSRC) # generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ - print Xref lxref hfiles Cfiles $(GHSRC) $(GSRC) longnames $(LCSRC) + print hfiles Cfiles $(GHSRC) $(GSRC) longnames $(LCSRC) # include files containing ALLOCDEF specifications OBJ = $(COBJ) $(LOBJ) $(GOBJ) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 0031317d3..6ccea0b96 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -161,8 +161,8 @@ code_scope(text, def) } } -static label return_label; -/* static char return_expr_occurred; */ +static label return_label, return2_label; +static char return_expr_occurred; static struct type *func_tp; static arith func_size; static label func_res_label; @@ -217,7 +217,8 @@ begin_proc(name, def) /* to be called when entering a procedure */ */ lab_count = (label) 1; return_label = text_label(); - /* return_expr_occurred = 0; */ + return2_label = text_label(); + return_expr_occurred = 0; LocalInit(); prc_entry(name); if (! options['L']) { /* profiling */ @@ -255,18 +256,21 @@ end_proc(fbytes) if (options['d']) DfaEndFunction(); #endif DATAFLOW - prc_exit(); - C_asp(-func_size); /* arbitrary return value */ + C_df_ilb(return2_label); + if (return_expr_occurred) C_asp(-func_size); C_df_ilb(return_label); prc_exit(); - if (func_res_label != 0) { - C_lae_dlb(func_res_label, (arith)0); - store_block(func_size, func_tp->tp_align); - C_lae_dlb(func_res_label, (arith)0); - C_ret(pointer_size); + if (return_expr_occurred) { + if (func_res_label != 0) { + C_lae_dlb(func_res_label, (arith)0); + store_block(func_size, func_tp->tp_align); + C_lae_dlb(func_res_label, (arith)0); + C_ret(pointer_size); + } + else + C_ret(func_size); } - else - C_ret(func_size); + else C_ret((arith) 0); /* getting the number of "local" bytes is posponed until here, because copying the function result in "func_res_label" may @@ -300,8 +304,7 @@ do_return() probably smarter than generating a direct return. Return sequences may be expensive. */ - C_asp(-func_size); /* arbitrary return value */ - C_bra(return_label); + C_bra(return2_label); } do_return_expr(expr) @@ -313,7 +316,7 @@ do_return_expr(expr) ch7cast(&expr, RETURN, func_tp); code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); C_bra(return_label); - /* return_expr_occurred = 1; */ + return_expr_occurred = 1; } code_declaration(idf, expr, lvl, sc) -- 2.34.1