]> git.sur5r.net Git - cc65/blob - src/cc65/codeent.h
4c37eeb4fbe982ab32e4f0c96cfeb013956ccf5b
[cc65] / src / cc65 / codeent.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 codeent.h                                 */
4 /*                                                                           */
5 /*                            Code segment entry                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 #ifndef CODEENT_H
37 #define CODEENT_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "coll.h"
45 #include "inline.h"
46
47 /* cc65 */
48 #include "codelab.h"
49 #include "opcodes.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Data                                    */
55 /*****************************************************************************/
56
57
58
59 /* Flags used */
60 #define CEF_USERMARK    0x0001U         /* Generic mark by user functions */
61 #define CEF_NUMARG      0x0002U         /* Insn has numerical argument */
62
63 /* Code entry structure */
64 typedef struct CodeEntry CodeEntry;
65 struct CodeEntry {
66     opc_t               OPC;            /* Opcode */
67     am_t                AM;             /* Adressing mode */
68     unsigned char       Size;           /* Estimated size */
69     unsigned char       Hints;          /* Hints for this entry */
70     char*               Arg;            /* Argument as string */
71     unsigned long       Num;            /* Numeric argument */
72     unsigned short      Flags;          /* Flags */
73     unsigned char       Info;           /* Additional code info */
74     unsigned char       Use;            /* Registers used */
75     unsigned char       Chg;            /* Registers changed/destroyed */
76     CodeLabel*          JumpTo;         /* Jump label */
77     Collection          Labels;         /* Labels for this instruction */
78 };
79
80
81
82 /*****************************************************************************/
83 /*                                   Code                                    */
84 /*****************************************************************************/
85
86
87
88 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg, CodeLabel* JumpTo);
89 /* Create a new code entry, initialize and return it */
90
91 void FreeCodeEntry (CodeEntry* E);
92 /* Free the given code entry */
93
94 void ReplaceOPC (CodeEntry* E, opc_t OPC);
95 /* Replace the opcode of the instruction. This will also replace related info,
96  * Size, Use and Chg, but it will NOT update any arguments or labels.
97  */
98
99 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2);
100 /* Check if both code entries are equal */
101
102 void AttachCodeLabel (CodeEntry* E, CodeLabel* L);
103 /* Attach the label to the entry */
104
105 #if defined(HAVE_INLINE)
106 INLINE int CodeEntryHasLabel (const CodeEntry* E)
107 /* Check if the given code entry has labels attached */
108 {
109     return (CollCount (&E->Labels) > 0);
110 }
111 #else
112 #  define CodeEntryHasLabel(E)  (CollCount (&(E)->Labels) > 0)
113 #endif
114
115 #if defined(HAVE_INLINE)
116 INLINE unsigned GetCodeLabelCount (const CodeEntry* E)
117 /* Get the number of labels attached to this entry */
118 {
119     return CollCount (&E->Labels);
120 }
121 #else
122 #  define GetCodeLabelCount(E)  CollCount (&(E)->Labels)
123 #endif
124
125 #if defined(HAVE_INLINE)
126 INLINE CodeLabel* GetCodeLabel (CodeEntry* E, unsigned Index)
127 /* Get a label from this code entry */
128 {
129     return CollAt (&E->Labels, Index);
130 }
131 #else
132 #  define GetCodeLabel(E, Index)        CollAt (&(E)->Labels, (Index))
133 #endif
134
135 void MoveCodeLabel (CodeLabel* L, CodeEntry* E);
136 /* Move the code label L from it's former owner to the code entry E. */
137
138 #if defined(HAVE_INLINE)
139 INLINE int CodeEntryHasMark (const CodeEntry* E)
140 /* Return true if the given code entry has the CEF_USERMARK flag set */
141 {
142     return (E->Flags & CEF_USERMARK) != 0;
143 }
144 #else
145 #  define CodeEntryHasMark(E)   (((E)->Flags & CEF_USERMARK) != 0)
146 #endif
147
148 #if defined(HAVE_INLINE)
149 INLINE void CodeEntrySetMark (CodeEntry* E)
150 /* Set the CEF_USERMARK flag for the given entry */
151 {
152     E->Flags |= CEF_USERMARK;
153 }
154 #else
155 #  define CodeEntrySetMark(E)   ((E)->Flags |= CEF_USERMARK)
156 #endif
157
158 #if defined(HAVE_INLINE)
159 INLINE void CodeEntryResetMark (CodeEntry* E)
160 /* Reset the CEF_USERMARK flag for the given entry */
161 {
162     E->Flags &= ~CEF_USERMARK;
163 }
164 #else
165 #  define CodeEntryResetMark(E) ((E)->Flags &= ~CEF_USERMARK)
166 #endif
167
168 void CodeEntrySetArg (CodeEntry* E, const char* Arg);
169 /* Set a new argument for the given code entry. An old string is deleted. */
170
171 void OutputCodeEntry (const CodeEntry* E, FILE* F);
172 /* Output the code entry to a file */
173
174
175
176 /* End of codeent.h */
177 #endif
178
179
180