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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [c64/] [source/] [ParseFunction.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        "c.h"
3
#include        "expr.h"
4
#include "Statement.h"
5
#include        "gen.h"
6
#include        "cglbdec.h"
7
 
8
/*
9
 *      68000 C compiler
10
 *
11
 *      Copyright 1984, 1985, 1986 Matthew Brandt.
12
 *  all commercial rights reserved.
13
 *
14
 *      This compiler is intended as an instructive tool for personal use. Any
15
 *      use for profit without the written consent of the author is prohibited.
16
 *
17
 *      This compiler may be distributed freely for non-commercial use as long
18
 *      as this notice stays intact. Please forward any enhancements or questions
19
 *      to:
20
 *
21
 *              Matthew Brandt
22
 *              Box 920337
23
 *              Norcross, Ga 30092
24
 */
25
/*******************************************************
26
        Copyright 2012  Robert Finch
27
        Modified to support Raptor64 'C64' language
28
        by Robert Finch
29
        robfinch@opencores.org
30
*******************************************************/
31
 
32
 
33
extern int funcdecl;
34
extern char *names[20];
35
extern int nparms;
36
 
37
void ParseFunctionBody(SYM *sp);
38
void funcbottom();
39
 
40
/*      function compilation routines           */
41
 
42
/*
43
 *      funcbody starts with the current symbol being either
44
 *      the first parameter id or the begin for the local
45
 *      block. If begin is the current symbol then funcbody
46
 *      assumes that the function has no parameters.
47
 */
48
void ParseFunction(SYM *sp)
49
{
50
        int poffset, i;
51
        int oldglobal;
52
    SYM *sp1, *sp2, *makeint();
53
 
54
                oldglobal = global_flag;
55
        global_flag = 0;
56
        poffset = 24;            /* size of return block */
57
        nparms = 0;
58
        if(lastst == id || 1) {              /* declare parameters */
59
                //while(lastst == id) {
60
                //        names[nparms++] = litlate(lastid);
61
                //        NextToken();
62
                //        if( lastst == comma)
63
                //                NextToken();
64
                //        else
65
                //                break;
66
                //        }
67
                //needpunc(closepa);
68
//                dodecl(sc_member);      /* declare parameters */
69
                                sp->parms = NULL;
70
                                ParseParameterDeclarations(1);
71
                for(i = 0;i < nparms;++i) {
72
                        if( (sp1 = search(names[i],&lsyms)) == NULL)
73
                                sp1 = makeint(names[i]);
74
                                                //if( sp1->tp->size < 8 )
75
                                                //{
76
                                                //      sp1->value.i = poffset;// + (8 - sp1->tp->size);
77
                                                //      poffset += 8;
78
                                                //}
79
                                                //else
80
                                                //{
81
                                                //      sp1->value.i = poffset;
82
                                                //      poffset += sp1->tp->size;
83
                                                //}
84
                                                sp1->value.i = poffset;
85
                                                poffset += 8;
86
                        sp1->storage_class = sc_auto;
87
                                                sp1->nextparm = NULL;
88
                                                // record parameter list
89
                                                if (sp->parms == NULL) {
90
                                                        sp->parms = sp1;
91
                                                }
92
                                                else {
93
                                                        sp1->nextparm = sp->parms;
94
                                                        sp->parms = sp1;
95
                                                }
96
                                        }
97
                }
98
                if (lastst == closepa)
99
                        NextToken();
100
                if (lastst == semicolon) {      // Function prototype
101
                        sp->IsPrototype = 1;
102
                        sp->IsNocall = isNocall;
103
                        sp->IsPascal = isPascal;
104
                        sp->IsInterrupt = isInterrupt;
105
                        sp->NumParms = nparms;
106
                        isPascal = FALSE;
107
                        isOscall = FALSE;
108
                        isInterrupt = FALSE;
109
                        isNocall = FALSE;
110
                    ReleaseLocalMemory();        /* release local symbols (parameters)*/
111
                }
112
                else if(lastst != begin) {
113
                        NextToken();
114
                        ParseParameterDeclarations(2);
115
                        sp->IsNocall = isNocall;
116
                        sp->IsPascal = isPascal;
117
                        sp->IsInterrupt = isInterrupt;
118
                        sp->NumParms = nparms;
119
                        ParseFunctionBody(sp);
120
                        funcbottom();
121
                }
122
//                error(ERR_BLOCK);
123
        else {
124
                        sp->IsNocall = isNocall;
125
                        sp->IsPascal = isPascal;
126
                        sp->IsInterrupt = isInterrupt;
127
                        sp->NumParms = nparms;
128
                        ParseFunctionBody(sp);
129
                        funcbottom();
130
        }
131
                global_flag = oldglobal;
132
}
133
 
134
SYM     *makeint(char *name)
135
{       SYM     *sp;
136
        TYP     *tp;
137
        sp = allocSYM();
138
        tp = allocTYP();
139
        tp->type = bt_long;
140
        tp->size = 8;
141
        tp->btp = 0;
142
                tp->lst.head = 0;
143
        tp->sname = 0;
144
        sp->name = name;
145
        sp->storage_class = sc_auto;
146
        sp->tp = tp;
147
                sp->IsPrototype = FALSE;
148
        insert(sp,&lsyms);
149
        return sp;
150
}
151
 
152
void check_table(SYM *head)
153
{
154
        while( head != 0 ) {
155
                if( head->storage_class == sc_ulabel )
156
                                fprintf(list,"*** UNDEFINED LABEL - %s\n",head->name);
157
                head = head->next;
158
        }
159
}
160
 
161
void funcbottom()
162
{
163
        nl();
164
    check_table(&lsyms);
165
    lc_auto = 0;
166
    fprintf(list,"\n\n*** local symbol table ***\n\n");
167
    ListTable(&lsyms,0);
168
    fprintf(list,"\n\n\n");
169
    ReleaseLocalMemory();        /* release local symbols */
170
        isPascal = FALSE;
171
        isOscall = FALSE;
172
        isInterrupt = FALSE;
173
        isNocall = FALSE;
174
}
175
 
176
void ParseFunctionBody(SYM *sp)
177
{
178 51 robfinch
        char lbl[200];
179
 
180 37 robfinch
        needpunc(begin);
181
    ParseAutoDeclarations();
182
        cseg();
183
        if (sp->storage_class == sc_static)
184 51 robfinch
        {
185
                strcpy(lbl,GetNamespace());
186
                strcat(lbl,"_");
187
                strcat(lbl,sp->name);
188
                gen_strlab(lbl);
189
        }
190
        //      put_label((unsigned int) sp->value.i);
191 37 robfinch
        else
192
                gen_strlab(sp->name);
193
        currentFn = sp;
194
        currentFn->IsLeaf = TRUE;
195
        currentFn->DoesThrow = FALSE;
196
    GenerateFunction(sp, ParseCompoundStatement());
197
//      if (optimize)
198
                flush_peep();
199
}

powered by: WebSVN 2.1.0

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