mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-08 10:35:18 +00:00
Basic infrastructure for using different quadword locations in codegen.
For the moment, this does not really do anything, but it lays the groundwork for not always having to load quadword values to the stack before operating on or storing them.
This commit is contained in:
parent
58f2ebddec
commit
3c0e4baf78
59
Gen.pas
59
Gen.pas
|
@ -39,12 +39,14 @@ procedure Gen (blk: blockPtr);
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
const
|
const
|
||||||
A_X = 1; {longword locations}
|
{longword/quadword locations}
|
||||||
|
A_X = 1; {longword only}
|
||||||
onStack = 2;
|
onStack = 2;
|
||||||
inPointer = 4;
|
inPointer = 4;
|
||||||
localAddress = 8;
|
localAddress = 8;
|
||||||
globalLabel = 16;
|
globalLabel = 16;
|
||||||
constant = 32;
|
constant = 32;
|
||||||
|
nowhere = 64;
|
||||||
|
|
||||||
{stack frame locations}
|
{stack frame locations}
|
||||||
{---------------------}
|
{---------------------}
|
||||||
|
@ -60,10 +62,20 @@ type
|
||||||
disp: integer; {fixed displacement/local addr}
|
disp: integer; {fixed displacement/local addr}
|
||||||
lval: longint; {value}
|
lval: longint; {value}
|
||||||
lab: stringPtr; {global label name}
|
lab: stringPtr; {global label name}
|
||||||
|
end;
|
||||||
|
{possible locations for 8 byte values}
|
||||||
|
{note: these always have fixed disp}
|
||||||
|
quadType = record {description of current 8 byte value}
|
||||||
|
preference: integer; {where you want the value}
|
||||||
|
where: integer; {where the value is at}
|
||||||
|
disp: integer; {fixed displacement/local addr}
|
||||||
|
lval: longlong; {value}
|
||||||
|
lab: stringPtr; {global label name}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
gLong: longType; {info about last long value}
|
gLong: longType; {info about last long value}
|
||||||
|
gQuad: quadType; {info about last quad value}
|
||||||
namePushed: boolean; {has a name been pushed in this proc?}
|
namePushed: boolean; {has a name been pushed in this proc?}
|
||||||
skipLoad: boolean; {skip load for a pc_lli, etc?}
|
skipLoad: boolean; {skip load for a pc_lli, etc?}
|
||||||
stackSaveDepth: integer; {nesting depth of saved stack positions}
|
stackSaveDepth: integer; {nesting depth of saved stack positions}
|
||||||
|
@ -689,7 +701,9 @@ procedure GenAdqSbq (op: icptr);
|
||||||
{ op - pc_adq or pc_sbq operation }
|
{ op - pc_adq or pc_sbq operation }
|
||||||
|
|
||||||
begin {GenAdqSbq}
|
begin {GenAdqSbq}
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
if op^.opcode = pc_adq then begin
|
if op^.opcode = pc_adq then begin
|
||||||
GenImplied(m_clc);
|
GenImplied(m_clc);
|
||||||
|
@ -721,6 +735,7 @@ else {if op^.opcode = pc_sbq then} begin
|
||||||
GenNative(m_sbc_s, direct, 7, nil, 0);
|
GenNative(m_sbc_s, direct, 7, nil, 0);
|
||||||
GenNative(m_sta_s, direct, 7, nil, 0);
|
GenNative(m_sta_s, direct, 7, nil, 0);
|
||||||
end; {else}
|
end; {else}
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {GenAdqSbq}
|
end; {GenAdqSbq}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1162,11 +1177,15 @@ else
|
||||||
|
|
||||||
cgQuad: begin
|
cgQuad: begin
|
||||||
if op^.opcode = pc_geq then begin
|
if op^.opcode = pc_geq then begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
end {if}
|
end {if}
|
||||||
else {if op^.opcode = pc_grt then} begin
|
else {if op^.opcode = pc_grt then} begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
end; {else}
|
end; {else}
|
||||||
GenCall(88);
|
GenCall(88);
|
||||||
|
@ -1192,7 +1211,9 @@ else
|
||||||
end; {case optype of cgQuad}
|
end; {case optype of cgQuad}
|
||||||
|
|
||||||
cgUQuad: begin
|
cgUQuad: begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
if op^.opcode = pc_geq then
|
if op^.opcode = pc_geq then
|
||||||
GenNative(m_ldx_imm, immediate, 1, nil, 0)
|
GenNative(m_ldx_imm, immediate, 1, nil, 0)
|
||||||
|
@ -1355,6 +1376,7 @@ begin {GenCnv}
|
||||||
lLong := gLong;
|
lLong := gLong;
|
||||||
gLong.preference := onStack+A_X+constant;
|
gLong.preference := onStack+A_X+constant;
|
||||||
gLong.where := onStack;
|
gLong.where := onStack;
|
||||||
|
gQuad.preference := onStack;
|
||||||
if ((op^.q & $00F0) >> 4) in [cDouble,cExtended,cComp] then begin
|
if ((op^.q & $00F0) >> 4) in [cDouble,cExtended,cComp] then begin
|
||||||
op^.q := (op^.q & $000F) | (cReal * 16);
|
op^.q := (op^.q & $000F) | (cReal * 16);
|
||||||
fromReal := true;
|
fromReal := true;
|
||||||
|
@ -1364,6 +1386,7 @@ else
|
||||||
if (op^.q & $000F) in [cDouble,cExtended,cComp] then
|
if (op^.q & $000F) in [cDouble,cExtended,cComp] then
|
||||||
op^.q := (op^.q & $00F0) | cReal;
|
op^.q := (op^.q & $00F0) | cReal;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
gQuad.where := onStack; {unless overridden below}
|
||||||
if op^.q in [wordToLong,wordToUlong] then begin
|
if op^.q in [wordToLong,wordToUlong] then begin
|
||||||
lab1 := GenLabel;
|
lab1 := GenLabel;
|
||||||
GenNative(m_ldx_imm, immediate, 0, nil, 0);
|
GenNative(m_ldx_imm, immediate, 0, nil, 0);
|
||||||
|
@ -1991,7 +2014,9 @@ else
|
||||||
end; {case optype of cgReal..cgExtended}
|
end; {case optype of cgReal..cgExtended}
|
||||||
|
|
||||||
cgQuad,cgUQuad: begin
|
cgQuad,cgUQuad: begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
|
|
||||||
lab1 := GenLabel;
|
lab1 := GenLabel;
|
||||||
|
@ -2931,6 +2956,7 @@ case optype of
|
||||||
GenImplied(m_pha);
|
GenImplied(m_pha);
|
||||||
end; {else}
|
end; {else}
|
||||||
end; {else}
|
end; {else}
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {case cgQuad,cgUQuad}
|
end; {case cgQuad,cgUQuad}
|
||||||
otherwise: Error(cge1);
|
otherwise: Error(cge1);
|
||||||
end; {case}
|
end; {case}
|
||||||
|
@ -3773,6 +3799,7 @@ case optype of
|
||||||
end; {case CGLong, cgULong}
|
end; {case CGLong, cgULong}
|
||||||
|
|
||||||
cgQuad, cgUQuad: begin
|
cgQuad, cgUQuad: begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
if opcode = pc_sro then
|
if opcode = pc_sro then
|
||||||
GenImplied(m_pla)
|
GenImplied(m_pla)
|
||||||
|
@ -3806,6 +3833,8 @@ case optype of
|
||||||
GenNative(m_sta_abs, absolute, q+6, lab, 0)
|
GenNative(m_sta_abs, absolute, q+6, lab, 0)
|
||||||
else
|
else
|
||||||
GenNative(m_sta_long, longabsolute, q+6, lab, 0);
|
GenNative(m_sta_long, longabsolute, q+6, lab, 0);
|
||||||
|
if opcode = pc_cpo then
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {case cgQuad, cgUQuad}
|
end; {case cgQuad, cgUQuad}
|
||||||
end; {case}
|
end; {case}
|
||||||
end; {GenSroCpo}
|
end; {GenSroCpo}
|
||||||
|
@ -3920,6 +3949,7 @@ case optype of
|
||||||
end; {case cgReal,cgDouble,cgComp,cgExtended}
|
end; {case cgReal,cgDouble,cgComp,cgExtended}
|
||||||
|
|
||||||
cgQuad,cgUQuad: begin
|
cgQuad,cgUQuad: begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
gLong.preference := A_X;
|
gLong.preference := A_X;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
@ -3954,6 +3984,8 @@ case optype of
|
||||||
else {if op^.opcode = pc_cpi then}
|
else {if op^.opcode = pc_cpi then}
|
||||||
GenNative(m_lda_s, direct, 7, nil, 0);
|
GenNative(m_lda_s, direct, 7, nil, 0);
|
||||||
GenNative(m_sta_indly, direct, dworkLoc, nil, 0);
|
GenNative(m_sta_indly, direct, dworkLoc, nil, 0);
|
||||||
|
if op^.opcode = pc_cpi then
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {case cgQuad,cgUQuad}
|
end; {case cgQuad,cgUQuad}
|
||||||
|
|
||||||
cgLong,cgULong: begin
|
cgLong,cgULong: begin
|
||||||
|
@ -4454,6 +4486,7 @@ case optype of
|
||||||
end;
|
end;
|
||||||
|
|
||||||
cgQuad, cgUQuad: begin
|
cgQuad, cgUQuad: begin
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
if disp < 250 then begin
|
if disp < 250 then begin
|
||||||
if op^.opcode = pc_str then
|
if op^.opcode = pc_str then
|
||||||
|
@ -4500,6 +4533,8 @@ case optype of
|
||||||
GenNative(m_lda_s, direct, 7, nil, 0);
|
GenNative(m_lda_s, direct, 7, nil, 0);
|
||||||
GenNative(m_sta_dirX, direct, 6, nil, 0);
|
GenNative(m_sta_dirX, direct, 6, nil, 0);
|
||||||
end; {else}
|
end; {else}
|
||||||
|
if op^.opcode = pc_cop then
|
||||||
|
gQuad.where := onStack;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
otherwise: Error(cge1);
|
otherwise: Error(cge1);
|
||||||
|
@ -4545,6 +4580,7 @@ procedure GenUnaryQuad (op: icptr);
|
||||||
{ generate a pc_bnq or pc_ngq }
|
{ generate a pc_bnq or pc_ngq }
|
||||||
|
|
||||||
begin {GenUnaryQuad}
|
begin {GenUnaryQuad}
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
case op^.opcode of {do the operation}
|
case op^.opcode of {do the operation}
|
||||||
|
|
||||||
|
@ -4580,6 +4616,7 @@ case op^.opcode of {do the operation}
|
||||||
GenNative(m_sta_s, direct, 7, nil, 0);
|
GenNative(m_sta_s, direct, 7, nil, 0);
|
||||||
end; {case pc_ngq}
|
end; {case pc_ngq}
|
||||||
end; {case}
|
end; {case}
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {GenUnaryQuad}
|
end; {GenUnaryQuad}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4774,7 +4811,9 @@ procedure GenTree {op: icptr};
|
||||||
end; {GenOp}
|
end; {GenOp}
|
||||||
|
|
||||||
begin {GenBinQuad}
|
begin {GenBinQuad}
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.right);
|
GenTree(op^.right);
|
||||||
case op^.opcode of
|
case op^.opcode of
|
||||||
pc_bqr: GenOp(m_ora_s);
|
pc_bqr: GenOp(m_ora_s);
|
||||||
|
@ -4833,6 +4872,7 @@ procedure GenTree {op: icptr};
|
||||||
|
|
||||||
otherwise: Error(cge1);
|
otherwise: Error(cge1);
|
||||||
end; {case}
|
end; {case}
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {GenBinQuad}
|
end; {GenBinQuad}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4982,6 +5022,7 @@ procedure GenTree {op: icptr};
|
||||||
|
|
||||||
{save the returned value}
|
{save the returned value}
|
||||||
gLong.where := A_X;
|
gLong.where := A_X;
|
||||||
|
gQuad.where := onStack;
|
||||||
SaveRetValue(op^.optype);
|
SaveRetValue(op^.optype);
|
||||||
argsSize := lArgsSize;
|
argsSize := lArgsSize;
|
||||||
end; {GenCui}
|
end; {GenCui}
|
||||||
|
@ -5076,6 +5117,7 @@ procedure GenTree {op: icptr};
|
||||||
|
|
||||||
{save the returned value}
|
{save the returned value}
|
||||||
gLong.where := A_X;
|
gLong.where := A_X;
|
||||||
|
gQuad.where := onStack;
|
||||||
SaveRetValue(op^.optype);
|
SaveRetValue(op^.optype);
|
||||||
argsSize := lArgsSize;
|
argsSize := lArgsSize;
|
||||||
end; {GenCup}
|
end; {GenCup}
|
||||||
|
@ -5402,6 +5444,7 @@ procedure GenTree {op: icptr};
|
||||||
GenNative(m_pea, immediate, long(op^.qval.hi).lsw, nil, 0);
|
GenNative(m_pea, immediate, long(op^.qval.hi).lsw, nil, 0);
|
||||||
GenNative(m_pea, immediate, long(op^.qval.lo).msw, nil, 0);
|
GenNative(m_pea, immediate, long(op^.qval.lo).msw, nil, 0);
|
||||||
GenNative(m_pea, immediate, long(op^.qval.lo).lsw, nil, 0);
|
GenNative(m_pea, immediate, long(op^.qval.lo).lsw, nil, 0);
|
||||||
|
gQuad.where := onStack;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
otherwise:
|
otherwise:
|
||||||
|
@ -5500,6 +5543,7 @@ procedure GenTree {op: icptr};
|
||||||
GenNative(m_lda_long, longabsolute, op^.q, op^.lab, 0);
|
GenNative(m_lda_long, longabsolute, op^.q, op^.lab, 0);
|
||||||
GenImplied(m_pha);
|
GenImplied(m_pha);
|
||||||
end; {else}
|
end; {else}
|
||||||
|
gQuad.where := onStack;
|
||||||
end; {case cgQuad,cgUQuad}
|
end; {case cgQuad,cgUQuad}
|
||||||
|
|
||||||
otherwise:
|
otherwise:
|
||||||
|
@ -5573,6 +5617,7 @@ procedure GenTree {op: icptr};
|
||||||
GenNative(m_pei_dir, direct, disp+2, nil, 0);
|
GenNative(m_pei_dir, direct, disp+2, nil, 0);
|
||||||
GenNative(m_pei_dir, direct, disp, nil, 0);
|
GenNative(m_pei_dir, direct, disp, nil, 0);
|
||||||
end; {else}
|
end; {else}
|
||||||
|
gQuad.where := onStack;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
cgLong, cgULong: begin
|
cgLong, cgULong: begin
|
||||||
|
@ -5929,6 +5974,7 @@ procedure GenTree {op: icptr};
|
||||||
|
|
||||||
begin {GenPop}
|
begin {GenPop}
|
||||||
glong.preference := A_X; {generate the operand}
|
glong.preference := A_X; {generate the operand}
|
||||||
|
gQuad.preference := nowhere;
|
||||||
isIncLoad := op^.left^.opcode in
|
isIncLoad := op^.left^.opcode in
|
||||||
[pc_lil,pc_lli,pc_ldl,pc_lld,pc_gil,pc_gli,pc_gdl,pc_gld,
|
[pc_lil,pc_lli,pc_ldl,pc_lld,pc_gil,pc_gli,pc_gdl,pc_gld,
|
||||||
pc_iil,pc_ili,pc_idl,pc_ild];
|
pc_iil,pc_ili,pc_idl,pc_ild];
|
||||||
|
@ -5954,10 +6000,12 @@ procedure GenTree {op: icptr};
|
||||||
{else do nothing}
|
{else do nothing}
|
||||||
|
|
||||||
cgQuad, cgUQuad: begin
|
cgQuad, cgUQuad: begin
|
||||||
GenImplied(m_tsc);
|
if gQuad.where = onStack then begin
|
||||||
GenImplied(m_clc);
|
GenImplied(m_tsc);
|
||||||
GenNative(m_adc_imm, immediate, 8, nil, 0);
|
GenImplied(m_clc);
|
||||||
GenImplied(m_tcs);
|
GenNative(m_adc_imm, immediate, 8, nil, 0);
|
||||||
|
GenImplied(m_tcs);
|
||||||
|
end; {if}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
cgReal, cgDouble, cgComp, cgExtended: begin
|
cgReal, cgDouble, cgComp, cgExtended: begin
|
||||||
|
@ -6301,6 +6349,7 @@ procedure GenTree {op: icptr};
|
||||||
otherwise: Error(cge1);
|
otherwise: Error(cge1);
|
||||||
end; {case}
|
end; {case}
|
||||||
glong.preference := onStack; {generate the operand}
|
glong.preference := onStack; {generate the operand}
|
||||||
|
gQuad.preference := onStack;
|
||||||
GenTree(op^.left);
|
GenTree(op^.left);
|
||||||
if op^.optype in {do the stk}
|
if op^.optype in {do the stk}
|
||||||
[cgByte, cgUByte, cgWord, cgUWord] then
|
[cgByte, cgUByte, cgWord, cgUWord] then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user