* Added several type casts to increase C++ compatibility.
* __fixargs__ is now an actual function symbol and no longer handled in the scanner. * Additional symbol __argsize__ that is a constant in normal functions and a const local variable for variadic functions. Using this symbol, the va_arg macro gets a lot simpler and smaller. * Added special code to handle the fixed parameters of a variadic function. The code has some overhead, but the va_fix macro is no longer needed (and the compiler generated code is better than va_fix anyway). git-svn-id: svn://svn.cc65.org/cc65/trunk@652 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Marker for an assembler code position */
|
/* Marker for an assembler code position */
|
||||||
typedef struct Line_* CodeMark;
|
typedef struct Line* CodeMark;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ static Line* NewLine (const char* Format, va_list ap)
|
|||||||
Len = strlen (Buf);
|
Len = strlen (Buf);
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
L = xmalloc (sizeof (Line) + Len);
|
L = (Line*) xmalloc (sizeof (Line) + Len);
|
||||||
|
|
||||||
/* Partially initialize the struct (the remaining fields are initialized
|
/* Partially initialize the struct (the remaining fields are initialized
|
||||||
* by the caller).
|
* by the caller).
|
||||||
|
|||||||
@@ -52,8 +52,8 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Structure that contains one line */
|
/* Structure that contains one line */
|
||||||
typedef struct Line_ Line;
|
typedef struct Line Line;
|
||||||
struct Line_ {
|
struct Line {
|
||||||
Line* Next; /* Next line on double linked list */
|
Line* Next; /* Next line on double linked list */
|
||||||
Line* Prev; /* Revious line in list */
|
Line* Prev; /* Revious line in list */
|
||||||
unsigned Flags; /* Flags for this line */
|
unsigned Flags; /* Flags for this line */
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ static void UseSeg (int NewSeg)
|
|||||||
/* Switch to a specific segment */
|
/* Switch to a specific segment */
|
||||||
{
|
{
|
||||||
if (CurSeg != NewSeg) {
|
if (CurSeg != NewSeg) {
|
||||||
CurSeg = NewSeg;
|
CurSeg = (segment_t) NewSeg;
|
||||||
AddCodeLine (".segment\t\"%s\"", SegmentNames [CurSeg]);
|
AddCodeLine (".segment\t\"%s\"", SegmentNames [CurSeg]);
|
||||||
AddCodeHint (SegmentHints [CurSeg]);
|
AddCodeHint (SegmentHints [CurSeg]);
|
||||||
}
|
}
|
||||||
@@ -967,6 +967,82 @@ void g_leasp (int offs)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void g_leavariadic (int Offs)
|
||||||
|
/* Fetch the address of a parameter in a variadic function into the primary
|
||||||
|
* register
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
unsigned ArgSizeOffs;
|
||||||
|
|
||||||
|
/* Calculate the offset relative to sp */
|
||||||
|
Offs -= oursp;
|
||||||
|
|
||||||
|
/* Get the offset of the parameter which is stored at sp+0 on function
|
||||||
|
* entry and check if this offset is reachable with a byte offset.
|
||||||
|
*/
|
||||||
|
CHECK (oursp <= 0);
|
||||||
|
ArgSizeOffs = -oursp;
|
||||||
|
CheckLocalOffs (ArgSizeOffs);
|
||||||
|
|
||||||
|
/* Get the stack pointer plus offset. Clear the carry as the result of
|
||||||
|
* this sequence.
|
||||||
|
*/
|
||||||
|
if (Offs > 0) {
|
||||||
|
AddCodeLine ("\tclc");
|
||||||
|
AddCodeLine ("\tlda\tsp");
|
||||||
|
AddCodeLine ("\tadc\t#$%02X", Offs & 0xFF);
|
||||||
|
if (Offs >= 256) {
|
||||||
|
AddCodeLine ("\tpha");
|
||||||
|
AddCodeLine ("\tlda\tsp+1");
|
||||||
|
AddCodeLine ("\tadc\t#$%02X", (Offs >> 8) & 0xFF);
|
||||||
|
AddCodeLine ("\ttax");
|
||||||
|
AddCodeLine ("\tpla");
|
||||||
|
AddCodeLine ("\tclc");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("\tldx\tsp+1");
|
||||||
|
AddCodeLine ("\tbcc\t*+4"); /* Jump over the clc */
|
||||||
|
AddCodeLine ("\tinx");
|
||||||
|
AddCodeHint ("x:!"); /* Invalidate X */
|
||||||
|
AddCodeLine ("\tclc");
|
||||||
|
}
|
||||||
|
} else if (Offs < 0) {
|
||||||
|
Offs = -Offs;
|
||||||
|
AddCodeLine ("\tsec");
|
||||||
|
AddCodeLine ("\tlda\tsp");
|
||||||
|
AddCodeLine ("\tsbc\t#$%02X", Offs & 0xFF);
|
||||||
|
if (Offs >= 256) {
|
||||||
|
AddCodeLine ("\tpha");
|
||||||
|
AddCodeLine ("\tlda\tsp+1");
|
||||||
|
AddCodeLine ("\tsbc\t#$%02X", (Offs >> 8) & 0xFF);
|
||||||
|
AddCodeLine ("\ttax");
|
||||||
|
AddCodeLine ("\tpla");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("\tldx\tsp+1");
|
||||||
|
AddCodeLine ("\tbcs\t*+3");
|
||||||
|
AddCodeLine ("\tdex");
|
||||||
|
AddCodeHint ("x:!"); /* Invalidate X */
|
||||||
|
}
|
||||||
|
AddCodeLine ("\tclc");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("\tlda\tsp");
|
||||||
|
AddCodeLine ("\tldx\tsp+1");
|
||||||
|
AddCodeLine ("\tclc");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the size of all parameters. Carry is clear on entry. */
|
||||||
|
if (ArgSizeOffs == 0 && CPU == CPU_65C02) {
|
||||||
|
AddCodeLine ("\tadc\t(sp)");
|
||||||
|
} else {
|
||||||
|
ldyconst (ArgSizeOffs);
|
||||||
|
AddCodeLine ("\tadc\t(sp),y");
|
||||||
|
}
|
||||||
|
AddCodeLine ("\tbcc\t*+3");
|
||||||
|
AddCodeLine ("\tinx");
|
||||||
|
AddCodeHint ("x:!"); /* Invalidate X */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Store into memory */
|
/* Store into memory */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -3748,13 +3824,16 @@ void g_defdata (unsigned flags, unsigned long val, unsigned offs)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void g_defbytes (const unsigned char* Bytes, unsigned Count)
|
void g_defbytes (const void* Bytes, unsigned Count)
|
||||||
/* Output a row of bytes as a constant */
|
/* Output a row of bytes as a constant */
|
||||||
{
|
{
|
||||||
unsigned Chunk;
|
unsigned Chunk;
|
||||||
char Buf [128];
|
char Buf [128];
|
||||||
char* B;
|
char* B;
|
||||||
|
|
||||||
|
/* Cast the buffer pointer */
|
||||||
|
const unsigned char* Data = (const unsigned char*) Bytes;
|
||||||
|
|
||||||
/* Output the stuff */
|
/* Output the stuff */
|
||||||
while (Count) {
|
while (Count) {
|
||||||
|
|
||||||
@@ -3768,7 +3847,7 @@ void g_defbytes (const unsigned char* Bytes, unsigned Count)
|
|||||||
strcpy (Buf, "\t.byte\t");
|
strcpy (Buf, "\t.byte\t");
|
||||||
B = Buf + 7;
|
B = Buf + 7;
|
||||||
do {
|
do {
|
||||||
B += sprintf (B, "$%02X", *Bytes++ & 0xFF);
|
B += sprintf (B, "$%02X", *Data++);
|
||||||
if (--Chunk) {
|
if (--Chunk) {
|
||||||
*B++ = ',';
|
*B++ = ',';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,11 +240,27 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void g_getimmed (unsigned flags, unsigned long val, unsigned offs);
|
void g_getimmed (unsigned Flags, unsigned long Val, unsigned Offs);
|
||||||
void g_getstatic (unsigned flags, unsigned long label, unsigned offs);
|
/* Load a constant into the primary register */
|
||||||
void g_getlocal (unsigned flags, int offs);
|
|
||||||
void g_getind (unsigned flags, unsigned offs);
|
void g_getstatic (unsigned Flags, unsigned long Label, unsigned Offs);
|
||||||
void g_leasp (int offs);
|
/* Fetch an static memory cell into the primary register */
|
||||||
|
|
||||||
|
void g_getlocal (unsigned Flags, int Offs);
|
||||||
|
/* Fetch specified local object (local var). */
|
||||||
|
|
||||||
|
void g_getind (unsigned Flags, unsigned Offs);
|
||||||
|
/* Fetch the specified object type indirect through the primary register
|
||||||
|
* into the primary register
|
||||||
|
*/
|
||||||
|
|
||||||
|
void g_leasp (int Offs);
|
||||||
|
/* Fetch the address of the specified symbol into the primary register */
|
||||||
|
|
||||||
|
void g_leavariadic (int Offs);
|
||||||
|
/* Fetch the address of a parameter in a variadic function into the primary
|
||||||
|
* register
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -406,7 +422,7 @@ void g_res (unsigned n);
|
|||||||
void g_defdata (unsigned flags, unsigned long val, unsigned offs);
|
void g_defdata (unsigned flags, unsigned long val, unsigned offs);
|
||||||
/* Define data with the size given in flags */
|
/* Define data with the size given in flags */
|
||||||
|
|
||||||
void g_defbytes (const unsigned char *bytes, unsigned count);
|
void g_defbytes (const void* bytes, unsigned count);
|
||||||
/* Output a row of bytes as a constant */
|
/* Output a row of bytes as a constant */
|
||||||
|
|
||||||
void g_zerobytes (unsigned n);
|
void g_zerobytes (unsigned n);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ type* TypeDup (const type* T)
|
|||||||
/* Create a copy of the given type on the heap */
|
/* Create a copy of the given type on the heap */
|
||||||
{
|
{
|
||||||
unsigned Len = (TypeLen (T) + 1) * sizeof (type);
|
unsigned Len = (TypeLen (T) + 1) * sizeof (type);
|
||||||
return memcpy (xmalloc (Len), T, Len);
|
return (type*) memcpy (xmalloc (Len), T, Len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ type* TypeAlloc (unsigned Len)
|
|||||||
* trailing T_END.
|
* trailing T_END.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
return xmalloc (Len * sizeof (type));
|
return (type*) xmalloc (Len * sizeof (type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -413,7 +413,7 @@ unsigned SizeOf (const type* T)
|
|||||||
|
|
||||||
case T_STRUCT:
|
case T_STRUCT:
|
||||||
case T_UNION:
|
case T_UNION:
|
||||||
Entry = DecodePtr (T+1);
|
Entry = (SymEntry*) DecodePtr (T+1);
|
||||||
return Entry->V.S.Size;
|
return Entry->V.S.Size;
|
||||||
|
|
||||||
case T_ARRAY:
|
case T_ARRAY:
|
||||||
@@ -475,7 +475,7 @@ unsigned TypeOf (const type* T)
|
|||||||
return CF_LONG | CF_UNSIGNED;
|
return CF_LONG | CF_UNSIGNED;
|
||||||
|
|
||||||
case T_FUNC:
|
case T_FUNC:
|
||||||
F = DecodePtr (T+1);
|
F = (FuncDesc*) DecodePtr (T+1);
|
||||||
return (F->Flags & FD_ELLIPSIS)? 0 : CF_FIXARGC;
|
return (F->Flags & FD_ELLIPSIS)? 0 : CF_FIXARGC;
|
||||||
|
|
||||||
case T_STRUCT:
|
case T_STRUCT:
|
||||||
@@ -642,18 +642,18 @@ int IsFastCallFunc (const type* T)
|
|||||||
{
|
{
|
||||||
FuncDesc* F;
|
FuncDesc* F;
|
||||||
CHECK (IsTypeFunc (T));
|
CHECK (IsTypeFunc (T));
|
||||||
F = DecodePtr (T+1);
|
F = (FuncDesc*) DecodePtr (T+1);
|
||||||
return (F->Flags & FD_FASTCALL) != 0;
|
return (F->Flags & FD_FASTCALL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int IsEllipsisFunc (const type* T)
|
int IsVariadicFunc (const type* T)
|
||||||
/* Return true if this is a function type with variable parameter list */
|
/* Return true if this is a function type with variable parameter list */
|
||||||
{
|
{
|
||||||
FuncDesc* F;
|
FuncDesc* F;
|
||||||
CHECK (IsTypeFunc (T));
|
CHECK (IsTypeFunc (T));
|
||||||
F = DecodePtr (T+1);
|
F = (FuncDesc*) DecodePtr (T+1);
|
||||||
return (F->Flags & FD_ELLIPSIS) != 0;
|
return (F->Flags & FD_ELLIPSIS) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,7 +717,7 @@ type GetQualifier (const type* T)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct FuncDesc* GetFuncDesc (const type* T)
|
FuncDesc* GetFuncDesc (const type* T)
|
||||||
/* Get the FuncDesc pointer from a function or pointer-to-function type */
|
/* Get the FuncDesc pointer from a function or pointer-to-function type */
|
||||||
{
|
{
|
||||||
if (T[0] == T_PTR) {
|
if (T[0] == T_PTR) {
|
||||||
@@ -729,7 +729,7 @@ struct FuncDesc* GetFuncDesc (const type* T)
|
|||||||
CHECK (T[0] == T_FUNC);
|
CHECK (T[0] == T_FUNC);
|
||||||
|
|
||||||
/* Decode the function descriptor and return it */
|
/* Decode the function descriptor and return it */
|
||||||
return DecodePtr (T+1);
|
return (FuncDesc*) DecodePtr (T+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@
|
|||||||
/* common */
|
/* common */
|
||||||
#include "attrib.h"
|
#include "attrib.h"
|
||||||
|
|
||||||
|
/* cc65 */
|
||||||
|
#include "funcdesc.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -283,7 +286,7 @@ int IsQualVolatile (const type* T) attribute ((const));
|
|||||||
int IsFastCallFunc (const type* T) attribute ((const));
|
int IsFastCallFunc (const type* T) attribute ((const));
|
||||||
/* Return true if this is a function type with __fastcall__ calling conventions */
|
/* Return true if this is a function type with __fastcall__ calling conventions */
|
||||||
|
|
||||||
int IsEllipsisFunc (const type* T) attribute ((const));
|
int IsVariadicFunc (const type* T) attribute ((const));
|
||||||
/* Return true if this is a function type with variable parameter list */
|
/* Return true if this is a function type with variable parameter list */
|
||||||
|
|
||||||
int IsTypeFuncPtr (const type* T) attribute ((const));
|
int IsTypeFuncPtr (const type* T) attribute ((const));
|
||||||
@@ -304,7 +307,7 @@ type GetSizeModifier (const type* T) attribute ((const));
|
|||||||
type GetQualifier (const type* T) attribute ((const));
|
type GetQualifier (const type* T) attribute ((const));
|
||||||
/* Get the qualifier from the given type string */
|
/* Get the qualifier from the given type string */
|
||||||
|
|
||||||
struct FuncDesc* GetFuncDesc (const type* T) attribute ((const));
|
FuncDesc* GetFuncDesc (const type* T) attribute ((const));
|
||||||
/* Get the FuncDesc pointer from a function or pointer-to-function type */
|
/* Get the FuncDesc pointer from a function or pointer-to-function type */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -775,10 +775,10 @@ static void Decl (Declaration* D, unsigned Mode)
|
|||||||
/* Set the fastcall flag */
|
/* Set the fastcall flag */
|
||||||
if (!IsTypeFunc (T)) {
|
if (!IsTypeFunc (T)) {
|
||||||
Error ("__fastcall__ modifier applied to non function");
|
Error ("__fastcall__ modifier applied to non function");
|
||||||
} else if (IsEllipsisFunc (T)) {
|
} else if (IsVariadicFunc (T)) {
|
||||||
Error ("Cannot apply __fastcall__ to functions with variable parameter list");
|
Error ("Cannot apply __fastcall__ to functions with variable parameter list");
|
||||||
} else {
|
} else {
|
||||||
FuncDesc* F = DecodePtr (T+1);
|
FuncDesc* F = (FuncDesc*) DecodePtr (T+1);
|
||||||
F->Flags |= FD_FASTCALL;
|
F->Flags |= FD_FASTCALL;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -68,13 +68,13 @@ static attrib_t FindAttribute (const char* Attr)
|
|||||||
* Return atNone if the attribute name is not known.
|
* Return atNone if the attribute name is not known.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
attrib_t A;
|
int A;
|
||||||
|
|
||||||
/* For now do a linear search */
|
/* For now do a linear search */
|
||||||
for (A = 0; A < atCount; ++A) {
|
for (A = 0; A < atCount; ++A) {
|
||||||
if (strcmp (Attr, AttrNames[A]) == 0) {
|
if (strcmp (Attr, AttrNames[A]) == 0) {
|
||||||
/* Found */
|
/* Found */
|
||||||
return A;
|
return (attrib_t) A;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -783,9 +783,20 @@ static int primary (struct expent* lval)
|
|||||||
lval->e_name = (unsigned long) Sym->Name;
|
lval->e_name = (unsigned long) Sym->Name;
|
||||||
lval->e_const = 0;
|
lval->e_const = 0;
|
||||||
} else if ((Sym->Flags & SC_AUTO) == SC_AUTO) {
|
} else if ((Sym->Flags & SC_AUTO) == SC_AUTO) {
|
||||||
/* Local variable */
|
/* Local variable. If this is a parameter for a variadic
|
||||||
|
* function, we have to add some address calculations, and the
|
||||||
|
* address is not const.
|
||||||
|
*/
|
||||||
|
if ((Sym->Flags & SC_PARAM) == SC_PARAM && IsVariadic (CurrentFunc)) {
|
||||||
|
/* Variadic parameter */
|
||||||
|
g_leavariadic (Sym->V.Offs - GetParamSize (CurrentFunc));
|
||||||
|
lval->e_flags = E_MEXPR;
|
||||||
|
lval->e_const = 0;
|
||||||
|
} else {
|
||||||
|
/* Normal parameter */
|
||||||
lval->e_flags = E_MLOCAL | E_TLOFFS;
|
lval->e_flags = E_MLOCAL | E_TLOFFS;
|
||||||
lval->e_const = Sym->V.Offs;
|
lval->e_const = Sym->V.Offs;
|
||||||
|
}
|
||||||
} else if ((Sym->Flags & SC_STATIC) == SC_STATIC) {
|
} else if ((Sym->Flags & SC_STATIC) == SC_STATIC) {
|
||||||
/* Static variable */
|
/* Static variable */
|
||||||
if (Sym->Flags & (SC_EXTERN | SC_STORAGE)) {
|
if (Sym->Flags & (SC_EXTERN | SC_STORAGE)) {
|
||||||
@@ -2915,7 +2926,7 @@ int evalexpr (unsigned flags, int (*f) (struct expent*), struct expent* lval)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int expr (int (*func) (), struct expent *lval)
|
int expr (int (*func) (struct expent*), struct expent *lval)
|
||||||
/* Expression parser; func is either hie0 or hie1. */
|
/* Expression parser; func is either hie0 or hie1. */
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ static ExprNodeBlock* NewExprNodeBlock (unsigned Count)
|
|||||||
unsigned Size = sizeof (ExprNodeBlock) + (Count-1) * sizeof (ExprNode);
|
unsigned Size = sizeof (ExprNodeBlock) + (Count-1) * sizeof (ExprNode);
|
||||||
|
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
ExprNodeBlock* B = xmalloc (Size);
|
ExprNodeBlock* B = (ExprNodeBlock*) xmalloc (Size);
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
B->Next = 0;
|
B->Next = 0;
|
||||||
@@ -106,7 +106,7 @@ static ExprHeap* NewExprHeap (void)
|
|||||||
/* Create and return a new expression tree */
|
/* Create and return a new expression tree */
|
||||||
{
|
{
|
||||||
/* Allocate memory */
|
/* Allocate memory */
|
||||||
ExprHeap* H = xmalloc (sizeof (ExprHeap));
|
ExprHeap* H = (ExprHeap*) xmalloc (sizeof (ExprHeap));
|
||||||
|
|
||||||
/* Allocate the first node block */
|
/* Allocate the first node block */
|
||||||
H->BlockRoot = NewExprNodeBlock (64);
|
H->BlockRoot = NewExprNodeBlock (64);
|
||||||
@@ -214,7 +214,7 @@ void FreeExprTree (ExprNode* N)
|
|||||||
unsigned I;
|
unsigned I;
|
||||||
unsigned Count = CollCount (&N->List);
|
unsigned Count = CollCount (&N->List);
|
||||||
for (I = 0; I < Count; ++I) {
|
for (I = 0; I < Count; ++I) {
|
||||||
FreeExprNode (CollAt (&N->List, I));
|
FreeExprNode ((ExprNode*) CollAt (&N->List, I));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ void SetRightNode (ExprNode* Root, ExprNode* Right)
|
|||||||
struct SymEntry* GetNodeSym (ExprNode* N)
|
struct SymEntry* GetNodeSym (ExprNode* N)
|
||||||
/* Get the symbol entry for a NT_SYM node */
|
/* Get the symbol entry for a NT_SYM node */
|
||||||
{
|
{
|
||||||
return GetItem (N, IDX_SYM);
|
return (struct SymEntry*) GetItem (N, IDX_SYM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ void DumpExpr (FILE* F, const ExprNode* E)
|
|||||||
case NT_LIST_EXPR:
|
case NT_LIST_EXPR:
|
||||||
Count = CollCount (&E->List);
|
Count = CollCount (&E->List);
|
||||||
for (I = 0; I < Count; ++I) {
|
for (I = 0; I < Count; ++I) {
|
||||||
DumpExpr (F, CollConstAt (&E->List, I));
|
DumpExpr (F, (const ExprNode*) CollConstAt (&E->List, I));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ FuncDesc* NewFuncDesc (void)
|
|||||||
/* Create a new symbol table with the given name */
|
/* Create a new symbol table with the given name */
|
||||||
{
|
{
|
||||||
/* Create a new function descriptor */
|
/* Create a new function descriptor */
|
||||||
FuncDesc* F = xmalloc (sizeof (FuncDesc));
|
FuncDesc* F = (FuncDesc*) xmalloc (sizeof (FuncDesc));
|
||||||
|
|
||||||
/* Nullify the fields */
|
/* Nullify the fields */
|
||||||
F->Flags = 0;
|
F->Flags = 0;
|
||||||
|
|||||||
@@ -84,12 +84,12 @@ static Function* NewFunction (struct SymEntry* Sym)
|
|||||||
/* Create a new function activation structure and return it */
|
/* Create a new function activation structure and return it */
|
||||||
{
|
{
|
||||||
/* Allocate a new structure */
|
/* Allocate a new structure */
|
||||||
Function* F = xmalloc (sizeof (Function));
|
Function* F = (Function*) xmalloc (sizeof (Function));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
F->FuncEntry = Sym;
|
F->FuncEntry = Sym;
|
||||||
F->ReturnType = Sym->Type + 1 + DECODE_SIZE;
|
F->ReturnType = Sym->Type + 1 + DECODE_SIZE;
|
||||||
F->Desc = DecodePtr (Sym->Type + 1);
|
F->Desc = (FuncDesc*) DecodePtr (Sym->Type + 1);
|
||||||
F->EntryCode = 0;
|
F->EntryCode = 0;
|
||||||
F->Reserved = 0;
|
F->Reserved = 0;
|
||||||
F->RetLab = GetLabel ();
|
F->RetLab = GetLabel ();
|
||||||
@@ -148,6 +148,14 @@ int HasVoidReturn (const Function* F)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsVariadic (const Function* F)
|
||||||
|
/* Return true if this is a variadic function */
|
||||||
|
{
|
||||||
|
return (F->Desc->Flags & FD_ELLIPSIS) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RememberEntry (Function* F)
|
void RememberEntry (Function* F)
|
||||||
/* Remember the current output position for local space creation later */
|
/* Remember the current output position for local space creation later */
|
||||||
{
|
{
|
||||||
@@ -211,7 +219,7 @@ void NewFunc (SymEntry* Func)
|
|||||||
unsigned Flags;
|
unsigned Flags;
|
||||||
|
|
||||||
/* Get the function descriptor from the function entry */
|
/* Get the function descriptor from the function entry */
|
||||||
FuncDesc* D = DecodePtr (Func->Type+1);
|
FuncDesc* D = (FuncDesc*) DecodePtr (Func->Type+1);
|
||||||
|
|
||||||
/* Allocate the function activation record for the function */
|
/* Allocate the function activation record for the function */
|
||||||
CurrentFunc = NewFunction (Func);
|
CurrentFunc = NewFunction (Func);
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ type* GetReturnType (Function* F);
|
|||||||
int HasVoidReturn (const Function* F);
|
int HasVoidReturn (const Function* F);
|
||||||
/* Return true if the function does not have a return value */
|
/* Return true if the function does not have a return value */
|
||||||
|
|
||||||
|
int IsVariadic (const Function* F);
|
||||||
|
/* Return true if this is a variadic function */
|
||||||
|
|
||||||
void RememberEntry (Function* F);
|
void RememberEntry (Function* F);
|
||||||
/* Remember the current output position for local space creation later */
|
/* Remember the current output position for local space creation later */
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ static char* Add (char* Orig, const char* New)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate memory for the new string */
|
/* Allocate memory for the new string */
|
||||||
NewPath = xmalloc (OrigLen + NewLen + 2);
|
NewPath = (char*) xmalloc (OrigLen + NewLen + 2);
|
||||||
|
|
||||||
/* Copy the strings */
|
/* Copy the strings */
|
||||||
memcpy (NewPath, Orig, OrigLen);
|
memcpy (NewPath, Orig, OrigLen);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ static IFile* NewIFile (const char* Name)
|
|||||||
unsigned Len = strlen (Name);
|
unsigned Len = strlen (Name);
|
||||||
|
|
||||||
/* Allocate a IFile structure */
|
/* Allocate a IFile structure */
|
||||||
IFile* IF = xmalloc (sizeof (IFile) + Len);
|
IFile* IF = (IFile*) xmalloc (sizeof (IFile) + Len);
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
IF->Index = CollCount (&IFiles) + 1;
|
IF->Index = CollCount (&IFiles) + 1;
|
||||||
@@ -132,7 +132,7 @@ static AFile* NewAFile (IFile* IF, FILE* F)
|
|||||||
/* Create and return a new AFile */
|
/* Create and return a new AFile */
|
||||||
{
|
{
|
||||||
/* Allocate a AFile structure */
|
/* Allocate a AFile structure */
|
||||||
AFile* AF = xmalloc (sizeof (AFile));
|
AFile* AF = (AFile*) xmalloc (sizeof (AFile));
|
||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
AF->Line = 0;
|
AF->Line = 0;
|
||||||
@@ -174,7 +174,7 @@ static IFile* FindFile (const char* Name)
|
|||||||
unsigned I;
|
unsigned I;
|
||||||
for (I = 0; I < CollCount (&IFiles); ++I) {
|
for (I = 0; I < CollCount (&IFiles); ++I) {
|
||||||
/* Get the file struct */
|
/* Get the file struct */
|
||||||
IFile* IF = CollAt (&IFiles, I);
|
IFile* IF = (IFile*) CollAt (&IFiles, I);
|
||||||
/* Check the name */
|
/* Check the name */
|
||||||
if (strcmp (Name, IF->Name) == 0) {
|
if (strcmp (Name, IF->Name) == 0) {
|
||||||
/* Found, return the struct */
|
/* Found, return the struct */
|
||||||
@@ -266,7 +266,7 @@ static void CloseIncludeFile (void)
|
|||||||
PRECONDITION (AFileCount > 0);
|
PRECONDITION (AFileCount > 0);
|
||||||
|
|
||||||
/* Get the current active input file */
|
/* Get the current active input file */
|
||||||
Input = CollLast (&AFiles);
|
Input = (AFile*) CollLast (&AFiles);
|
||||||
|
|
||||||
/* Close the current input file (we're just reading so no error check) */
|
/* Close the current input file (we're just reading so no error check) */
|
||||||
fclose (Input->F);
|
fclose (Input->F);
|
||||||
@@ -342,7 +342,7 @@ int NextLine (void)
|
|||||||
if (CollCount (&AFiles) == 0) {
|
if (CollCount (&AFiles) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Input = CollLast (&AFiles);
|
Input = (AFile*) CollLast (&AFiles);
|
||||||
|
|
||||||
/* Read lines until we get one with real contents */
|
/* Read lines until we get one with real contents */
|
||||||
Len = 0;
|
Len = 0;
|
||||||
@@ -363,7 +363,7 @@ int NextLine (void)
|
|||||||
if (CollCount (&AFiles) == 0) {
|
if (CollCount (&AFiles) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Input = CollLast (&AFiles);
|
Input = (AFile*) CollLast (&AFiles);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,13 +410,13 @@ const char* GetCurrentFile (void)
|
|||||||
{
|
{
|
||||||
unsigned AFileCount = CollCount (&AFiles);
|
unsigned AFileCount = CollCount (&AFiles);
|
||||||
if (AFileCount > 0) {
|
if (AFileCount > 0) {
|
||||||
const AFile* AF = CollAt (&AFiles, AFileCount-1);
|
const AFile* AF = (const AFile*) CollAt (&AFiles, AFileCount-1);
|
||||||
return AF->Name;
|
return AF->Name;
|
||||||
} else {
|
} else {
|
||||||
/* No open file. Use the main file if we have one. */
|
/* No open file. Use the main file if we have one. */
|
||||||
unsigned IFileCount = CollCount (&IFiles);
|
unsigned IFileCount = CollCount (&IFiles);
|
||||||
if (IFileCount > 0) {
|
if (IFileCount > 0) {
|
||||||
const IFile* IF = CollAt (&IFiles, 0);
|
const IFile* IF = (const IFile*) CollAt (&IFiles, 0);
|
||||||
return IF->Name;
|
return IF->Name;
|
||||||
} else {
|
} else {
|
||||||
return "(outside file scope)";
|
return "(outside file scope)";
|
||||||
@@ -431,7 +431,7 @@ unsigned GetCurrentLine (void)
|
|||||||
{
|
{
|
||||||
unsigned AFileCount = CollCount (&AFiles);
|
unsigned AFileCount = CollCount (&AFiles);
|
||||||
if (AFileCount > 0) {
|
if (AFileCount > 0) {
|
||||||
const AFile* AF = CollAt (&AFiles, AFileCount-1);
|
const AFile* AF = (const AFile*) CollAt (&AFiles, AFileCount-1);
|
||||||
return AF->Line;
|
return AF->Line;
|
||||||
} else {
|
} else {
|
||||||
/* No open file */
|
/* No open file */
|
||||||
@@ -455,7 +455,7 @@ void WriteDependencies (FILE* F, const char* OutputFile)
|
|||||||
/* Loop over all files */
|
/* Loop over all files */
|
||||||
for (I = 0; I < IFileCount; ++I) {
|
for (I = 0; I < IFileCount; ++I) {
|
||||||
/* Get the next input file */
|
/* Get the next input file */
|
||||||
const IFile* IF = CollAt (&IFiles, I);
|
const IFile* IF = (const IFile*) CollAt (&IFiles, I);
|
||||||
/* If this is not the first file, add a space */
|
/* If this is not the first file, add a space */
|
||||||
const char* Format = (I == 0)? "%s" : " %s";
|
const char* Format = (I == 0)? "%s" : " %s";
|
||||||
/* Print the dependency */
|
/* Print the dependency */
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ void InitRegVars (void)
|
|||||||
* will usually waste some space but we don't need to dynamically
|
* will usually waste some space but we don't need to dynamically
|
||||||
* grow the array.
|
* grow the array.
|
||||||
*/
|
*/
|
||||||
RegSyms = xmalloc (MaxRegSpace * sizeof (RegSyms[0]));
|
RegSyms = (const SymEntry**) xmalloc (MaxRegSpace * sizeof (RegSyms[0]));
|
||||||
RegOffs = MaxRegSpace;
|
RegOffs = MaxRegSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,10 +63,8 @@ LoopDesc* AddLoop (unsigned sp, unsigned loop, unsigned label,
|
|||||||
unsigned linc, unsigned lstat)
|
unsigned linc, unsigned lstat)
|
||||||
/* Create and add a new loop descriptor */
|
/* Create and add a new loop descriptor */
|
||||||
{
|
{
|
||||||
LoopDesc* L;
|
|
||||||
|
|
||||||
/* Allocate a new struct */
|
/* Allocate a new struct */
|
||||||
L = xmalloc (sizeof (LoopDesc));
|
LoopDesc* L = (LoopDesc*) xmalloc (sizeof (LoopDesc));
|
||||||
|
|
||||||
/* Fill in the data */
|
/* Fill in the data */
|
||||||
L->StackPtr = sp;
|
L->StackPtr = sp;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Macro* NewMacro (const char* Name)
|
|||||||
unsigned Len = strlen(Name);
|
unsigned Len = strlen(Name);
|
||||||
|
|
||||||
/* Allocate the structure */
|
/* Allocate the structure */
|
||||||
Macro* M = xmalloc (sizeof(Macro) + Len);
|
Macro* M = (Macro*) xmalloc (sizeof(Macro) + Len);
|
||||||
|
|
||||||
/* Initialize the data */
|
/* Initialize the data */
|
||||||
M->Next = 0;
|
M->Next = 0;
|
||||||
@@ -152,7 +152,7 @@ void InsertMacro (Macro* M)
|
|||||||
|
|
||||||
/* Allocate the ActualArgs parameter array */
|
/* Allocate the ActualArgs parameter array */
|
||||||
if (M->ArgCount > 0) {
|
if (M->ArgCount > 0) {
|
||||||
M->ActualArgs = xmalloc (M->ArgCount * sizeof(char*));
|
M->ActualArgs = (char const**) xmalloc (M->ArgCount * sizeof(char*));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the hash value of the macro name */
|
/* Get the hash value of the macro name */
|
||||||
@@ -291,11 +291,11 @@ void AddMacroArg (Macro* M, const char* Arg)
|
|||||||
/* Check if we have enough room available, otherwise expand the array
|
/* Check if we have enough room available, otherwise expand the array
|
||||||
* that holds the formal argument list.
|
* that holds the formal argument list.
|
||||||
*/
|
*/
|
||||||
if (M->ArgCount >= M->MaxArgs) {
|
if (M->ArgCount >= (int) M->MaxArgs) {
|
||||||
/* We must expand the array */
|
/* We must expand the array */
|
||||||
char** OldArgs = M->FormalArgs;
|
char** OldArgs = M->FormalArgs;
|
||||||
M->MaxArgs += 10;
|
M->MaxArgs += 10;
|
||||||
M->FormalArgs = xmalloc (M->MaxArgs * sizeof(char*));
|
M->FormalArgs = (char**) xmalloc (M->MaxArgs * sizeof(char*));
|
||||||
memcpy (M->FormalArgs, OldArgs, M->ArgCount * sizeof (char*));
|
memcpy (M->FormalArgs, OldArgs, M->ArgCount * sizeof (char*));
|
||||||
xfree (OldArgs);
|
xfree (OldArgs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ static void DefineSym (const char* Def)
|
|||||||
*/
|
*/
|
||||||
char* Q;
|
char* Q;
|
||||||
unsigned Len = strlen (Def)+1;
|
unsigned Len = strlen (Def)+1;
|
||||||
char* S = xmalloc (Len);
|
char* S = (char*) xmalloc (Len);
|
||||||
memcpy (S, Def, Len);
|
memcpy (S, Def, Len);
|
||||||
Q = S + (P - Def);
|
Q = S + (P - Def);
|
||||||
*Q++ = '\0';
|
*Q++ = '\0';
|
||||||
@@ -473,7 +473,7 @@ int main (int argc, char* argv[])
|
|||||||
|
|
||||||
/* Parse the command line */
|
/* Parse the command line */
|
||||||
I = 1;
|
I = 1;
|
||||||
while (I < ArgCount) {
|
while (I < (int)ArgCount) {
|
||||||
|
|
||||||
const char* P;
|
const char* P;
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ static void StdFunc_strlen (struct expent*);
|
|||||||
/* Table with all known functions and their handlers. Must be sorted
|
/* Table with all known functions and their handlers. Must be sorted
|
||||||
* alphabetically!
|
* alphabetically!
|
||||||
*/
|
*/
|
||||||
static struct FuncDesc {
|
static struct StdFuncDesc {
|
||||||
const char* Name;
|
const char* Name;
|
||||||
void (*Handler) (struct expent*);
|
void (*Handler) (struct expent*);
|
||||||
} StdFuncs [] = {
|
} StdFuncs [] = {
|
||||||
@@ -86,12 +86,12 @@ static struct FuncDesc {
|
|||||||
static int CmpFunc (const void* Key, const void* Elem)
|
static int CmpFunc (const void* Key, const void* Elem)
|
||||||
/* Compare function for bsearch */
|
/* Compare function for bsearch */
|
||||||
{
|
{
|
||||||
return strcmp ((const char*) Key, ((const struct FuncDesc*) Elem)->Name);
|
return strcmp ((const char*) Key, ((const struct StdFuncDesc*) Elem)->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static struct FuncDesc* FindFunc (const char* Name)
|
static struct StdFuncDesc* FindFunc (const char* Name)
|
||||||
/* Find a function with the given name. Return a pointer to the descriptor if
|
/* Find a function with the given name. Return a pointer to the descriptor if
|
||||||
* found, return NULL otherwise.
|
* found, return NULL otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -173,7 +173,7 @@ void HandleStdFunc (struct expent* lval)
|
|||||||
/* Generate code for a known standard function. */
|
/* Generate code for a known standard function. */
|
||||||
{
|
{
|
||||||
/* Get a pointer to the table entry */
|
/* Get a pointer to the table entry */
|
||||||
struct FuncDesc* F = FindFunc ((const char*) lval->e_name);
|
struct StdFuncDesc* F = FindFunc ((const char*) lval->e_name);
|
||||||
CHECK (F != 0);
|
CHECK (F != 0);
|
||||||
|
|
||||||
/* Call the handler function */
|
/* Call the handler function */
|
||||||
|
|||||||
Reference in New Issue
Block a user