Working on the condes feature

git-svn-id: svn://svn.cc65.org/cc65/trunk@451 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2000-11-20 15:22:57 +00:00
parent 9c35f5278a
commit b9970cb7da
35 changed files with 1029 additions and 388 deletions

80
src/common/cddefs.h Normal file
View File

@@ -0,0 +1,80 @@
/*****************************************************************************/
/* */
/* cddefs.h */
/* */
/* Definitions for module constructor/destructors */
/* */
/* */
/* */
/* (C) 2000 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 CDDEFS_H
#define CDDEFS_H
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* ConDes types. Count is only 7 because we want to encode 0..count in 3 bits */
#define CD_TYPE_COUNT 7 /* Number of table types */
#define CD_TYPE_MIN 0 /* Minimum numeric type value */
#define CD_TYPE_MAX 6 /* Maximum numeric type value */
/* ConDes priorities, zero is no valid priority and used to mark an empty
* (missing) decl for this type throughout the code.
*/
#define CD_PRIO_NONE 0 /* No priority (no decl) */
#define CD_PRIO_MIN 1 /* Lowest priority */
#define CD_PRIO_DEF 7 /* Default priority */
#define CD_PRIO_MAX 32 /* Highest priority */
/* Predefined types */
#define CD_TYPE_CON 0 /* Constructor */
#define CD_TYPE_DES 1 /* Destructor */
/* When part of an export in an object file, type and priority are encoded in
* one byte. In this case, the following macros access the fields:
*/
#define CD_GET_TYPE(v) (((v) >> 5) & 0x07)
#define CD_GET_PRIO(v) (((v) & 0x1F) + 1)
/* Macro to build the byte value: */
#define CD_BUILD(type,prio) ((((type) & 0x07) << 5) | (((prio) - 1) & 0x1F))
/* End of cddefs.h */
#endif

View File

@@ -225,14 +225,64 @@ void CollReplace (Collection* C, void* Item, unsigned Index)
void CollSort (Collection* C, int (*Compare) (const void*, const void*))
/* Sort the collection using the given compare function.
* BEWARE: The function uses qsort internally, so the Compare function does
* actually get pointers to the object pointers, not just object pointers!
*/
static void QuickSort (Collection* C, int Lo, int Hi,
int (*Compare) (void*, const void*, const void*),
void* Data)
/* Internal recursive sort function. */
{
/* Use qsort */
qsort (C->Items, C->Count, sizeof (void*), Compare);
/* Get a pointer to the items */
void** Items = C->Items;
/* Quicksort */
while (Hi > Lo) {
int I = Lo + 1;
int J = Hi;
while (I <= J) {
while (I <= J && Compare (Data, Items[Lo], Items[I]) >= 0) {
++I;
}
while (I <= J && Compare (Data, Items[Lo], Items[J]) < 0) {
--J;
}
if (I <= J) {
/* Swap I and J */
void* Tmp = Items[I];
Items[I] = Items[J];
Items[J] = Tmp;
++I;
--J;
}
}
if (J != Lo) {
/* Swap J and Lo */
void* Tmp = Items[J];
Items[J] = Items[Lo];
Items[Lo] = Tmp;
}
if (J > (Hi + Lo) / 2) {
QuickSort (C, J + 1, Hi, Compare, Data);
Hi = J - 1;
} else {
QuickSort (C, Lo, J - 1, Compare, Data);
Lo = J + 1;
}
}
}
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),
void* Data)
/* Sort the collection using the given compare function. The data pointer is
* passed as *first* element to the compare function, it's not used by the
* sort function itself. The other two pointer passed to the Compare function
* are pointers to objects.
*/
{
if (C->Count > 1) {
QuickSort (C, 0, C->Count-1, Compare, Data);
}
}

View File

@@ -113,10 +113,13 @@ void CollReplace (Collection* C, void* Item, unsigned Index);
* just the pointer will et replaced.
*/
void CollSort (Collection* C, int (*Compare) (const void*, const void*));
/* Sort the collection using the given compare function.
* BEWARE: The function uses qsort internally, so the Compare function does
* actually get pointers to the object pointers, not just object pointers!
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),
void* Data);
/* Sort the collection using the given compare function. The data pointer is
* passed as *first* element to the compare function, it's not used by the
* sort function itself. The other two pointer passed to the Compare function
* are pointers to objects.
*/

View File

@@ -46,7 +46,7 @@
/* Defines for magic and version */
#define OBJ_MAGIC 0x616E7A55
#define OBJ_VERSION 0x0007
#define OBJ_VERSION 0x0008
/* Size of an object file header */
#define OBJ_HDR_SIZE 56

View File

@@ -58,28 +58,26 @@
/* Export size */
#define EXP_ABS 0x00 /* Export as normal value */
#define EXP_ZP 0x20 /* Export as zero page value */
#define EXP_MASK_SIZE 0x20 /* Size mask */
#define EXP_ZP 0x08 /* Export as zero page value */
#define EXP_MASK_SIZE 0x08 /* Size mask */
#define IS_EXP_ABS(x) (((x) & EXP_MASK_SIZE) == EXP_ABS)
#define IS_EXP_ZP(x) (((x) & EXP_MASK_SIZE) == EXP_ZP)
/* Export value type */
#define EXP_CONST 0x00 /* Mask bit for const values */
#define EXP_EXPR 0x40 /* Mask bit for expr values */
#define EXP_MASK_VAL 0x40 /* Value mask */
#define EXP_EXPR 0x10 /* Mask bit for expr values */
#define EXP_MASK_VAL 0x10 /* Value mask */
#define IS_EXP_CONST(x) (((x) & EXP_MASK_VAL) == EXP_CONST)
#define IS_EXP_EXPR(x) (((x) & EXP_MASK_VAL) == EXP_EXPR)
/* Export initializer flag */
#define EXP_INIT_MIN 0x01 /* Minimum value */
#define EXP_INIT_MAX 0x1F /* Maximum value */
#define EXP_INIT_DEF 0x18 /* Default value */
#define EXP_MASK_INIT 0x1F /* Initializer value mask */
/* Number of module constructor/destructor declarations for an export */
#define EXP_CONDES_MASK 0x07
#define IS_EXP_INIT(x) (((x) & EXP_MASK_INIT) != 0)
#define GET_EXP_INIT_VAL(x) ((x) & EXP_MASK_INIT)
#define IS_EXP_CONDES(x) (((x) & EXP_CONDES_MASK) != 0)
#define GET_EXP_CONDES_COUNT(x) ((x) & EXP_CONDES_MASK)
#define INC_EXP_CONDES_COUNT(x) ((x)++)

View File

@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "target.h"