1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-07-03 05:29:30 +00:00

Constant op codes

This commit is contained in:
Dave Schmenk 2018-03-03 18:55:39 -08:00
parent 40c3dcd197
commit 793b1760a0
8 changed files with 163 additions and 50 deletions

View File

@ -614,6 +614,21 @@ void emit_conststr(long conststr)
printf("\t%s\t$2E\t\t\t; CS\n", DB);
emit_data(0, STRING_TYPE, conststr, 0);
}
void emit_addi(int cval)
{
emit_pending_seq();
printf("\t%s\t$34,$%02X\t\t\t; ADDI\t%d\n", DB, cval, cval);
}
void emit_andi(int cval)
{
emit_pending_seq();
printf("\t%s\t$3C,$%02X\t\t\t; ANDI\t%d\n", DB, cval, cval);
}
void emit_ori(int cval)
{
emit_pending_seq();
printf("\t%s\t$52,$%02X\t\t\t; IORI\t%d\n", DB, cval, cval);
}
void emit_lb(void)
{
printf("\t%s\t$60\t\t\t; LB\n", DB);
@ -793,28 +808,28 @@ void emit_brlt(int tag)
printf("\t%s\t$3A\t\t\t; BRLT\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_nxtup(int tag)
void emit_brle(int tag)
{
emit_pending_seq();
printf("\t%s\t$32\t\t\t; NXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t$80\t\t\t; NXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_inxtup(int tag)
void emit_incbrle(int tag)
{
emit_pending_seq();
printf("\t%s\t$34\t\t\t; INXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t$82\t\t\t; INXTUP\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_nxtdn(int tag)
void emit_brge(int tag)
{
emit_pending_seq();
printf("\t%s\t$3C\t\t\t; NXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t$84\t\t\t; NXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_dnxtdn(int tag)
void emit_decbrge(int tag)
{
emit_pending_seq();
printf("\t%s\t$52\t\t\t; DNXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t$84\t\t\t; DNXTDN\t_B%03d\n", DB, tag);
printf("\t%s\t_B%03d-*\n", DW, tag);
}
void emit_call(int tag, int type)
@ -865,6 +880,11 @@ void emit_drop(void)
emit_pending_seq();
printf("\t%s\t$30\t\t\t; DROP\n", DB);
}
void emit_dup(void)
{
emit_pending_seq();
printf("\t%s\t$32\t\t\t; DUP\n", DB);
}
int emit_unaryop(t_token op)
{
emit_pending_seq();
@ -1240,6 +1260,27 @@ int crunch_seq(t_opseq **seq, int pass)
if ((pass > 0) && (freeops == 0) && (op->val != 0))
crunched = try_dupify(op);
break; // CONST_CODE
case BINARY_CODE(ADD_TOKEN):
if (op->val >= 0 && op->val <= 255)
{
op->code = ADDI_CODE;
freeops = 1;
}
break;
case BINARY_CODE(AND_TOKEN):
if (op->val >= 0 && op->val <= 255)
{
op->code = ANDI_CODE;
freeops = 1;
}
break;
case BINARY_CODE(OR_TOKEN):
if (op->val >= 0 && op->val <= 255)
{
op->code = ORI_CODE;
freeops = 1;
}
break;
case BINARY_CODE(MUL_TOKEN):
for (shiftcnt = 0; shiftcnt < 16; shiftcnt++)
{
@ -1607,6 +1648,15 @@ int emit_pending_seq()
case STR_CODE:
emit_conststr(op->val);
break;
case ADDI_CODE:
emit_addi(op->val);
break;
case ANDI_CODE:
emit_andi(op->val);
break;
case ORI_CODE:
emit_ori(op->val);
break;
case LB_CODE:
emit_lb();
break;
@ -1676,6 +1726,9 @@ int emit_pending_seq()
case DROP_CODE:
emit_drop();
break;
case DUP_CODE:
emit_dup();
break;
case BRNCH_CODE:
emit_brnch(op->tag);
break;

View File

@ -59,11 +59,14 @@ typedef struct _opseq {
#define INDEXW_CODE 0x0317
#define DROP_CODE 0x0318
#define DUP_CODE 0x0319
#define BRNCH_CODE 0x031C
#define BRFALSE_CODE 0x031D
#define BRTRUE_CODE 0x031E
#define CODETAG_CODE 0x031F
#define NOP_CODE 0x0320
#define ADDI_CODE 0x031A
#define ANDI_CODE 0x031B
#define ORI_CODE 0x31C
#define BRNCH_CODE 0x031D
#define BRFALSE_CODE 0x031E
#define BRTRUE_CODE 0x031F
#define CODETAG_CODE 0x0320
#define NOP_CODE 0x0321
#define gen_uop(seq,op) gen_seq(seq,UNARY_CODE(op),0,0,0,0)
#define gen_op(seq,op) gen_seq(seq,BINARY_CODE(op),0,0,0,0)
@ -102,6 +105,9 @@ int emit_data(int vartype, int consttype, long constval, int constsize);
void emit_codetag(int tag);
void emit_const(int cval);
void emit_conststr(long conststr);
void emit_addi(int cval);
void emit_andi(int cval);
void emit_ori(int cval);
void emit_lb(void);
void emit_lw(void);
void emit_llb(int index);
@ -128,16 +134,17 @@ int emit_unaryop(t_token op);
int emit_op(t_token op);
void emit_brtru(int tag);
void emit_brfls(int tag);
void emit_brgt(int tag);
void emit_brlt(int tag);
void emit_brne(int tag);
void emit_brnch(int tag);
void emit_nxtup(int tag);
void emit_inxtup(int tag);
void emit_nxtdn(int tag);
void emit_dnxtdn(int tag);
void emit_brgt(int tag);
void emit_brlt(int tag);
void emit_brle(int tag);
void emit_incbrle(int tag);
void emit_brge(int tag);
void emit_decbrge(int tag);
void emit_empty(void);
void emit_drop(void);
void emit_dup(void);
void emit_leave(void);
void emit_ret(void);
void emit_enter(int cparams);

View File

@ -191,24 +191,24 @@ def emit_brlt(tag)#0
emit_byte($3A)
emit_reladdr(tag)
end
def emit_nxtup(tag)#0
def emit_brle(tag)#0
emit_pending_seq
emit_byte($32)
emit_byte($80)
emit_reladdr(tag)
end
def emit_inxtup(tag)#0
def emit_incbrle(tag)#0
emit_pending_seq
emit_byte($34)
emit_byte($82)
emit_reladdr(tag)
end
def emit_nxtdn(tag)#0
def emit_brge(tag)#0
emit_pending_seq
emit_byte($3C)
emit_byte($84)
emit_reladdr(tag)
end
def emit_dnxtdn(tag)#0
def emit_decbrge(tag)#0
emit_pending_seq
emit_byte($52)
emit_byte($86)
emit_reladdr(tag)
end
def emit_leave#0
@ -300,6 +300,9 @@ def emit_pending_seq#0
codeptr=>1 = op=>opval
codeptr = codeptr + 3
fin
else
*codeptr = op->opcode | (op->opval << 8)
codeptr = codeptr + 2
fin
break
//

View File

@ -214,6 +214,24 @@ def crunch_seq(seq, pass)
crunched = try_dupify(op)
fin
break // CONST_CODE
is ADD_CODE
if op=>opval >= 0 and op=>opval <= 255
op->opcode = ADDI_CODE
freeops = 1
fin
break
is AND_CODE
if op=>opval >= 0 and op=>opval <= 255
op->opcode = ANDI_CODE
freeops = 1
fin
break
is OR_CODE
if op=>opval >= 0 and op=>opval <= 255
op->opcode = ORI_CODE
freeops = 1
fin
break
is MUL_CODE
for shiftcnt = 0 to 15
if op=>opval == 1 << shiftcnt

View File

@ -3,6 +3,9 @@
//
const CONST_GROUP = $00
const CONST_CODE = $2C
const ADDI_CODE = $34
const ANDI_CODE = $3C
const ORI_CODE = $52
const CONSTR_GROUP = $01
const CONSTR_CODE = $2E
//

View File

@ -979,10 +979,10 @@ int parse_stmnt(void)
{
emit_seq(seq);
emit_op(ADD_TOKEN);
emit_nxtup(tag_for);
emit_brle(tag_for);
}
else
emit_inxtup(tag_for);
emit_incbrle(tag_for);
}
else
{
@ -990,10 +990,10 @@ int parse_stmnt(void)
{
emit_seq(seq);
emit_op(SUB_TOKEN);
emit_nxtdn(tag_for);
emit_brge(tag_for);
}
else
emit_dnxtdn(tag_for);
emit_decbrge(tag_for);
}
emit_codetag(break_tag);
break_tag = tag_prevbrk;

View File

@ -762,17 +762,17 @@ def parse_stmnt
if seq
emit_seq(seq)
emit_code(ADD_CODE)
emit_nxtup(tag_for)
emit_brle(tag_for)
else
emit_inxtup(tag_for)
emit_incbrle(tag_for)
fin
else
if seq
emit_seq(seq)
emit_code(SUB_CODE)
emit_nxtdn(tag_for)
emit_brge(tag_for)
else
emit_dnxtdn(tag_for)
emit_decbrge(tag_for)
fin
fin

View File

@ -198,11 +198,12 @@ VMCORE = *
OPTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
!WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,NXTUP,INXTUP,DIVMOD,BRGT,BRLT,NXTDN,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,ADDI,DIVMOD,BRGT,BRLT,ANDI,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
!WORD BRNCH,DNXTDN,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD BRNCH,ORI,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD BRLE,INCBRLE,BRGE,DECBRGE ; 80 82 84 86 88 8A 8C 8E
;*
;* ENTER INTO BYTECODE INTERPRETER
;*
@ -407,11 +408,12 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY
OPXTBL !WORD ZERO,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 00 02 04 06 08 0A 0C 0E
!WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 10 12 14 16 18 1A 1C 1E
!WORD LNOT,LOR,LAND,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E
!WORD DROP,NXTUP,INXTUP,DIVMOD,BRGT,BRLT,NXTDN,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD DROP,DUP,ADDI,DIVMOD,BRGT,BRLT,ANDI,BRNE ; 30 32 34 36 38 3A 3C 3E
!WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E
!WORD BRNCH,DNXTDN,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD BRNCH,ORI,CALLX,ICALX,ENTER,LEAVEX,RETX,CFFB ; 50 52 54 56 58 5A 5C 5E
!WORD LBX,LWX,LLBX,LLWX,LABX,LAWX,DLB,DLW ; 60 62 64 66 68 6A 6C 6E
!WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E
!WORD BRLE,INCBRLE,BRGE,DECBRGE ; 80 82 84 86 88 8A 8C 8E
;*
;* ADD TOS TO TOS-1
;*
@ -710,12 +712,12 @@ LOR LDA ESTKL,X
;*
;* DUPLICATE TOS
;*
;DUP DEX
; LDA ESTKL+1,X
; STA ESTKL,X
; LDA ESTKH+1,X
; STA ESTKH,X
; JMP NEXTOP
DUP DEX
LDA ESTKL+1,X
STA ESTKL,X
LDA ESTKH+1,X
STA ESTKH,X
JMP NEXTOP
;*
;* LOGICAL NOT
;*
@ -752,6 +754,33 @@ CB DEX
STA ESTKL,X
JMP NEXTOP
;*
;* ADD IMMEDIATE TO TOS
;*
ADDI INY ;+INC_IP
LDA (IP),Y
CLC
ADC ESTKL,X
STA ESTKL,X
BCC +
INC ESTKH,X
+ JMP NEXTOP
;*
;* AND IMMEDIATE TO TOS
;*
ANDI INY ;+INC_IP
LDA (IP),Y
AND ESTKL,X
STA ESTKL,X
JMP NEXTOP
;*
;* IOR IMMEDIATE TO TOS
;*
ORI INY ;+INC_IP
LDA (IP),Y
ORA ESTKL,X
STA ESTKL,X
JMP NEXTOP
;*
;* LOAD ADDRESS & LOAD CONSTANT WORD (SAME THING, WITH OR WITHOUT FIXUP)
;*
- TYA ; RENORMALIZE IP
@ -1340,11 +1369,11 @@ BRLT LDA ESTKL,X
BNE BRNCH ; BMI BRNCH
+ BMI NOBRNCH
BPL -
DNXTDN LDA ESTKL,X
DECBRGE LDA ESTKL,X
BNE +
DEC ESTKH,X
+ DEC ESTKL,X
NXTDN LDA ESTKL,X ; BRGE
BRGE LDA ESTKL,X ; BRGE
CMP ESTKL+1,X
LDA ESTKH,X
SBC ESTKH+1,X
@ -1353,10 +1382,10 @@ NXTDN LDA ESTKL,X ; BRGE
- INX ; DROP FOR VALUES
INX
BNE NOBRNCH ; BMI NOBRNCH
INXTUP INC ESTKL,X
BNE NXTUP
INCBRLE INC ESTKL,X
BNE BRLE
INC ESTKH,X
NXTUP LDA ESTKL+1,X ; BRLE
BRLE LDA ESTKL+1,X ; BRLE
CMP ESTKL,X
LDA ESTKH+1,X
SBC ESTKH,X