#include <stdio.h>
+#include "../common/xsprintf.h"
+
#include "error.h"
#include "mem.h"
#include "asmline.h"
/* Interal routine to create a new line from the given text */
{
char Buf [8192];
- int OVF;
unsigned Len;
Line* L;
/* Make a string from the given format and arguments */
-#if defined(__WATCOMC__)
- OVF = (_vbprintf (Buf, sizeof (Buf), Format, ap) >= sizeof (S));
-#else
- /* Assume gcc running on a Unix OS */
- OVF = (vsnprintf (Buf, sizeof (Buf), Format, ap) < 0);
-#endif
- if (OVF) {
- Internal ("String size overflow");
- }
+ xvsprintf (Buf, sizeof (Buf), Format, ap);
/* Get the length of the line */
Len = strlen (Buf);
static int funcargs;
-void g_enter (unsigned flags, const char* Name, unsigned argsize)
-/* Function prologue */
+void g_enter (unsigned flags, unsigned argsize)
+/* Function prologue */
{
- g_defgloblabel (Name); /* Define function name as label */
if ((flags & CF_FIXARGC) != 0) {
/* Just remember the argument size for the leave */
funcargs = argsize;
-void g_enter (unsigned flags, const char* Name, unsigned argsize);
+void g_enter (unsigned flags, unsigned argsize);
/* Function prologue */
void g_leave (int flags, int val);
/*****************************************************************************/
-/* code */
+/* Subroutines working with struct Function */
/*****************************************************************************/
F->FuncEntry = Sym;
F->ReturnType = Sym->Type + 1 + DECODE_SIZE;
F->Desc = DecodePtr (Sym->Type + 1);
- F->EntryCode = GetCodePos ();
+ F->EntryCode = 0;
F->LocalMax = 0;
F->LocalSize = 0;
F->RetLab = GetLabel ();
+void RememberEntry (Function* F)
+/* Remember the current output position for local space creation later */
+{
+ F->EntryCode = GetCodePos ();
+}
+
+
+
unsigned GetRetLab (const Function* F)
/* Return the return jump label */
{
-unsigned AllocLocalSpace (Function* F, unsigned Size)
+int AllocLocalSpace (Function* F, unsigned Size)
/* Allocate space for the function locals, return stack offset */
{
/* Remember the current offset */
F->LocalMax = F->LocalSize;
}
- /* Return the offset */
- return Offs;
+ /* Return the offset, it is below the initial stack pointer */
+ return -(int)Offs;
}
+unsigned GetLocalSpace (const Function* F)
+/* Get the local variable space needed for the function */
+{
+ return F->LocalMax;
+}
+
+
+
+/*****************************************************************************/
+/* code */
+/*****************************************************************************/
+
+
+
void NewFunc (SymEntry* Func)
/* Parse argument declarations and function body. */
{
/* C functions cannot currently have __fastcall__ calling conventions */
if (IsFastCallFunc (Func->Type)) {
- Error (ERR_FASTCALL);
+ Error (ERR_FASTCALL);
}
/* Need a starting curly brace */
/* Setup register variables */
InitRegVars ();
- /* Switch to the code segment and generate function entry code */
+ /* Switch to the code segment and define the function name label */
g_usecode ();
- g_enter (TypeOf (Func->Type), Func->Name, GetParamSize (CurrentFunc));
+ g_defgloblabel (Func->Name);
+
+ /* Generate function entry code if needed */
+ g_enter (TypeOf (Func->Type), GetParamSize (CurrentFunc));
+
+ /* Remember the current code position to create local variable space once
+ * we have created the function body itself.
+ */
+ RememberEntry (Func);
/* Parse the function body */
oursp = 0;
int HasVoidReturn (const Function* F);
/* Return true if the function does not have a return value */
+void RememberEntry (Function* F);
+/* Remember the current output position for local space creation later */
+
unsigned GetRetLab (const Function* F);
/* Return the return jump label */
-unsigned AllocLocalSpace (Function* F, unsigned Size);
+int AllocLocalSpace (Function* F, unsigned Size);
/* Allocate space for the function locals, return stack offset */
void FreeLocalSpace (Function* F, unsigned Size);
void NewFunc (struct SymEntry* Func);
/* Parse argument declarations and function body. */
+unsigned GetLocalSpace (const Function* F);
+/* Get the local variable space needed for the function */
+
/* End of function.h */
#endif
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* hashstr.c */
-/* */
-/* Hash function for strings */
-/* */
-/* */
-/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
-/* */
-/* */
-/* This software is provided 'as-is', without any expressed or implied */
-/* warranty. In no event will the authors be held liable for any damages */
-/* arising from the use of this software. */
-/* */
-/* Permission is granted to anyone to use this software for any purpose, */
-/* including commercial applications, and to alter it and redistribute it */
-/* freely, subject to the following restrictions: */
-/* */
-/* 1. The origin of this software must not be misrepresented; you must not */
-/* claim that you wrote the original software. If you use this software */
-/* in a product, an acknowledgment in the product documentation would be */
-/* appreciated but is not required. */
-/* 2. Altered source versions must be plainly marked as such, and must not */
-/* be misrepresented as being the original software. */
-/* 3. This notice may not be removed or altered from any source */
-/* distribution. */
-/* */
-/*****************************************************************************/
-
-
-
-#include "hashstr.h"
-
-
-
-/*****************************************************************************/
-/* Code */
-/*****************************************************************************/
-
-
-
-unsigned HashStr (const char* S)
-/* Return a hash value for the given string */
-{
- unsigned L, H;
-
- /* Do the hash */
- H = L = 0;
- while (*S) {
- H = ((H << 3) ^ ((unsigned char) *S++)) + L++;
- }
- return H;
-}
-
-
-
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* hashstr.h */
-/* */
-/* Hash function for strings */
-/* */
-/* */
-/* */
-/* (C) 1998 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
-/* */
-/* */
-/* This software is provided 'as-is', without any expressed or implied */
-/* warranty. In no event will the authors be held liable for any damages */
-/* arising from the use of this software. */
-/* */
-/* Permission is granted to anyone to use this software for any purpose, */
-/* including commercial applications, and to alter it and redistribute it */
-/* freely, subject to the following restrictions: */
-/* */
-/* 1. The origin of this software must not be misrepresented; you must not */
-/* claim that you wrote the original software. If you use this software */
-/* in a product, an acknowledgment in the product documentation would be */
-/* appreciated but is not required. */
-/* 2. Altered source versions must be plainly marked as such, and must not */
-/* be misrepresented as being the original software. */
-/* 3. This notice may not be removed or altered from any source */
-/* distribution. */
-/* */
-/*****************************************************************************/
-
-
-
-#ifndef HASHSTR_H
-#define HASHSTR_H
-
-
-
-/*****************************************************************************/
-/* Code */
-/*****************************************************************************/
-
-
-
-unsigned HashStr (const char* S);
-/* Return a hash value for the given string */
-
-
-
-/* End of hashstr.h */
-
-#endif
-
-
-
#include <stdio.h>
#include <string.h>
+#include "../common/hashstr.h"
+
#include "error.h"
-#include "hashstr.h"
#include "mem.h"
#include "macrotab.h"
function.o \
global.o \
goto.o \
- hashstr.o \
ident.o \
include.o \
io.o \
symtab.o \
util.o
+LIBS = ../common/common.a
+
EXECS = cc65
cc65: $(OBJS)
- $(CC) $(LDFLAGS) -o cc65 $(CFLAGS) $(OBJS)
+ $(CC) $(LDFLAGS) -o cc65 $(CFLAGS) $(OBJS) $(LIBS)
clean:
rm -f *~ core *.map
function.obj \
global.obj \
goto.obj \
- hashstr.obj \
ident.obj \
include.obj \
io.obj \
FILE function.obj
FILE global.obj
FILE goto.obj
-FILE hashstr.obj
FILE ident.obj
FILE include.obj
FILE io.obj
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+
+#include "../common/hashstr.h"
#include "asmcode.h"
#include "asmlabel.h"
#include "error.h"
#include "funcdesc.h"
#include "global.h"
-#include "hashstr.h"
#include "io.h"
#include "mem.h"
#include "symentry.h"
}
}
}
-
+
/* If the entry is a label, check if it was defined in the function */
if (Flags & SC_LABEL) {
if ((Flags & SC_DEF) == 0) {
Warning (WARN_UNUSED_ITEM, Entry->Name);
}
}
-
+
}
/* Next entry */