1 | /*****************************************************************************/ |
2 | /* */ |
3 | /* segments.h */ |
4 | /* */ |
5 | /* Segment management */ |
6 | /* */ |
7 | /* */ |
8 | /* */ |
9 | /* (C) 2000-2009, Ullrich von Bassewitz */ |
10 | /* Roemerstrasse 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 | #ifndef SEGMENTS_H |
37 | #define SEGMENTS_H |
38 | |
39 | |
40 | |
41 | #include <stdio.h> |
42 | |
43 | /* common */ |
44 | #include "attrib.h" |
45 | |
46 | /* cc65 */ |
47 | #include "opcodes.h" |
48 | |
49 | |
50 | /*****************************************************************************/ |
51 | /* Forwards */ |
52 | /*****************************************************************************/ |
53 | |
54 | |
55 | |
56 | struct CodeEntry; |
57 | struct CodeLabel; |
58 | struct CodeSeg; |
59 | struct DataSeg; |
60 | struct TextSeg; |
61 | struct SymEntry; |
62 | |
63 | |
64 | |
65 | /*****************************************************************************/ |
66 | /* Data */ |
67 | /*****************************************************************************/ |
68 | |
69 | |
70 | |
71 | /* Segment types */ |
72 | typedef enum segment_t { |
73 | SEG_CODE, |
74 | SEG_RODATA, |
75 | SEG_DATA, |
76 | SEG_BSS, |
77 | SEG_COUNT |
78 | } segment_t; |
79 | |
80 | /* A list of all segments used when generating code */ |
81 | typedef struct Segments Segments; |
82 | struct Segments { |
83 | struct TextSeg* Text; /* Text segment */ |
84 | struct CodeSeg* Code; /* Code segment */ |
85 | struct DataSeg* Data; /* Data segment */ |
86 | struct DataSeg* ROData; /* Readonly data segment */ |
87 | struct DataSeg* BSS; /* Segment for uninitialized data */ |
88 | segment_t CurDSeg; /* Current data segment */ |
89 | }; |
90 | |
91 | /* Pointer to the current segment list. Output goes here. */ |
92 | extern Segments* CS; |
93 | |
94 | /* Pointer to the global segment list */ |
95 | extern Segments* GS; |
96 | |
97 | |
98 | |
99 | /*****************************************************************************/ |
100 | /* Code */ |
101 | /*****************************************************************************/ |
102 | |
103 | |
104 | |
105 | void InitSegNames (void); |
106 | /* Initialize the segment names */ |
107 | |
108 | void SetSegName (segment_t Seg, const char* Name); |
109 | /* Set a new name for a segment */ |
110 | |
111 | void PushSegName (segment_t Seg, const char* Name); |
112 | /* Push the current segment name and set a new name for a segment */ |
113 | |
114 | void PopSegName (segment_t Seg); |
115 | /* Restore a segment name from the segment name stack */ |
116 | |
117 | const char* GetSegName (segment_t Seg); |
118 | /* Get the name of the given segment */ |
119 | |
120 | Segments* PushSegments (struct SymEntry* Func); |
121 | /* Make the new segment list current but remember the old one */ |
122 | |
123 | void PopSegments (void); |
124 | /* Pop the old segment list (make it current) */ |
125 | |
126 | void CreateGlobalSegments (void); |
127 | /* Create the global segments and remember them in GS */ |
128 | |
129 | void UseDataSeg (segment_t DSeg); |
130 | /* For the current segment list, use the data segment DSeg */ |
131 | |
132 | struct DataSeg* GetDataSeg (void); |
133 | /* Return the current data segment */ |
134 | |
135 | void AddTextLine (const char* Format, ...) attribute ((format (printf, 1, 2))); |
136 | /* Add a line to the current text segment */ |
137 | |
138 | void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2))); |
139 | /* Add a line of code to the current code segment */ |
140 | |
141 | void AddCode (opc_t OPC, am_t AM, const char* Arg, struct CodeLabel* JumpTo); |
142 | /* Add a code entry to the current code segment */ |
143 | |
144 | void AddDataLine (const char* Format, ...) attribute ((format (printf, 1, 2))); |
145 | /* Add a line of data to the current data segment */ |
146 | |
147 | int HaveGlobalCode (void); |
148 | /* Return true if the global code segment contains entries (which is an error) */ |
149 | |
150 | void RemoveGlobalCode (void); |
151 | /* Remove all code from the global code segment. Used for error recovery. */ |
152 | |
153 | void OutputSegments (const Segments* S); |
154 | /* Output the given segments to the output file */ |
155 | |
156 | |
157 | |
158 | /* End of segments.h */ |
159 | |
160 | #endif |
161 | |