]> git.sur5r.net Git - cc65/blob - src/cc65/exprdesc.c
4b5de5bfcd8da85af10f982acea1b32f64760c1e
[cc65] / src / cc65 / exprdesc.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                exprdesc.c                                 */
4 /*                                                                           */
5 /*                      Expression descriptor structure                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 52                                              */
11 /*               D-70794 Filderstadt                                         */
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 ExprDesc* ED_MakeConstInt (ExprDesc* Expr, long Value)
50 /* Make Expr a constant integer expression with the given value */
51 {
52     Expr->Flags = E_MCONST | E_RVAL;
53     Expr->Type = type_int;
54     Expr->ConstVal = Value;
55     return Expr;
56 }
57
58
59
60 void PrintExprDesc (FILE* F, ExprDesc* E)
61 /* Print an ExprDesc */
62 {
63     fprintf (F, "Symbol:   %s\n", E->Sym? E->Sym->Name : "(none)");
64     if (E->Type) {
65         fprintf (F, "Type:     ");
66         PrintType (F, E->Type);
67         fprintf (F, "\nRaw type: ");
68         PrintRawType (F, E->Type);
69     } else {
70         fprintf (F, "Type:     (unknown)\n"
71                     "Raw type: (unknown)\n");
72     }
73     fprintf (F, "Value:    0x%08lX\n", E->ConstVal);
74     fprintf (F, "Flags:    ");
75     switch (E->Flags & E_MCTYPE) {
76         case E_TCONST:    fprintf (F, "E_TCONST ");                    break;
77         case E_TGLAB:     fprintf (F, "E_TGLAB ");                     break;
78         case E_TLIT:      fprintf (F, "E_TLIT ");                      break;
79         case E_TLOFFS:    fprintf (F, "E_TLOFFS ");                    break;
80         case E_TLLAB:     fprintf (F, "E_TLLAB ");                     break;
81         case E_TREGISTER: fprintf (F, "E_TREGISTER ");                 break;
82         default:          fprintf (F, "0x%02X ", E->Flags & E_MCTYPE); break;
83     }
84     if ((E->Flags & E_MREG) == E_MREG) {
85         fprintf (F, "E_MREG ");
86     } else if ((E->Flags & E_MEOFFS) == E_MEOFFS) {
87         fprintf (F, "E_MEOFFS ");
88     } else if ((E->Flags & E_MEXPR) == E_MEXPR) {
89         fprintf (F, "E_MEXPR ");
90     }
91     if ((E->Flags & E_MGLOBAL) == E_MGLOBAL) {
92         fprintf (F, "E_MGLOBAL ");
93     }
94     if ((E->Flags & E_MLOCAL) == E_MLOCAL) {
95         fprintf (F, "E_MLOCAL ");
96     }
97     if ((E->Flags & E_MCONST) == E_MCONST) {
98         fprintf (F, "E_MCONST ");
99     }
100
101     fprintf (F, "\nTest:     ");
102     if (E->Test & E_CC) {
103         fprintf (F, "E_CC ");
104     }
105     if (E->Test & E_FORCETEST) {
106         fprintf (F, "E_FORCETEST ");
107     }
108
109     fprintf (F, "\nName:     0x%08lX\n", E->Name);
110 }
111
112
113
114 type* ReplaceType (ExprDesc* Expr, const type* NewType)
115 /* Replace the type of Expr by a copy of Newtype and return the old type string */
116 {
117     type* OldType = Expr->Type;
118     Expr->Type = TypeDup (NewType);
119     return OldType;
120 }
121
122
123