$(CC) $(COPT) $(CFLAGS) -c $< -o $@
$(OBJS_ALL) : $(INC)
+
+clean:
+ rm -f *~ *.rel *.asm *.lst *.sym *.o *.map *.noi *.bin *.lk
+- Parse assignment to local variables
+ auto x = 4; etc
- Write some copt rules to stop the output sucking so much
- Steal the rst tricks done by BDS C
- Output mixed code/data so we can flush the literal pool every line of asm
#include "defs.h"
#include "data.h"
-int nextreg = 0;
-int xdirty = 0;
-int xsprel = 0;
-int xtype = 0; /* 0 = D, 1 = S */
-int regv[8];
+static int nextreg = 0;
+static int xdirty = 0;
+static int xsprel = 0;
+static int xtype = 0; /* 0 = D, 1 = S */
+static int regv[8];
+static int indata;
/*
* Some predefinitions:
newline ();
output_line ("\t;program area SMALLC_GENERATED is RELOCATABLE");
output_line ("\t.module SMALLC_GENERATED");
+ gen_code();
}
/**
* Output internal generated label prefix
*/
void output_label_prefix(void) {
- xdirty = 1;
output_byte('$');
}
*/
void output_label_terminator (void) {
output_byte (':');
+ if (!indata)
+ xdirty = 1;
}
/**
void gen_statement_end(void)
{
output_line(";end");
-}
\ No newline at end of file
+}
+
+void gen_data(void)
+{
+ indata = 1;
+ output_line(".data");
+}
+
+void gen_code(void)
+{
+ indata = 0;
+ output_line(".code");
+}
output_line("ldb ,x");
else {
/* TODO work out what we can damage here */
- /* Can we avoid using ,u ?? */
- output_line("tfr d,u");
- output_line("ldb ,u");
+ output_line("tfr d,x");
+ output_line("ldb ,x");
}
if (typeobj == CCHAR)
output_line("sex");
if (reg & DE_REG)
output_line("ldd ,x"); /* Can't happen ?? */
else {
- output_line("exg d,x");
- output_line("ldx ,x");
- output_line("exg d,x");
+ output_line("tfr d,x");
+ output_line("ldd ,x");
}
}
}
* FIXME: probably want a gen_call_indirect so targets can do sane things
*/
void gen_swap_stack(void) {
- /* FIXME: if we can get rid of u register stuff we can get two
- register variables */
- output_line("ldu ,s");
+ output_line("ldx ,s");
output_line("std ,s");
- output_line("tfr u,d");
+ output_line("tfr x,d");
}
/**
output_number(i);
newline();
}
- /* FIXME: need to adjust the stack if there is cruft in the way */
+ /* Need to adjust the stack if there is cruft in the way */
if (nextreg > 1) {
+ gen_modify_stack(regv[1]);
output_line("puls y,u");
stkp + 4;
}
else if (nextreg) {
+ gen_modify_stack(regv[0]);
output_line("puls y");
stkp += 2;
}
* @param lval2
*/
void gen_add(LVALUE *lval, LVALUE *lval2) {
- if (dbltest (lval2, lval)) {
- output_line("asl 1,s");
- output_line("rol ,s");
- }
+ if (dbltest (lval2, lval))
+ output_line("addd ,s");
output_line ("addd ,s++");
stkp += INTSIZE;
}
gen_multiply_by_two();
break;
case STRUCT:
+ if (nextreg > 1)
+ output_line("pshs y");
output_with_tab("ldy ");
output_immediate(size);
newline();
gen_call("__muli ");
newline();
+ if (nextreg > 1)
+ output_line("puls y");
break;
default:
break;
}
/**
- * divide the primary register by INTSIZE, never used
+ * divide the primary register by INTSIZE
*/
void gen_divide_by_two(void) {
- gen_push(HL_REG); /* push primary in prep for gasr */
- gen_immediate ();
- output_number (1);
- newline ();
- gen_arithm_shift_right (); /* divide by two */
+ output_line("srl h");
+ output_line("rr l");
}
/**
*/
void gen_add(LVALUE *lval, LVALUE *lval2) {
gen_pop ();
- if (dbltest (lval2, lval)) {
- gen_swap ();
- gen_multiply_by_two();
- gen_swap ();
- }
+ if (dbltest (lval2, lval))
+ output_line("add hl,de");
output_line ("add hl,de");
}
if (amatch ("void", 4)) {
return VOID;
}
+#if 0
if (amatch ("register", 8)) {
if (amatch("char", 4))
return CCHAR;
return CINT;
else
return CINT;
- } else if(amatch("unsigned", 8)) {
+ } else
+#endif
+ if(amatch("unsigned", 8)) {
if (amatch("char", 4)) {
return UCHAR;
} else if (amatch("int", 3)) {
return UINT;
}
- } else if(amatch("signed", 8)) {
+ } else if(amatch("signed", 6)) {
if (amatch("char", 4)) {
return CCHAR;
} else if (amatch("int", 3)) {
extern void gen_epilogue(void);
extern int gen_register(int vp, int size, int typ);
extern void gen_statement_end(void);
+extern void gen_code(void);
+extern void gen_data(void);
extern char *inclib(void);
extern void gnargs(int d);
extern int assemble(char *s);