* as/mcs51/asnoice.c: fixed bug #1447412:
[fw/sdcc] / as / mcs51 / asnoice.c
1 /* asnoice.c */
2
3 /*
4  * Extensions to CUG 292 assembler ASxxxx to produce NoICE debug files
5  *
6  * 3-Nov-1997 by John Hartman
7  */
8
9 #include <stdio.h>
10 #include <setjmp.h>
11 #include <string.h>
12 #include <ctype.h>
13 #include "asm.h"
14
15 /* Return basic file name without path or extension.
16    If spacesToUnderscores != 0 then spaces are converted to underscores */
17
18 char* BaseFileName( int fileNumber, int spacesToUnderscores )
19 {
20         static int prevFile = -1;
21         static char baseName[ PATH_MAX ];
22
23         char *p1, *p2;
24
25         if (fileNumber != prevFile)
26         {
27                 prevFile = fileNumber;
28
29                 p1 = srcfn[prevFile];
30
31                 /* issue a FILE command with full path and extension */
32                 fprintf( ofp, ";!FILE %s\n", p1 );
33
34                 /* Name starts after any colon or backslash (DOS) */
35                 p2 = strrchr( p1, '\\' );
36                 if (p2 == NULL) p2 = strrchr( p1, '/' );
37                 if (p2 == NULL) p2 = strrchr( p1, ':' );
38                 if (p2 == NULL) p2 = p1-1;
39                 strcpy( baseName, p2+1 );
40
41                 /* Name ends at any separator */
42                 p2 = strrchr( baseName, FSEPX );
43                 if (p2 != NULL) *p2 = 0;
44                 /* SD comment this out since not a ANSI Function */
45                 /* strupr( baseName ); */
46
47                 if (spacesToUnderscores)
48                 {
49                   /* Convert spaces to underscores */
50                   for (p1 = baseName; *p1; ++p1)
51                     if (isspace(*p1))
52                       *p1 = '_';
53                 }
54
55         }
56         return baseName;
57 }
58
59 /* Define a symbol for current location:  FILE.line# */
60 void DefineNoICE_Line()
61 {
62         char name[ NCPS ];
63         struct sym *pSym;
64
65         /* symbol is FILE.nnn */
66         sprintf( name, "%s.%u", BaseFileName( cfile, 0 ), srcline[ cfile ] );
67
68         pSym = lookup( name );
69         pSym->s_type = S_USER;
70         pSym->s_area = dot.s_area;
71         pSym->s_addr = laddr;
72         pSym->s_flag |= S_GBL;
73 }
74
75 /* Define a symbol for current location:  A$FILE$line# */
76 void DefineCDB_Line()
77 {
78         char name[ NCPS ];
79         struct sym *pSym;
80
81         /* symbol is FILE.nnn */
82         sprintf( name, "A$%s$%u", BaseFileName( cfile, 1 ), srcline[ cfile ] );
83
84         pSym = lookup( name );
85         pSym->s_type = S_USER;
86         pSym->s_area = dot.s_area;
87         pSym->s_addr = laddr;
88         pSym->s_flag |= S_GBL;
89 }
90
91 #if 0
92 OLD VERSION
93 /* Define a symbol for current location:  FILE.line# */
94 void DefineNoICE_Line()
95 {
96         static int prevFile = -1;
97         static struct area *pPrevArea = NULL;
98         static char baseName[ PATH_MAX ];
99
100         int j;
101         char *p1, *p2;
102
103         /* Get outfilename without extension for use as base symbol name */
104         if (baseName[0] == 0)
105         {
106                 p1 = srcfn[0];
107                 p2 = baseName;
108                 while ((*p1 != 0) && (*p1 != FSEPX))
109                 {
110                         *p2++ = *p1++;
111                 }
112                 *p2 = 0;
113                 /* SD Commented this out since it is not a 
114                    ASNI Function */
115                 /* strupr( baseName ); */
116         }
117
118         if ((cfile != prevFile) || (dot.s_area != pPrevArea))
119         {
120                 prevFile = cfile;
121                 pPrevArea = dot.s_area;
122
123                 /* file or area change: issue FILE command with base @ */
124                 fprintf( ofp, ";!FILE %s %s_%s\n", srcfn[ cfile ],
125                          baseName,
126                          dot.s_area->a_id );
127         }
128
129         fprintf( ofp, ";!LINE %u. 0x%X\n", srcline[ cfile ], laddr );
130 }
131
132 #endif