improve constant loading. Still sucks, but oh well
[oota-llvm.git] / utils / Burg / list.c
1 char rcsid_list[] = "$Id$";
2
3 #include "b.h"
4
5 IntList
6 newIntList(x, next) int x; IntList next;
7 {
8   IntList l;
9
10   l = (IntList) zalloc(sizeof(*l));
11   assert(l);
12   l->x = x;
13   l->next = next;
14
15   return l;
16 }
17
18 List
19 newList(x, next) void *x; List next;
20 {
21   List l;
22
23   l = (List) zalloc(sizeof(*l));
24   assert(l);
25   l->x = x;
26   l->next = next;
27
28   return l;
29 }
30
31 List
32 appendList(x, l) void *x; List l;
33 {
34   List last;
35   List p;
36
37   last = 0;
38   for (p = l; p; p = p->next) {
39     last = p;
40   }
41   if (last) {
42     last->next = newList(x, 0);
43     return l;
44   } else {
45     return newList(x, 0);
46   }
47 }
48
49 void
50 foreachList(f, l) ListFn f; List l;
51 {
52   for (; l; l = l->next) {
53     (*f)(l->x);
54   }
55 }
56
57 void
58 reveachList(f, l) ListFn f; List l;
59 {
60   if (l) {
61     reveachList(f, l->next);
62     (*f)(l->x);
63   }
64 }
65
66 int
67 length(l) List l;
68 {
69   int c = 0;
70
71   for(; l; l = l->next) {
72     c++;
73   }
74   return c;
75 }