File: xref.c

package info (click to toggle)
crasm 1.8-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 376 kB
  • sloc: ansic: 3,505; makefile: 65
file content (139 lines) | stat: -rwxr-xr-x 3,037 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*  Copyright (C) 1987- Leon Bottou
 * 
 *  This is free documentation; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 * 
 *  The GNU General Public License's references to "object code"
 *  and "executables" are to be interpreted as the output of any
 *  document formatting or typesetting system, including
 *  intermediate and printed output.
 * 
 *  This manual is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public
 *  License along with this manual. Otherwise check the web site
 *  of the Free Software Foundation at http://www.fsf.org.
 */
/*
	CRASM: xref.c
	sorties des references croisees
	LYB 9/87
*/


#include "dcl.h"
#include "label.h"
extern unsigned long pc,codelen;
extern int segment;


#define RECLEN (LABLEN+13)
char *msgs[] =
{ "Undefined","Mnemonic","Macro","Abs","Rel","Register(s)","Bit%d" };

void
printlabel(struct label *label)
{
	char buffer[RECLEN+2];
	char *s,*b;
	int newpos;
	register int i;
	
 	if ( lpos+RECLEN >= llen)
		outputEOL();
	newpos=lpos+RECLEN;
	
	if (label->type != L_ABSOLUTE && label->type != L_RELATIVE )
		if (label->flags & NOREDEF)
			return;
	if  (label->type <0 )
		label->type = 1;
	if  (label->name[0] == '*' || label->name[0] <= '9' )
		return;
	if  ((label->flags & UNDEF) && !(label->flags & FORWARD))
		label->type = 0;

	s=label->name;
	i=label->type;
	i= (i==3 || i==4 || i==6);

	if (! (label->flags & USED))
		outputcar('?');
	else if (label->flags & FORWARD)
		outputcar('^');
	else
		outputcar(' ');
		
	if ( i )
		outputaddr(label->value);

	sprintf(buffer,msgs[label->type],label->modifier);
	position(newpos-LABLEN-2-strlen(buffer));
	output(buffer);

	position(newpos-LABLEN-1);
	b=buffer;
	for (i=0; i<LABLEN && *s ; i++)
			*b++ = *s++;
	*b=0;
	output(buffer);
	position(newpos);
}


static void
xref2(struct label *label)
{
	if (label)
	{
		xref2 ( label->left );
		printlabel( label );
		xref2 ( label->right );
	};
}


void
result(void)
{
	extern int errnumber,warnnumber;
	char buffer[40];
	
	
	if ( plen-ppos < 10 )
	{	outputEOP();
		outputEOL(); outputEOL();
	};
	outputEOL();
	sprintf(buffer,"ERRORS:    %4d",errnumber);
	output(buffer); outputEOL();
	sprintf(buffer,"WARNINGS:  %4d",warnnumber);
	output(buffer); outputEOL(); outputEOL();
	if ( !errnumber )
	{	output( "Successful assembly..." );
		outputEOL();
		sprintf(buffer," Last address %8lx (%ld)",pc-1,pc-1);
		output(buffer); outputEOL();
		sprintf(buffer," Code length  %8lx (%ld)",codelen,codelen);
		output(buffer); outputEOL();
	}
	else
	{	output( "No code generated..." );
		outputEOL();
	}
}


void
xref(void)
{
	outputEOP();
	xref2(lroot);
	outputEOL();
	outputEOP();
}