]> git.sur5r.net Git - cc65/blobdiff - src/cc65/function.c
Fixed a bug in CascadeSwitch
[cc65] / src / cc65 / function.c
index 3ed80600f2d4fa729ecfbb3afa9767cf6d760d8e..06786e6e8cf16a6fa0f5a7d12f1683db42098f50 100644 (file)
@@ -47,6 +47,7 @@
 #include "litpool.h"
 #include "locals.h"
 #include "scanner.h"
+#include "segments.h"
 #include "stmt.h"
 #include "symtab.h"
 #include "function.h"
@@ -190,9 +191,6 @@ void AllocLocalSpace (Function* F)
 {
     if (F->Reserved > 0) {
 
-       /* Switch to the code segment */
-       g_usecode ();
-
        /* Create space on the stack */
        g_space (F->Reserved);
 
@@ -217,7 +215,6 @@ void NewFunc (SymEntry* Func)
 {
     int HadReturn;
     int IsVoidFunc;
-    unsigned Flags;
 
     /* Get the function descriptor from the function entry */
     FuncDesc* D = Func->V.F.Func;
@@ -249,7 +246,7 @@ void NewFunc (SymEntry* Func)
     InitRegVars ();
 
     /* Allocate code and data segments for this function */
-    g_pushseg (&Func->V.F.CS, &Func->V.F.DS, Func->Name);
+    Func->V.F.Seg = PushSegments (Func);
 
     /* If this is a fastcall function, push the last parameter onto the stack */
     if (IsFastCallFunc (Func->Type) && D->ParamCount > 0) {
@@ -297,9 +294,9 @@ void NewFunc (SymEntry* Func)
 
     /* Now process statements in this block */
     HadReturn = 0;
-    while (curtok != TOK_RCURLY) {
-       if (curtok != TOK_CEOF) {
-           HadReturn = Statement ();
+    while (CurTok.Tok != TOK_RCURLY) {
+       if (CurTok.Tok != TOK_CEOF) {
+           HadReturn = Statement (0);
        } else {
            break;
        }
@@ -317,14 +314,13 @@ void NewFunc (SymEntry* Func)
 #endif
 
     /* Output the function exit code label */
-    g_defloclabel (GetRetLab (CurrentFunc));
+    g_defcodelabel (GetRetLab (CurrentFunc));
 
     /* Restore the register variables */
     RestoreRegVars (!IsVoidFunc);
 
     /* Generate the exit code */
-    Flags = IsVoidFunc? CF_NONE : CF_REG;
-    g_leave (Flags, 0);
+    g_leave ();
 
     /* Eat the closing brace */
     ConsumeRCurly ();
@@ -339,7 +335,7 @@ void NewFunc (SymEntry* Func)
     LeaveFunctionLevel ();
 
     /* Switch back to the old segments */
-    g_popseg ();
+    PopSegments ();
 
     /* Reset the current function pointer */
     FreeFunction (CurrentFunc);