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...
14 #if !defined(_MSC_VER)
19 static void DefineGlobal( char *name, addr_t value, int page );
20 static void DefineScoped( char *name, addr_t value, int page );
21 static void DefineFile( char *name, addr_t value, int page );
22 static void DefineFunction( char *name, addr_t value, int page );
23 static void DefineStaticFunction( char *name, addr_t value, int page );
24 static void DefineEndFunction( addr_t value, int page );
25 static void DefineLine( char *lineString, addr_t value, int page );
26 static void PagedAddress( addr_t value, int page );
29 * Called from lstarea in lklist.c for each symbol.
31 * Generates appropriate NoICE commands into output file, if any is open
34 void DefineNoICE( char *name, addr_t value, int page )
36 char token1[NCPS]; /* parse for file.function.symbol */
43 /* no output if file is not open */
44 if (jfp == NULL) return;
46 j = sscanf( name, "%[^.]%c%[^.]%c%s",
47 token1, &sep1, token2, &sep2, token3 );
50 /* file.function.symbol, or file.function..SPECIAL */
52 DefineFile( token1, 0, 0 );
55 if (strcmp( token3, ".FN" ) == 0)
58 DefineFunction( token2, value, page );
60 else if (strcmp( token3, ".SFN" ) == 0)
62 /* Static (file-scope) function */
63 DefineStaticFunction( token2, value, page );
65 else if (strcmp( token3, ".EFN" ) == 0)
68 DefineEndFunction( value, page );
73 /* Function-scope var. */
74 DefineFunction( token2, 0, 0 );
76 /* Look for optional level integer */
77 j = sscanf( token3, "%[^.]%c%u", token1, &sep1, &level );
78 if ((j == 3) && (level != 0))
80 sprintf( &token1[ strlen(token1) ], "_%u", level );
82 DefineScoped( token1, value, page );
86 /* file.func. is illegal */
90 /* either file.symbol or file.line# */
92 DefineFile( token1, 0, 0 );
93 if ((token2[0] >= '0') && (token2[0] <= '9'))
96 DefineLine( token2, value, page );
100 /* File-scope symbol. (Kill any function) */
101 DefineEndFunction( 0, 0 );
102 DefineScoped( token2, value, page );
106 /* symbol. is illegal */
112 DefineGlobal( token1, value, page );
117 static char currentFile[NCPS];
118 static char currentFunction[NCPS];
122 * Define "name" as a global symbol
124 void DefineGlobal( char *name, addr_t value, int page )
126 fprintf( jfp, "DEF %s ", name );
127 PagedAddress( value, page );
132 * Define "name" as a static (scoped) symbol
134 void DefineScoped( char *name, addr_t value, int page )
136 fprintf( jfp, "DEFS %s ", name );
137 PagedAddress( value, page );
142 * Define "name" as the current file
144 void DefineFile( char *name, addr_t value, int page )
146 if (strcmpi( name, currentFile ) != 0)
148 strcpy( currentFile, name );
151 fprintf( jfp, "FILE %s ", name );
152 PagedAddress( value, page );
156 fprintf( jfp, "FILE %s\n", name );
163 * Define "name" as the current function
165 void DefineFunction( char *name, addr_t value, int page )
167 if (strcmpi( name, currentFunction ) != 0)
169 strcpy( currentFunction, name );
172 fprintf( jfp, "DEF %s ", name );
173 PagedAddress( value, page );
174 fprintf( jfp, "FUNC %s ", name );
175 PagedAddress( value, page );
179 fprintf( jfp, "FUNC %s\n", name );
186 * Define "name" as the current static (scoped) function
188 void DefineStaticFunction( char *name, addr_t value, int page )
190 if (strcmpi( name, currentFunction ) != 0)
192 strcpy( currentFunction, name );
195 fprintf( jfp, "DEFS %s ", name );
196 PagedAddress( value, page );
197 fprintf( jfp, "SFUNC %s ", name );
198 PagedAddress( value, page );
202 fprintf( jfp, "SFUNC %s\n", name );
209 * Define the end of the current function
211 void DefineEndFunction( addr_t value, int page )
213 if (currentFunction[0] != 0)
217 fprintf( jfp, "ENDF " );
218 PagedAddress( value, page );
222 fprintf( jfp, "ENDF\n" );
225 currentFunction[0] = 0;
231 * Define "lineNumber" as a line in the current file
233 void DefineLine( char *lineString, addr_t value, int page )
235 int indigit, lineNumber = 0;
237 while( (indigit=digit( *lineString++, 10 )) >= 0)
239 lineNumber = 10*lineNumber + indigit;
241 fprintf( jfp, "LINE %u ", lineNumber );
242 PagedAddress( value, page );
245 void PagedAddress( addr_t value, int page )
247 fprintf( jfp, "%X:0x%X\n", page, value );