MS VC6 Port
[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 #if !defined(_MSC_VER)
13 #include <alloc.h>
14 #endif
15 #include "asm.h"
16
17 /* Return basic file name without path or extension */
18 static char* BaseFileName( int fileNumber );
19
20 char* BaseFileName( int fileNumber )
21 {
22         static int prevFile = -1;
23         static char baseName[ FILSPC ];
24
25         char *p1, *p2;
26
27         if (fileNumber != prevFile)
28         {
29                 prevFile = fileNumber;
30
31                 p1 = srcfn[prevFile];
32
33                 /* issue a FILE command with full path and extension */
34                 fprintf( ofp, ";!FILE %s\n", p1 );
35
36                 /* Name starts after any colon or backslash (DOS) */
37                 p2 = strrchr( p1, '\\' );
38                 if (p2 == NULL) p2 = strrchr( p1, ':' );
39                 if (p2 == NULL) p2 = p1-1;
40                 strcpy( baseName, p2+1 );
41
42                 /* Name ends at any separator */
43                 p2 = strrchr( baseName, FSEPX );
44                 if (p2 != NULL) *p2 = 0;
45                 /* SD comment this out since not a ANSI Function */
46                 /* strupr( baseName ); */
47         }
48         return baseName;
49 }
50
51 /* Define a symbol for current location:  FILE.line# */
52 void DefineNoICE_Line()
53 {
54         char name[ NCPS ];
55         struct sym *pSym;
56
57         /* symbol is FILE.nnn */
58         sprintf( name, "%s.%u", BaseFileName( cfile ), srcline[ cfile ] );
59
60         pSym = lookup( name );
61         pSym->s_type = S_USER;
62         pSym->s_area = dot.s_area;
63         pSym->s_addr = laddr;
64         pSym->s_flag |= S_GBL;
65 }
66
67 /* Define a symbol for current location:  A$FILE$line# */
68 void DefineCDB_Line()
69 {
70         char name[ NCPS ];
71         struct sym *pSym;
72
73         /* symbol is FILE.nnn */
74         sprintf( name, "A$%s$%u", BaseFileName( cfile ), srcline[ cfile ] );
75
76         pSym = lookup( name );
77         pSym->s_type = S_USER;
78         pSym->s_area = dot.s_area;
79         pSym->s_addr = laddr;
80         pSym->s_flag |= S_GBL;
81 }
82
83 #if 0
84 OLD VERSION
85 /* Define a symbol for current location:  FILE.line# */
86 void DefineNoICE_Line()
87 {
88         static int prevFile = -1;
89         static struct area *pPrevArea = NULL;
90         static char baseName[ FILSPC ];
91
92         int j;
93         char *p1, *p2;
94
95         /* Get outfilename without extension for use as base symbol name */
96         if (baseName[0] == 0)
97         {
98                 p1 = srcfn[0];
99                 p2 = baseName;
100                 while ((*p1 != 0) && (*p1 != FSEPX))
101                 {
102                         *p2++ = *p1++;
103                 }
104                 *p2 = 0;
105                 /* SD Commented this out since it is not a 
106                    ASNI Function */
107                 /* strupr( baseName ); */
108         }
109
110         if ((cfile != prevFile) || (dot.s_area != pPrevArea))
111         {
112                 prevFile = cfile;
113                 pPrevArea = dot.s_area;
114
115                 /* file or area change: issue FILE command with base @ */
116                 fprintf( ofp, ";!FILE %s %s_%s\n", srcfn[ cfile ],
117                          baseName,
118                          dot.s_area->a_id );
119         }
120
121         fprintf( ofp, ";!LINE %u. 0x%X\n", srcline[ cfile ], laddr );
122 }
123
124 #endif