7c182e82015322c212257bf664f7355b19a50dc2
[fw/sdcc] / as / asxxsrc / 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         return baseName;
56 }
57
58 /* Define a symbol for current location:  FILE.line# */
59 void DefineNoICE_Line()
60 {
61         char name[ NCPS ];
62         struct sym *pSym;
63
64         /* symbol is FILE.nnn */
65         sprintf( name, "%s.%u", BaseFileName( cfile, 0 ), srcline[ cfile ] );
66
67         pSym = lookup( name );
68         pSym->s_type = S_USER;
69         pSym->s_area = dot.s_area;
70         pSym->s_addr = laddr;
71         pSym->s_flag |= S_GBL;
72 }
73
74 /* Define a symbol for current location:  A$FILE$line# */
75 void DefineCDB_Line()
76 {
77         char name[ NCPS ];
78         struct sym *pSym;
79
80         /* symbol is FILE.nnn */
81         sprintf( name, "A$%s$%u", BaseFileName( cfile, 1 ), srcline[ cfile ] );
82
83         pSym = lookup( name );
84         pSym->s_type = S_USER;
85         pSym->s_area = dot.s_area;
86         pSym->s_addr = laddr;
87         pSym->s_flag |= S_GBL;
88 }
89
90 #if 0
91 OLD VERSION
92 /* Define a symbol for current location:  FILE.line# */
93 void DefineNoICE_Line()
94 {
95         static int prevFile = -1;
96         static struct area *pPrevArea = NULL;
97         static char baseName[ PATH_MAX ];
98
99         int j;
100         char *p1, *p2;
101
102         /* Get outfilename without extension for use as base symbol name */
103         if (baseName[0] == 0)
104         {
105                 p1 = srcfn[0];
106                 p2 = baseName;
107                 while ((*p1 != 0) && (*p1 != FSEPX))
108                 {
109                         *p2++ = *p1++;
110                 }
111                 *p2 = 0;
112                 /* SD Commented this out since it is not a
113                    ASNI Function */
114                 /* strupr( baseName ); */
115         }
116
117         if ((cfile != prevFile) || (dot.s_area != pPrevArea))
118         {
119                 prevFile = cfile;
120                 pPrevArea = dot.s_area;
121
122                 /* file or area change: issue FILE command with base @ */
123                 fprintf( ofp, ";!FILE %s %s_%s\n", srcfn[ cfile ],
124                          baseName,
125                          dot.s_area->a_id );
126         }
127
128         fprintf( ofp, ";!LINE %u. 0x%X\n", srcline[ cfile ], laddr );
129 }
130
131 #endif