1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 22:24:28 +00:00

Order DFD by address

This commit is contained in:
David Schmenk 2018-03-21 16:23:32 -07:00
parent fa71ec3948
commit cb7f86a911
7 changed files with 89 additions and 62 deletions

View File

@ -344,11 +344,11 @@ def compiler(defptr)#0
^codeptr = $D0; codeptr++ // BNE rel ^codeptr = $D0; codeptr++ // BNE rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $88; codeptr++ // DEY ^codeptr = $88; codeptr++ // DEY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $42 is $42
puts("ISNE") puts("ISNE")
@ -367,11 +367,11 @@ def compiler(defptr)#0
^codeptr = $D0; codeptr++ // BNE rel ^codeptr = $D0; codeptr++ // BNE rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $C8; codeptr++ // INY ^codeptr = $C8; codeptr++ // INY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $44 is $44
puts("ISGT") puts("ISGT")
@ -392,11 +392,11 @@ def compiler(defptr)#0
^codeptr = $30; codeptr++ // BMI rel ^codeptr = $30; codeptr++ // BMI rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $C8; codeptr++ // INY ^codeptr = $C8; codeptr++ // INY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $46 is $46
puts("ISLT") puts("ISLT")
@ -417,11 +417,11 @@ def compiler(defptr)#0
^codeptr = $30; codeptr++ // BMI rel ^codeptr = $30; codeptr++ // BMI rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $C8; codeptr++ // INY ^codeptr = $C8; codeptr++ // INY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $48 is $48
puts("ISGE") puts("ISGE")
@ -442,11 +442,11 @@ def compiler(defptr)#0
^codeptr = $10; codeptr++ // BPL rel ^codeptr = $10; codeptr++ // BPL rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $C8; codeptr++ // INY ^codeptr = $C8; codeptr++ // INY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $4A is $4A
puts("ISLE") puts("ISLE")
@ -467,11 +467,11 @@ def compiler(defptr)#0
^codeptr = $10; codeptr++ // BPL rel ^codeptr = $10; codeptr++ // BPL rel
^codeptr = $01; codeptr++ // +1 ^codeptr = $01; codeptr++ // +1
^codeptr = $C8; codeptr++ // INY ^codeptr = $C8; codeptr++ // INY
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0+1; codeptr++ // ESTKL+1
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0+1; codeptr++ // ESTKH+1
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $D0; codeptr++ // ESTKL
^codeptr = $94; codeptr++ // STY zp,X
^codeptr = $C0; codeptr++ // ESTKH
break break
is $4C is $4C
i++ i++
@ -527,11 +527,12 @@ def compiler(defptr)#0
is $52 is $52
i++ i++
case = i + *(bytecode+i) case = i + *(bytecode+i)
puts("SEL "); puti(case) i++
j = ^case puts("SEL "); puti(case); putln
j = ^(bytecode+case)
dest = codeptr + 8 + case * 11) dest = codeptr + 8 + case * 11)
if isule(dest, codemax) if isule(dest, codemax)
^case = $FF // Flag as NOP ^(bytecode+case) = $FF // Flag as NOP
case++ case++
^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $B5; codeptr++ // LDA zp,X
^codeptr = $D0; codeptr++ // ESTKL ^codeptr = $D0; codeptr++ // ESTKL
@ -539,7 +540,7 @@ def compiler(defptr)#0
^codeptr = $C0; codeptr++ // ESTKH ^codeptr = $C0; codeptr++ // ESTKH
^codeptr = $E8; codeptr++ // INX ^codeptr = $E8; codeptr++ // INX
repeat repeat
puts(" $"); puth(*case) puts(" $"); puth(*(bytecode+case))
^codeptr = $C9; codeptr++ // CMP #imm ^codeptr = $C9; codeptr++ // CMP #imm
^codeptr = ^(bytecode+case); codeptr++ ^codeptr = ^(bytecode+case); codeptr++
^codeptr = $D0; codeptr++ // BNE rel ^codeptr = $D0; codeptr++ // BNE rel
@ -548,16 +549,16 @@ def compiler(defptr)#0
^codeptr = ^(bytecode+case+1); codeptr++ ^codeptr = ^(bytecode+case+1); codeptr++
^codeptr = $D0; codeptr++ // BNE rel ^codeptr = $D0; codeptr++ // BNE rel
^codeptr = $03; codeptr++ // +3 ^codeptr = $03; codeptr++ // +3
*case = $FFFF *(bytecode+case) = $FFFF
case = case + 2 case = case + 2
puts("-->"); puti(case + *case) puts("-->"); puti(case + *(bytecode+case)); putln
^codeptr = $4C; codeptr++ // JMP abs ^codeptr = $4C; codeptr++ // JMP abs
*codeptr = addrxlate=>[case] *codeptr = addrxlate=>[case]
if not (*codeptr & $8000) // Unresolved address list if not (*codeptr & $8000) // Unresolved address list
addrxlate=>[case] = codeptr - *jitcodeptr addrxlate=>[case] = codeptr - *jitcodeptr
fin fin
codeptr = codeptr + 2 codeptr = codeptr + 2
*case = $FFFF *(bytecode+case) = $FFFF
case = case + 2 case = case + 2
j-- j--
until not j until not j
@ -567,7 +568,6 @@ def compiler(defptr)#0
addrxlate=>[case] = codeptr - *jitcodeptr addrxlate=>[case] = codeptr - *jitcodeptr
fin fin
codeptr = codeptr + 2 codeptr = codeptr + 2
i++
else else
codeptr = dest codeptr = dest
fin fin

View File

@ -382,12 +382,13 @@ void emit_header(void)
} }
void emit_rld(void) void emit_rld(void)
{ {
int i; int i, j;
printf(";\n; RE-LOCATEABLE DICTIONARY\n;\n"); printf(";\n; RE-LOCATEABLE DICTIONARY\n;\n");
/* /*
* First emit the bytecode definition entrypoint information. * First emit the bytecode definition entrypoint information.
*/ */
/*
for (i = 0; i < globals; i++) for (i = 0; i < globals; i++)
if (!(idglobal_type[i] & EXTERN_TYPE) && (idglobal_type[i] & DEF_TYPE)) if (!(idglobal_type[i] & EXTERN_TYPE) && (idglobal_type[i] & DEF_TYPE))
{ {
@ -395,6 +396,14 @@ void emit_rld(void)
printf("\t%s\t_C%03d\t\t\n", DW, idglobal_tag[i]); printf("\t%s\t_C%03d\t\t\n", DW, idglobal_tag[i]);
printf("\t%s\t$00\n", DB); printf("\t%s\t$00\n", DB);
} }
*/
j = outflags & INIT ? defs - 1 : defs;
for (i = 0; i < j; i++)
{
printf("\t%s\t$02\t\t\t; CODE TABLE FIXUP\n", DB);
printf("\t%s\t_C%03d\t\t\n", DW, i);
printf("\t%s\t$00\n", DB);
}
/* /*
* Now emit the fixup table. * Now emit the fixup table.
*/ */

View File

@ -529,11 +529,13 @@ def init_idglobal#0
word op word op
word i word i
dfd_num = DFDNUM
tag_num = TAGNUM tag_num = TAGNUM
fixup_num = FIXUPNUM fixup_num = FIXUPNUM
globalbufsz = IDGLOBALSZ globalbufsz = IDGLOBALSZ
localbufsz = IDLOCALSZ localbufsz = IDLOCALSZ
if isult(heapavail, $8000) if isult(heapavail, $4000)
dfd_num = DFDNUM/2
tag_num = TAGNUM/2 tag_num = TAGNUM/2
fixup_num = FIXUPNUM/2 fixup_num = FIXUPNUM/2
globalbufsz = IDGLOBALSZ globalbufsz = IDGLOBALSZ
@ -552,6 +554,7 @@ def init_idglobal#0
// //
// Allocate remaining buffers // Allocate remaining buffers
// //
dfd_tag = heapalloc(dfd_num*2)
tag_addr = heapalloc(tag_num*2) tag_addr = heapalloc(tag_num*2)
tag_type = heapalloc(tag_num) tag_type = heapalloc(tag_num)
fixup_tag = heapalloc(fixup_num*2) fixup_tag = heapalloc(fixup_num*2)
@ -604,6 +607,14 @@ def new_moddep(nameptr, len)#0
if moddep_cnt > MODDEPNUM; parse_warn("Module dependency overflow"); fin if moddep_cnt > MODDEPNUM; parse_warn("Module dependency overflow"); fin
end end
// //
// DFD list
//
def new_dfd(tag)#0
if dfd_cnt >= dfd_num; exit_err(ERR_OVER|ERR_CODE|ERR_TABLE); fin
dfd_tag=>[dfd_cnt] = tag
dfd_cnt++
end
//
// Generate/add to a sequence of code // Generate/add to a sequence of code
// //
def gen_op(seq, code) def gen_op(seq, code)
@ -870,20 +881,23 @@ end
// Write DeFinition Directory // Write DeFinition Directory
// //
def writeDFD(refnum, modfix)#0 def writeDFD(refnum, modfix)#0
word dfd, idptr, idcnt word dfd, idptr, cnt
byte defdir[128] byte defdir[128]
dfd, idptr, idcnt = @defdir, idglobal_tbl, globals dfd = @defdir
while idcnt for cnt = 0 to dfd_cnt-1
if idptr=>idtype & (FUNC_TYPE|EXTERN_TYPE) == FUNC_TYPE //dfd, idptr, cnt = @defdir, idglobal_tbl, globals
//while cnt
//if idptr=>idtype & (FUNC_TYPE|EXTERN_TYPE) == FUNC_TYPE
dfd->0 = $02 dfd->0 = $02
dfd=>1 = tag_addr=>[idptr=>idval] + modfix dfd=>1 = tag_addr=>[dfd_tag=>[cnt]] + modfix
dfd->3 = 0 dfd->3 = 0
dfd = dfd + 4 dfd = dfd + 4
fin //fin
idptr = idptr + idptr->idname + t_id //idptr = idptr + idptr->idname + t_id
idcnt-- //cnt--
loop //loop
next
fileio:write(refnum, @defdir, dfd - @defdir) fileio:write(refnum, @defdir, dfd - @defdir)
end end
// //

View File

@ -1624,8 +1624,9 @@ int parse_defs(void)
emit_const(0); emit_const(0);
emit_leave(); emit_leave();
} }
while (lambda_cnt--) for (cfnvals = 0; cfnvals < lambda_cnt; cfnvals++)
emit_lambdafunc(lambda_tag[lambda_cnt], lambda_id[lambda_cnt], lambda_cparams[lambda_cnt], lambda_seq[lambda_cnt]); emit_lambdafunc(lambda_tag[cfnvals], lambda_id[cfnvals], lambda_cparams[cfnvals], lambda_seq[cfnvals]);
lambda_cnt = 0;
return (1); return (1);
} }
else if (scantoken == ASM_TOKEN) else if (scantoken == ASM_TOKEN)
@ -1705,21 +1706,21 @@ int parse_module(void)
while (parse_mods()) next_line(); while (parse_mods()) next_line();
while (parse_vars(GLOBAL_TYPE)) next_line(); while (parse_vars(GLOBAL_TYPE)) next_line();
while (parse_defs()) next_line(); while (parse_defs()) next_line();
emit_bytecode_seg();
emit_start();
idlocal_reset();
emit_idfunc(0, 0, NULL, 1);
prevstmnt = 0;
if (scantoken != DONE_TOKEN && scantoken != EOF_TOKEN) if (scantoken != DONE_TOKEN && scantoken != EOF_TOKEN)
{ {
emit_bytecode_seg();
emit_start();
idlocal_reset();
emit_idfunc(0, 0, NULL, 1);
prevstmnt = 0;
while (parse_stmnt()) next_line(); while (parse_stmnt()) next_line();
if (scantoken != DONE_TOKEN) if (scantoken != DONE_TOKEN)
parse_error("Missing DONE"); parse_error("Missing DONE");
if (prevstmnt != RETURN_TOKEN) }
{ if (prevstmnt != RETURN_TOKEN)
emit_const(0); {
emit_ret(); emit_const(0);
} emit_ret();
} }
} }
emit_trailer(); emit_trailer();

View File

@ -1259,6 +1259,7 @@ def parse_defs
new_idfunc(idstr, idlen, type, func_tag, cfnparms, infuncvals) new_idfunc(idstr, idlen, type, func_tag, cfnparms, infuncvals)
fin fin
emit_tag(func_tag) emit_tag(func_tag)
new_dfd(func_tag)
while parse_vars(LOCAL_TYPE); nextln; loop while parse_vars(LOCAL_TYPE); nextln; loop
emit_enter(cfnparms) emit_enter(cfnparms)
prevstmnt = 0 prevstmnt = 0
@ -1273,10 +1274,10 @@ def parse_defs
next next
emit_leave emit_leave
fin fin
while lambda_cnt for cfnvals = 0 to lambda_cnt-1
lambda_cnt-- emit_lambdafunc(lambda_tag[cfnvals], lambda_cparms[cfnvals], lambda_seq[cfnvals])
emit_lambdafunc(lambda_tag[lambda_cnt], lambda_cparms[lambda_cnt], lambda_seq[lambda_cnt]) new_dfd(lambda_tag[cfnvals])
loop next
fin fin
return token == EOL_TKN ?? TRUE :: FALSE return token == EOL_TKN ?? TRUE :: FALSE
end end

View File

@ -232,6 +232,7 @@ end
// Generated code buffers // Generated code buffers
// //
const OPSEQNUM = 256 const OPSEQNUM = 256
const DFDNUM = 128
const TAGNUM = 1024 const TAGNUM = 1024
const FIXUPNUM = 2048 const FIXUPNUM = 2048
const MODDEPNUM = 8 const MODDEPNUM = 8
@ -239,12 +240,13 @@ const IDGLOBALSZ = 4096
const IDLOCALSZ = 512 const IDLOCALSZ = 512
const CASENUM = 64 const CASENUM = 64
word fixup_cnt, tag_cnt = -1 word fixup_cnt, tag_cnt = -1
word dfd_tag, dfd_cnt
word fixup_tag, fixup_addr word fixup_tag, fixup_addr
word tag_addr, tag_type word tag_addr, tag_type
word idglobal_tbl, idlocal_tbl word idglobal_tbl, idlocal_tbl
word pending_seq word pending_seq
word globals, lastglobal, lastglobalsize, lastlocal, savelast word globals, lastglobal, lastglobalsize, lastlocal, savelast
word tag_num, fixup_num, globalbufsz, localbufsz, codebufsz word dfd_num, tag_num, fixup_num, globalbufsz, localbufsz, codebufsz
word datasize, framesize, savesize word datasize, framesize, savesize
byte locals, savelocals byte locals, savelocals
word codebuff, codeptr, entrypoint word codebuff, codeptr, entrypoint

View File

@ -39,7 +39,7 @@ end
// //
// JIT compiler constants // JIT compiler constants
// //
const jitcount = $10 const jitcount = $01//$10
const jitcomp = $03E2 const jitcomp = $03E2
const jitcodeptr = $03E4 const jitcodeptr = $03E4
const jitcode = $BF00 const jitcode = $BF00