ORCA-C/CGC.pas
Stephen Heumann 8c81b23b6f Expand the size of the object buffer from 64K to 128K, and use 32-bit values to track related sizes.
This allows functions that require an OMF segment byte count of up to 128K to be compiled, although the length in memory at run time is still limited to 64K. (The OMF segment byte count is usually larger, due to the size of relocation records, etc.)

This is useful for compiling large functions, e.g. the main interpreter loop in git. It also fixes the bug shown in the compca23 test case, where functions that require a segment of over 64K may appear to compile correctly but generate corrupted OMF segment headers. This related to tracking sizes with 16-bit values that could roll over.

This patch increases the memory needed at run time by 64K. This shouldn’t generally be a problem on systems with sufficient memory, although it does increase the minimum memory requirement a bit. If behavior in low-memory configurations is a concern, buffSize could be made into a run-time option.
2017-10-21 20:36:21 -05:00

125 lines
4.9 KiB
ObjectPascal

{$optimize 7}
{---------------------------------------------------------------}
{ }
{ ORCA Code Generator Common }
{ }
{ This unit contains the command constants, types, }
{ variables and procedures used throughout the code }
{ generator, but which are not available to the compiler. }
{ }
{---------------------------------------------------------------}
{ }
{ These routines are defined in the compiler, but used from }
{ the code generator. }
{ }
{ Error - flag an error }
{ CMalloc - Clear and allocate memory from a pool. }
{ Malloc - Allocate memory from a pool. }
{ }
{---------------------------------------------------------------}
unit CGC;
interface
{$LibPrefix '0/obj/'}
uses CCommon, CGI;
{$segment 'cg'}
type
{pcode code generation}
{---------------------}
realrec = record {used to convert from real to in-SANE}
itsReal: double;
inSANE: packed array[1..10] of byte;
inCOMP: packed array[1..8] of byte;
end;
var
{msc}
{---}
blkcnt: longint; {number of bytes in current segment}
{buffers}
{-------}
cbufflen: 0..maxcbuff; {number of bytes now in cbuff}
segDisp: longint; {disp in the current segment}
{-- Global subroutines -----------------------------------------}
procedure CnvSC (rec: realrec); extern;
{ convert a real number to SANE comp format }
{ }
{ parameters: }
{ rec - record containing the value to convert; also }
{ has space for the result }
procedure CnvSX (rec: realrec); extern;
{ convert a real number to SANE extended format }
{ }
{ parameters: }
{ rec - record containing the value to convert; also }
{ has space for the result }
procedure InitLabels; extern;
{ initialize the labels array for a procedure }
{ }
{ Note: also defined in CGI.pas }
{-- These routines are defined in the compiler, but used from cg --}
function Calloc (bytes: integer): ptr; extern;
{ Allocate memory from a pool and clear it. }
{ }
{ Parameters: }
{ bytes - number of bytes to allocate }
{ ptr - points to the first byte of the allocated memory }
{ }
{ Globals: }
{ useGlobalPool - should the memory come from the global }
{ (or local) pool }
procedure Error (err: integer); extern;
{ flag an error }
{ }
{ err - error number }
{procedure Error2 (loc, err: integer); extern; {debug} {in scanner.pas}
{ flag an error }
{ }
{ loc - error location }
{ err - error number }
function Malloc (bytes: integer): ptr; extern;
{ Allocate memory from a pool. }
{ }
{ Parameters: }
{ bytes - number of bytes to allocate }
{ ptr - points to the first byte of the allocated memory }
{ }
{ Globals: }
{ useGlobalPool - should the memory come from the global }
{ (or local) pool }
{---------------------------------------------------------------}
implementation
end.
{$append 'CGC.asm'}