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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [c64/] [source/] [MemoryManagement.c] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 37 robfinch
#include        <stdio.h>
2
#include                <stdlib.h>
3
#include <string.h>
4
#include        "c.h"
5
#include        "expr.h"
6
#include "Statement.h"
7
#include        "gen.h"
8
#include        "cglbdec.h"
9
 
10
/*
11
 *      68000 C compiler
12
 *
13
 *      Copyright 1984, 1985, 1986 Matthew Brandt.
14
 *  all commercial rights reserved.
15
 *
16
 *      This compiler is intended as an instructive tool for personal use. Any
17
 *      use for profit without the written consent of the author is prohibited.
18
 *
19
 *      This compiler may be distributed freely for non-commercial use as long
20
 *      as this notice stays intact. Please forward any enhancements or questions
21
 *      to:
22
 *
23
 *              Matthew Brandt
24
 *              Box 920337
25
 *              Norcross, Ga 30092
26
 */
27
/*******************************************************
28
        Modified to support Raptor64 'C64' language
29
        by Robert Finch
30
        robfinch@opencores.org
31
*******************************************************/
32
 
33
#define BLKSIZE         4000
34
 
35
struct blk {
36
        char name[8];                   // string overwrite area
37
    struct blk *next;
38
    char       m[1];           /* memory area */
39
};
40
 
41
static int      glbsize = 0,    /* size left in current global block */
42
                locsize = 0,    /* size left in current local block */
43
                glbindx = 0,    /* global index */
44
                locindx = 0;    /* local index */
45
 
46
static struct blk       *locblk = 0,    /* pointer to local block */
47
                        *glbblk = 0;    /* pointer to global block */
48
 
49
char    *xalloc(int siz)
50
{
51
        struct blk *bp;
52
    char       *rv;
53
 
54
        while(siz % 8)  // align word
55
                siz++;
56
    if( global_flag ) {
57
        if( glbsize >= siz ) {
58
            rv = &(glbblk->m[glbindx]);
59
            glbsize -= siz;
60
            glbindx += siz;
61
            return rv;
62
        }
63
        else {
64
            bp = calloc(1,sizeof(struct blk) + BLKSIZE);
65
                        if( bp == NULL )
66
                        {
67
                                printf(" not enough memory.\n");
68
                                exit(1);
69
                        }
70
                        strcpy(bp->name,"C64    ");
71
            bp->next = glbblk;
72
            glbblk = bp;
73
            glbsize = BLKSIZE - siz;
74
            glbindx = siz;
75
            return glbblk->m;
76
        }
77
    }
78
    else    {
79
        if( locsize >= siz ) {
80
            rv = &(locblk->m[locindx]);
81
            locsize -= siz;
82
            locindx += siz;
83
            return rv;
84
        }
85
        else {
86
            bp = calloc(1,sizeof(struct blk) + BLKSIZE);
87
                        if( bp == NULL )
88
                        {
89
                                printf(" not enough local memory.\n");
90
                                exit(1);
91
                        }
92
                        strcpy(bp->name,"C64    ");
93
            bp->next = locblk;
94
            locblk = bp;
95
            locsize = BLKSIZE - siz;
96
            locindx = siz;
97
            return locblk->m;
98
        }
99
    }
100
}
101
 
102
void ReleaseLocalMemory()
103
{
104
        struct blk      *bp1, *bp2;
105
    int             blkcnt;
106
    blkcnt = 0;
107
    bp1 = locblk;
108
    while( bp1 != NULL ) {
109
        bp2 = bp1->next;
110
        free( bp1 );
111
        ++blkcnt;
112
        bp1 = bp2;
113
    }
114
    locblk = NULL;
115
    locsize = 0;
116
    lsyms.head = NULL;
117
        lsyms.tail = NULL;
118
        printf(" releasing %d bytes local tables.\n",blkcnt * BLKSIZE);
119
}
120
 
121
void ReleaseGlobalMemory()
122
{
123
        struct blk      *bp1, *bp2;
124
    int             blkcnt;
125
    bp1 = glbblk;
126
    blkcnt = 0;
127 51 robfinch
    while( bp1 != NULL ) {
128 37 robfinch
        bp2 = bp1->next;
129
        free(bp1);
130
        ++blkcnt;
131
        bp1 = bp2;
132
    }
133
    glbblk = NULL;
134
    glbsize = 0;
135
//    gsyms.head = NULL;         /* clear global symbol table */
136
//      gsyms.tail = NULL;
137
        memset(gsyms,0,sizeof(gsyms));
138
    printf(" releasing %d bytes global tables.\n",blkcnt * BLKSIZE);
139 51 robfinch
    strtab = NULL;             /* clear literal table */
140 37 robfinch
}
141
 
142
SYM *allocSYM() { return (SYM *)xalloc(sizeof(SYM)); };
143
TYP *allocTYP() { return (TYP *)xalloc(sizeof(TYP)); };
144
struct snode *allocSnode() { return (struct snode *)xalloc(sizeof(struct snode)); };
145
ENODE *allocEnode() { return (ENODE *)xalloc(sizeof(ENODE)); };
146
AMODE *allocAmode() { return (AMODE *)xalloc(sizeof(AMODE)); };
147
CSE *allocCSE() { return (CSE *)xalloc(sizeof(CSE)); };
148
 

powered by: WebSVN 2.1.0

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