]> git.sur5r.net Git - cc65/blob - src/cc65/exprdesc.c
Move default segment names into segnames.h
[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     if (E->Type) {
64         fprintf (F, "Type:     ");
65         PrintType (F, E->Type);
66         fprintf (F, "\nRaw type: ");
67         PrintRawType (F, E->Type);
68     } else {
69         fprintf (F, "Type:     (unknown)\n"
70                     "Raw type: (unknown)\n");
71     }
72     fprintf (F, "Value:    0x%08lX\n", E->ConstVal);
73     fprintf (F, "Flags:    ");
74     switch (E->Flags & E_MCTYPE) {
75         case E_TCONST:    fprintf (F, "E_TCONST ");                    break;
76         case E_TGLAB:     fprintf (F, "E_TGLAB ");                     break;
77         case E_TLIT:      fprintf (F, "E_TLIT ");                      break;
78         case E_TLOFFS:    fprintf (F, "E_TLOFFS ");                    break;
79         case E_TLLAB:     fprintf (F, "E_TLLAB ");                     break;
80         case E_TREGISTER: fprintf (F, "E_TREGISTER ");                 break;
81         default:          fprintf (F, "0x%02X ", E->Flags & E_MCTYPE); break;
82     }
83     if ((E->Flags & E_MREG) == E_MREG) {
84         fprintf (F, "E_MREG ");
85     } else if ((E->Flags & E_MEOFFS) == E_MEOFFS) {
86         fprintf (F, "E_MEOFFS ");
87     } else if ((E->Flags & E_MEXPR) == E_MEXPR) {
88         fprintf (F, "E_MEXPR ");
89     }
90     if ((E->Flags & E_MGLOBAL) == E_MGLOBAL) {
91         fprintf (F, "E_MGLOBAL ");
92     }
93     if ((E->Flags & E_MLOCAL) == E_MLOCAL) {
94         fprintf (F, "E_MLOCAL ");
95     }
96     if ((E->Flags & E_MCONST) == E_MCONST) {
97         fprintf (F, "E_MCONST ");
98     }
99
100     fprintf (F, "\nTest:     ");
101     if (E->Test & E_CC) {
102         fprintf (F, "E_CC ");
103     }
104     if (E->Test & E_FORCETEST) {
105         fprintf (F, "E_FORCETEST ");
106     }
107
108     fprintf (F, "\nName:     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