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
56struct CodeEntry;
57struct CodeLabel;
58struct CodeSeg;
59struct DataSeg;
60struct TextSeg;
61struct SymEntry;
62
63
64
65/*****************************************************************************/
66/* Data */
67/*****************************************************************************/
68
69
70
71/* Segment types */
72typedef 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 */
81typedef struct Segments Segments;
82struct 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. */
92extern Segments* CS;
93
94/* Pointer to the global segment list */
95extern Segments* GS;
96
97
98
99/*****************************************************************************/
100/* Code */
101/*****************************************************************************/
102
103
104
105void InitSegNames (void);
106/* Initialize the segment names */
107
108void SetSegName (segment_t Seg, const char* Name);
109/* Set a new name for a segment */
110
111void PushSegName (segment_t Seg, const char* Name);
112/* Push the current segment name and set a new name for a segment */
113
114void PopSegName (segment_t Seg);
115/* Restore a segment name from the segment name stack */
116
117const char* GetSegName (segment_t Seg);
118/* Get the name of the given segment */
119
120Segments* PushSegments (struct SymEntry* Func);
121/* Make the new segment list current but remember the old one */
122
123void PopSegments (void);
124/* Pop the old segment list (make it current) */
125
126void CreateGlobalSegments (void);
127/* Create the global segments and remember them in GS */
128
129void UseDataSeg (segment_t DSeg);
130/* For the current segment list, use the data segment DSeg */
131
132struct DataSeg* GetDataSeg (void);
133/* Return the current data segment */
134
135void AddTextLine (const char* Format, ...) attribute ((format (printf, 1, 2)));
136/* Add a line to the current text segment */
137
138void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2)));
139/* Add a line of code to the current code segment */
140
141void AddCode (opc_t OPC, am_t AM, const char* Arg, struct CodeLabel* JumpTo);
142/* Add a code entry to the current code segment */
143
144void AddDataLine (const char* Format, ...) attribute ((format (printf, 1, 2)));
145/* Add a line of data to the current data segment */
146
147int HaveGlobalCode (void);
148/* Return true if the global code segment contains entries (which is an error) */
149
150void RemoveGlobalCode (void);
151/* Remove all code from the global code segment. Used for error recovery. */
152
153void 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