OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [cpp/] [hideset.c] - Blame information for rev 147

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include "cpp.h"
5
 
6
/*
7
 * A hideset is a null-terminated array of Nlist pointers.
8
 * They are referred to by indices in the hidesets array.
9
 * Hideset 0 is empty.
10
 */
11
 
12
#define HSSIZ   32
13
typedef Nlist   **Hideset;
14
Hideset *hidesets;
15
int     nhidesets = 0;
16
int     maxhidesets = 3;
17
int     inserths(Hideset, Hideset, Nlist *);
18
 
19
/*
20
 * Test for membership in a hideset
21
 */
22
int
23
checkhideset(int hs, Nlist *np)
24
{
25
        Hideset hsp;
26
 
27
        if (hs>=nhidesets)
28
                abort();
29
        for (hsp = hidesets[hs]; *hsp; hsp++) {
30
                if (*hsp == np)
31
                        return 1;
32
        }
33
        return 0;
34
}
35
 
36
/*
37
 * Return the (possibly new) hideset obtained by adding np to hs.
38
 */
39
int
40
newhideset(int hs, Nlist *np)
41
{
42
        int i, len;
43
        Nlist *nhs[HSSIZ+3];
44
        Hideset hs1, hs2;
45
 
46
        len = inserths(nhs, hidesets[hs], np);
47
        for (i=0; i<nhidesets; i++) {
48
                for (hs1=nhs, hs2=hidesets[i]; *hs1==*hs2; hs1++, hs2++)
49
                        if (*hs1 == NULL)
50
                                return i;
51
        }
52
        if (len>=HSSIZ)
53
                return hs;
54
        if (nhidesets >= maxhidesets) {
55
                maxhidesets = 3*maxhidesets/2+1;
56
                hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets);
57
                if (hidesets == NULL)
58
                        error(FATAL, "Out of memory from realloc");
59
        }
60
        hs1 = (Hideset)domalloc(len*sizeof *hs1);
61
        memmove(hs1, nhs, len*sizeof *hs1);
62
        hidesets[nhidesets] = hs1;
63
        return nhidesets++;
64
}
65
 
66
int
67
inserths(Hideset dhs, Hideset shs, Nlist *np)
68
{
69
        Hideset odhs = dhs;
70
 
71
        while (*shs && *shs < np)
72
                *dhs++ = *shs++;
73
        if (*shs != np)
74
                *dhs++ = np;
75
        do {
76
                *dhs++ = *shs;
77
        } while (*shs++);
78
        return dhs - odhs;
79
}
80
 
81
/*
82
 * Hideset union
83
 */
84
int
85
unionhideset(int hs1, int hs2)
86
{
87
        Hideset hp;
88
 
89
        for (hp = hidesets[hs2]; *hp; hp++)
90
                hs1 = newhideset(hs1, *hp);
91
        return hs1;
92
}
93
 
94
void
95
iniths(void)
96
{
97
        hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *));
98
        hidesets[0] = (Hideset)domalloc(sizeof *hidesets[0]);
99
        *hidesets[0] = NULL;
100
        nhidesets++;
101
}
102
 
103
void
104
prhideset(int hs)
105
{
106
        Hideset np;
107
 
108
        for (np = hidesets[hs]; *np; np++) {
109
                fprintf(stderr, (char*)(*np)->name, (*np)->len);
110
                fprintf(stderr, " ");
111
        }
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.