oberon07 compiler: bug fix

git-svn-id: svn://kolibrios.org@7667 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2019-06-04 07:22:50 +00:00
parent b6b8407c4f
commit 920044111f
6 changed files with 77 additions and 21 deletions

View File

@ -666,6 +666,7 @@ VAR
reg: INTEGER; reg: INTEGER;
max: INTEGER; max: INTEGER;
loop: INTEGER; loop: INTEGER;
param2: INTEGER;
BEGIN BEGIN
loop := 1; loop := 1;
@ -730,9 +731,36 @@ BEGIN
|CODE.opCALL, CODE.opCALLP, CODE.opCALLI, |CODE.opCALL, CODE.opCALLP, CODE.opCALLI,
CODE.opWIN64CALL, CODE.opWIN64CALLP, CODE.opWIN64CALLI, CODE.opWIN64CALL, CODE.opWIN64CALLP, CODE.opWIN64CALLI,
CODE.opSYSVCALL, CODE.opSYSVCALLP, CODE.opSYSVCALLI: CODE.opSYSVCALL, CODE.opSYSVCALLP, CODE.opSYSVCALLI,
CODE.opSAVES, CODE.opRSET, CODE.opRSETR,
CODE.opRSETL, CODE.opRSET1,
CODE.opEQS .. CODE.opGES,
CODE.opEQS2 .. CODE.opGES2,
CODE.opEQSW .. CODE.opGESW,
CODE.opEQSW2 .. CODE.opGESW2,
CODE.opCOPY, CODE.opMOVE, CODE.opCOPYA,
CODE.opCOPYS, CODE.opCOPYS2, CODE.opROT,
CODE.opNEW, CODE.opDISP, CODE.opISREC,
CODE.opIS, CODE.opTYPEGR, CODE.opTYPEGP,
CODE.opCASET, CODE.opDIV,
CODE.opDIVL, CODE.opMOD,
CODE.opMODL, CODE.opLENGTH, CODE.opLENGTHW:
leaf := FALSE leaf := FALSE
|CODE.opDIVR, CODE.opMODR:
param2 := cur.param2;
IF param2 >= 1 THEN
param2 := X86.log2(param2)
ELSIF param2 <= -1 THEN
param2 := X86.log2(-param2)
ELSE
param2 := -1
END;
IF param2 < 0 THEN
leaf := FALSE
END
ELSE ELSE
END; END;
@ -1427,6 +1455,14 @@ BEGIN
PushAll(n) PushAll(n)
END END
|CODE.opACC:
IF (R.top # 0) OR (R.stk[0] # rax) THEN
PushAll(0);
GetRegA;
pop(rax);
DEC(R.pushed)
END
|CODE.opJNZ: |CODE.opJNZ:
UnOp(reg1); UnOp(reg1);
test(reg1); test(reg1);

View File

@ -90,6 +90,8 @@ CONST
opWIN64CALL* = 238; opWIN64CALLI* = 239; opWIN64CALLP* = 240; opLOOP* = 241; opENDLOOP* = 242; opWIN64CALL* = 238; opWIN64CALLI* = 239; opWIN64CALLP* = 240; opLOOP* = 241; opENDLOOP* = 242;
opSYSVCALL* = 243; opSYSVCALLI* = 244; opSYSVCALLP* = 245; opSYSVALIGN16* = 246; opWIN64ALIGN16* = 247; opSYSVCALL* = 243; opSYSVCALLI* = 244; opSYSVCALLP* = 245; opSYSVALIGN16* = 246; opWIN64ALIGN16* = 247;
opACC* = 248;
opSADR_PARAM* = 1000; opLOAD64_PARAM* = 1001; opLLOAD64_PARAM* = 1002; opGLOAD64_PARAM* = 1003; opSADR_PARAM* = 1000; opLOAD64_PARAM* = 1001; opLLOAD64_PARAM* = 1002; opGLOAD64_PARAM* = 1003;
opVADR_PARAM* = 1004; opCONST_PARAM* = 1005; opGLOAD32_PARAM* = 1006; opLLOAD32_PARAM* = 1007; opVADR_PARAM* = 1004; opCONST_PARAM* = 1005; opGLOAD32_PARAM* = 1006; opLLOAD32_PARAM* = 1007;

View File

@ -1861,6 +1861,7 @@ VAR
IF e.obj = eCONST THEN IF e.obj = eCONST THEN
CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e.value))) CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e.value)))
END; END;
CODE.AddCmd0(CODE.opACC);
CODE.AddJmpCmd(CODE.opJZ, label); CODE.AddJmpCmd(CODE.opJZ, label);
CODE.drop CODE.drop
END END
@ -1983,7 +1984,8 @@ VAR
e.obj := eEXPR; e.obj := eEXPR;
IF e1.obj = eCONST THEN IF e1.obj = eCONST THEN
CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e1.value))) CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e1.value)))
END END;
CODE.AddCmd0(CODE.opACC)
END END
END END
@ -2056,6 +2058,7 @@ VAR
IF e.obj = eCONST THEN IF e.obj = eCONST THEN
CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e.value))) CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e.value)))
END; END;
CODE.AddCmd0(CODE.opACC);
CODE.AddJmpCmd(CODE.opJNZ, label); CODE.AddJmpCmd(CODE.opJNZ, label);
CODE.drop CODE.drop
END END
@ -2122,7 +2125,8 @@ VAR
e.obj := eEXPR; e.obj := eEXPR;
IF e1.obj = eCONST THEN IF e1.obj = eCONST THEN
CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e1.value))) CODE.AddCmd(CODE.opCONST, ORD(ARITH.getBool(e1.value)))
END END;
CODE.AddCmd0(CODE.opACC)
END END
END END

View File

@ -1,7 +1,7 @@
(* (*
BSD 2-Clause License BSD 2-Clause License
Copyright (c) 2018, Anton Krotov Copyright (c) 2018, 2019, Anton Krotov
All rights reserved. All rights reserved.
*) *)
@ -255,19 +255,19 @@ BEGIN
|0C1X..0DFX: |0C1X..0DFX:
u := LSL(ORD(c) - 0C0H, 6); u := LSL(ORD(c) - 0C0H, 6);
IF i + 1 < srclen THEN IF i + 1 < srclen THEN
u := u + ROR(LSL(ORD(src[i + 1]), 26), 26); INC(i);
INC(i) INC(u, ORD(BITS(ORD(src[i])) * {0..5}))
END END
|0E1X..0EFX: |0E1X..0EFX:
u := LSL(ORD(c) - 0E0H, 12); u := LSL(ORD(c) - 0E0H, 12);
IF i + 1 < srclen THEN IF i + 1 < srclen THEN
u := u + ROR(LSL(ORD(src[i + 1]), 26), 20); INC(i);
INC(i) INC(u, ORD(BITS(ORD(src[i])) * {0..5}) * 64)
END; END;
IF i + 1 < srclen THEN IF i + 1 < srclen THEN
u := u + ROR(LSL(ORD(src[i + 1]), 26), 26); INC(i);
INC(i) INC(u, ORD(BITS(ORD(src[i])) * {0..5}))
END END
(* (*
|0F1X..0F7X: |0F1X..0F7X:

View File

@ -308,6 +308,12 @@ BEGIN
END setcc; END setcc;
PROCEDURE xor (reg1, reg2: INTEGER);
BEGIN
OutByte2(31H, 0C0H + reg2 * 8 + reg1) // xor reg1, reg2
END xor;
PROCEDURE drop; PROCEDURE drop;
BEGIN BEGIN
REG.Drop(R) REG.Drop(R)
@ -937,7 +943,7 @@ BEGIN
ELSIF a = -1 THEN ELSIF a = -1 THEN
neg(reg1) neg(reg1)
ELSIF a = 0 THEN ELSIF a = 0 THEN
OutByte2(31H, 0C0H + reg1 * 9) // xor reg1, reg1 xor(reg1, reg1)
ELSE ELSE
IF n > 0 THEN IF n > 0 THEN
IF a < 0 THEN IF a < 0 THEN
@ -1080,7 +1086,7 @@ BEGIN
reg1 := REG.GetAnyReg(R); reg1 := REG.GetAnyReg(R);
setcc(cc + 16, reg1); setcc(cc + 16, reg1);
andrc(reg1, 1) andrc(reg1, 1)
END; END
|CODE.opGT, CODE.opGE, CODE.opLT, |CODE.opGT, CODE.opGE, CODE.opLT,
CODE.opLE, CODE.opEQ, CODE.opNE: CODE.opLE, CODE.opEQ, CODE.opNE:
@ -1129,6 +1135,14 @@ BEGIN
END; END;
andrc(reg1, 1) andrc(reg1, 1)
|CODE.opACC:
IF (R.top # 0) OR (R.stk[0] # eax) THEN
PushAll(0);
GetRegA;
pop(eax);
DEC(R.pushed)
END
|CODE.opDROP: |CODE.opDROP:
UnOp(reg1); UnOp(reg1);
drop drop
@ -1344,7 +1358,7 @@ BEGIN
|CODE.opDIVS: |CODE.opDIVS:
BinOp(reg1, reg2); BinOp(reg1, reg2);
OutByte2(31H, 0C0H + reg2 * 8 + reg1); // xor reg1, reg2 xor(reg1, reg2);
drop drop
|CODE.opDIVSC: |CODE.opDIVSC:
@ -1478,7 +1492,7 @@ BEGIN
BinOp(reg1, reg2); BinOp(reg1, reg2);
cmprc(reg1, 32); cmprc(reg1, 32);
OutByte2(72H, 4); // jb L OutByte2(72H, 4); // jb L
OutByte2(31H, 0C0H + reg1 * 9); // xor reg1, reg1 xor(reg1, reg1);
jmp(label); jmp(label);
//L: //L:
OutByte3(0FH, 0A3H, 0C0H + reg2 + 8 * reg1); // bt reg2, reg1 OutByte3(0FH, 0A3H, 0C0H + reg2 + 8 * reg1); // bt reg2, reg1
@ -1493,7 +1507,7 @@ BEGIN
reg2 := REG.GetAnyReg(R); reg2 := REG.GetAnyReg(R);
cmprc(reg1, 32); cmprc(reg1, 32);
OutByte2(72H, 4); // jb L OutByte2(72H, 4); // jb L
OutByte2(31H, 0C0H + reg1 * 9); // xor reg1, reg1 xor(reg1, reg1);
jmp(label); jmp(label);
//L: //L:
movrc(reg2, param2); movrc(reg2, param2);
@ -1631,7 +1645,7 @@ BEGIN
IF ABS(a) = 1 THEN IF ABS(a) = 1 THEN
UnOp(reg1); UnOp(reg1);
OutByte2(31H, 0C0H + reg1 * 9) // xor reg1, reg1 xor(reg1, reg1)
ELSE ELSE
IF n > 0 THEN IF n > 0 THEN
UnOp(reg1); UnOp(reg1);