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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Cmain.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-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
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
void makename(char *s, char *e);
46
void summary();
47
int options(char *);
48
int openfiles(char *);
49
void closefiles();
50
int PreProcessFile(char *);
51
 
52
char            infile[256],
53
                listfile[256],
54
                outfile[256],
55
                                outfileG[256];
56
std::string     dbgfile;
57
 
58
extern TABLE    tagtable;
59
int             mainflag;
60
extern int      total_errors;
61
int uctran_off;
62
extern int lstackptr;
63
 
64
Compiler compiler;
65
 
66
int main(int argc, char **argv)
67
{
68
        opt_nopeep = FALSE;
69
        uctran_off = 0;
70
        optimize =1;
71
        exceptions=1;
72
        cpu.SupportsPop = false;
73
        cpu.SupportsPush = false;
74
        cpu.SupportsLink = false;
75
        cpu.SupportsUnlink = false;
76
 
77
//      printf("c64 starting...\r\n");
78
        while(--argc) {
79
    if( **++argv == '-')
80
      options(*argv);
81
                else {
82
                        if (PreProcessFile(*argv) == -1)
83
                                break;
84
                        if( openfiles(*argv)) {
85
                                lineno = 0;
86
                                initsym();
87
        compiler.compile();
88
//                              compile();
89
                                summary();
90
                                MBlk::ReleaseAll();
91
//                              ReleaseGlobalMemory();
92
                                closefiles();
93
                        }
94
    }
95
    dfs.printf("<CmdNext>Next on command line (%d).</CmdNext>\n", argc);
96
  }
97
        //getchar();
98
        dfs.printf("<Exit></Exit>\n");
99
        dfs.close();
100
        exit(0);
101
        return (0);
102
}
103
 
104
int     options(char *s)
105
{
106
    int nn;
107
 
108
        if (s[1]=='o') {
109
        for (nn = 2; s[nn]; nn++) {
110
            switch(s[nn]) {
111
            case 'r':     opt_noregs = TRUE; break;
112
                        case 'p':     ::opt_nopeep = TRUE; break;
113
            case 'x':     opt_noexpr = TRUE; break;
114
                        case 'c':         opt_nocgo = TRUE; break;
115
            }
116
        }
117
        if (nn==2) {
118
            opt_noregs = TRUE;
119
            ::opt_nopeep = TRUE;
120
            opt_noexpr = TRUE;
121
                        opt_nocgo = TRUE;
122
            optimize = FALSE;
123
        }
124
    }
125
        else if (s[1]=='f') {
126
                if (strcmp(&s[2],"no-exceptions")==0)
127
                        exceptions = 0;
128
                if (strcmp(&s[2],"farcode")==0)
129
                        farcode = 1;
130
        }
131
        else if (s[1]=='a') {
132
        address_bits = atoi(&s[2]);
133
    }
134
        else if (s[1]=='p') {
135
        if (strcmp(&s[2],"FISA64")==0) {
136
             gCpu = FISA64;
137
             regLR = 31;
138
             regPC = 29;
139
             regSP = 30;
140
             regFP = 27;
141
             regGP = 26;
142
             regXLR = 28;
143
             use_gp = TRUE;
144
        }
145
        }
146
        else if (s[1]=='w')
147
                wcharSupport = 0;
148
        else if (s[1]=='v') {
149
         if (s[2]=='0')
150
             verbose = 0;
151
         else
152
             verbose = 1;
153
    }
154
        else if (s[1] == 'r') {
155
                if (s[2] == 'v') {
156
                        opt_vreg = TRUE;
157
                        regSP = 1023;
158
                        regFP = 1022;
159
                        regLR = 1021;
160
                        regXLR = 1020;
161
                        regGP = 1019;
162
                        regTP = 1018;
163
                        regCLP = 1017;              // class pointer
164
                        regPP = 1016;                           // program pointer
165
                        regZero = 0;
166
                        regFirstTemp = 3;
167
                        regLastTemp = 511;
168
                        regFirstRegvar = 512;
169
                        regLastRegvar = 979;
170
                        regFirstArg = 980;
171
                        regLastArg = 1011;
172
                }
173
                else
174
                {
175
                        regSP = 31;
176
                        regFP = 30;
177
                        regLR = 29;
178
                        regXLR = 28;
179
                        regGP = 27;
180
                        regTP = 26;
181
                        regCLP = 25;                // class pointer
182
                        regPP = 24;                                     // program pointer
183
                        regZero = 0;
184
                        regFirstTemp = 3;
185
                        regLastTemp = 10;
186
                        regFirstRegvar = 11;
187
                        regLastRegvar = 17;
188
                        regFirstArg = 18;
189
                        regLastArg = 22;
190
                }
191
        }
192
    else if (s[1]=='S')
193
        mixedSource = TRUE;
194
        return 0;
195
}
196
 
197
int PreProcessFile(char *nm)
198
{
199
        static char outname[1000];
200
        static char sysbuf[500];
201
 
202
        strcpy_s(outname, sizeof(outname), nm);
203
        makename(outname,".fpp");
204
        snprintf(sysbuf, sizeof(sysbuf), "fpp -b %s %s", nm, outname);
205
        return system(sysbuf);
206
}
207
 
208
int openfiles(char *s)
209
{
210
        char *p;
211
        strcpy_s(infile,sizeof(infile),s);
212
        strcpy_s(listfile,sizeof(listfile),s);
213
        strcpy_s(outfile,sizeof(outfile),s);
214
  dbgfile = s;
215
 
216
                //strcpy(outfileG,s);
217
                _splitpath(s,NULL,NULL,nmspace[0],NULL);
218
//              strcpy(nmspace[0],basename(s));
219
                p = strrchr(nmspace[0],'.');
220
                if (p)
221
                        *p = '\0';
222
                makename(infile,".fpp");
223
        makename(listfile,".lis");
224
        makename(outfile,".s");
225
    dbgfile += ".xml";
226
                ifs = new std::ifstream();
227
                ifs->open(infile,std::ios::in);
228
/*
229
        if( (input = fopen(infile,"r")) == 0) {
230
                                i = errno;
231
                printf(" cant open %s\n",infile);
232
                return 0;
233
                }
234
*/
235
/*
236
        ofl = creat(outfile,-1);
237
        if( ofl < 0 )
238
                {
239
                printf(" cant create %s\n",outfile);
240
                fclose(input);
241
                return 0;
242
                }
243
*/
244
        //oflg = _creat(outfileG,-1);
245
        //if( oflg < 0 )
246
        //        {
247
        //        printf(" cant create %s\n",outfileG);
248
        //        fclose(input);
249
        //        return 0;
250
        //        }
251
                ofs.open(outfile,std::ios::out|std::ios::trunc);
252
                dfs.open(dbgfile.c_str(),std::ios::out|std::ios::trunc);
253
                dfs.level = 1;
254
                dfs.puts("<title>C64D Compiler debug file</title>\n");
255
                dfs.level = 1;
256
                lfs.level = 1;
257
                ofs.level = 1;
258
/*
259
        if( (output = fdopen(ofl,"w")) == 0) {
260
                printf(" cant open %s\n",outfile);
261
                fclose(input);
262
                return 0;
263
                }
264
*/
265
        //if( (outputG = _fdopen(oflg,"w")) == 0) {
266
        //        printf(" cant open %s\n",outfileG);
267
        //        fclose(input);
268
        //        fclose(output);
269
        //        return 0;
270
        //        }
271
        try {
272
                        lfs.open(listfile,std::ios::out|std::ios::trunc);
273
                }
274
                catch(...) {
275
                        closefiles();
276
                        return 0;
277
                }
278
/*
279
        if( (list = fopen(listfile,"w")) == 0) {
280
                printf(" cant open %s\n",listfile);
281
                fclose(input);
282
                fclose(output);
283
                //fclose(outputG);
284
                return 0;
285
                }
286
*/
287
        return 1;
288
}
289
 
290
void makename(char *s, char *e)
291
{
292
        int n;
293
 
294
        n = strlen(s);
295
        while(s[n]!='.' && n >= 0) n--;
296
        strcpy(&s[n],e);
297
        //while(*s != 0 && *s != '.')
298
 //       ++s;
299
 //   while(*s++ = *e++);
300
}
301
 
302
void summary()
303
{
304
//    if (verbose > 0)
305
  dfs.printf("<summary>\n");
306
        printf("\n -- %d errors found.",total_errors);
307
    lfs.write("\f\n *** global scope typedef symbol table ***\n\n");
308
    ListTable(&gsyms[0],0);
309
    lfs.write("\n *** structures and unions ***\n\n");
310
    ListTable(&tagtable,0);
311
  dfs.printf("</summary>\n");
312
//      fflush(list);
313
}
314
 
315
void closefiles()
316
{
317
        dfs.printf("<closefiles>\n");
318
        ifs->close();
319
        delete ifs;
320
        dfs.printf("A");
321
        lfs.close();
322
        dfs.printf("B");
323
        ofs.close();
324
        dfs.printf("C");
325
        dfs.printf("</closefiles>\n");
326
}
327
 
328
char *GetNamespace()
329
{
330
        return nmspace[0];
331
//      return nmspace[incldepth];
332
}

powered by: WebSVN 2.1.0

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