CC = gcc
-CFLAGS = -O2
+CFLAGS = -ggdb -O2
YACC = bison -y -d
LEX = flex -i
LEXLIB =
xa_asm: xa_main.o xa_asm.tab.o xa_asm.lex.o xa_dasm.o
$(CC) -o xa_asm xa_main.o xa_asm.tab.o xa_asm.lex.o xa_dasm.o $(LEXLIB)
- strip xa_asm
+ #strip xa_asm
xa_asm.lex.o: xa_asm.lex.c xa_asm.tab.h xa_main.h
$(CC) $(CFLAGS) -c xa_asm.lex.c
}
[0-9]+\$ {
LIST;
- /* should print error is base_symbol_name */
+ /* should print error if base_symbol_name */
/* is not defined */
sprintf(lex_sym_name, "%s:%s",
base_symbol_name, yytext);
extern char * disasm(int byte, int memory_location);
extern void hexout(int byte, int memory_location, int end);
void error(char *s);
-void fatal_error(char *s);
static int bitmask[]={1, 2, 4, 8, 16, 32, 64, 128};
}
| '.' MODULE WORD {
/* ignore module definition */
- build_sym_list(lex_sym_name);
- assign_value(lex_sym_name, 0);
$$ = 0;
}
| '.' GLOBL WORD {
}
void error(char *s)
-{
- yyerror(s);
-}
-
-void fatal_error(char *s)
{
yyerror(s);
exit(1);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#define printf(x...) fprintf(stderr,x)
/* global variables */
-FILE *fhex, *fmem, *list_fp;
+FILE *fhex, *fmem, *list_fp, *sym_fp;
extern FILE *yyin;
extern char *yytext;
extern char last_line_text[];
struct symbol *p;
p = sym_list;
while (p != NULL) {
- printf("Sym in %-5s: %s\n", areaToString(p->area), p->name);
- printf(" at: 0x%04X (%5d)", p->value, p->value);
- printf(" Def:%s", p->isdef ? "Yes" : "No ");
- printf(" Bit:%s", p->isbit ? "Yes" : "No ");
- printf(" Target:%s", p->istarget ? "Yes" : "No ");
- printf(" Line %d\n", p->line_def);
+ fprintf(sym_fp, "Sym in %-5s: %s\n", areaToString(p->area), p->name);
+ fprintf(sym_fp, " at: 0x%04X (%5d)", p->value, p->value);
+ fprintf(sym_fp, " Def:%s", p->isdef ? "Yes" : "No ");
+ fprintf(sym_fp, " Bit:%s", p->isbit ? "Yes" : "No ");
+ fprintf(sym_fp, " Target:%s", p->istarget ? "Yes" : "No ");
+ fprintf(sym_fp, " Line %d\n", p->line_def);
p = p->next;
}
}
return (sum);
}
-void print_usage();
+void print_usage(int);
/* todo: someday this will allow the user to control where the */
void init_areas(void)
{
- area[AREA_CSEG].alloc_position = 0;
- area[AREA_DSEG].alloc_position = 0x30;
- area[AREA_OSEG].alloc_position = 0x80;
- area[AREA_ISEG].alloc_position = 0;
- area[AREA_BSEG].alloc_position = 0;
- area[AREA_XSEG].alloc_position = 0;
- area[AREA_XISEG].alloc_position = 0;
- area[AREA_GSINIT].alloc_position = 0;
- area[AREA_GSFINAL].alloc_position = 0;
- area[AREA_HOME].alloc_position = 0;
+ area[AREA_CSEG].start=area[AREA_CSEG].alloc_position = 0;
+ area[AREA_DSEG].start=area[AREA_DSEG].alloc_position = 0x30;
+ area[AREA_OSEG].start=area[AREA_OSEG].alloc_position = 0x80;
+ area[AREA_ISEG].start=area[AREA_ISEG].alloc_position = 0;
+ area[AREA_BSEG].start=area[AREA_BSEG].alloc_position = 0;
+ area[AREA_XSEG].start=area[AREA_XSEG].alloc_position = 0;
+ area[AREA_XISEG].start=area[AREA_XISEG].alloc_position = 0;
+ area[AREA_XINIT].start=area[AREA_XINIT].alloc_position = 0;
+ area[AREA_GSINIT].start=area[AREA_GSINIT].alloc_position = 0;
+ area[AREA_GSFINAL].start=area[AREA_GSFINAL].alloc_position = 0;
+ area[AREA_HOME].alloc_position = 0;
}
+void printVersion() {
+ printf("\nPaul's XA51 Assembler\n");
+ printf("Copyright 1997,2002 Paul Stoffregen\n\n");
+ printf("This program is free software; you can redistribute it\n");
+ printf("and/or modify it under the terms of the GNU General Public\n");
+ printf("License, Version 2, published by the Free Software Foundation\n\n");
+ printf("This program is distributed in the hope that it will be useful,\n");
+ printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
+}
+
+char infilename[PATH_MAX];
+char outfilename[PATH_MAX];
+char listfilename[PATH_MAX];
+char symfilename[PATH_MAX];
+//char mapfilename[PATH_MAX];
+
+int verbose=0, createSymbolFile=0;
+
+void process_args(int argc, char **argv)
+{
+ int i=0;
+
+ if (argc < 2) print_usage(1);
+
+ while (++i<argc && *argv[i]=='-') {
+ if (strcmp(argv[i], "--version")==0) {
+ printVersion();
+ exit (0);
+ }
+ if (strcmp(argv[i], "--help")==0) {
+ print_usage(0);
+ }
+ if (strcmp(argv[i], "-v")==0) {
+ verbose++;
+ continue;
+ }
+ if (strcmp(argv[i], "-s")==0) {
+ createSymbolFile++;
+ continue;
+ }
+ print_usage(1);
+ }
+
+ if (i!=argc-1) {
+ // only 1 source file for now
+ print_usage(1);
+ }
+
+ strcpy(infilename, argv[i]);
+
+ if (strncasecmp(infilename+strlen(infilename)-3, ".xa", 3)) {
+ fprintf (stderr, "unrecognized input file: \"%s\"\n", argv[i]);
+ print_usage(1);
+ }
+
+ strcpy(outfilename, infilename);
+ outfilename[strlen(outfilename)-3] = '\0';
+ strcpy(listfilename, outfilename);
+ if (createSymbolFile) {
+ strcpy(symfilename, outfilename);
+ strcat(symfilename, ".sym");
+ }
+ //strcpy(mapfilename, outfilename);
+ strcat(outfilename, ".hex");
+ strcat(listfilename, ".lst");
+ //strcat(mapfilename, ".map");
+}
/* pass #1 (p1=1) find all symbol defs and branch target names */
/* pass #2 (p2=1) align branch targets, evaluate all symbols */
int main(int argc, char **argv)
{
- char infilename[200], outfilename[200], listfilename[200];
-
- if (argc < 2) print_usage();
- strcpy(infilename, argv[1]);
- if(strlen(infilename) > 3) {
- if (strncasecmp(infilename+strlen(infilename)-3, ".xa", 3))
- strcat(infilename, ".xa");
- } else strcat(infilename, ".xa");
- strcpy(outfilename, infilename);
- outfilename[strlen(outfilename)-3] = '\0';
- strcpy(listfilename, outfilename);
- strcat(outfilename, ".hex");
- strcat(listfilename, ".lst");
+ process_args (argc, argv);
+
yyin = fopen(infilename, "r");
if (yyin == NULL) {
fprintf(stderr, "Can't open file '%s'.\n", infilename);
fprintf(stderr, "Can't write file '%s'.\n", listfilename);
exit(1);
}
+ if (createSymbolFile) {
+ sym_fp = fopen(symfilename, "w");
+ if (sym_fp == NULL) {
+ fprintf(stderr, "Can't write file '%s'.\n", symfilename);
+ exit(1);
+ }
+ }
- /* todo: add a command line option to supress verbose messages */
- printf("\nPaul's XA51 Assembler\n");
- printf("Copyright 1997,2002 Paul Stoffregen\n\n");
- printf("This program is free software; you can redistribute it\n");
- printf("and/or modify it under the terms of the GNU General Public\n");
- printf("License, Version 2, published by the Free Software Foundation\n\n");
- printf("This program is distributed in the hope that it will be useful,\n");
- printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
- printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
-
-
-
- printf(" Building Symbol Table:\n");
+ if (verbose) printf("Pass 1: Building Symbol Table:\n");
p1 = 1;
- //mem = 0;
init_areas();
yyparse();
flag_targets();
- print_symbol_table();
+ if (createSymbolFile) print_symbol_table();
check_redefine();
+
+ if (verbose) printf("Pass 2: Aligning Branch Targets:\n");
p1 = 0;
p2 = 1;
rewind(yyin);
yyrestart(yyin);
lineno = 1;
- printf(" Aligning Branch Targets:\n");
- //mem = 0;
init_areas();
yyparse();
- // print_symbol_table();
+
+ if (verbose) printf("Pass 3: Generating Object Code:\n");
p2 = 0;
p3 = 1;
rewind(yyin);
yyrestart(yyin);
lineno = 1;
- printf(" Generating Object Code:\n");
- //mem = 0;
init_areas();
yyparse();
+
fclose(yyin);
hexout(0, 0, 1); /* flush and close intel hex file output */
return 0;
}
-void print_usage()
+void print_usage(int fatal)
{
- fprintf(stderr, "Usage: xa_asm file\n");
- fprintf(stderr, " or xa_asm file.asm\n");
- exit(1);
+ FILE *out = fatal ? stderr : stdout;
+
+ fprintf (out, "Usage: xa_asm [-s] [-v] file.xa\n");
+ fprintf (out, " -v verbose: show progress\n");
+ fprintf (out, " -s create symbol file\n");
+ fprintf (out, " --version show version/copyright info and exit\n");
+ fprintf (out, " --help show this and exit\n");
+#if 0
+ // some usefull options I can think of.
+ fprintf (out, " -m create map file\n");
+ fprintf (out, " -ss create symbol file sorted by symbol\n");
+ fprintf (out, " -sa create symbol file sorted by segment/address\n");
+ fprintf (out, " --no-temps supress temp symbols in map and sym file\n");
+ fprintf (out, " --code-loc=# sets the start address of the code\n");
+ fprintf (out, " --xdata-loc=# sets the start address of the external data\n");
+ fprintf (out, " --stack-loc=# sets the start address of the stack\n");
+#endif
+ exit(fatal);
}
struct target *next; };
struct area_struct {
+ int start;
int alloc_position;
};
Z80OBJECTS = $(Z80SOURCES:%.c=$(PORTDIR)/%.o)
+XA51SOURCES = _atoi.c _atol.c _schar2fs.c \
+ _divsint.c _divslong.c _divuint.c \
+ _divulong.c _fs2schar.c _fs2sint.c _fs2slong.c \
+ _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \
+ _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \
+ _fsneq.c _fssub.c \
+ _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \
+ _islower.c _isprint.c _ispunct.c _isspace.c \
+ _isupper.c _isxdigit.c _slong2fs.c _memcmp.c \
+ _memcpy.c _memset.c _modsint.c _modslong.c \
+ _moduint.c _modulong.c _mulint.c _mullong.c \
+ _strchr.c _strcmp.c _strcpy.c \
+ _strcspn.c _strlen.c _strncat.c _strncmp.c \
+ _strncpy.c _strpbrk.c _strrchr.c _strspn.c \
+ _strstr.c _strtok.c _uchar2fs.c _uint2fs.c \
+ _ulong2fs.c malloc.c puts.c gets.c \
+ assert.c _strcat.c time.c \
+ fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \
+ cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \
+ asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \
+ sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c
+
+XA51OBJECTS = $(XA51SOURCES:%.c=$(PORTDIR)/%.xa)
+
OEXT = .rel
include incl.mk
$(MAKE) MODELFLAGS="-mds390" PORT=ds390 objects; \
fi
+model-xa51:
+ if [ "`grep xa51 ../../ports.build`" = xa51 ]; then \
+ $(MAKE) MODELFLAGS="-mxa51" PORT=xa51 objects-xa51 OEXT=.xa; \
+ fi
+
+objects-xa51: build-dir $(XA51OBJECTS) port-specific-objects
+ cd $(PORTDIR); ls *$(OEXT) > $(PORT).lib
+
model-z80:
if [ "`grep z80 ../../ports.build`" = z80 ]; then \
$(MAKE) MODELFLAGS="-mz80" PORT=z80 objects-z80 OEXT=.o; \
$(PORTDIR)/%$(OEXT): %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
mv -f `basename $@` $@
- mv -f `basename $@ $(OEXT)`.asm $(PORTDIR)
+ -mv -f `basename $@ $(OEXT)`.asm $(PORTDIR)
# Remaking configuration
# ----------------------
{"hashedstr", "#%s"},
{"lsbimmeds", "#<%s"},
{"msbimmeds", "#>%s"},
- {"module", ".module %s"},
+ {"module", "; .module %s"},
{"global", ".globl %s"},
{"fileprelude", ""},
{"functionheader",
-/* The only ops for now are:
- genAssign
- genIfx
- genAddrOf
- genPointerSet
- genPointerGet
-*/
-
/*-------------------------------------------------------------------------
SDCCgen51.c - source file for code generation for 8051
static char *MOVB="mov.b";
static char *MOVW="mov.w";
-static char *MOVCB="movc.b";
-static char *MOVCW="movc.w";
+//static char *MOVCB="movc.b";
+//static char *MOVCW="movc.w";
void bailOut (char *mesg) {
fprintf (stderr, "%s: bailing out\n", mesg);
char *getStackOffset(int stack) {
static char gsoBuf[1024];
- // dit slaat natuurlijk nergens op
+ // dit slaat natuurlijk nergens op, maar ja voor nou
sprintf (gsoBuf, "r7+(%+d+0%+d%+d)", stack,
FUNC_ISISR(currFunc->type) ?
port->stack.isr_overhead : port->stack.call_overhead,
case AOP_DIR: return "dir";
case AOP_FAR: return "far";
case AOP_CODE: return "code";
+ case AOP_GPTR: return "gptr";
case AOP_STK: return "stack";
case AOP_IMMD: return "imm";
- case AOP_CRY: return "bit";
+ case AOP_BIT: return "bit";
}
return "unknown";
}
/*-----------------------------------------------------------------*/
/* aopForSym - for a true symbol */
/*-----------------------------------------------------------------*/
-static asmop *aopForSym(symbol *sym, bool result) {
+static asmop *aopForSym(symbol *sym, bool result, bool cantUsePointer) {
int size;
asmop *aop;
if (sym->nRegs && sym->regs[0]) {
aop->type=AOP_REG;
sprintf (aop->name[0], sym->regs[0]->name);
- if (size>2) {
+ if (size > 2) {
sprintf (aop->name[1], sym->regs[1]->name);
}
return aop;
// if it is on stack
if (sym->onStack) {
+ if (cantUsePointer) {
+ aop->type=AOP_REG;
+ switch (size)
+ {
+ case 1:
+ emitcode ("mov.b", "r0l,[%s]", getStackOffset(sym->stack));
+ sprintf (aop->name[0], "r0l");
+ return aop;
+ case 2:
+ emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+ sprintf (aop->name[0], "r0");
+ return aop;
+ case 3:
+ emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+ sprintf (aop->name[0], "r0");
+ emitcode ("mov.b", "r1l,[%s]", getStackOffset(sym->stack+2));
+ sprintf (aop->name[1], "r1l");
+ return aop;
+ case 4:
+ emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+ sprintf (aop->name[0], "r0");
+ emitcode ("mov.w", "r1,[%s]", getStackOffset(sym->stack+2));
+ sprintf (aop->name[1], "r1");
+ return aop;
+ }
+ bailOut("aopForSym: onStack CantUsePointer unknown size");
+ }
aop->type=AOP_STK;
sprintf (aop->name[0], "[%s]", getStackOffset(sym->stack));
if (size > 2) {
// if it has a spillLoc
if (sym->usl.spillLoc) {
- return aopForSym (sym->usl.spillLoc, result);
+ return aopForSym (sym->usl.spillLoc, result, cantUsePointer);
}
// if in bit space
if (IN_BITSPACE(SPEC_OCLS(sym->etype))) {
- aop->type=AOP_CRY;
+ aop->type=AOP_BIT;
sprintf (aop->name[0], sym->rname);
return aop;
}
aop->type=AOP_DIR;
sprintf (aop->name[0], sym->rname);
if (size>2) {
- sprintf (aop->name[0], "%s+2", sym->rname);
+ sprintf (aop->name[1], "%s+2", sym->rname);
}
return aop;
}
bailOut("aopForSym: result can not be in code space");
}
aop->type=AOP_CODE;
- emitcode ("mov", "r0,#%s", sym->rname);
+ emitcode ("mov", "r0,#%s ; aopForSym:code", sym->rname);
sprintf (aop->name[0], "[r0]");
if (size>2) {
- sprintf (aop->name[1], "[r0+1]");
+ sprintf (aop->name[1], "[r0+2]");
}
return aop;
}
// if in far space
if (IN_FARSPACE(SPEC_OCLS(sym->etype))) {
aop->type=AOP_FAR;
- emitcode ("mov", "r0,#%s", sym->rname);
+ emitcode ("mov", "r0,#%s ; aopForSym:far", sym->rname);
sprintf (aop->name[0], "[r0]");
if (size>2) {
- sprintf (aop->name[1], "[r0+1]");
+ sprintf (aop->name[1], "[r0+2]");
}
return aop;
}
/*-----------------------------------------------------------------*/
static asmop *aopForVal(operand *op) {
asmop *aop;
- long v=(long long)floatFromVal(OP_VALUE(op));
if (IS_OP_LITERAL(op)) {
op->aop = aop = newAsmop (AOP_LIT);
switch ((aop->size=getSize(operandType(op))))
{
case 1:
- sprintf (aop->name[0], "#0x%02lx", v);
+ sprintf (aop->name[0], "#0x%02x",
+ SPEC_CVAL(operandType(op)).v_int & 0xff);
+ sprintf (aop->name[1], "#0");
break;
case 2:
- sprintf (aop->name[0], "#0x%04lx", v);
+ sprintf (aop->name[0], "#0x%04x",
+ SPEC_CVAL(operandType(op)).v_int & 0xffff);
+ sprintf (aop->name[1], "#0");
+ break;
+ case 3:
+ // must be a generic pointer, can only be zero
+ // ?? if (v!=0) fprintf (stderr, "invalid val op for gptr\n"); exit(1);
+ sprintf (aop->name[0], "#0x%04x",
+ SPEC_CVAL(operandType(op)).v_uint & 0xffff);
+ sprintf (aop->name[1], "#0");
break;
case 4:
- sprintf (aop->name[0], "#(0x%08lx >> 16)", v);
- sprintf (aop->name[1], "#(0x%08lx & 0xffff)", v);
+ sprintf (aop->name[0], "#0x%04lx",
+ SPEC_CVAL(operandType(op)).v_ulong >> 16);
+ sprintf (aop->name[1], "#0x%04x",
+ SPEC_CVAL(operandType(op)).v_ulong && 0xffff);
break;
default:
bailOut("aopForVal");
return aop;
}
}
+
bailOut ("aopForVal: unknown type");
return NULL;
}
-static void aopOp(operand *op, bool result) {
+static void aopOp(operand *op, bool result, bool cantUsePointer) {
if (IS_SYMOP(op)) {
- op->aop=aopForSym (OP_SYMBOL(op), result);
+ op->aop=aopForSym (OP_SYMBOL(op), result, cantUsePointer);
return;
}
if (IS_VALOP(op)) {
if (result) {
bailOut("aopOp: result can not be a value");
}
- aopForVal (op);
+ op->aop=aopForVal (op);
return;
}
bailOut("aopOp: unexpected operand");
}
+bool aopIsPtr(operand *op) {
+ if (AOP_TYPE(op)==AOP_STK ||
+ AOP_TYPE(op)==AOP_CODE ||
+ AOP_TYPE(op)==AOP_FAR) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
char *opRegName(operand *op, int offset, char *opName) {
if (IS_SYMOP(op)) {
sprintf (line+strlen(line), "stack%+d", sym->stack);
return line;
}
+ if (IN_CODESPACE(SPEC_OCLS(sym->etype))) {
+ strcat (line, "code");
+ return line;
+ }
if (IN_FARSPACE(SPEC_OCLS(sym->etype))) {
strcat (line, "far");
return line;
printIc ("genRet", ic, 0,1,0);
- aopOp(IC_LEFT(ic),FALSE);
+ aopOp(IC_LEFT(ic),FALSE, FALSE);
switch (AOP_SIZE(IC_LEFT(ic)))
{
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void genPointerGet (iCode * ic, iCode *pi) {
- char *instr;
-
- operand *result=IC_RESULT(ic), *left=IC_LEFT(ic);
-
printIc ("genPointerGet", ic, 1,1,0);
+#if 0
+ char *instr, *scratchReg;
+ operand *result=IC_RESULT(ic), *left=IC_LEFT(ic);
if (!IS_PTR(operandType(left))) {
bailOut ("genPointerGet: pointer required");
case AOP_REG:
if (AOP_SIZE(result)==1) {
instr=MOVB;
+ scratchReg=R0L;
} else {
instr=MOVW;
+ scratchReg=R0;
}
// if result=onstack
if (AOP_TYPE(result)==AOP_STK) {
- emitcode (instr, "r0,[%s]", AOP_NAME(left)[0]);
- emitcode (instr, "%s,r0", AOP_NAME(result)[0]);
+ emitcode (instr, "%s,[%s]", scratchReg, AOP_NAME(left)[0]);
+ emitcode (instr, "%s,%s", AOP_NAME(result)[0], scratchReg);
} else {
emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]);
}
sym_link *optype=operandType(left);
sym_link *opetype=getSpec(optype);
if (IS_PTR(optype) && !IS_GENPTR(optype)) {
- emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(result)[1],
+ emitcode (MOVB, "%s,#0x%02x", AOP_NAME(result)[1],
PTR_TYPE(SPEC_OCLS(opetype)));
} else {
- emitcode ("mov.b", "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+ emitcode (MOVB, "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]);
}
}
return;
return;
}
bailOut ("genPointerGet: unknown pointer");
+#endif
}
/*-----------------------------------------------------------------*/
/* genPointerSet - stores the value into a pointer location */
/*-----------------------------------------------------------------*/
static void genPointerSet (iCode * ic, iCode *pi) {
- char *instr;
-
- operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic);
-
printIc ("genPointerSet", ic, 1,0,1);
-
- if (!IS_PTR(operandType(result))) {
- bailOut ("genPointerSet: pointer required");
- }
-
- aopOp(right,FALSE);
- aopOp(result,TRUE);
-
- if (IS_GENPTR(operandType(result))) {
- emitcode (";", "INLINE _gptrset ; [%s %s]= %s %s",
- AOP_NAME(result)[0], AOP_NAME(result)[1],
- AOP_NAME(right)[0], AOP_NAME(right)[1]);
- return;
- }
-
- switch (AOP_TYPE(result))
- {
- case AOP_REG:
- case AOP_DIR:
- case AOP_FAR:
- case AOP_STK:
- if (AOP_SIZE(result)==1) {
- instr=MOVB;
- } else {
- instr=MOVW;
- }
- emitcode (instr, "[%s],%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
- if (AOP_SIZE(result) > 2) {
- if (AOP_SIZE(result)==3) {
- instr=MOVB;
- } else {
- instr=MOVW;
- }
- emitcode (instr, "[%s],%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
- }
- return;
- }
- bailOut ("genPointerSet: unknown pointer");
}
/*-----------------------------------------------------------------*/
IC_TRUE(ic) ? IC_TRUE(ic)->name : "NULL",
IC_FALSE(ic) ? IC_FALSE(ic)->name : "NULL");
- aopOp(cond,FALSE);
+ aopOp(cond,FALSE,FALSE);
if (IC_TRUE(ic)) {
trueOrFalse=TRUE;
switch (AOP_TYPE(cond) )
{
- case AOP_CRY:
+ case AOP_BIT:
emitcode (trueOrFalse ? "jb" : "jbc", "%s,%05d$",
AOP_NAME(cond)[0], jlbl->key+100);
return;
printIc ("genAddrOf", ic, 1,1,0);
- aopOp (IC_RESULT(ic),TRUE);
+ aopOp (IC_RESULT(ic),TRUE, FALSE);
if (isOperandOnStack(left)) {
emitcode ("lea", "%s,%s", AOP_NAME(IC_RESULT(ic))[0],
getStackOffset(OP_SYMBOL(left)->stack));
if (AOP_SIZE(IC_RESULT(ic)) > 2) {
// this must be a generic pointer
- emitcode ("mov", "%s,#0x01", AOP_NAME(IC_RESULT(ic))[1]);
+ emitcode ("mov", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], FPOINTER);
}
return;
}
if (isOperandInDirSpace(left) ||
isOperandInFarSpace(left) ||
isOperandInCodeSpace(left)) {
- emitcode ("mov", "%s,#%s", AOP_NAME(IC_RESULT(ic))[0],
- OP_SYMBOL(left));
+ emitcode ("mov.w", "%s,#%s", AOP_NAME(IC_RESULT(ic))[0],
+ OP_SYMBOL(left)->rname);
if (AOP_SIZE(IC_RESULT(ic)) > 2) {
// this must be a generic pointer
int space=0; // dir space
} else if (isOperandInCodeSpace(left)) {
space=2;
}
- emitcode ("mov", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], space);
+ emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], space);
}
return;
}
bailOut("genAssign: result is not a symbol");
}
- aopOp(right, FALSE);
- aopOp(result, TRUE);
+ aopOp(result, TRUE, FALSE);
+ aopOp(right, FALSE, aopIsPtr(result));
size=AOP_SIZE(result);
- if (result->aop->type==AOP_REG ||
- right->aop->type==AOP_REG ||
- right->aop->type==AOP_LIT ||
- right->aop->type==AOP_STK ||
- right->aop->type==AOP_IMMD) {
- // everything will do
- } else {
- // they have to match
- if (result->aop->type != right->aop->type) {
- fprintf (stderr, "genAssign: types don't match (%s!=%s)\n",
- aopTypeName(result->aop), aopTypeName(right->aop));
- exit (1);
- }
- }
-
/* if result is a bit */
- if (AOP_TYPE(result) == AOP_CRY) {
+ if (AOP_TYPE(result) == AOP_BIT) {
/* if right is literal, we know what the value is */
if (AOP_TYPE(right) == AOP_LIT) {
if (operandLitValue(right)) {
return;
}
/* if right is also a bit */
- if (AOP_TYPE(right) == AOP_CRY) {
+ if (AOP_TYPE(right) == AOP_BIT) {
emitcode ("mov", "c,%s", AOP_NAME(right));
emitcode ("mov", "%s,c", AOP_NAME(result));
return;
} else {
instr=MOVW;
}
- if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) {
- emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[0]);
- emitcode (instr, "%s,%s", AOP_NAME(result)[0], size==1 ? "r0l":"r0");
- } else {
- emitcode (instr, "%s,%s",
- result->aop->name[0], right->aop->name[0]);
- }
+ emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
+
if (AOP_SIZE(result) > 2) {
- if (AOP_TYPE(right)==AOP_LIT) {
- emitcode (instr, "%s,%s", result->aop->name[1],
- *AOP_NAME(right)[1] ? AOP_NAME(right)[1] : "#0x00");
- return;
- }
if (size==3) {
+ // generic pointer
instr=MOVB;
} else {
instr=MOVW;
}
- if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) {
- emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[1]);
- emitcode (instr, "%s,%s", AOP_NAME(result)[1], size==1 ? "r0l":"r0");
- } else {
- emitcode (instr, "%s,%s",
- result->aop->name[1], right->aop->name[1]);
- }
+ emitcode (instr, "%s,%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
return;
}
}
lbl = newiTempLabel (NULL);
lbl1 = newiTempLabel (NULL);
- aopOp (IC_RESULT (ic), TRUE);
+ aopOp (IC_RESULT (ic), TRUE, FALSE);
if (AOP_TYPE(IC_RESULT(ic))==AOP_REG || AOP_TYPE(IC_RESULT(ic))==AOP_DIR) {
emitcode ("djnz", "%s,%05d$", AOP_NAME(IC_RESULT(ic)), lbl->key+100);
- emitcode ("bra", "%05d$", lbl1->key + 100);
+ emitcode ("br", "%05d$", lbl1->key + 100);
emitcode ("", "%05d$:", lbl->key + 100);
emitcode ("jmp", "%05d$", IC_TRUE (ifx)->key + 100);
emitcode ("", "%05d$:", lbl1->key + 100);
return TRUE;
}
- bailOut("genDjnz: aop type");
- return FALSE;
+
+ bailOut("genDjnz: aop type");
+ return FALSE;
}
/*-----------------------------------------------------------------*/
iCode *ic;
int cln = 0;
- fprintf (stderr, "genXA51Code\n");
lineHead = lineCurr = NULL;
/* print the allocation information */
AOP_FAR,
AOP_CODE,
AOP_GPTR,
- AOP_STK,
+ AOP_STK,
AOP_IMMD,
- AOP_CRY
+ AOP_BIT
};
/* type asmop : a homogenised type for
extern int rewinds;
void _xa51_genAssemblerEnd () {
- fprintf (stderr, "Did %d rewind%c for c-line in asm comments\n", rewinds,
- rewinds==1 ? '\0' : 's');
+ //fprintf (stderr, "Did %d rewind%c for c-line in asm comments\n", rewinds,
+ //rewinds==1 ? '\0' : 's');
}
void xa51_assignRegisters (eBBlock ** ebbs, int count);
/*-----------------------------------------------------------------*/
extern void genXA51Code (iCode *);
+
#define D(x)
/* Global data */
}
if (!silent) {
- fprintf (stderr, "freeReg: (%08x) %s (%s) ", xa51RegsInUse,
- reg->name, reg->sym->name);
+ D(fprintf (stderr, "freeReg: (%08x) %s (%s) ", xa51RegsInUse,
+ reg->name, reg->sym->name));
}
if (reg->isFree || ((xa51RegsInUse®->regMask)!=reg->regMask)) {
xa51RegsInUse &= ~reg->regMask;
reg->isFree = 1;
reg->sym = NULL;
- if (!silent) fprintf (stderr, "(%08x)\n", xa51RegsInUse);
+ if (!silent) D(fprintf (stderr, "(%08x)\n", xa51RegsInUse));
checkRegMask(__FUNCTION__);
}
checkRegMask(__FUNCTION__);
if (!silent) {
- fprintf (stderr, "allocReg (%08x) for %s size:%d, type:%s ",
+ D(fprintf (stderr, "allocReg (%08x) for %s size:%d, type:%s ",
xa51RegsInUse,
sym->name,
- size, regTypeToStr(type));
+ size, regTypeToStr(type)));
}
switch (size)
reg->isFree=0; // redundant
reg->sym = sym;
if (!silent) {
- fprintf (stderr, "(using gap) %s\n", reg->name);
+ D(fprintf (stderr, "(using gap) %s\n", reg->name));
}
checkRegMask(__FUNCTION__);
return TRUE;
regsXA51[i].isFree = 0; // redundant
regsXA51[i].sym = sym;
if (!silent) {
- fprintf (stderr, "%s\n", regsXA51[i].name);
+ D(fprintf (stderr, "%s\n", regsXA51[i].name));
}
sym->regs[offset]=®sXA51[i];
checkRegMask(__FUNCTION__);
}
}
if (!silent) {
- fprintf (stderr, "failed (%08x)\n", xa51RegsInUse);
+ D(fprintf (stderr, "failed (%08x)\n", xa51RegsInUse));
}
checkRegMask(__FUNCTION__);
return FALSE;
case 3:
// this must be a generic pointer
if (!silent) {
- fprintf (stderr, "trying 2+1\n");
+ D(fprintf (stderr, "trying 1+2\n"));
}
- // get the pointer part
- if (allocReg (2, REG_PTR, sym, offset, silent)) {
- // get the generic part
- if ((xa51HasGprRegs && allocReg (1, REG_GPR, sym, offset+1, silent)) ||
- allocReg (1, REG_PTR, sym, offset+1, silent)) {
+ // get the generic part
+ if ((xa51HasGprRegs && allocReg (1, REG_GPR, sym, offset+1, silent)) ||
+ allocReg (1, REG_PTR, sym, offset+1, silent)) {
+ // get the pointer part
+ if (allocReg (2, REG_PTR, sym, offset, silent)) {
checkRegMask(__FUNCTION__);
return TRUE;
}
- freeReg(sym->regs[offset], silent);
- sym->regs[offset]=NULL;
+ freeReg(sym->regs[offset+1], silent);
+ sym->regs[offset+1]=NULL;
}
checkRegMask(__FUNCTION__);
return FALSE;
break;
case 4: // this is a dword
if (!silent) {
- fprintf (stderr, "trying 2+2\n");
+ D(fprintf (stderr, "trying 2+2\n"));
}
if ((xa51HasGprRegs && allocReg (2, REG_GPR, sym, offset, silent)) ||
allocReg (2, REG_PTR, sym, offset, silent)) {
char slocBuffer[30];
- fprintf (stderr, " createStackSpil: %s\n", sym->name);
+ D(fprintf (stderr, " createStackSpil: %s\n", sym->name));
/* first go try and find a free one that is already
existing on the stack */
{
int i;
- fprintf (stderr, " spillThis: %s\n", sym->name);
+ D(fprintf (stderr, " spillThis: %s\n", sym->name));
/* if this is rematerializable or has a spillLocation
we are okay, else we need to create a spillLocation
/* get something we can spil */
ssym = selectSpil (ic, ebp, forSym);
- fprintf (stderr, " spillSomething: spilling %s\n", ssym->name);
+ D(fprintf (stderr, " spillSomething: spilling %s\n", ssym->name));
/* mark it as spilt */
ssym->isspilt = ssym->spillA = 1;
/*-----------------------------------------------------------------*/
static bool getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym, short offset) {
- fprintf (stderr, "getRegPtr: %s ", sym->name);
- printTypeChain(sym->type, stderr);
- fprintf (stderr, "\n");
+ D(fprintf (stderr, "getRegPtr: %s ", sym->name));
+ D(printTypeChain(sym->type, stderr));
+ D(fprintf (stderr, "\n"));
tryAgain:
/* try for a ptr type */
/*-----------------------------------------------------------------*/
static bool getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym, short offset) {
- fprintf (stderr, "getRegGpr: %s ", sym->name);
- printTypeChain(sym->type, stderr);
- fprintf (stderr, "\n");
+ D(fprintf (stderr, "getRegGpr: %s ", sym->name));
+ D(printTypeChain(sym->type, stderr));
+ D(fprintf (stderr, "\n"));
tryAgain:
/* try for gpr type */
}
return FALSE;
}
- fprintf (stderr, " %s will cause a spill\n", sym->name);
+ D(fprintf (stderr, " %s will cause a spill\n", sym->name));
return TRUE;
}
fprintf (stderr, "allocated more than 4 or 0 registers for type ");
printTypeChain (sym->type, stderr);
fprintf (stderr, "\n");
+ exit (1);
}
/* determine the type of register required */