1.1 --- a/types.c Fri Feb 08 11:19:36 2008 -0500
1.2 +++ b/types.c Fri Feb 08 14:39:34 2008 -0500
1.3 @@ -43,48 +43,58 @@
1.4 return p;
1.5 }
1.6
1.7 -#define RAZOR_ENTRY_LAST 0x80000000ul
1.8 -#define RAZOR_IMMEDIATE 0x80000000ul
1.9 -#define RAZOR_ENTRY_MASK 0x00fffffful
1.10 +/* RAZOR_IMMEDIATE and RAZOR_ENTRY_LAST must have the same value */
1.11 +#define RAZOR_ENTRY_LAST 0x2
1.12 +#define RAZOR_IMMEDIATE 0x2
1.13 +#define RAZOR_EMPTY_LIST 0x3
1.14
1.15 void
1.16 -list_init(uint32_t *list)
1.17 +list_set_empty(struct list_head *head)
1.18 {
1.19 - *list = ~0;
1.20 + head->list_ptr = ~0;
1.21 + head->flags = RAZOR_EMPTY_LIST;
1.22 }
1.23
1.24 void
1.25 -list_set(uint32_t *list, struct array *pool, struct array *items)
1.26 +list_set_ptr(struct list_head *head, uint32_t ptr)
1.27 {
1.28 - uint32_t *p;
1.29 + head->list_ptr = ptr;
1.30 + head->flags = 0;
1.31 +}
1.32 +
1.33 +void
1.34 +list_set_array(struct list_head *head, struct array *pool, struct array *items)
1.35 +{
1.36 + struct list *p;
1.37
1.38 if (items->size == 0) {
1.39 - list_init(list);
1.40 + list_set_empty(head);
1.41 } else if (items->size == sizeof (uint32_t)) {
1.42 - *list = *(uint32_t *) items->data | RAZOR_IMMEDIATE;
1.43 + head->list_ptr = *(uint32_t *) items->data;
1.44 + head->flags = RAZOR_IMMEDIATE;
1.45 } else {
1.46 p = array_add(pool, items->size);
1.47 memcpy(p, items->data, items->size);
1.48 - p[items->size / sizeof *p - 1] |= RAZOR_ENTRY_LAST;
1.49 - *list = p - (uint32_t *) pool->data;
1.50 + p[items->size / sizeof *p - 1].flags = RAZOR_ENTRY_LAST;
1.51 + list_set_ptr(head, p - (struct list *) pool->data);
1.52 }
1.53 }
1.54
1.55 -uint32_t *
1.56 -list_first(uint32_t *list, struct array *pool)
1.57 +struct list *
1.58 +list_first(struct list_head *head, struct array *pool)
1.59 {
1.60 - if (*list == ~0)
1.61 + if (head->flags == RAZOR_EMPTY_LIST)
1.62 return NULL;
1.63 - else if (*list & RAZOR_IMMEDIATE)
1.64 - return list;
1.65 + else if (head->flags == RAZOR_IMMEDIATE)
1.66 + return (struct list *) head;
1.67 else
1.68 - return (uint32_t *) pool->data + (*list & RAZOR_ENTRY_MASK);
1.69 + return (struct list *) pool->data + head->list_ptr;
1.70 }
1.71
1.72 -uint32_t *
1.73 -list_next(uint32_t *list)
1.74 +struct list *
1.75 +list_next(struct list *list)
1.76 {
1.77 - if (*list & ~RAZOR_ENTRY_MASK)
1.78 + if (list->flags)
1.79 return NULL;
1.80 return ++list;
1.81 }
1.82 @@ -92,18 +102,18 @@
1.83 void
1.84 list_remap_pool(struct array *pool, uint32_t *map)
1.85 {
1.86 - uint32_t *p, *end;
1.87 + struct list *p, *end;
1.88
1.89 end = pool->data + pool->size;
1.90 for (p = pool->data; p < end; p++)
1.91 - *p = map[LIST_VALUE(p)] | LIST_FLAGS(p);
1.92 + p->data = map[p->data];
1.93 }
1.94
1.95 void
1.96 -list_remap_if_immediate(uint32_t *list, uint32_t *map)
1.97 +list_remap_head(struct list_head *head, uint32_t *map)
1.98 {
1.99 - if ((*list & ~RAZOR_ENTRY_MASK) == RAZOR_IMMEDIATE)
1.100 - *list = map[LIST_VALUE(list)] | LIST_FLAGS(list);
1.101 + if (head->flags == RAZOR_IMMEDIATE)
1.102 + head->list_ptr = map[head->list_ptr];
1.103 }
1.104
1.105