mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-02 04:31:25 +00:00
Pass constant data to backend as pointers into buffer.
This avoids needing to generate many intermediate code records representing the data at most 8 bytes at a time, which should reduce memory use and probably improve performance for large initialized arrays or structs.
This commit is contained in:
parent
28e119afb1
commit
d56cf7e666
40
CGI.pas
40
CGI.pas
@ -279,7 +279,11 @@ type
|
|||||||
cgDouble,
|
cgDouble,
|
||||||
cgComp,
|
cgComp,
|
||||||
cgExtended : (rval: extended);
|
cgExtended : (rval: extended);
|
||||||
cgString : (str: longStringPtr);
|
cgString : (
|
||||||
|
case isByteSeq: boolean of
|
||||||
|
false : (str: longStringPtr);
|
||||||
|
true : (data: ptr; len: longint);
|
||||||
|
);
|
||||||
cgVoid,
|
cgVoid,
|
||||||
ccPointer : (pval: longint; pstr: longStringPtr);
|
ccPointer : (pval: longint; pstr: longStringPtr);
|
||||||
end;
|
end;
|
||||||
@ -574,6 +578,16 @@ procedure GenS (fop: pcodes; str: longstringPtr);
|
|||||||
{ str - pointer to string }
|
{ str - pointer to string }
|
||||||
|
|
||||||
|
|
||||||
|
procedure GenBS (fop: pcodes; data: ptr; len: longint);
|
||||||
|
|
||||||
|
{ generate an instruction that uses a byte sequence operand }
|
||||||
|
{ }
|
||||||
|
{ parameters: }
|
||||||
|
{ fop - operation code }
|
||||||
|
{ data - pointer to data }
|
||||||
|
{ data - length of data }
|
||||||
|
|
||||||
|
|
||||||
procedure GenL1 (fop: pcodes; lval: longint; fp1: integer);
|
procedure GenL1 (fop: pcodes; lval: longint; fp1: integer);
|
||||||
|
|
||||||
{ generate an instruction that uses a longint and an int }
|
{ generate an instruction that uses a longint and an int }
|
||||||
@ -1230,6 +1244,30 @@ if codeGeneration then begin
|
|||||||
end; {GenS}
|
end; {GenS}
|
||||||
|
|
||||||
|
|
||||||
|
procedure GenBS {fop: pcodes; data: ptr; len: longint};
|
||||||
|
|
||||||
|
{ generate an instruction that uses a byte sequence operand }
|
||||||
|
{ }
|
||||||
|
{ parameters: }
|
||||||
|
{ fop - operation code }
|
||||||
|
{ data - pointer to data }
|
||||||
|
{ len - length of data }
|
||||||
|
|
||||||
|
var
|
||||||
|
lcode: icptr; {local copy of code}
|
||||||
|
|
||||||
|
begin {GenBS}
|
||||||
|
if codeGeneration then begin
|
||||||
|
lcode := code;
|
||||||
|
lcode^.optype := cgString;
|
||||||
|
lcode^.isByteSeq := true;
|
||||||
|
lcode^.data := data;
|
||||||
|
lcode^.len := len;
|
||||||
|
Gen0(fop);
|
||||||
|
end; {if}
|
||||||
|
end; {GenBS}
|
||||||
|
|
||||||
|
|
||||||
procedure GenL1 {fop: pcodes; lval: longint; fp1: integer};
|
procedure GenL1 {fop: pcodes; lval: longint; fp1: integer};
|
||||||
|
|
||||||
{ generate an instruction that uses a longint and an int }
|
{ generate an instruction that uses a longint and an int }
|
||||||
|
1
DAG.pas
1
DAG.pas
@ -202,6 +202,7 @@ else if (op1 <> nil) and (op2 <> nil) then
|
|||||||
or fastMath then
|
or fastMath then
|
||||||
CodesMatch := true;
|
CodesMatch := true;
|
||||||
cgString:
|
cgString:
|
||||||
|
if not (op1^.isByteSeq or op1^.isByteSeq) then
|
||||||
CodesMatch := LongStrCmp(op1^.str, op2^.str);
|
CodesMatch := LongStrCmp(op1^.str, op2^.str);
|
||||||
cgVoid, ccPointer:
|
cgVoid, ccPointer:
|
||||||
if op1^.pval = op2^.pval then
|
if op1^.pval = op2^.pval then
|
||||||
|
12
Native.pas
12
Native.pas
@ -361,6 +361,7 @@ type
|
|||||||
rkind = (k1,k2,k3,k4); {cnv record types}
|
rkind = (k1,k2,k3,k4); {cnv record types}
|
||||||
|
|
||||||
var
|
var
|
||||||
|
bp: ^byte; {byte pointer}
|
||||||
ch: char; {temp storage for string constants}
|
ch: char; {temp storage for string constants}
|
||||||
cns: realRec; {for converting reals to bytes}
|
cns: realRec; {for converting reals to bytes}
|
||||||
cnv: record {for converting double, real to bytes}
|
cnv: record {for converting double, real to bytes}
|
||||||
@ -672,9 +673,20 @@ case mode of
|
|||||||
CnOut(cns.inSANE[j]);
|
CnOut(cns.inSANE[j]);
|
||||||
end;
|
end;
|
||||||
cgString : begin
|
cgString : begin
|
||||||
|
if not icptr(name)^.isByteSeq then begin
|
||||||
sptr := icptr(name)^.str;
|
sptr := icptr(name)^.str;
|
||||||
for j := 1 to sptr^.length do
|
for j := 1 to sptr^.length do
|
||||||
CnOut(ord(sPtr^.str[j]));
|
CnOut(ord(sPtr^.str[j]));
|
||||||
|
end {if}
|
||||||
|
else begin
|
||||||
|
lval := 0;
|
||||||
|
while lval < icptr(name)^.len do begin
|
||||||
|
bp := pointer(
|
||||||
|
ord4(icptr(name)^.data) + lval);
|
||||||
|
CnOut(bp^);
|
||||||
|
lval := lval + 1;
|
||||||
|
end;
|
||||||
|
end; {else}
|
||||||
end;
|
end;
|
||||||
ccPointer : begin
|
ccPointer : begin
|
||||||
if icptr(name)^.lab <> nil then begin
|
if icptr(name)^.lab <> nil then begin
|
||||||
|
26
Symbol.pas
26
Symbol.pas
@ -801,7 +801,7 @@ procedure DoGlobals;
|
|||||||
begin {StaticInit}
|
begin {StaticInit}
|
||||||
{allocate buffer}
|
{allocate buffer}
|
||||||
{(+3 for possible bitfield overhang)}
|
{(+3 for possible bitfield overhang)}
|
||||||
buffHandle := NewHandle(variable^.itype^.size+3, UserID, $8000, nil);
|
buffHandle := NewHandle(variable^.itype^.size+3, globalID, $8000, nil);
|
||||||
if ToolError <> 0 then TermError(5);
|
if ToolError <> 0 then TermError(5);
|
||||||
buffPtr := buffHandle^;
|
buffPtr := buffHandle^;
|
||||||
|
|
||||||
@ -892,25 +892,9 @@ procedure DoGlobals;
|
|||||||
endDisp := variable^.itype^.size
|
endDisp := variable^.itype^.size
|
||||||
else
|
else
|
||||||
endDisp := relocs^.disp;
|
endDisp := relocs^.disp;
|
||||||
while endDisp - disp >= 8 do begin
|
if disp <> endDisp then begin
|
||||||
qp := pointer(ord4(buffPtr) + disp);
|
GenBS(dc_cns, pointer(ord4(buffPtr) + disp), endDisp - disp);
|
||||||
GenQ1(dc_cns, qp^, 1);
|
disp := endDisp;
|
||||||
disp := disp + 8;
|
|
||||||
end; {while}
|
|
||||||
if endDisp - disp >= 4 then begin
|
|
||||||
lp := pointer(ord4(buffPtr) + disp);
|
|
||||||
GenL1(dc_cns, lp^, 1);
|
|
||||||
disp := disp + 4;
|
|
||||||
end; {if}
|
|
||||||
if endDisp - disp >= 2 then begin
|
|
||||||
wp := pointer(ord4(buffPtr) + disp);
|
|
||||||
Gen2t(dc_cns, wp^, 1, cgUWord);
|
|
||||||
disp := disp + 2;
|
|
||||||
end; {if}
|
|
||||||
if endDisp - disp >= 1 then begin
|
|
||||||
bp := pointer(ord4(buffPtr) + disp);
|
|
||||||
Gen2t(dc_cns, bp^, 1, cgUByte);
|
|
||||||
disp := disp + 1;
|
|
||||||
end; {if}
|
end; {if}
|
||||||
if relocs <> nil then begin
|
if relocs <> nil then begin
|
||||||
code^.optype := ccPointer;
|
code^.optype := ccPointer;
|
||||||
@ -930,8 +914,6 @@ procedure DoGlobals;
|
|||||||
disp := disp + cgPointerSize;
|
disp := disp + cgPointerSize;
|
||||||
end; {if}
|
end; {if}
|
||||||
end; {while}
|
end; {while}
|
||||||
|
|
||||||
DisposeHandle(buffHandle);
|
|
||||||
end; {StaticInit}
|
end; {StaticInit}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user