struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / linksrc / lksdcdb.c
blob762e6a29b47b0ba9ce7581e2619e3cafaecf2cef
1 /* lksdcdb.c */
3 /*
4 * Copyright (C) 2001-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
25 #include "aslink.h"
27 #if SDCDB
29 /*Module lkcdb.c
31 * The module lkcdb.c contains the functions
32 * required to create a SDCDB debug file.
34 * lksdcdb.c contains the following functions:
35 * VOID SDCDBfopen()
36 * VOID SDCDBcopy()
37 * VOID DefineSDCDB()
40 /*)Function VOID SDCDBfopen()
42 * The function SDCDBfopen() opens the SDCDB output file
43 * and sets the map flag, mflag, to create a map file.
44 * SDCDB processing is performed during map generation.
46 * local variables:
47 * none
49 * global variables:
50 * int yflag SDCDB Debug flag
51 * FILE * yfp SDCDB Debug File handle
52 * struct lfile *linkp Pointer to the Linker output file name
53 * int mflag Map output flag
55 * functions called:
56 * FILE * afile() lkmain.c
57 * VOID lkexit() lkmain.c
59 * side effects:
60 * The SDCDB output file is opened.
61 * Failure to open the file will
62 * terminate the linker.
65 VOID SDCDBfopen(void)
67 if (yflag) {
68 SaveLinkedFilePath(linkp->f_idp); //Must be the first one...
69 yfp = afile(linkp->f_idp, "cdb", 1);
70 if (yfp == NULL) {
71 lkexit(1);
73 mflag = 1;
78 /*)Function VOID SDCDBcopy()
80 * char * str pointer to the file spec
82 * The function SDCDBcopy() copies an existing adb file
83 * into the linker cdb file.
85 * The function is called from lklex.c and lklibr.c
87 * local variables:
88 * FILE * xfp file handle
89 * char line[] line from file
91 * global variables:
92 * int yflag SDCDB Debug flag
93 * FILE * yfp SDCDB Debug File handle
95 * functions called:
96 * FILE * afile() lkmain.c
97 * int fgets() c_library
98 * int fprintf() c_library
99 * int fclose() c_library
101 * side effects:
102 * SDCDB cdb file is copied into
103 * the linker cdb output file.
106 VOID SDCDBcopy(char * str)
108 FILE * xfp;
111 * Copy .adb file if present and requested.
113 if (yflag && yfp) {
114 xfp = afile(str, "adb", 0); //JCF: Nov 30, 2002
115 if (xfp) {
116 copyfile(yfp, xfp);
117 fclose(xfp);
123 /*)Function VOID DefineSDCDB()
125 * char * name pointer to the symbol string
126 * a_uint value value of symbol
128 * The function DefineSDCDB() processes the symbols into
129 * SDCDB commands for inclusion in the SDCDB output file.
131 * The function is called from lstarea in lklist.c
132 * for each symbol.
134 * local variables:
135 * int j argument count
136 * char * p1 temporary string pointer
138 * global variables:
139 * FILE * yfp SDCDB Debug File handle
141 * functions called:
142 * int fprintf() c_library
143 * int strchr() c_library
145 * side effects:
146 * SDCDB debug symbols are placed
147 * into the output file.
150 VOID DefineSDCDB(char *name, a_uint value)
152 int j;
153 char *p1;
155 /* no output if file is not open */
156 if (yfp == NULL) return;
159 * SDCC symbols have 2 or more $ characters
160 * with the shortest being the Linker ASM Record
161 * eg L:A$TinyBuffer$2320:A13
163 j = 0;
164 p1 = name;
165 while ((p1 = strchr(p1, '$')) != NULL) {
166 p1++;
167 j += 1;
170 if (j > 1) {
171 #ifdef LONGINT
172 fprintf(yfp, "L:%s:%lX\n", name ,value);
173 #else
174 fprintf(yfp, "L:%s:%X\n", name ,value);
175 #endif
180 #endif