COPT = -O2
OBJS = initials.rel data.rel error.rel expr.rel function.rel gen.rel io.rel \
- lex.rel main.rel preproc.rel primary.rel stmt.rel struct.rel sym.rel while.rel
+ lex.rel main.rel outstack.rel preproc.rel primary.rel stmt.rel struct.rel sym.rel while.rel
OBJ_Z80 = codez80.rel
OBJ_8080 = code8080.rel
COPT = -O2
OBJS = initials.o data.o error.o expr.o function.o gen.o io.o \
- lex.o main.o preproc.o primary.o stmt.o struct.o sym.o while.o
+ lex.o main.o outstack.o preproc.o primary.o stmt.o struct.o sym.o while.o
OBJ_Z80 = codez80.o
OBJ_8080 = code8080.o
cmode,
lastst;
-int input, input2, output;
+int input, input2, output, target;
int inclstk[INCLSIZ] = {-1, -1, -1 };
int inclsp;
char fname[20];
cmode,
lastst;
-extern int input, input2, output;
+extern int input, input2, output, target;
extern int inclstk[];
extern int inclsp;
extern char fname[];
extern INITIALS initials_table[NUMBER_OF_GLOBALS];
extern char initials_data_table[INITIALS_SIZE]; // 5kB space for initialisation data
extern int initials_idx, initials_data_idx;
+
+extern char obuf[];
#include "defs.h"
#include "data.h"
-static char obuf[512];
+char obuf[512]; /* Shared with outstack for defer uses */
static char *optr = obuf;
void oflush(void)
macptr = 0;
ctext = 0;
errs = 0;
- aflag = 1;
+ aflag = 0;
uflag = 0;
for (i=1; i<argc; i++) {
case 't': case 'T': // output c source as asm comments
ctext = 1;
break;
- case 'a': case 'A': // no argument count in A to function calls
- aflag = 0;
+ case 'a': case 'A': // argument count in A to function calls
+ aflag = 1;
break;
case 'u': case 'U': // use undocumented 8085 instructions
uflag = 1;
rglobal_table_index = global_table_index; //rglbptr = glbptr;
//add_global("etext", ARRAY, CCHAR, 0, EXTERN);
//add_global("edata", ARRAY, CCHAR, 0, EXTERN);
+ /* Eww FIXME when we do types!! */
defmac("short\tint");
initmac();
// compiler body
output = 1;
} else if (!openout())
return;
+ target = output;
+ defer_init();
header();
code_segment_gtext();
parse();
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include "defs.h"
+#include "data.h"
+
+#define MAX_DEFER 64
+
+static off_t offset_stack[MAX_DEFER];
+static uint8_t next_defer;
+static int defer;
+
+/* Stack chunks of assembler output to be pasted back into the file later.
+ We use this to put arguments in the right order while not having to use
+ tons of RAM */
+
+void defer_output(void)
+{
+ oflush();
+ if (next_defer == MAX_DEFER)
+ error("too many defers");
+ /* Remember where our block started */
+ offset_stack[next_defer++] = lseek(defer, 0L, 1);
+ output = defer;
+}
+
+static void copy_block(void)
+{
+ /* obuf is free at this point */
+ long p = offset_stack[next_defer];
+ long size = lseek(defer, 0L, 1) - p;
+ lseek(defer, p, 0);
+
+ while (size) {
+ /* Can this ever really be over 64K ?? */
+ unsigned int n = size;
+ if (n > 512)
+ n = 512;
+ if (read(defer, obuf, n) != n)
+ error("rd");
+ if (write(target, obuf, n) !=n)
+ error("wr");
+ size -= n;
+ }
+ lseek(defer, p, 0);
+}
+
+void end_defer(void)
+{
+ --next_defer;
+ /* FIXME: we should fastpath the case of all the bits being in
+ the buffer - in which case we can just fire it at target */
+ oflush();
+ /* Copy from this position to the current position into the target
+ file */
+ copy_block();
+ /* We are back into the main flow, stop outputting via the defer file */
+ if (next_defer == 0)
+ output = target;
+}
+
+void defer_init(void)
+{
+ defer = open("scc-spool", O_RDWR|O_CREAT|O_TRUNC, 0600);
+// unlink("scc-spool");
+}
*/
void callfunction(char *ptr) {
int nargs;
+ int i;
nargs = 0;
+
blanks ();
if (ptr == 0)
gen_push (HL_REG);
expression (NO);
if (ptr == 0)
gen_swap_stack ();
+ /* Worth making the first argument pass in HL ?? */
gen_push (HL_REG);
- nargs = nargs + INTSIZE;
+ nargs++;
+ /* Will need to track sizes later */
if (!match (","))
break;
}
+ /* Now paste the argument generation blocks into the output
+ in reverse order so the stack is right */
+ for (i = 0; i < nargs; i++)
+ end_defer();
needbrack (")");
if (aflag)
- gnargs(nargs / INTSIZE);
+ gnargs(nargs);
if (ptr)
gen_call (ptr);
else
callstk ();
- stkp = gen_modify_stack (stkp + nargs);
+ stkp = gen_modify_stack (stkp + nargs * INTSIZE);
}
void needlval(void) {
extern WHILE *findwhile(void);
extern WHILE *readswitch(void);
extern void addcase(int val);
+extern void defer_output(void);
+extern void end_defer(void);
+extern void defer_init(void);