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