4 * Extensions to CUG 292 linker ASLINK to produce NoICE debug files
6 * 31-Oct-1997 by John Hartman
7 * 30-Jan-98 JLH add page to DefineNoICE for 8051
8 * 2-Feb-98 JLH Allow optional .nest on local vars - C scoping rules...
17 static void DefineGlobal( char *name, Addr_T value, int page );
18 static void DefineScoped( char *name, Addr_T value, int page );
19 static void DefineFile( char *name, Addr_T value, int page );
20 static void DefineFunction( char *name, Addr_T value, int page );
21 static void DefineStaticFunction( char *name, Addr_T value, int page );
22 static void DefineEndFunction( Addr_T value, int page );
23 static void DefineLine( char *lineString, Addr_T value, int page );
24 static void PagedAddress( Addr_T value, int page );
27 * Called from lstarea in lklist.c for each symbol.
29 * Generates appropriate NoICE commands into output file, if any is open
32 void DefineNoICE( char *name, Addr_T value, int page )
34 char token1[NCPS]; /* parse for file.function.symbol */
41 /* no output if file is not open */
42 if (jfp == NULL) return;
44 j = sscanf( name, "%[^.]%c%[^.]%c%s",
45 token1, &sep1, token2, &sep2, token3 );
48 /* file.function.symbol, or file.function..SPECIAL */
50 DefineFile( token1, 0, 0 );
53 if (strcmp( token3, ".FN" ) == 0)
56 DefineFunction( token2, value, page );
58 else if (strcmp( token3, ".SFN" ) == 0)
60 /* Static (file-scope) function */
61 DefineStaticFunction( token2, value, page );
63 else if (strcmp( token3, ".EFN" ) == 0)
66 DefineEndFunction( value, page );
71 /* Function-scope var. */
72 DefineFunction( token2, 0, 0 );
74 /* Look for optional level integer */
75 j = sscanf( token3, "%[^.]%c%u", token1, &sep1, &level );
76 if ((j == 3) && (level != 0))
78 sprintf( &token1[ strlen(token1) ], "_%u", level );
80 DefineScoped( token1, value, page );
84 /* file.func. is illegal */
88 /* either file.symbol or file.line# */
90 DefineFile( token1, 0, 0 );
91 if ((token2[0] >= '0') && (token2[0] <= '9'))
94 DefineLine( token2, value, page );
98 /* File-scope symbol. (Kill any function) */
99 DefineEndFunction( 0, 0 );
100 DefineScoped( token2, value, page );
104 /* symbol. is illegal */
110 DefineGlobal( token1, value, page );
115 static char currentFile[NCPS];
116 static char currentFunction[NCPS];
120 * Define "name" as a global symbol
122 void DefineGlobal( char *name, Addr_T value, int page )
124 fprintf( jfp, "DEF %s ", name );
125 PagedAddress( value, page );
130 * Define "name" as a static (scoped) symbol
132 void DefineScoped( char *name, Addr_T value, int page )
134 fprintf( jfp, "DEFS %s ", name );
135 PagedAddress( value, page );
140 * Define "name" as the current file
142 void DefineFile( char *name, Addr_T value, int page )
144 if (as_strcmpi( name, currentFile ) != 0)
146 strcpy( currentFile, name );
149 fprintf( jfp, "FILE %s ", name );
150 PagedAddress( value, page );
154 fprintf( jfp, "FILE %s\n", name );
161 * Define "name" as the current function
163 void DefineFunction( char *name, Addr_T value, int page )
165 if (as_strcmpi( name, currentFunction ) != 0)
167 strcpy( currentFunction, name );
170 fprintf( jfp, "DEF %s ", name );
171 PagedAddress( value, page );
172 fprintf( jfp, "FUNC %s ", name );
173 PagedAddress( value, page );
177 fprintf( jfp, "FUNC %s\n", name );
184 * Define "name" as the current static (scoped) function
186 void DefineStaticFunction( char *name, Addr_T value, int page )
188 if (as_strcmpi( name, currentFunction ) != 0)
190 strcpy( currentFunction, name );
193 fprintf( jfp, "DEFS %s ", name );
194 PagedAddress( value, page );
195 fprintf( jfp, "SFUNC %s ", name );
196 PagedAddress( value, page );
200 fprintf( jfp, "SFUNC %s\n", name );
207 * Define the end of the current function
209 void DefineEndFunction( Addr_T value, int page )
211 if (currentFunction[0] != 0)
215 fprintf( jfp, "ENDF " );
216 PagedAddress( value, page );
220 fprintf( jfp, "ENDF\n" );
223 currentFunction[0] = 0;
229 * Define "lineNumber" as a line in the current file
231 void DefineLine( char *lineString, Addr_T value, int page )
233 int indigit, lineNumber = 0;
235 while( (indigit=digit( *lineString++, 10 )) >= 0)
237 lineNumber = 10*lineNumber + indigit;
239 fprintf( jfp, "LINE %u ", lineNumber );
240 PagedAddress( value, page );
243 void PagedAddress( Addr_T value, int page )
245 fprintf( jfp, "%X:0x%X\n", page, value );