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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Intexpr.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
//  - 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
int64_t GetIntegerExpression(ENODE **pnode)       /* simple integer value */
29
{
30
        TYP *tp;
31
        ENODE *node;
32
 
33
        tp = NonCommaExpression(&node);
34
        if (node==NULL) {
35
                error(ERR_SYNTAX);
36
                return 0;
37
        }
38
        opt_const(&node);       // This should reduce to a single integer expression
39
        if (node==NULL) {
40
                fatal("Compiler Error: GetIntegerExpression: node is NULL");
41
                return 0;
42
        }
43
        if (node->nodetype != en_icon && node->nodetype != en_cnacon) {
44
        printf("\r\nnode:%d \r\n", node->nodetype);
45
                error(ERR_INT_CONST);
46
                return 0;
47
        }
48
        if (pnode)
49
                *pnode = node;
50
        return node->i;
51
}
52
 
53
Float128 *GetFloatExpression(ENODE **pnode)       /* simple integer value */
54
{
55
        TYP *tp;
56
        ENODE *node;
57
        Float128 *flt;
58
 
59
        flt = (Float128 *)allocx(sizeof(Float128));
60
        tp = NonCommaExpression(&node);
61
        if (node==NULL) {
62
                error(ERR_SYNTAX);
63
                return 0;
64
        }
65
        opt_const(&node);       // This should reduce to a single integer expression
66
        if (node==NULL) {
67
                fatal("Compiler Error: GetFloatExpression: node is NULL");
68
                return 0;
69
        }
70
        if (node->nodetype != en_fcon) {
71
                if (node->nodetype==en_uminus) {
72
                        if (node->p[0]->nodetype != en_fcon) {
73
                                printf("\r\nnode:%d \r\n", node->nodetype);
74
                                error(ERR_INT_CONST);
75
                                return 0;
76
                        }
77
                        Float128::Assign(flt, &node->p[0]->f128);
78
                        flt->sign = !flt->sign;
79
                        if (pnode)
80
                                *pnode = node;
81
                        return (flt);
82
                }
83
        }
84
        if (pnode)
85
                *pnode = node;
86
        return &node->f128;
87
}
88
 
89
int64_t GetConstExpression(ENODE **pnode)       /* simple integer value */
90
{
91
        TYP *tp;
92
        ENODE *node;
93
        Float128 *flt;
94
 
95
        tp = NonCommaExpression(&node);
96
        if (node == NULL) {
97
                error(ERR_SYNTAX);
98
                return (0);
99
        }
100
        opt_const(&node);       // This should reduce to a single integer expression
101
        if (node == NULL) {
102
                fatal("Compiler Error: GetConstExpression: node is NULL");
103
                return (0);
104
        }
105
        switch (node->nodetype)
106
        {
107
        case en_uminus:
108
                switch (node->p[0]->nodetype) {
109
                case en_icon:
110
                        if (pnode)
111
                                *pnode = node;
112
                        return (-node->i);
113
                case en_fcon:
114
                        flt = (Float128 *)allocx(sizeof(Float128));
115
                        Float128::Assign(flt, &node->p[0]->f128);
116
                        flt->sign = !flt->sign;
117
                        if (pnode)
118
                                *pnode = node;
119
                        return ((int64_t)flt);
120
                default:
121
                        error(ERR_CONST);
122
                        return (0);
123
                }
124
                break;
125
        case en_fcon:
126
                if (pnode)
127
                        *pnode = node;
128
                return ((int64_t)&node->f128);
129
        case en_icon:
130
        case en_cnacon:
131
                if (pnode)
132
                        *pnode = node;
133
                return (node->i);
134
        default:
135
                error(ERR_CONST);
136
                return (0);
137
        }
138
        error(ERR_CONST);
139
        return (0);
140
}

powered by: WebSVN 2.1.0

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