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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Preprocessor.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2017  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// C64 - 'C' derived language compiler
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//                                                                          
23
// ============================================================================
24
//
25
#include "stdafx.h"
26
 
27
/*
28
 *      68000 C compiler
29
 *
30
 *      Copyright 1984, 1985, 1986 Matthew Brandt.
31
 *  all commercial rights reserved.
32
 *
33
 *      This compiler is intended as an instructive tool for personal use. Any
34
 *      use for profit without the written consent of the author is prohibited.
35
 *
36
 *      This compiler may be distributed freely for non-commercial use as long
37
 *      as this notice stays intact. Please forward any enhancements or questions
38
 *      to:
39
 *
40
 *              Matthew Brandt
41
 *              Box 920337
42
 *              Norcross, Ga 30092
43
 */
44
 
45
std::ifstream *inclfile[10];
46
//int             incldepth = 0;
47
int             inclline[10];
48
char            *lptr;
49
extern char     inpline[132];
50
int endifCount = 0;
51
extern void searchenv(char *filename, int, char *envname, char *pathname, int);
52
int dodefine();
53
int doinclude();
54
extern void getFilename();
55
 
56
int doifdef();
57
int doifndef();
58
int doendif();
59
 
60
int preprocess()
61
{
62
        ++lptr;
63
    lastch = ' ';
64
    NextToken();               /* get first word on line */
65
    if( lastst != id ) {
66
            error(ERR_PREPROC);
67
            return getline(incldepth == 0);
68
            }
69
    if( strcmp(lastkw,"include") == 0 )
70
            return doinclude();
71
    else if( strcmp(lastkw,"define") == 0 )
72
            return dodefine();
73
    else if (strcmp(lastkw,"ifdef")==0)
74
                        return doifdef();
75
    else if (strcmp(lastkw,"ifndef")==0)
76
                        return doifndef();
77
    else if (strcmp(lastkw,"endif")==0)
78
                        return doendif();
79
        else
80
        {
81
        error(ERR_PREPROC);
82
        return getline(incldepth == 0);
83
    }
84
}
85
 
86
int doinclude()
87
{
88
        int     rv;
89
        static char pathname[5000];
90
        char *p;
91
 
92
        parseEsc = FALSE;
93
    NextToken();               /* get file to include */
94
        if (lastst==lt) {
95
                getFilename();
96
                searchenv(laststr, sizeof(laststr), "C64INC", pathname, sizeof(pathname));
97
        }
98
        else
99
                strcpy_s(pathname, sizeof(pathname), laststr);
100
        parseEsc = TRUE;
101
    if( lastst != sconst ) {
102
            error(ERR_INCLFILE);
103
            return getline(incldepth == 0);
104
            }
105
    inclline[incldepth] = lineno;
106
    inclfile[incldepth++] = ifs;  /* push current input file */
107
        ifs = new std::ifstream();
108
    printf("%s\r\n", pathname);
109
    if( ifs == nullptr ) {
110
            ifs = inclfile[--incldepth];
111
            error(ERR_CANTOPEN);
112
            rv = getline(incldepth == 0);
113
            }
114
    else    {
115
                        ifs->open(pathname,std::ios::in);
116
                        _splitpath_s(pathname,NULL,0,NULL,0,nmspace[incldepth],100,NULL,0);
117
//                      strcpy(nmspace[incldepth],basename(pathname));
118
                        p = strrchr(nmspace[incldepth],'.');
119
                        if (p) *p = '\0';
120
            rv = getline(incldepth == 1);
121
            lineno = -32768;        /* dont list include files */
122
            }
123
    return rv;
124
}
125
 
126
int dodefine()
127
{
128
        SYM *sp;
129
 
130
    NextToken();               /* get past #define */
131
    if( lastst != id ) {
132
            error(ERR_DEFINE);
133
            return getline(incldepth == 0);
134
            }
135
    ++global_flag;          /* always do #define as globals */
136
    sp = allocSYM();
137
    sp->SetName(std::string(lastid));
138
    sp->value.s = my_strdup(lptr-1);
139
    defsyms.insert(sp);
140
    --global_flag;
141
    return getline(incldepth == 0);
142
}
143
 
144
int doifdef()
145
{
146
        SYM *sp;
147
        int rv;
148
        char *lne;
149
 
150
        lne = inpline;
151
        NextToken();
152
    if( lastst != id ) {
153
        error(ERR_DEFINE);
154
        return getline(incldepth == 0);
155
    }
156
        endifCount++;
157
        sp = defsyms.Find(lastid,false);
158
        if (sp == NULL) {
159
                do
160
                        rv = getline(incldepth == 0);
161
                while (rv==0 && endifCount!=0);
162
        }
163
    return getline(incldepth == 0);
164
}
165
 
166
int doifndef()
167
{
168
        SYM *sp;
169
        int rv;
170
 
171
        NextToken();
172
    if( lastst != id ) {
173
        error(ERR_DEFINE);
174
        return getline(incldepth == 0);
175
    }
176
        endifCount++;
177
        sp = defsyms.Find(lastid,false);
178
        if (sp != NULL) {
179
                do
180
                        rv = getline(incldepth == 0);
181
                while (rv==0 && endifCount!=0);
182
        }
183
    return getline(incldepth == 0);
184
}
185
 
186
int doendif()
187
{
188
        endifCount--;
189
    return getline(incldepth == 0);
190
}

powered by: WebSVN 2.1.0

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