From 161bb952e3090bff056d69098d34d68c97d39ec5 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 8 Jun 2022 22:09:30 -0500 Subject: [PATCH] Dynamically allocate string space, and make it larger. This increases the limit on total bytes of strings in a function, and also frees up space in the blank segment. --- CGI.pas | 8 ++++++-- Gen.pas | 12 ++++++------ Native.pas | 4 ++-- Symbol.pas | 4 ++-- cc.notes | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CGI.pas b/CGI.pas index 666f0d3..5f560f1 100644 --- a/CGI.pas +++ b/CGI.pas @@ -209,7 +209,7 @@ const {Note: maxlabel is also defined in CGC.asm} maxLabel = 3200; {max # of internal labels} maxLocalLabel = 220; {max # local variables} - maxString = 12500; {max # chars in string space} + maxString = 32760; {max # chars in string space} {size of internal types} {----------------------} @@ -225,6 +225,7 @@ const type segNameType = packed array[1..10] of char; {segment name} + stringSpaceType = packed array[1..maxstring] of char; {string space} {p code} {------} @@ -343,7 +344,7 @@ var stackSize: integer; {amount of stack space to reserve} strictVararg: boolean; {repair stack around vararg calls?} stringsize: 0..maxstring; {amount of string space left} - stringspace: packed array[1..maxstring] of char; {string table} + stringspace: ^stringSpaceType; {string table} symLength: integer; {length of debug symbol table} toolParms: boolean; {generate tool format parameters?} volatile: boolean; {has a volatile qualifier been used?} @@ -822,6 +823,9 @@ fastMath := cLineOptimize; commonSubexpression := cLineOptimize; {not doing common subexpression elimination} loopOptimizations := cLineOptimize; {not doing loop optimizations, yet} +{allocate string space} +new(stringspace); + {allocate the initial p-code} code := pointer(Calloc(sizeof(intermediate_code))); code^.optype := cgWord; diff --git a/Gen.pas b/Gen.pas index 6a3e7bc..2faf765 100644 --- a/Gen.pas +++ b/Gen.pas @@ -5136,9 +5136,9 @@ len := debugFile^.theString.size; if len > 255 then len := 255; if maxString-stringSize >= len+1 then begin - stringSpace[stringSize+1] := chr(len); + stringSpace^[stringSize+1] := chr(len); for i := 1 to len do - stringSpace[i+stringSize+1] := + stringSpace^[i+stringSize+1] := debugFile^.theString.theString[i]; stringSize := stringSize + len + 1; end {if} @@ -5937,7 +5937,7 @@ procedure GenTree {op: icptr}; GenNative(m_pea, immediate, stringSize, nil, stringReference); if maxString-stringSize >= op^.q then begin for i := 1 to op^.q do - stringSpace[i+stringSize] := op^.str^.str[i]; + stringSpace^[i+stringSize] := op^.str^.str[i]; stringSize := stringSize+op^.q; end else @@ -6375,7 +6375,7 @@ procedure GenTree {op: icptr}; GenNative(opcode, immediate, stringsize, nil, StringReference); if maxstring-stringsize >= op^.q then begin for i := 1 to op^.q do - stringspace[i+stringsize] := op^.str^.str[i]; + stringspace^[i+stringsize] := op^.str^.str[i]; stringsize := stringsize + op^.q; end {if} else @@ -6491,9 +6491,9 @@ procedure GenTree {op: icptr}; {place the name in the string buffer} if maxString-stringSize >= op^.q+1 then begin - stringSpace[stringSize+1] := chr(op^.q); + stringSpace^[stringSize+1] := chr(op^.q); for i := 1 to op^.q do - stringSpace[i+stringSize+1] := op^.str^.str[i]; + stringSpace^[i+stringSize+1] := op^.str^.str[i]; stringSize := stringSize + op^.q + 1; end {if} else diff --git a/Native.pas b/Native.pas index 53727af..7947096 100644 --- a/Native.pas +++ b/Native.pas @@ -676,7 +676,7 @@ case mode of j := sptr^.length; if maxString-stringSize >= j then begin for k := 1 to j do - stringSpace[k+stringSize] := + stringSpace^[k+stringSize] := sptr^.str[k]; stringSize := stringSize+j; end {if} @@ -1337,7 +1337,7 @@ Purge; {dump constant buffer} if stringsize <> 0 then begin {define string space} UpDate(maxLabel, pc); {define the local label for the string space} for i := 1 to stringsize do - CnOut(ord(stringspace[i])); + CnOut(ord(stringspace^[i])); Purge; end; {if} Out(0); {end the segment} diff --git a/Symbol.pas b/Symbol.pas index 83004e0..d012d52 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -1176,9 +1176,9 @@ var Out(0); len := length(ip^.name^); {place the name in the string buffer} if maxstring-stringsize >= len+1 then begin - stringspace[stringsize+1] := chr(len); + stringspace^[stringsize+1] := chr(len); for j := 1 to len do - stringspace[j+stringsize+1] := ip^.name^[j]; + stringspace^[j+stringsize+1] := ip^.name^[j]; stringsize := stringsize+len+1; end {if} else diff --git a/cc.notes b/cc.notes index 706da80..6647de8 100644 --- a/cc.notes +++ b/cc.notes @@ -144,7 +144,7 @@ Character and string constants may now have prefixes indicating they should use p. 238 -The limit on the length of a single string constant is now 32760 bytes. The limit on the total length of string constants in a single function is now 12500 bytes (larger string constants can be used to initialize static arrays). +The limits on the length of a single string constant and on the total length of string constants in a single function have both been raised to 32760 bytes. p. 239