mirror of
https://github.com/fachat/xa65.git
synced 2025-04-11 22:37:02 +00:00
make -U option work to accept all undef'd labels in -R mode
This commit is contained in:
parent
8175681d48
commit
1e296b8495
@ -74,7 +74,7 @@ int romaddr = 0;
|
||||
int noglob = 0;
|
||||
int showblk = 0;
|
||||
int crossref = 0;
|
||||
int noundef = 0; // overrides -R acceptance of undefined labels
|
||||
int undefok = 0; // -R only accepts -Llabels; with -U all undef'd labels are ok in -R mode
|
||||
char altppchar;
|
||||
|
||||
/* local variables */
|
||||
@ -287,7 +287,7 @@ int main(int argc,char *argv[])
|
||||
relmode = 1;
|
||||
break;
|
||||
case 'U':
|
||||
noundef = 1;
|
||||
undefok = 1;
|
||||
break;
|
||||
case 'D':
|
||||
s = (signed char*)strstr(argv[i]+2,"=");
|
||||
@ -951,7 +951,7 @@ static void usage(int default816, FILE *fp)
|
||||
" -Xcompatset set compatibility flags for other assemblers, known values are:\n"
|
||||
" MASM, CA65\n"
|
||||
" -R start assembler in relocating mode\n"
|
||||
" -U do not allow undefined labels in relocating mode\n");
|
||||
" -U allow all undefined labels in relocating mode\n");
|
||||
fprintf(fp,
|
||||
" -Llabel defines `label' as absolute, undefined label even when linking\n"
|
||||
" -p<c> replace preprocessor char '#' with custom, e.g. '-p!' replaces it with '!'\n"
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "xah.h" /* For SEG_MAX */
|
||||
|
||||
extern int ncmos, cmosfl, w65816, n65816;
|
||||
extern int masm, ca65, nolink, noundef, ppinstr;
|
||||
extern int masm, ca65, nolink, undefok, ppinstr;
|
||||
extern int noglob;
|
||||
extern int showblk;
|
||||
extern int relmode;
|
||||
|
@ -123,12 +123,13 @@ static int ag_term(signed char *s, int p, int *v, int *nafl, int *label)
|
||||
if(s[pp]==T_LABEL)
|
||||
{
|
||||
er=l_get(cval(s+pp+1),v, &afl);
|
||||
|
||||
/*
|
||||
printf("label: er=%d, seg=%d, afl=%d, nolink=%d, fundef=%d\n",
|
||||
er, segment, afl, nolink, fundef);
|
||||
*/
|
||||
if(er==E_NODEF && segment != SEG_ABS && fundef ) {
|
||||
if( (nolink && !noundef) || ((afl==SEG_UNDEF) || (afl==SEG_UNDEFZP))) {
|
||||
if( nolink || ((afl==SEG_UNDEF) || (afl==SEG_UNDEFZP))) {
|
||||
er = E_OK;
|
||||
*v = 0;
|
||||
if(afl!=SEG_UNDEFZP) {
|
||||
|
@ -60,6 +60,7 @@ typedef struct {
|
||||
int fl; /* 0 = label value not valid/known,
|
||||
* 1 = label value known
|
||||
* 2 = label value not known, external global label (imported on link)
|
||||
* 3 = label value not known, temporarily on external global label list (for -U)
|
||||
*/
|
||||
int afl; /* 0 = no address (no relocation), 1 = address label */
|
||||
int nextindex;
|
||||
|
66
xa/src/xal.c
66
xa/src/xal.c
@ -58,26 +58,6 @@ static int cll_get();
|
||||
static void cll_clear();
|
||||
static int cll_getcur();
|
||||
|
||||
/*
|
||||
static void unn_init();
|
||||
static int unn_get();
|
||||
static void unn_clear();
|
||||
*/
|
||||
|
||||
/* local variables */
|
||||
|
||||
/*
|
||||
static int hashindex[256];
|
||||
static Labtab *lt = NULL;
|
||||
static int lti = 0;
|
||||
static int ltm = 0;
|
||||
*/
|
||||
|
||||
/*
|
||||
static char *ln;
|
||||
static unsigned long lni;
|
||||
static long sl;
|
||||
*/
|
||||
|
||||
static Labtab *ltp;
|
||||
|
||||
@ -86,24 +66,6 @@ int l_init(void)
|
||||
cll_init();
|
||||
//unn_init();
|
||||
return 0;
|
||||
#if 0
|
||||
int er;
|
||||
|
||||
for(er=0;er<256;er++)
|
||||
hashindex[er]=0;
|
||||
|
||||
/*sl=(long)sizeof(Labtab);*/
|
||||
|
||||
/* if(!(er=m_alloc((long)(sizeof(Labtab)*ANZLAB),(char**)<)))
|
||||
er=m_alloc((long)LABMEM,&ln);*/
|
||||
|
||||
er=m_alloc((long)(sizeof(Labtab)*ANZLAB),(char**)<);
|
||||
|
||||
lti=0;
|
||||
/* lni=0L;*/
|
||||
|
||||
return(er);
|
||||
#endif
|
||||
}
|
||||
|
||||
int ga_lab(void)
|
||||
@ -224,6 +186,26 @@ int lg_import(int n) {
|
||||
return er;
|
||||
}
|
||||
|
||||
/*
|
||||
* re-define a previously undef'd label as globally undefined
|
||||
* (for -U option)
|
||||
*/
|
||||
int lg_toglobal(char *s ) {
|
||||
int n, er;
|
||||
|
||||
//printf("lg_toglobal(%s)\n", s);
|
||||
er = ll_search(s,&n, STD);
|
||||
|
||||
if(er==E_OK) {
|
||||
ltp=afile->la.lt+n;
|
||||
ltp->fl=3;
|
||||
ltp->afl=SEG_UNDEF;
|
||||
ltp->blk=0;
|
||||
}
|
||||
return er;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* define a global zeropage label (from the .importzp pseudo opcode))
|
||||
* "s" is a pointer to the first label character, end is at \0
|
||||
@ -306,6 +288,7 @@ int l_def(char *s, int *l, int *x, int *f)
|
||||
|
||||
if(er==E_OK)
|
||||
{
|
||||
//printf("l_def OK: cll_fl=%d, i=%d, s=%s\n", cll_fl, i, s);
|
||||
/* we actually found an existing label in the same scope */
|
||||
ltp=afile->la.lt+n;
|
||||
|
||||
@ -314,7 +297,7 @@ int l_def(char *s, int *l, int *x, int *f)
|
||||
/* redefinition of label */
|
||||
*l=ltp->len+i;
|
||||
} else
|
||||
if(ltp->fl==0)
|
||||
if(ltp->fl == 0 || ltp->fl == 3)
|
||||
{
|
||||
/* label has not been defined yet, (e.g. pass1 forward ref), so we try to set it. */
|
||||
*l=ltp->len+i;
|
||||
@ -540,7 +523,7 @@ void l_set(int n, int v, int afl)
|
||||
ltp->val = v;
|
||||
ltp->fl = 1;
|
||||
ltp->afl = afl;
|
||||
/*printf("l_set('%s'(%d), v=$%04x, afl=%d\n",ltp->n, n, v, afl);*/
|
||||
//printf("l_set('%s'(%d), v=$%04x, afl=%d\n",ltp->n, n, v, afl);
|
||||
}
|
||||
|
||||
static void ll_exblk(int a, int b)
|
||||
@ -665,6 +648,7 @@ int ll_search(char *s, int *n, label_t cll_fl) /* search Label in Tabel
|
||||
if (cll_fl == UNNAMED) {
|
||||
// TODO
|
||||
} else {
|
||||
//printf("ll_search:match labels %s with %p (%s) from block %d, block check is %d\n", s, ltp, ltp->n, ltp->blk, b_test(ltp->blk));
|
||||
/* check if the found label is in any of the blocks in the
|
||||
current block stack */
|
||||
if((j==k)&&(!b_test(ltp->blk)))
|
||||
@ -691,6 +675,8 @@ int ll_search(char *s, int *n, label_t cll_fl) /* search Label in Tabel
|
||||
getchar();
|
||||
}
|
||||
#endif
|
||||
//printf("l_search(%s) returns er=%d, n=%d\n", s, er, *n);
|
||||
|
||||
return(er);
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,8 @@ long ga_labm(void);
|
||||
int lg_set(char *);
|
||||
int lg_import(int);
|
||||
int lg_importzp(int);
|
||||
// used to re-define undef'd labels as global for -U option
|
||||
int lg_toglobal(char *);
|
||||
|
||||
int b_init(void);
|
||||
int b_depth(void);
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include "xao.h"
|
||||
#include "xau.h"
|
||||
|
||||
#undef DEBUG_RELOC
|
||||
|
||||
File *afile = NULL;
|
||||
|
||||
int rmode = RMODE_RELOC;
|
||||
@ -43,8 +45,10 @@ int r_set(int pc, int afl, int l) {
|
||||
*/
|
||||
|
||||
int u_set(int pc, int afl, int label, int l) {
|
||||
/*printf("set relocation @$%04x, l=%d, afl=%04x, segment=%d, label=%d\n",
|
||||
pc, l, afl,segment, label);*/
|
||||
#ifdef DEBUG_RELOC
|
||||
printf("set relocation @$%04x, l=%d, afl=%04x, segment=%d, label=%d\n",
|
||||
pc, l, afl,segment, label);
|
||||
#endif
|
||||
if(((afl & A_FMASK) == (SEG_UNDEF<<8))
|
||||
|| ((afl & A_FMASK) == (SEG_UNDEFZP<<8))
|
||||
) {
|
||||
|
22
xa/src/xat.c
22
xa/src/xat.c
@ -26,10 +26,7 @@
|
||||
#undef DEBUG_CONV
|
||||
#undef DEBUG_CAST
|
||||
#undef DEBUG_RELOC
|
||||
|
||||
/*
|
||||
#define DEBUG_AM
|
||||
*/
|
||||
#undef DEBUG_AM
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
@ -819,6 +816,9 @@ fprintf(stderr, "E_OK ... t_p2 xat.c %i %i\n", t[0], *ll);
|
||||
/* this actually calls pass2 on the current tokenization stream,
|
||||
* but without including the Klisting token listing */
|
||||
er=t_p2(t,ll,(0 | byte), al);
|
||||
#ifdef DEBUG_AM
|
||||
fprintf(stderr, "... --> er=%d\n", er);
|
||||
#endif
|
||||
}
|
||||
|
||||
} else
|
||||
@ -2267,16 +2267,10 @@ static int t_conv(signed char *s, signed char *t, int *l, int pc, int *nk,
|
||||
} else {
|
||||
//m=n;
|
||||
er=l_search((char*)s+p,&ll,&n,&v,&afl);
|
||||
/*
|
||||
if(m==Kglobl || m==Kextzero) {
|
||||
if(er==E_NODEF) {
|
||||
er=E_OK;
|
||||
}
|
||||
t[q++]=T_LABEL;
|
||||
t[q++]=n & 255;
|
||||
t[q++]=(n>>8) & 255;
|
||||
} else
|
||||
*/
|
||||
|
||||
if (er == E_NODEF && undefok) {
|
||||
lg_toglobal(s+p);
|
||||
}
|
||||
|
||||
if(!er)
|
||||
{
|
||||
|
12
xa/src/xau.c
12
xa/src/xau.c
@ -1,6 +1,6 @@
|
||||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 André Fachat (fachat@web.de)
|
||||
*
|
||||
* Undefined label tracking module (also see xal.c)
|
||||
*
|
||||
@ -27,15 +27,13 @@
|
||||
#include "xah.h"
|
||||
#include "xal.h"
|
||||
|
||||
/*
|
||||
static int *ulist = NULL;
|
||||
static int un = 0;
|
||||
static int um = 0;
|
||||
*/
|
||||
#undef DEBUG_UNDEF
|
||||
|
||||
int u_label(int labnr) {
|
||||
int i;
|
||||
/*printf("u_label: %d\n",labnr);*/
|
||||
#ifdef DEBUG_UNDEF
|
||||
printf("u_label: %d\n",labnr);
|
||||
#endif
|
||||
if(!afile->ud.ulist) {
|
||||
afile->ud.ulist = malloc(200*sizeof(int));
|
||||
if(afile->ud.ulist) afile->ud.um=200;
|
||||
|
33
xa/tests/undef/Makefile
Normal file
33
xa/tests/undef/Makefile
Normal file
@ -0,0 +1,33 @@
|
||||
#
|
||||
# Makefile for tests
|
||||
#
|
||||
|
||||
XA=../../xa
|
||||
|
||||
tests: undef1 undef2 undef3 clean
|
||||
|
||||
|
||||
undef1: undef.a65
|
||||
@echo This should fail
|
||||
${XA} $< || exit 0 && exit 1
|
||||
${XA} -R $< || exit 0 && exit 1
|
||||
${XA} -R -U -DFAIL $< || exit 0 && exit 1
|
||||
${XA} -R -Ll1 -Ll3 -Ll4 -Ll5 $< || exit 0 && exit 1
|
||||
|
||||
undef2: undef.a65
|
||||
${XA} -R -Ll1 -Ll3 $<
|
||||
file65 -V a.o65
|
||||
reloc65 -bt 40960 -o b.o65 a.o65
|
||||
hexdump -C b.o65 > b.hex
|
||||
cmp undef2.out b.hex
|
||||
|
||||
undef3: undef.a65
|
||||
${XA} -R -U $<
|
||||
file65 -V a.o65
|
||||
reloc65 -bt 40960 -o b.o65 a.o65
|
||||
hexdump -C b.o65 > b.hex
|
||||
cmp undef2.out b.hex
|
||||
|
||||
clean:
|
||||
rm -f a.err a.o65 a.hex b.o65 b.hex
|
||||
|
23
xa/tests/undef/undef.a65
Normal file
23
xa/tests/undef/undef.a65
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
.text
|
||||
|
||||
lda l1
|
||||
|
||||
*=$2000
|
||||
|
||||
#ifdef FAIL
|
||||
lda l2
|
||||
#endif
|
||||
|
||||
*=
|
||||
|
||||
lda l3
|
||||
|
||||
.(
|
||||
|
||||
lda l4
|
||||
|
||||
.)
|
||||
l4=1
|
||||
lda l5
|
||||
l5
|
6
xa/tests/undef/undef2.out
Normal file
6
xa/tests/undef/undef2.out
Normal file
@ -0,0 +1,6 @@
|
||||
00000000 01 00 6f 36 35 00 00 00 00 a0 0c 00 00 04 00 00 |..o65...........|
|
||||
00000010 00 40 00 00 04 00 00 00 00 00 00 ad 00 00 ad 00 |.@..............|
|
||||
00000020 00 ad 01 00 ad 0c a0 02 00 6c 31 00 6c 33 00 02 |.........l1.l3..|
|
||||
00000030 80 00 00 03 80 01 00 06 82 00 00 02 00 6c 34 00 |.............l4.|
|
||||
00000040 01 01 00 6c 35 00 02 0c a0 |...l5....|
|
||||
00000049
|
Loading…
x
Reference in New Issue
Block a user