mirror of
https://github.com/dschmenk/PLASMA.git
synced 2024-10-18 22:24:28 +00:00
Make sure sequnce opcode is invalidated for gen_ctag
This commit is contained in:
parent
023030831c
commit
20790d2dbb
@ -1129,13 +1129,6 @@ int crunch_seq(t_opseq **seq, int pass)
|
|||||||
freeops = 1;
|
freeops = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (opnext->code == BINARY_CODE(SHL_TOKEN))
|
|
||||||
{
|
|
||||||
op->code = DUP_CODE;
|
|
||||||
opnext->code = BINARY_CODE(ADD_TOKEN);
|
|
||||||
crunched = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (opnext->code)
|
switch (opnext->code)
|
||||||
{
|
{
|
||||||
@ -1193,6 +1186,14 @@ int crunch_seq(t_opseq **seq, int pass)
|
|||||||
freeops = 1;
|
freeops = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case BROR_CODE:
|
||||||
|
if (!op->val)
|
||||||
|
freeops = -2; // Remove zero constant
|
||||||
|
break;
|
||||||
|
case BRAND_CODE:
|
||||||
|
if (op->val)
|
||||||
|
freeops = -2; // Remove non-zero constant
|
||||||
|
break;
|
||||||
case NE_CODE:
|
case NE_CODE:
|
||||||
if (!op->val)
|
if (!op->val)
|
||||||
freeops = -2; // Remove ZERO:ISNE
|
freeops = -2; // Remove ZERO:ISNE
|
||||||
@ -1279,16 +1280,36 @@ int crunch_seq(t_opseq **seq, int pass)
|
|||||||
crunched = try_dupify(op);
|
crunched = try_dupify(op);
|
||||||
break; // CONST_CODE
|
break; // CONST_CODE
|
||||||
case BINARY_CODE(ADD_TOKEN):
|
case BINARY_CODE(ADD_TOKEN):
|
||||||
if (op->val >= 0 && op->val <= 255)
|
if (op->val == 0)
|
||||||
|
{
|
||||||
|
freeops = -2;
|
||||||
|
}
|
||||||
|
else if (op->val > 0 && op->val <= 255)
|
||||||
{
|
{
|
||||||
op->code = ADDI_CODE;
|
op->code = ADDI_CODE;
|
||||||
freeops = 1;
|
freeops = 1;
|
||||||
}
|
}
|
||||||
break;
|
else if (op->val >= -255 && op->val < 0)
|
||||||
case BINARY_CODE(SUB_TOKEN):
|
|
||||||
if (op->val >= 0 && op->val <= 255)
|
|
||||||
{
|
{
|
||||||
op->code = SUBI_CODE;
|
op->code = SUBI_CODE;
|
||||||
|
op->val = -op->val;
|
||||||
|
freeops = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BINARY_CODE(SUB_TOKEN):
|
||||||
|
if (op->val == 0)
|
||||||
|
{
|
||||||
|
freeops = -2;
|
||||||
|
}
|
||||||
|
else if (op->val > 0 && op->val <= 255)
|
||||||
|
{
|
||||||
|
op->code = SUBI_CODE;
|
||||||
|
freeops = 1;
|
||||||
|
}
|
||||||
|
else if (op->val >= -255 && op->val < 0)
|
||||||
|
{
|
||||||
|
op->code = ADDI_CODE;
|
||||||
|
op->val = -op->val;
|
||||||
freeops = 1;
|
freeops = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1300,7 +1321,11 @@ int crunch_seq(t_opseq **seq, int pass)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BINARY_CODE(OR_TOKEN):
|
case BINARY_CODE(OR_TOKEN):
|
||||||
if (op->val >= 0 && op->val <= 255)
|
if (op->val == 0)
|
||||||
|
{
|
||||||
|
freeops = -2;
|
||||||
|
}
|
||||||
|
else if (op->val > 0 && op->val <= 255)
|
||||||
{
|
{
|
||||||
op->code = ORI_CODE;
|
op->code = ORI_CODE;
|
||||||
freeops = 1;
|
freeops = 1;
|
||||||
|
@ -313,7 +313,7 @@ def emit_pending_seq#0
|
|||||||
^codeptr = $20
|
^codeptr = $20
|
||||||
codeptr++
|
codeptr++
|
||||||
elsif op=>opval & $FFF0 == $0000 // Constant NYBBLE
|
elsif op=>opval & $FFF0 == $0000 // Constant NYBBLE
|
||||||
^codeptr = op->opval*2)
|
^codeptr = op->opval*2
|
||||||
codeptr++
|
codeptr++
|
||||||
elsif op=>opval & $FF00 == $0000 // Constant BYTE
|
elsif op=>opval & $FF00 == $0000 // Constant BYTE
|
||||||
*codeptr = $2A | (op->opval << 8)
|
*codeptr = $2A | (op->opval << 8)
|
||||||
@ -327,7 +327,7 @@ def emit_pending_seq#0
|
|||||||
codeptr = codeptr + 3
|
codeptr = codeptr + 3
|
||||||
fin
|
fin
|
||||||
else
|
else
|
||||||
*codeptr = op->opcode | (op->opval << 8)
|
*codeptr = op->opcode | (op->opval << 8) // IMMEDIATE BYTE OP
|
||||||
codeptr = codeptr + 2
|
codeptr = codeptr + 2
|
||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
@ -720,6 +720,7 @@ def gen_ctag(seq, tag)
|
|||||||
op=>opnext = new_op
|
op=>opnext = new_op
|
||||||
op = op=>opnext
|
op = op=>opnext
|
||||||
fin
|
fin
|
||||||
|
op->opcode = INVALID_CODE
|
||||||
op->opgroup = CODETAG_GROUP
|
op->opgroup = CODETAG_GROUP
|
||||||
op=>optag = tag
|
op=>optag = tag
|
||||||
return seq
|
return seq
|
||||||
@ -805,10 +806,6 @@ def gen_bop(seq, tkn)
|
|||||||
code = $44; break
|
code = $44; break
|
||||||
is LE_TKN
|
is LE_TKN
|
||||||
code = $4A; break
|
code = $4A; break
|
||||||
//is LOGIC_OR_TKN
|
|
||||||
// code = $22; break
|
|
||||||
//is LOGIC_AND_TKN
|
|
||||||
// code = $24; break
|
|
||||||
otherwise
|
otherwise
|
||||||
exit_err(ERR_INVAL|ERR_SYNTAX)
|
exit_err(ERR_INVAL|ERR_SYNTAX)
|
||||||
wend
|
wend
|
||||||
|
@ -79,13 +79,6 @@ def crunch_seq(seq, pass)
|
|||||||
freeops = 1
|
freeops = 1
|
||||||
break
|
break
|
||||||
fin
|
fin
|
||||||
if nextop->opcode == SHL_CODE
|
|
||||||
op->opcode = DUP_CODE
|
|
||||||
op->opgroup = STACK_GROUP
|
|
||||||
nextop->opcode = ADD_CODE
|
|
||||||
crunched = 1
|
|
||||||
break
|
|
||||||
fin
|
|
||||||
fin
|
fin
|
||||||
when nextop->opcode
|
when nextop->opcode
|
||||||
is NEG_CODE
|
is NEG_CODE
|
||||||
@ -120,6 +113,16 @@ def crunch_seq(seq, pass)
|
|||||||
freeops = 1
|
freeops = 1
|
||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
|
is BROR_CODE
|
||||||
|
if not op=>opval
|
||||||
|
freeops = -2 // Remove zero constant
|
||||||
|
fin
|
||||||
|
break
|
||||||
|
is BRAND_CODE
|
||||||
|
if op=>opval
|
||||||
|
freeops = -2 // Remove non-zero constant
|
||||||
|
fin
|
||||||
|
break
|
||||||
is NE_CODE
|
is NE_CODE
|
||||||
if not op=>opval
|
if not op=>opval
|
||||||
freeops = -2 // Remove ZERO:ISNE
|
freeops = -2 // Remove ZERO:ISNE
|
||||||
@ -133,7 +136,7 @@ def crunch_seq(seq, pass)
|
|||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
is CONST_CODE // Collapse constant operation
|
is CONST_CODE // Collapse constant operation
|
||||||
nextopnext = nextop->nextop
|
nextopnext = nextop=>opnext
|
||||||
if nextopnext
|
if nextopnext
|
||||||
when nextopnext->opcode
|
when nextopnext->opcode
|
||||||
is MUL_CODE
|
is MUL_CODE
|
||||||
@ -200,14 +203,6 @@ def crunch_seq(seq, pass)
|
|||||||
op=>opval = op=>opval <= nextop=>opval
|
op=>opval = op=>opval <= nextop=>opval
|
||||||
freeops = 2
|
freeops = 2
|
||||||
break
|
break
|
||||||
// is LOGIC_OR_CODE
|
|
||||||
// op=>opval = op=>opval or nextop=>opval
|
|
||||||
// freeops = 2
|
|
||||||
// break
|
|
||||||
// is LOGIC_AND_CODE
|
|
||||||
// op=>opval = op=>opval and nextop=>opval
|
|
||||||
// freeops = 2
|
|
||||||
// break
|
|
||||||
wend // End of collapse constant operation
|
wend // End of collapse constant operation
|
||||||
fin
|
fin
|
||||||
if pass and not freeops and op=>opval
|
if pass and not freeops and op=>opval
|
||||||
@ -215,15 +210,27 @@ def crunch_seq(seq, pass)
|
|||||||
fin
|
fin
|
||||||
break // CONST_CODE
|
break // CONST_CODE
|
||||||
is ADD_CODE
|
is ADD_CODE
|
||||||
if op=>opval >= 0 and op=>opval <= 255
|
if op=>opval == 0
|
||||||
|
freeops = -2
|
||||||
|
elsif op=>opval > 0 and op=>opval <= 255
|
||||||
op->opcode = ADDI_CODE
|
op->opcode = ADDI_CODE
|
||||||
freeops = 1
|
freeops = 1
|
||||||
|
elsif op=>opval >= -255 and op=>opval < 0
|
||||||
|
op->opcode = SUBI_CODE
|
||||||
|
op=>opval = -op=>opval
|
||||||
|
freeops = 1
|
||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
is SUB_CODE
|
is SUB_CODE
|
||||||
if op=>opval >= 0 and op=>opval <= 255
|
if op=>opval == 0
|
||||||
|
freeops = -2
|
||||||
|
elsif op=>opval > 0 and op=>opval <= 255
|
||||||
op->opcode = SUBI_CODE
|
op->opcode = SUBI_CODE
|
||||||
freeops = 1
|
freeops = 1
|
||||||
|
elsif op=>opval >= -255 and op=>opval < 0
|
||||||
|
op->opcode = ADDI_CODE
|
||||||
|
op=>opval = -op=>opval
|
||||||
|
freeops = 1
|
||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
is AND_CODE
|
is AND_CODE
|
||||||
@ -233,7 +240,9 @@ def crunch_seq(seq, pass)
|
|||||||
fin
|
fin
|
||||||
break
|
break
|
||||||
is OR_CODE
|
is OR_CODE
|
||||||
if op=>opval >= 0 and op=>opval <= 255
|
if op=>opval == 0
|
||||||
|
freeops = -2
|
||||||
|
elsif op=>opval > 0 and op=>opval <= 255
|
||||||
op->opcode = ORI_CODE
|
op->opcode = ORI_CODE
|
||||||
freeops = 1
|
freeops = 1
|
||||||
fin
|
fin
|
||||||
|
@ -84,6 +84,10 @@ const BROR_CODE = $AE
|
|||||||
//
|
//
|
||||||
const CODETAG_GROUP = $06
|
const CODETAG_GROUP = $06
|
||||||
//
|
//
|
||||||
|
// Invalid code
|
||||||
|
//
|
||||||
|
const INVALID_CODE = $FF
|
||||||
|
//
|
||||||
// Code sequence op
|
// Code sequence op
|
||||||
//
|
//
|
||||||
struc t_opseq
|
struc t_opseq
|
||||||
|
Loading…
Reference in New Issue
Block a user