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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [c64/] [source/] [Preprocessor.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 <string.h>
3
#include        "c.h"
4
#include        "expr.h"
5
#include "Statement.h"
6
#include        "gen.h"
7
#include        "cglbdec.h"
8
 
9
/*
10
 *      68000 C compiler
11
 *
12
 *      Copyright 1984, 1985, 1986 Matthew Brandt.
13
 *  all commercial rights reserved.
14
 *
15
 *      This compiler is intended as an instructive tool for personal use. Any
16
 *      use for profit without the written consent of the author is prohibited.
17
 *
18
 *      This compiler may be distributed freely for non-commercial use as long
19
 *      as this notice stays intact. Please forward any enhancements or questions
20
 *      to:
21
 *
22
 *              Matthew Brandt
23
 *              Box 920337
24
 *              Norcross, Ga 30092
25
 */
26
/*******************************************************
27
        Copyright 2012  Robert Finch
28
        Modified to support Raptor64 'C64' language
29
        by Robert Finch
30
        robfinch@opencores.org
31
*******************************************************/
32
 
33
FILE            *inclfile[10];
34 51 robfinch
//int             incldepth = 0;
35 37 robfinch
int             inclline[10];
36
char            *lptr;
37
extern char     inpline[132];
38
int endifCount = 0;
39
int dodefine();
40
int doinclude();
41
 
42
int preprocess()
43
{
44
        ++lptr;
45
    lastch = ' ';
46
    NextToken();               /* get first word on line */
47
    if( lastst != id ) {
48
            error(ERR_PREPROC);
49
            return getline(incldepth == 0);
50
            }
51
    if( strcmp(lastid,"include") == 0 )
52
            return doinclude();
53
    else if( strcmp(lastid,"define") == 0 )
54
            return dodefine();
55
    else if (strcmp(lastid,"ifdef")==0)
56
                        return doifdef();
57
    else if (strcmp(lastid,"ifndef")==0)
58
                        return doifndef();
59
    else if (strcmp(lastid,"endif")==0)
60
                        return doendif();
61
        else
62
        {
63
        error(ERR_PREPROC);
64
        return getline(incldepth == 0);
65
    }
66
}
67
 
68
int doinclude()
69
{
70
        int     rv;
71
    NextToken();               /* get file to include */
72
    if( lastst != sconst ) {
73
            error(ERR_INCLFILE);
74
            return getline(incldepth == 0);
75
            }
76
    inclline[incldepth] = lineno;
77
    inclfile[incldepth++] = input;  /* push current input file */
78
    input = fopen(laststr,"r");
79
    if( input == 0 ) {
80
            input = inclfile[--incldepth];
81
            error(ERR_CANTOPEN);
82
            rv = getline(incldepth == 0);
83
            }
84
    else    {
85 51 robfinch
                        _splitpath(laststr,NULL,NULL,nmspace[incldepth],NULL);
86 37 robfinch
            rv = getline(incldepth == 1);
87
            lineno = -32768;        /* dont list include files */
88
            }
89
    return rv;
90
}
91
 
92
int dodefine()
93
{
94
        SYM     *sp;
95
    NextToken();               /* get past #define */
96
    if( lastst != id ) {
97
            error(ERR_DEFINE);
98
            return getline(incldepth == 0);
99
            }
100
    ++global_flag;          /* always do #define as globals */
101
    sp = allocSYM();
102
    sp->name = litlate(lastid);
103
    sp->value.s = litlate(lptr-1);
104
    insert(sp,&defsyms);
105
    --global_flag;
106
    return getline(incldepth == 0);
107
}
108
 
109
int doifdef()
110
{
111
        SYM *sp;
112
        int rv;
113
        char *lne;
114
 
115
        lne = inpline;
116
        NextToken();
117
    if( lastst != id ) {
118
        error(ERR_DEFINE);
119
        return getline(incldepth == 0);
120
    }
121
        endifCount++;
122
        sp = search(lastid,&defsyms);
123
        if (sp == NULL) {
124
                do
125
                        rv = getline(incldepth == 0);
126
                while (rv==0 && endifCount!=0);
127
        }
128
    return getline(incldepth == 0);
129
}
130
 
131
int doifndef()
132
{
133
        SYM *sp;
134
        int rv;
135
 
136
        NextToken();
137
    if( lastst != id ) {
138
        error(ERR_DEFINE);
139
        return getline(incldepth == 0);
140
    }
141
        endifCount++;
142
        sp = search(lastid,&defsyms);
143
        if (sp != NULL) {
144
                do
145
                        rv = getline(incldepth == 0);
146
                while (rv==0 && endifCount!=0);
147
        }
148
    return getline(incldepth == 0);
149
}
150
 
151
int doendif()
152
{
153
        endifCount--;
154
    return getline(incldepth == 0);
155
}
156
 
157


powered by: WebSVN 2.1.0

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