* asranlib/asranlib.c, link/lkar.h, link/lkar.c:
[fw/sdcc] / as / asxxsrc / asnoice.c
1 /* asnoice.c - Extensions to CUG 292 assembler ASxxxx to produce NoICE debug files
2
3    Copyright (C) 1989-1995 Alan R. Baldwin
4    721 Berkeley St., Kent, Ohio 44240
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19 /*
20  * Extensions to CUG 292 assembler ASxxxx to produce NoICE debug files
21  *
22  * 3-Nov-1997 by John Hartman
23  */
24
25 #include <stdio.h>
26 #include <setjmp.h>
27 #include <string.h>
28 #include <ctype.h>
29 #include "asm.h"
30
31 /* Return basic file name without path or extension.
32    If spacesToUnderscores != 0 then spaces are converted to underscores */
33
34 char* BaseFileName( int fileNumber, int spacesToUnderscores )
35 {
36         static int prevFile = -1;
37         static char baseName[ PATH_MAX ];
38
39         char *p1, *p2;
40
41         if (fileNumber != prevFile)
42         {
43                 prevFile = fileNumber;
44
45                 p1 = srcfn[prevFile];
46
47                 /* issue a FILE command with full path and extension */
48                 fprintf( ofp, ";!FILE %s\n", p1 );
49
50                 /* Name starts after any colon or backslash (DOS) */
51                 p2 = strrchr( p1, '\\' );
52                 if (p2 == NULL) p2 = strrchr( p1, '/' );
53                 if (p2 == NULL) p2 = strrchr( p1, ':' );
54                 if (p2 == NULL) p2 = p1-1;
55                 strcpy( baseName, p2+1 );
56
57                 /* Name ends at any separator */
58                 p2 = strrchr( baseName, FSEPX );
59                 if (p2 != NULL) *p2 = 0;
60                 /* SD comment this out since not a ANSI Function */
61                 /* strupr( baseName ); */
62
63                 if (spacesToUnderscores)
64                 {
65                   /* Convert spaces to underscores */
66                   for (p1 = baseName; *p1; ++p1)
67                     if (isspace(*p1))
68                       *p1 = '_';
69                 }
70         }
71         return baseName;
72 }
73
74 /* Define a symbol for current location:  FILE.line# */
75 void DefineNoICE_Line()
76 {
77         char name[ NCPS ];
78         struct sym *pSym;
79
80         /* symbol is FILE.nnn */
81         sprintf( name, "%s.%u", BaseFileName( cfile, 0 ), 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 /* Define a symbol for current location:  A$FILE$line# */
91 void DefineCDB_Line()
92 {
93         char name[ NCPS ];
94         struct sym *pSym;
95
96         /* symbol is FILE.nnn */
97         sprintf( name, "A$%s$%u", BaseFileName( cfile, 1 ), srcline[ cfile ] );
98
99         pSym = lookup( name );
100         pSym->s_type = S_USER;
101         pSym->s_area = dot.s_area;
102         pSym->s_addr = laddr;
103         pSym->s_flag |= S_GBL;
104 }
105
106 #if 0
107 OLD VERSION
108 /* Define a symbol for current location:  FILE.line# */
109 void DefineNoICE_Line()
110 {
111         static int prevFile = -1;
112         static struct area *pPrevArea = NULL;
113         static char baseName[ PATH_MAX ];
114
115         int j;
116         char *p1, *p2;
117
118         /* Get outfilename without extension for use as base symbol name */
119         if (baseName[0] == 0)
120         {
121                 p1 = srcfn[0];
122                 p2 = baseName;
123                 while ((*p1 != 0) && (*p1 != FSEPX))
124                 {
125                         *p2++ = *p1++;
126                 }
127                 *p2 = 0;
128                 /* SD Commented this out since it is not a
129                    ASNI Function */
130                 /* strupr( baseName ); */
131         }
132
133         if ((cfile != prevFile) || (dot.s_area != pPrevArea))
134         {
135                 prevFile = cfile;
136                 pPrevArea = dot.s_area;
137
138                 /* file or area change: issue FILE command with base @ */
139                 fprintf( ofp, ";!FILE %s %s_%s\n", srcfn[ cfile ],
140                          baseName,
141                          dot.s_area->a_id );
142         }
143
144         fprintf( ofp, ";!LINE %u. 0x%X\n", srcline[ cfile ], laddr );
145 }
146
147 #endif