]> git.sur5r.net Git - cc65/blob - src/cc65/exprdesc.c
f31d4ef6bd175bacf12b11a7205e512c834ce1e6
[cc65] / src / cc65 / exprdesc.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                exprdesc.c                                 */
4 /*                                                                           */
5 /*                      Expression descriptor structure                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* cc65 */
37 #include "datatype.h"
38 #include "symentry.h"
39 #include "exprdesc.h"
40
41
42
43 /*****************************************************************************/
44 /*                                   Code                                    */
45 /*****************************************************************************/
46
47
48
49 void MakeConstIntExpr (ExprDesc* Expr, long Value)
50 /* Make Expr a constant integer expression with the given value */
51 {
52     Expr->Flags = E_MCONST;
53     Expr->Type = type_int;
54     Expr->ConstVal = Value;
55 }
56
57
58
59 void PrintExprDesc (FILE* F, ExprDesc* E)
60 /* Print an ExprDesc */
61 {
62     fprintf (F, "Symbol: %s\n", E->Sym? E->Sym->Name : "(none)");
63     fprintf (F, "Type:   ");
64     if (E->Type) {
65         PrintType (F, E->Type);
66     } else {
67         fprintf (F, "(unknown)");
68     }
69     fprintf (F, "\n");
70     fprintf (F, "Value:  0x%08lX\n", E->ConstVal);
71     fprintf (F, "Flags:  ");
72     switch (E->Flags & E_MCTYPE) {
73         case E_TCONST:    fprintf (F, "E_TCONST ");                    break;
74         case E_TGLAB:     fprintf (F, "E_TGLAB ");                     break;
75         case E_TLIT:      fprintf (F, "E_TLIT ");                      break;
76         case E_TLOFFS:    fprintf (F, "E_TLOFFS ");                    break;
77         case E_TLLAB:     fprintf (F, "E_TLLAB ");                     break;
78         case E_TREGISTER: fprintf (F, "E_TREGISTER ");                 break;
79         default:          fprintf (F, "0x%02X ", E->Flags & E_MCTYPE); break;
80     }
81     if ((E->Flags & E_MREG) == E_MREG) {
82         fprintf (F, "E_MREG ");
83     } else if ((E->Flags & E_MEOFFS) == E_MEOFFS) {
84         fprintf (F, "E_MEOFFS ");
85     } else if ((E->Flags & E_MEXPR) == E_MEXPR) {
86         fprintf (F, "E_MEXPR ");
87     }
88     if ((E->Flags & E_MGLOBAL) == E_MGLOBAL) {
89         fprintf (F, "E_MGLOBAL ");
90     }
91     if ((E->Flags & E_MLOCAL) == E_MLOCAL) {
92         fprintf (F, "E_MLOCAL ");
93     }
94     if ((E->Flags & E_MCONST) == E_MCONST) {
95         fprintf (F, "E_MCONST ");
96     }
97     fprintf (F, "\n");
98
99     fprintf (F, "Test:    ");
100     if (E->Test & E_CC) {
101         fprintf (F, "E_CC ");
102     }
103     if (E->Test & E_FORCETEST) {
104         fprintf (F, "E_FORCETEST ");
105     }
106     fprintf (F, "\n");
107
108     fprintf (F, "Name:   0x%08lX\n", E->Name);
109 }
110
111
112
113 type* ReplaceType (ExprDesc* Expr, const type* NewType)
114 /* Replace the type of Expr by a copy of Newtype and return the old type string */
115 {
116     type* OldType = Expr->Type;
117     Expr->Type = TypeDup (NewType);
118     return OldType;
119 }
120
121
122