]> git.sur5r.net Git - cc65/blob - src/cc65/codeent.h
Extend usage information
[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 "lineinfo.h"
50 #include "opcodes.h"
51 #include "reginfo.h"
52
53
54
55 /*****************************************************************************/
56 /*                                   Data                                    */
57 /*****************************************************************************/
58
59
60
61 /* Flags used */
62 #define CEF_USERMARK    0x0001U         /* Generic mark by user functions */
63 #define CEF_NUMARG      0x0002U         /* Insn has numerical argument */
64
65 /* Code entry structure */
66 typedef struct CodeEntry CodeEntry;
67 struct CodeEntry {
68     opc_t               OPC;            /* Opcode */
69     am_t                AM;             /* Adressing mode */
70     char*               Arg;            /* Argument as string */
71     unsigned long       Num;            /* Numeric argument */
72     unsigned short      Flags;          /* Flags */
73     unsigned short      Info;           /* Additional code info */
74     unsigned short      Use;            /* Registers used */
75     unsigned short      Chg;            /* Registers changed/destroyed */
76     unsigned char       Size;           /* Estimated size */
77     CodeLabel*          JumpTo;         /* Jump label */
78     Collection          Labels;         /* Labels for this instruction */
79     LineInfo*           LI;             /* Source line info for this insn */
80     RegInfo*            RI;             /* Register info for this insn */
81 };
82
83
84
85 /*****************************************************************************/
86 /*                                   Code                                    */
87 /*****************************************************************************/
88
89
90
91 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
92                          CodeLabel* JumpTo, LineInfo* LI);
93 /* Create a new code entry, initialize and return it */
94
95 void FreeCodeEntry (CodeEntry* E);
96 /* Free the given code entry */
97
98 void CE_ReplaceOPC (CodeEntry* E, opc_t OPC);
99 /* Replace the opcode of the instruction. This will also replace related info,
100  * Size, Use and Chg, but it will NOT update any arguments or labels.
101  */
102
103 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2);
104 /* Check if both code entries are equal */
105
106 void CE_AttachLabel (CodeEntry* E, CodeLabel* L);
107 /* Attach the label to the entry */
108
109 #if defined(HAVE_INLINE)
110 INLINE int CE_HasLabel (const CodeEntry* E)
111 /* Check if the given code entry has labels attached */
112 {
113     return (CollCount (&E->Labels) > 0);
114 }
115 #else
116 #  define CE_HasLabel(E)        (CollCount (&(E)->Labels) > 0)
117 #endif
118
119 #if defined(HAVE_INLINE)
120 INLINE unsigned CE_GetLabelCount (const CodeEntry* E)
121 /* Get the number of labels attached to this entry */
122 {
123     return CollCount (&E->Labels);
124 }
125 #else
126 #  define CE_GetLabelCount(E)   CollCount (&(E)->Labels)
127 #endif
128
129 #if defined(HAVE_INLINE)
130 INLINE CodeLabel* CE_GetLabel (CodeEntry* E, unsigned Index)
131 /* Get a label from this code entry */
132 {
133     return CollAt (&E->Labels, Index);
134 }
135 #else
136 #  define CE_GetLabel(E, Index) CollAt (&(E)->Labels, (Index))
137 #endif
138
139 void CE_MoveLabel (CodeLabel* L, CodeEntry* E);
140 /* Move the code label L from it's former owner to the code entry E. */
141
142 #if defined(HAVE_INLINE)
143 INLINE int CE_HasMark (const CodeEntry* E)
144 /* Return true if the given code entry has the CEF_USERMARK flag set */
145 {
146     return (E->Flags & CEF_USERMARK) != 0;
147 }
148 #else
149 #  define CE_HasMark(E) (((E)->Flags & CEF_USERMARK) != 0)
150 #endif
151
152 #if defined(HAVE_INLINE)
153 INLINE void CE_SetMark (CodeEntry* E)
154 /* Set the CEF_USERMARK flag for the given entry */
155 {
156     E->Flags |= CEF_USERMARK;
157 }
158 #else
159 #  define CE_SetMark(E) ((E)->Flags |= CEF_USERMARK)
160 #endif
161
162 #if defined(HAVE_INLINE)
163 INLINE void CE_ResetMark (CodeEntry* E)
164 /* Reset the CEF_USERMARK flag for the given entry */
165 {
166     E->Flags &= ~CEF_USERMARK;
167 }
168 #else
169 #  define CE_ResetMark(E)       ((E)->Flags &= ~CEF_USERMARK)
170 #endif
171
172 void CE_SetArg (CodeEntry* E, const char* Arg);
173 /* Set a new argument for the given code entry. An old string is deleted. */
174
175 int CE_KnownImm (const CodeEntry* E);
176 /* Return true if the argument of E is a known immediate value */
177
178 void CE_FreeRegInfo (CodeEntry* E);
179 /* Free an existing register info struct */
180
181 void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs);
182 /* Generate register info for this instruction. If an old info exists, it is
183  * overwritten.
184  */
185
186 void CE_Output (const CodeEntry* E, FILE* F);
187 /* Output the code entry to a file */
188
189
190
191 /* End of codeent.h */
192 #endif
193
194
195
196