scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit dfaab330047216d4902aa71dea50c28728698da4
parent f693fc0846b9cd1727a65994793c460bc0387e8f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 27 Aug 2015 16:40:58 +0200

remove the type in return statements

The type is already in the optional expression,
so it is not needed and make 'y' more similar to
'j'.

Diffstat:
Mcc1/code.c | 22+++++++---------------
Mcc1/ir.md | 4++--
Mcc1/stmt.c | 2+-
Mcc1/tests/test001.c | 2+-
Mcc1/tests/test003.c | 6+++---
Mcc1/tests/test004.c | 4++--
Mcc1/tests/test005.c | 4++--
Mcc1/tests/test006.c | 10+++++-----
Mcc1/tests/test007.c | 2+-
Mcc1/tests/test008.c | 2+-
Mcc1/tests/test009.c | 4++--
Mcc1/tests/test010.c | 2+-
Mcc1/tests/test011.c | 6+++---
Mcc1/tests/test012.c | 14+++++++-------
Mcc1/tests/test014.c | 2+-
Mcc1/tests/test015.c | 4++--
Mcc1/tests/test016.c | 8++++----
Mcc1/tests/test017.c | 6+++---
Mcc1/tests/test018.c | 10+++++-----
19 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -13,7 +13,7 @@ static void emitbin(unsigned, void *), emitswitcht(unsigned, void *), emitexp(unsigned, void *), emitsymid(unsigned, void *), emittext(unsigned, void *), emitfun(unsigned, void *), - emitret(unsigned, void *), emitdcl(unsigned, void *); + emitdcl(unsigned, void *); char *optxt[] = { [OADD] = "+", @@ -58,9 +58,10 @@ char *optxt[] = { [OCASE] = "\tv\tL%d", [OJUMP] = "\tj\tL%d\n", [OBRANCH] = "\tj\tL%d", - [OEFUN] = "}", - [OELOOP] = "\tb", - [OBLOOP] = "\td", + [OEFUN] = "}\n", + [OELOOP] = "\tb\n", + [OBLOOP] = "\td\n", + [ORET] = "\ty", [OPAR] = "p", [OCALL] = "c", [OFIELD] = "." @@ -118,7 +119,7 @@ void (*opcode[])(unsigned, void *) = { [OELOOP] = emittext, [OBLOOP] = emittext, [OFUN] = emitfun, - [ORET] = emitret, + [ORET] = emittext, [ODECL] = emitdcl, [OSWITCH] = emitswitch, [OSWITCHT] = emitswitcht, @@ -347,18 +348,9 @@ emitfun(unsigned op, void *arg) } static void -emitret(unsigned op, void *arg) -{ - Type *tp = arg; - - fputs("\ty", stdout); - emitletter(tp); -} - -static void emittext(unsigned op, void *arg) { - puts(optxt[op]); + fputs(optxt[op], stdout); } static void diff --git a/cc1/ir.md b/cc1/ir.md @@ -246,7 +246,7 @@ generates: > } Another form of jump is the return statement, which uses the -letter 'y' with a return type and an optional expression. +letter 'y' with an optional expression. For example: > int @@ -261,7 +261,7 @@ produces: > G1 F1 main > { > - -> yI #I10 +> y #I10 > } diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -143,7 +143,7 @@ Return(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) else if ((np = convert(np, tp, 0)) == NULL) error("incorrect type in return"); } - emit(ORET, tp); + emit(ORET, NULL); emit(OEXPR, np); } diff --git a/cc1/tests/test001.c b/cc1/tests/test001.c @@ -9,7 +9,7 @@ G2 F1 main { - X1 "68656C6C6F20776F726C640A 'P pP cI - yI #I0 + y #I0 } */ diff --git a/cc1/tests/test003.c b/cc1/tests/test003.c @@ -6,17 +6,17 @@ F1 G1 F1 foo { - - yI #I2A + y #I2A } G2 F1 bar { - - yI #I18 + y #I18 } G3 F1 main { - - yI G1 cI + y G1 cI } */ diff --git a/cc1/tests/test004.c b/cc1/tests/test004.c @@ -23,9 +23,9 @@ A2 I x A2 A2 A2 #I1 >I #I1 #I0 ?I +I :I A2 A2 A2 #I4 <I #I1 #I0 ?I +I :I j L3 A2 #I4 =I - yI #I1 + y #I1 L3 - yI #I0 + y #I0 } */ diff --git a/cc1/tests/test005.c b/cc1/tests/test005.c @@ -13,9 +13,9 @@ A2 I x A2 A2 ~I :I A2 A2 _I :I j L3 A2 #I2 =I - yI #I1 + y #I1 L3 - yI #I0 + y #I0 } */ diff --git a/cc1/tests/test006.c b/cc1/tests/test006.c @@ -11,7 +11,7 @@ G2 F1 main { - j L2 #I0 - yI #I1 + y #I1 j L3 L2 j L4 #I0 @@ -19,18 +19,18 @@ L2 L4 j L6 #I1 j L7 G1 MI #I0 =I - yI #I1 + y #I1 j L8 L7 - yI #I0 + y #I0 L8 j L9 L6 - yI #I1 + y #I1 L9 L5 L3 - yI #I1 + y #I1 } */ diff --git a/cc1/tests/test007.c b/cc1/tests/test007.c @@ -16,7 +16,7 @@ L5 j L3 A2 #I0 !I b L4 - yI A2 + y A2 } */ diff --git a/cc1/tests/test008.c b/cc1/tests/test008.c @@ -20,7 +20,7 @@ L5 j L5 A2 #I14 <I b L6 - yI A2 #I14 -I + y A2 #I14 -I } */ diff --git a/cc1/tests/test009.c b/cc1/tests/test009.c @@ -17,9 +17,9 @@ L5 b L4 j L6 A2 #IA =I - yI #I1 + y #I1 L6 - yI #I0 + y #I0 } */ diff --git a/cc1/tests/test010.c b/cc1/tests/test010.c @@ -55,7 +55,7 @@ L16 j L14 #I1 b L15 - yI A2 #IF -I + y A2 #IF -I } */ diff --git a/cc1/tests/test011.c b/cc1/tests/test011.c @@ -10,13 +10,13 @@ G1 F1 main - L2 j L3 - yI #I1 + y #I1 L4 - yI #I0 + y #I0 L3 L5 j L4 - yI #I1 + y #I1 } */ diff --git a/cc1/tests/test012.c b/cc1/tests/test012.c @@ -22,7 +22,7 @@ L8 L11 j L12 L13 - yI #I1 + y #I1 j L9 L10 t #2 @@ -34,11 +34,11 @@ L7 t #1 v L8 #I0 L6 - yI #I2 + y #I2 L12 s L15 A2 L16 - yI #I3 + y #I3 j L14 L15 t #1 @@ -48,7 +48,7 @@ L14 A2 #I2 :I L19 L20 - yI #I4 + y #I4 j L17 L18 t #1 @@ -56,11 +56,11 @@ L18 L17 s L22 A2 L23 - yI A2 + y A2 L24 - yI #I1 + y #I1 L25 - yI #I1 + y #I1 j L21 L22 t #3 diff --git a/cc1/tests/test014.c b/cc1/tests/test014.c @@ -29,7 +29,7 @@ T3 M i R4 W j X5 I k T6 Z a - yI #I0 + y #I0 } F2 I G6 F2 func2 diff --git a/cc1/tests/test015.c b/cc1/tests/test015.c @@ -24,8 +24,8 @@ G13 F1 main j L2 A3 S2 s A4 I s - yI A4 - yI A3 M11 .S5 M6 .I A3 M11 .S5 M10 .S8 M9 .I +I + y A4 + y A3 M11 .S5 M6 .I A3 M11 .S5 M10 .S8 M9 .I +I L2 ???? */ diff --git a/cc1/tests/test016.c b/cc1/tests/test016.c @@ -16,14 +16,14 @@ A4 P p A4 A2 'P :P A4 @I #I0 :I j L5 A2 #I0 =I - yI #I1 + y #I1 L5 A4 G1 'P :P A4 @I #I0 :I j L6 A4 #I0 IP !I - yI #I1 + y #I1 L6 - yI #I0 + y #I0 } G3 F1 func2 { @@ -38,7 +38,7 @@ A4 P pp A4 @P @I #I0 :I L5 A2 #I0 IP :P - yI A1 + y A1 } ???? */ diff --git a/cc1/tests/test017.c b/cc1/tests/test017.c @@ -21,12 +21,12 @@ A3 S6 v A3 M8 .P @S2 M3 .I #I1 :I A3 M8 .P @S2 M4 .I #I2 :I j L4 A2 M3 .I #I1 =I - yI #I1 + y #I1 L4 j L5 A2 M4 .I #I2 =I - yI #I2 + y #I2 L5 - yI #I0 + y #I0 } */ diff --git a/cc1/tests/test018.c b/cc1/tests/test018.c @@ -18,18 +18,18 @@ A10 V9 v A4 'P #P4 +P #P3 +P @M #M2 :M A10 'P @I #I2 :I j L12 A4 'P #P4 +P #P3 +P @M MI #I2 =I - yI #I1 + y #I1 L12 j L13 A6 #P4 +P #P3 +P @M MI #I2 =I - yI #I1 + y #I1 L13 j L14 A8 @M MI #I2 =I - yI #I1 + y #I1 L14 j L15 A10 @I #I2 =I - yI #I1 + y #I1 L15 - yI #I0 + y #I0 } */