mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-28 16:30:59 +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,
|
||||
cgComp,
|
||||
cgExtended : (rval: extended);
|
||||
cgString : (str: longStringPtr);
|
||||
cgString : (
|
||||
case isByteSeq: boolean of
|
||||
false : (str: longStringPtr);
|
||||
true : (data: ptr; len: longint);
|
||||
);
|
||||
cgVoid,
|
||||
ccPointer : (pval: longint; pstr: longStringPtr);
|
||||
end;
|
||||
@ -574,6 +578,16 @@ procedure GenS (fop: pcodes; str: longstringPtr);
|
||||
{ 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);
|
||||
|
||||
{ generate an instruction that uses a longint and an int }
|
||||
@ -1230,6 +1244,30 @@ if codeGeneration then begin
|
||||
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};
|
||||
|
||||
{ generate an instruction that uses a longint and an int }
|
||||
|
3
DAG.pas
3
DAG.pas
@ -202,7 +202,8 @@ else if (op1 <> nil) and (op2 <> nil) then
|
||||
or fastMath then
|
||||
CodesMatch := true;
|
||||
cgString:
|
||||
CodesMatch := LongStrCmp(op1^.str, op2^.str);
|
||||
if not (op1^.isByteSeq or op1^.isByteSeq) then
|
||||
CodesMatch := LongStrCmp(op1^.str, op2^.str);
|
||||
cgVoid, ccPointer:
|
||||
if op1^.pval = op2^.pval then
|
||||
CodesMatch := LongStrCmp(op1^.str, op2^.str);
|
||||
|
18
Native.pas
18
Native.pas
@ -361,6 +361,7 @@ type
|
||||
rkind = (k1,k2,k3,k4); {cnv record types}
|
||||
|
||||
var
|
||||
bp: ^byte; {byte pointer}
|
||||
ch: char; {temp storage for string constants}
|
||||
cns: realRec; {for converting reals to bytes}
|
||||
cnv: record {for converting double, real to bytes}
|
||||
@ -672,9 +673,20 @@ case mode of
|
||||
CnOut(cns.inSANE[j]);
|
||||
end;
|
||||
cgString : begin
|
||||
sptr := icptr(name)^.str;
|
||||
for j := 1 to sptr^.length do
|
||||
CnOut(ord(sPtr^.str[j]));
|
||||
if not icptr(name)^.isByteSeq then begin
|
||||
sptr := icptr(name)^.str;
|
||||
for j := 1 to sptr^.length do
|
||||
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;
|
||||
ccPointer : begin
|
||||
if icptr(name)^.lab <> nil then begin
|
||||
|
26
Symbol.pas
26
Symbol.pas
@ -801,7 +801,7 @@ procedure DoGlobals;
|
||||
begin {StaticInit}
|
||||
{allocate buffer}
|
||||
{(+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);
|
||||
buffPtr := buffHandle^;
|
||||
|
||||
@ -892,25 +892,9 @@ procedure DoGlobals;
|
||||
endDisp := variable^.itype^.size
|
||||
else
|
||||
endDisp := relocs^.disp;
|
||||
while endDisp - disp >= 8 do begin
|
||||
qp := pointer(ord4(buffPtr) + disp);
|
||||
GenQ1(dc_cns, qp^, 1);
|
||||
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;
|
||||
if disp <> endDisp then begin
|
||||
GenBS(dc_cns, pointer(ord4(buffPtr) + disp), endDisp - disp);
|
||||
disp := endDisp;
|
||||
end; {if}
|
||||
if relocs <> nil then begin
|
||||
code^.optype := ccPointer;
|
||||
@ -930,8 +914,6 @@ procedure DoGlobals;
|
||||
disp := disp + cgPointerSize;
|
||||
end; {if}
|
||||
end; {while}
|
||||
|
||||
DisposeHandle(buffHandle);
|
||||
end; {StaticInit}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user