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...
16 static void DefineGlobal( char *name, Addr_T value, int page );
17 static void DefineScoped( char *name, Addr_T value, int page );
18 static void DefineFile( char *name, Addr_T value, int page );
19 static void DefineFunction( char *name, Addr_T value, int page );
20 static void DefineStaticFunction( char *name, Addr_T value, int page );
21 static void DefineEndFunction( Addr_T value, int page );
22 static void DefineLine( char *lineString, Addr_T value, int page );
23 static void PagedAddress( Addr_T value, int page );
26 * Called from lstarea in lklist.c for each symbol.
28 * Generates appropriate NoICE commands into output file, if any is open
31 void DefineNoICE( char *name, Addr_T value, int page )
33 char token1[NCPS]; /* parse for file.function.symbol */
40 /* no output if file is not open */
41 if (jfp == NULL) return;
43 j = sscanf( name, "%[^.]%c%[^.]%c%s",
44 token1, &sep1, token2, &sep2, token3 );
47 /* file.function.symbol, or file.function..SPECIAL */
49 DefineFile( token1, 0, 0 );
52 if (strcmp( token3, ".FN" ) == 0)
55 DefineFunction( token2, value, page );
57 else if (strcmp( token3, ".SFN" ) == 0)
59 /* Static (file-scope) function */
60 DefineStaticFunction( token2, value, page );
62 else if (strcmp( token3, ".EFN" ) == 0)
65 DefineEndFunction( value, page );
70 /* Function-scope var. */
71 DefineFunction( token2, 0, 0 );
73 /* Look for optional level integer */
74 j = sscanf( token3, "%[^.]%c%u", token1, &sep1, &level );
75 if ((j == 3) && (level != 0))
77 sprintf( &token1[ strlen(token1) ], "_%u", level );
79 DefineScoped( token1, value, page );
83 /* file.func. is illegal */
87 /* either file.symbol or file.line# */
89 DefineFile( token1, 0, 0 );
90 if ((token2[0] >= '0') && (token2[0] <= '9'))
93 DefineLine( token2, value, page );
97 /* File-scope symbol. (Kill any function) */
98 DefineEndFunction( 0, 0 );
99 DefineScoped( token2, value, page );
103 /* symbol. is illegal */
109 DefineGlobal( token1, value, page );
114 static char currentFile[NCPS];
115 static char currentFunction[NCPS];
119 * Define "name" as a global symbol
121 void DefineGlobal( char *name, Addr_T value, int page )
123 fprintf( jfp, "DEF %s ", name );
124 PagedAddress( value, page );
129 * Define "name" as a static (scoped) symbol
131 void DefineScoped( char *name, Addr_T value, int page )
133 fprintf( jfp, "DEFS %s ", name );
134 PagedAddress( value, page );
139 * Define "name" as the current file
141 void DefineFile( char *name, Addr_T value, int page )
143 if (as_strcmpi( name, currentFile ) != 0)
145 strcpy( currentFile, name );
148 fprintf( jfp, "FILE %s ", name );
149 PagedAddress( value, page );
153 fprintf( jfp, "FILE %s\n", name );
160 * Define "name" as the current function
162 void DefineFunction( char *name, Addr_T value, int page )
164 if (as_strcmpi( name, currentFunction ) != 0)
166 strcpy( currentFunction, name );
169 fprintf( jfp, "DEF %s ", name );
170 PagedAddress( value, page );
171 fprintf( jfp, "FUNC %s ", name );
172 PagedAddress( value, page );
176 fprintf( jfp, "FUNC %s\n", name );
183 * Define "name" as the current static (scoped) function
185 void DefineStaticFunction( char *name, Addr_T value, int page )
187 if (as_strcmpi( name, currentFunction ) != 0)
189 strcpy( currentFunction, name );
192 fprintf( jfp, "DEFS %s ", name );
193 PagedAddress( value, page );
194 fprintf( jfp, "SFUNC %s ", name );
195 PagedAddress( value, page );
199 fprintf( jfp, "SFUNC %s\n", name );
206 * Define the end of the current function
208 void DefineEndFunction( Addr_T value, int page )
210 if (currentFunction[0] != 0)
214 fprintf( jfp, "ENDF " );
215 PagedAddress( value, page );
219 fprintf( jfp, "ENDF\n" );
222 currentFunction[0] = 0;
228 * Define "lineNumber" as a line in the current file
230 void DefineLine( char *lineString, Addr_T value, int page )
232 int indigit, lineNumber = 0;
234 while( (indigit=digit( *lineString++, 10 )) >= 0)
236 lineNumber = 10*lineNumber + indigit;
238 fprintf( jfp, "LINE %u ", lineNumber );
239 PagedAddress( value, page );
242 void PagedAddress( Addr_T value, int page )
244 fprintf( jfp, "%X:0x%X\n", page, value );