2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2023-01-21 15:34:25 +01:00
|
|
|
Copyright (c) 2018-2023, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE PROG;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IMPORT SCAN, LISTS, ARITH, ERRORS, C := COLLECTIONS, IL, UTILS, TARGETS, STRINGS, PATHS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
MAXARRDIM* = 5;
|
|
|
|
MAXSCOPE = 16;
|
|
|
|
MAXSYSVPARAM* = 26;
|
|
|
|
|
|
|
|
idNONE* = 0; idGUARD = 1; idMODULE* = 2; idCONST* = 3;
|
|
|
|
idTYPE* = 4; idSTFUNC* = 5; idSTPROC* = 6; idVAR* = 7;
|
|
|
|
idPROC* = 8; idVPAR* = 9; idPARAM* = 10; idSYSFUNC* = 11;
|
|
|
|
idSYSPROC* = 12; idIMP* = 13;
|
|
|
|
|
|
|
|
tINTEGER* = 1; tBYTE* = 2; tCHAR* = 3; tSET* = 4;
|
|
|
|
tBOOLEAN* = 5; tREAL* = 6; tARRAY* = 7; tRECORD* = 8;
|
|
|
|
tPOINTER* = 9; tPROCEDURE* = 10; tSTRING* = 11; tNIL* = 12;
|
2020-10-13 09:58:51 +02:00
|
|
|
tCARD32* = 13; tANYREC* = 14; tWCHAR* = 15; tNONE* = 16;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
BASICTYPES* = {tINTEGER, tBYTE, tCHAR, tSET, tBOOLEAN, tREAL, tCARD32, tWCHAR};
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
stABS* = 1; stASR* = 2; stCHR* = 3; stFLOOR* = 4;
|
|
|
|
stFLT* = 5; stLEN* = 6; stLSL* = 7; stODD* = 8;
|
|
|
|
stORD* = 9; stROR* = 10; stASSERT* = 11; stDEC* = 12;
|
|
|
|
stEXCL* = 13; stINC* = 14; stINCL* = 15; stNEW* = 16;
|
|
|
|
stPACK* = 17; stUNPK* = 18; sysADR* = 19; sysSIZE* = 20;
|
|
|
|
sysGET* = 21; sysPUT* = 22;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
stDISPOSE* = 23; stLSR* = 24; stBITS* = 25; sysCODE* = 26;
|
|
|
|
sysMOVE* = 27; stLENGTH* = 28; stMIN* = 29; stMAX* = 30;
|
|
|
|
sysSADR* = 31; sysTYPEID* = 32; sysCOPY* = 33; sysINF* = 34;
|
|
|
|
sysPUT8* = 35; sysPUT16* = 36; stCOPY* = 37; stWCHR* = 38;
|
|
|
|
sysWSADR* = 39; sysPUT32* = 40; (*sysNOP* = 41; sysEINT* = 42;
|
|
|
|
sysDINT* = 43;*)sysGET8* = 44; sysGET16* = 45; sysGET32* = 46;
|
2023-01-21 15:34:25 +01:00
|
|
|
sysVAL* = 47;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
default32* = 2; _default32* = default32 + 1;
|
2019-03-11 09:59:55 +01:00
|
|
|
stdcall* = 4; _stdcall* = stdcall + 1;
|
2021-06-15 19:33:16 +02:00
|
|
|
cdecl* = 6; _cdecl* = cdecl + 1;
|
|
|
|
ccall* = 8; _ccall* = ccall + 1;
|
2019-03-11 09:59:55 +01:00
|
|
|
win64* = 10; _win64* = win64 + 1;
|
2021-06-15 19:33:16 +02:00
|
|
|
default64* = 12; _default64* = default64 + 1;
|
|
|
|
systemv* = 14; _systemv* = systemv + 1;
|
|
|
|
default16* = 16; _default16* = default16 + 1;
|
|
|
|
code* = 18; _code* = code + 1;
|
2022-06-21 22:32:43 +02:00
|
|
|
fastcall* = 20; _fastcall* = fastcall + 1;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
noalign* = 22;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
callee_clean_up* = {default32, _default32, stdcall, _stdcall, default64, _default64, fastcall, _fastcall};
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
sf_stdcall* = 0; sf_oberon* = 1; sf_cdecl* = 2; sf_ccall* = 3;
|
|
|
|
sf_win64* = 4; sf_systemv* = 5; sf_windows* = 6; sf_linux* = 7;
|
2022-06-21 22:32:43 +02:00
|
|
|
sf_code* = 8; sf_fastcall* = 9;
|
|
|
|
sf_noalign* = 10;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
proc_flags* = {sf_stdcall, sf_cdecl, sf_ccall, sf_win64, sf_systemv, sf_windows, sf_linux, sf_code, sf_oberon, sf_fastcall};
|
2019-09-26 22:23:06 +02:00
|
|
|
rec_flags* = {sf_noalign};
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
STACK_FRAME = 2;
|
|
|
|
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
OPTIONS* = RECORD
|
|
|
|
|
2021-09-03 19:21:37 +02:00
|
|
|
version*, stack*, ram*, rom*, tab*: INTEGER;
|
2022-01-05 21:42:22 +01:00
|
|
|
pic*, lower*, uses*: BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
checking*: SET
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IDENT* = POINTER TO rIDENT;
|
|
|
|
|
|
|
|
UNIT* = POINTER TO rUNIT;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_TYPE* = POINTER TO rTYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
FRWPTR* = POINTER TO RECORD (LISTS.ITEM)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
baseIdent: SCAN.IDENT;
|
|
|
|
linked: BOOLEAN;
|
|
|
|
|
|
|
|
pos*: SCAN.POSITION;
|
|
|
|
notRecord*: BOOLEAN
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
PROC* = POINTER TO RECORD (LISTS.ITEM)
|
|
|
|
|
|
|
|
label*: INTEGER;
|
|
|
|
used*: BOOLEAN;
|
|
|
|
processed*: BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
_import*: LISTS.ITEM;
|
2019-03-11 09:59:55 +01:00
|
|
|
using*: LISTS.LIST;
|
|
|
|
enter*,
|
|
|
|
leave*: LISTS.ITEM
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
USED_PROC = POINTER TO RECORD (LISTS.ITEM)
|
|
|
|
|
|
|
|
proc: PROC
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
rUNIT = RECORD (LISTS.ITEM)
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
fname*: PATHS.PATH;
|
2019-03-11 09:59:55 +01:00
|
|
|
name*: SCAN.IDENT;
|
2019-09-26 22:23:06 +02:00
|
|
|
idents*: LISTS.LIST;
|
2019-03-11 09:59:55 +01:00
|
|
|
frwPointers: LISTS.LIST;
|
|
|
|
gscope: IDENT;
|
|
|
|
closed*: BOOLEAN;
|
|
|
|
scopeLvl*: INTEGER;
|
|
|
|
sysimport*: BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
scopes*: ARRAY MAXSCOPE OF PROC
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
FIELD* = POINTER TO rFIELD;
|
|
|
|
|
|
|
|
PARAM* = POINTER TO rPARAM;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
rTYPE = RECORD (LISTS.ITEM)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
typ*: INTEGER;
|
|
|
|
size*: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
parSize*: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
length*: INTEGER;
|
|
|
|
align*: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
base*: _TYPE;
|
2019-09-26 22:23:06 +02:00
|
|
|
fields*: LISTS.LIST;
|
|
|
|
params*: LISTS.LIST;
|
2019-03-11 09:59:55 +01:00
|
|
|
unit*: UNIT;
|
|
|
|
closed*: BOOLEAN;
|
|
|
|
num*: INTEGER;
|
|
|
|
call*: INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
_import*: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
noalign*: BOOLEAN
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
rFIELD = RECORD (LISTS.ITEM)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_type*: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
name*: SCAN.IDENT;
|
|
|
|
export*: BOOLEAN;
|
|
|
|
offset*: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
rPARAM = RECORD (LISTS.ITEM)
|
|
|
|
|
|
|
|
name*: SCAN.IDENT;
|
2020-10-13 09:58:51 +02:00
|
|
|
_type*: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
vPar*: BOOLEAN;
|
|
|
|
offset*: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
rIDENT = RECORD (LISTS.ITEM)
|
|
|
|
|
|
|
|
name*: SCAN.IDENT;
|
|
|
|
typ*: INTEGER;
|
|
|
|
export*: BOOLEAN;
|
2020-10-13 09:58:51 +02:00
|
|
|
_import*: LISTS.ITEM;
|
2019-03-11 09:59:55 +01:00
|
|
|
unit*: UNIT;
|
|
|
|
value*: ARITH.VALUE;
|
2020-10-13 09:58:51 +02:00
|
|
|
_type*: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
stproc*: INTEGER;
|
|
|
|
global*: BOOLEAN;
|
|
|
|
scopeLvl*: INTEGER;
|
|
|
|
offset*: INTEGER;
|
|
|
|
proc*: PROC;
|
|
|
|
pos*: SCAN.POSITION
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROGRAM = RECORD
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
recCount: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
units*: LISTS.LIST;
|
2019-03-11 09:59:55 +01:00
|
|
|
types*: LISTS.LIST;
|
|
|
|
sysunit*: UNIT;
|
|
|
|
rtl*: UNIT;
|
|
|
|
bss*: INTEGER;
|
|
|
|
locsize*: INTEGER;
|
|
|
|
|
|
|
|
procs*: LISTS.LIST;
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
sysflags*: SET;
|
|
|
|
options*: OPTIONS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
stTypes*: RECORD
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
tINTEGER*, tBYTE*, tCHAR*, tWCHAR*, tSET*, tBOOLEAN*, tREAL*,
|
2020-10-13 09:58:51 +02:00
|
|
|
tSTRING*, tNIL*, tCARD32*, tANYREC*, tNONE*: _TYPE
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
DELIMPORT = PROCEDURE (_import: LISTS.ITEM);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
LowerCase*: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
idents: C.COLLECTION;
|
2020-10-13 09:58:51 +02:00
|
|
|
program*: PROGRAM;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE NewIdent (): IDENT;
|
|
|
|
VAR
|
|
|
|
ident: IDENT;
|
|
|
|
citem: C.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
citem := C.pop(idents);
|
|
|
|
IF citem = NIL THEN
|
|
|
|
NEW(ident)
|
|
|
|
ELSE
|
|
|
|
ident := citem(IDENT)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN ident
|
|
|
|
END NewIdent;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE getOffset* (varIdent: IDENT): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2023-01-21 15:34:25 +01:00
|
|
|
size, glob_align: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF varIdent.offset = -1 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
size := varIdent._type.size;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF varIdent.global THEN
|
2023-01-21 15:34:25 +01:00
|
|
|
IF TARGETS.WinLin THEN
|
|
|
|
glob_align := 16
|
|
|
|
ELSE
|
|
|
|
glob_align := varIdent._type.align
|
|
|
|
END;
|
|
|
|
IF UTILS.Align(program.bss, glob_align) THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
IF UTILS.maxint - program.bss >= size THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
varIdent.offset := program.bss;
|
2019-10-06 19:55:12 +02:00
|
|
|
INC(program.bss, size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
IF UTILS.Align(size, TARGETS.WordSize) THEN
|
|
|
|
size := size DIV TARGETS.WordSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF UTILS.maxint - program.locsize >= size THEN
|
|
|
|
INC(program.locsize, size);
|
2019-10-06 19:55:12 +02:00
|
|
|
varIdent.offset := program.locsize
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
2019-10-06 19:55:12 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF varIdent.offset = -1 THEN
|
|
|
|
ERRORS.Error(204)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN varIdent.offset
|
|
|
|
END getOffset;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE closeUnit* (unit: UNIT);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident, prev: IDENT;
|
|
|
|
offset: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ident := unit.idents.last(IDENT);
|
|
|
|
WHILE (ident # NIL) & (ident.typ # idGUARD) DO
|
|
|
|
IF (ident.typ = idVAR) & (ident.offset = -1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.HintMsg(ident.name.s, ident.pos.line, ident.pos.col, 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ident.export THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
offset := getOffset(ident)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
ident := ident.prev(IDENT)
|
|
|
|
END;
|
|
|
|
|
|
|
|
ident := unit.idents.last(IDENT);
|
|
|
|
WHILE ident # NIL DO
|
|
|
|
prev := ident.prev(IDENT);
|
|
|
|
IF ~ident.export THEN
|
|
|
|
LISTS.delete(unit.idents, ident);
|
|
|
|
C.push(idents, ident)
|
|
|
|
END;
|
|
|
|
ident := prev
|
|
|
|
END;
|
|
|
|
|
|
|
|
unit.closed := TRUE
|
2019-09-26 22:23:06 +02:00
|
|
|
END closeUnit;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE IdEq* (a, b: SCAN.IDENT): BOOLEAN;
|
|
|
|
RETURN (a.hash = b.hash) & (a.s = b.s)
|
|
|
|
END IdEq;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE unique (unit: UNIT; ident: SCAN.IDENT): BOOLEAN;
|
|
|
|
VAR
|
|
|
|
item: IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
item := unit.idents.last(IDENT);
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (item.typ # idGUARD) & ~IdEq(item.name, ident) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.prev(IDENT)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item.typ = idGUARD
|
|
|
|
END unique;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE addIdent* (unit: UNIT; ident: SCAN.IDENT; typ: INTEGER): IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
item: IDENT;
|
|
|
|
res: BOOLEAN;
|
|
|
|
proc: PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(unit # NIL);
|
|
|
|
|
|
|
|
res := unique(unit, ident);
|
|
|
|
|
|
|
|
IF res THEN
|
|
|
|
item := NewIdent();
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
item.name := ident;
|
|
|
|
item.typ := typ;
|
|
|
|
item.unit := NIL;
|
|
|
|
item.export := FALSE;
|
|
|
|
item._import := NIL;
|
|
|
|
item._type := NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
item.value.typ := 0;
|
|
|
|
item.stproc := 0;
|
|
|
|
|
|
|
|
item.global := unit.scopeLvl = 0;
|
|
|
|
item.scopeLvl := unit.scopeLvl;
|
|
|
|
item.offset := -1;
|
|
|
|
|
|
|
|
IF item.typ IN {idPROC, idIMP} THEN
|
|
|
|
NEW(proc);
|
2020-10-13 09:58:51 +02:00
|
|
|
proc._import := NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
proc.label := 0;
|
|
|
|
proc.used := FALSE;
|
|
|
|
proc.processed := FALSE;
|
|
|
|
proc.using := LISTS.create(NIL);
|
2020-10-13 09:58:51 +02:00
|
|
|
LISTS.push(program.procs, proc);
|
2019-03-11 09:59:55 +01:00
|
|
|
item.proc := proc
|
|
|
|
END;
|
|
|
|
|
|
|
|
LISTS.push(unit.idents, item)
|
|
|
|
ELSE
|
|
|
|
item := NIL
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item
|
|
|
|
END addIdent;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE UseProc* (unit: UNIT; call_proc: PROC);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
procs: LISTS.LIST;
|
|
|
|
cur: LISTS.ITEM;
|
|
|
|
proc: USED_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF unit.scopeLvl = 0 THEN
|
|
|
|
call_proc.used := TRUE
|
|
|
|
ELSE
|
|
|
|
procs := unit.scopes[unit.scopeLvl].using;
|
|
|
|
|
|
|
|
cur := procs.first;
|
|
|
|
WHILE (cur # NIL) & (cur(USED_PROC).proc # call_proc) DO
|
|
|
|
cur := cur.next
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF cur = NIL THEN
|
|
|
|
NEW(proc);
|
|
|
|
proc.proc := call_proc;
|
|
|
|
LISTS.push(procs, proc)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END UseProc;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE setVarsType* (unit: UNIT; _type: _TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(_type # NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
item := unit.idents.last(IDENT);
|
2020-10-13 09:58:51 +02:00
|
|
|
WHILE (item # NIL) & (item.typ = idVAR) & (item._type = NIL) DO
|
|
|
|
item._type := _type;
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.prev(IDENT)
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END setVarsType;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE getIdent* (unit: UNIT; ident: SCAN.IDENT; currentScope: BOOLEAN): IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
item := unit.idents.last(IDENT);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF item # NIL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF currentScope THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (item.typ # idGUARD) & ~IdEq(item.name, ident) DO
|
2019-09-26 22:23:06 +02:00
|
|
|
item := item.prev(IDENT)
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
IF item.typ = idGUARD THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
item := NIL
|
|
|
|
END
|
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (item # NIL) & ~IdEq(item.name, ident) DO
|
2019-09-26 22:23:06 +02:00
|
|
|
item := item.prev(IDENT)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item
|
|
|
|
END getIdent;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE openScope* (unit: UNIT; proc: PROC): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: IDENT;
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
INC(unit.scopeLvl);
|
|
|
|
|
|
|
|
res := unit.scopeLvl < MAXSCOPE;
|
|
|
|
|
|
|
|
IF res THEN
|
|
|
|
|
|
|
|
unit.scopes[unit.scopeLvl] := proc;
|
|
|
|
|
|
|
|
NEW(item);
|
|
|
|
item := NewIdent();
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
item.name.s := "";
|
|
|
|
item.name.hash := 0;
|
2019-03-11 09:59:55 +01:00
|
|
|
item.typ := idGUARD;
|
|
|
|
|
|
|
|
LISTS.push(unit.idents, item)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END openScope;
|
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE closeScope* (unit: UNIT);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: IDENT;
|
|
|
|
del: IDENT;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
item := unit.idents.last(IDENT);
|
|
|
|
|
|
|
|
WHILE (item # NIL) & (item.typ # idGUARD) DO
|
|
|
|
del := item;
|
|
|
|
item := item.prev(IDENT);
|
|
|
|
IF (del.typ = idVAR) & (del.offset = -1) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.HintMsg(del.name.s, del.pos.line, del.pos.col, 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
LISTS.delete(unit.idents, del);
|
|
|
|
C.push(idents, del)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF (item # NIL) & (item.typ = idGUARD) THEN
|
|
|
|
LISTS.delete(unit.idents, item);
|
|
|
|
C.push(idents, item)
|
|
|
|
END;
|
|
|
|
|
|
|
|
DEC(unit.scopeLvl)
|
|
|
|
END closeScope;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE frwPtr* (unit: UNIT; _type: _TYPE; baseIdent: SCAN.IDENT; pos: SCAN.POSITION);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
newptr: FRWPTR;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(unit # NIL);
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(_type # NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
NEW(newptr);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
newptr._type := _type;
|
2019-09-26 22:23:06 +02:00
|
|
|
newptr.baseIdent := baseIdent;
|
|
|
|
newptr.pos := pos;
|
|
|
|
newptr.linked := FALSE;
|
|
|
|
newptr.notRecord := FALSE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
LISTS.push(unit.frwPointers, newptr)
|
2019-09-26 22:23:06 +02:00
|
|
|
END frwPtr;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE linkPtr* (unit: UNIT): FRWPTR;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: FRWPTR;
|
|
|
|
ident: IDENT;
|
|
|
|
res: FRWPTR;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := NIL;
|
|
|
|
item := unit.frwPointers.last(FRWPTR);
|
|
|
|
|
|
|
|
WHILE (item # NIL) & ~item.linked & (res = NIL) DO
|
2019-09-26 22:23:06 +02:00
|
|
|
ident := getIdent(unit, item.baseIdent, TRUE);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF (ident # NIL) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (ident.typ = idTYPE) & (ident._type.typ = tRECORD) THEN
|
|
|
|
item._type.base := ident._type;
|
2019-03-11 09:59:55 +01:00
|
|
|
item.linked := TRUE
|
|
|
|
ELSE
|
|
|
|
item.notRecord := TRUE;
|
|
|
|
res := item
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
item.notRecord := FALSE;
|
|
|
|
res := item
|
|
|
|
END;
|
|
|
|
|
|
|
|
item := item.prev(FRWPTR)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
2019-09-26 22:23:06 +02:00
|
|
|
END linkPtr;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE isTypeEq* (t1, t2: _TYPE): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
param1, param2: LISTS.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF t1 = t2 THEN
|
|
|
|
res := TRUE
|
|
|
|
ELSIF (t1 = NIL) OR (t2 = NIL) THEN
|
|
|
|
res := FALSE
|
|
|
|
ELSIF (t1.typ = tPROCEDURE) & (t2.typ = tPROCEDURE) THEN
|
|
|
|
|
|
|
|
param1 := t1.params.first;
|
|
|
|
param2 := t2.params.first;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
res := ((t1.call = t2.call) OR (t1.call IN {code, _code}) OR (t2.call IN {code, _code})) & ((param1 # NIL) = (param2 # NIL));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
WHILE res & (param1 # NIL) & (param2 # NIL) DO
|
2020-10-13 09:58:51 +02:00
|
|
|
res := (param1(PARAM).vPar = param2(PARAM).vPar) & isTypeEq(param1(PARAM)._type, param2(PARAM)._type);
|
2019-03-11 09:59:55 +01:00
|
|
|
param1 := param1.next;
|
|
|
|
param2 := param2.next;
|
|
|
|
res := res & ((param1 # NIL) = (param2 # NIL))
|
|
|
|
END;
|
|
|
|
|
|
|
|
res := res & isTypeEq(t1.base, t2.base)
|
|
|
|
|
|
|
|
ELSIF (t1.typ = tARRAY) & (t2.typ = tARRAY) THEN
|
|
|
|
res := (t1.length = 0) & (t2.length = 0) & isTypeEq(t1.base, t2.base)
|
|
|
|
ELSE
|
|
|
|
res := FALSE
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END isTypeEq;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE isBaseOf* (t0, t1: _TYPE): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
res := (t0.typ = t1.typ) & (t0.typ IN {tPOINTER, tRECORD});
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF res & (t0.typ = tPOINTER) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
t0 := t0.base;
|
|
|
|
t1 := t1.base
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF res THEN
|
|
|
|
WHILE (t1 # NIL) & (t1 # t0) DO
|
|
|
|
t1 := t1.base
|
|
|
|
END;
|
|
|
|
res := t1 # NIL
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN res
|
2019-03-11 09:59:55 +01:00
|
|
|
END isBaseOf;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE isOpenArray* (t: _TYPE): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN (t.typ = tARRAY) & (t.length = 0)
|
|
|
|
END isOpenArray;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE arrcomp* (src, dst: _TYPE): BOOLEAN;
|
2019-10-06 19:55:12 +02:00
|
|
|
RETURN (dst.typ = tARRAY) & isOpenArray(src) &
|
|
|
|
~isOpenArray(src.base) & ~isOpenArray(dst.base) &
|
|
|
|
isTypeEq(src.base, dst.base)
|
|
|
|
END arrcomp;
|
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE getUnit* (name: PATHS.PATH): UNIT;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: UNIT;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
item := program.units.first(UNIT);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (item # NIL) & (item.fname # name) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.next(UNIT)
|
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF (item = NIL) & ((name = "SYSTEM") OR LowerCase & (name = "system")) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
item := program.sysunit
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item
|
2019-09-26 22:23:06 +02:00
|
|
|
END getUnit;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE enterStTypes (unit: UNIT);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE enter (unit: UNIT; nameStr: SCAN.IDSTR; _type: _TYPE);
|
2020-10-13 09:58:51 +02:00
|
|
|
VAR
|
|
|
|
ident: IDENT;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper: SCAN.IDSTR;
|
|
|
|
name: SCAN.IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
BEGIN
|
|
|
|
IF LowerCase THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, nameStr);
|
|
|
|
ident := addIdent(unit, name, idTYPE);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := _type
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper := nameStr;
|
2020-10-13 09:58:51 +02:00
|
|
|
STRINGS.UpCase(upper);
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, upper);
|
|
|
|
ident := addIdent(unit, name, idTYPE);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := _type
|
|
|
|
END enter;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
BEGIN
|
|
|
|
enter(unit, "integer", program.stTypes.tINTEGER);
|
|
|
|
enter(unit, "byte", program.stTypes.tBYTE);
|
|
|
|
enter(unit, "char", program.stTypes.tCHAR);
|
|
|
|
enter(unit, "set", program.stTypes.tSET);
|
|
|
|
enter(unit, "boolean", program.stTypes.tBOOLEAN);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.RealSize # 0 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
enter(unit, "real", program.stTypes.tREAL)
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.BitDepth >= 32 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
enter(unit, "wchar", program.stTypes.tWCHAR)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END enterStTypes;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE enterStProcs (unit: UNIT);
|
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE Enter (unit: UNIT; nameStr: SCAN.IDSTR; nfunc, tfunc: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident: IDENT;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper: SCAN.IDSTR;
|
|
|
|
name: SCAN.IDENT;
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF LowerCase THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, nameStr);
|
|
|
|
ident := addIdent(unit, name, tfunc);
|
|
|
|
ident.stproc := nfunc;
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := program.stTypes.tNONE
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper := nameStr;
|
2020-10-13 09:58:51 +02:00
|
|
|
STRINGS.UpCase(upper);
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, upper);
|
|
|
|
ident := addIdent(unit, name, tfunc);
|
|
|
|
ident.stproc := nfunc;
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := program.stTypes.tNONE
|
2021-06-15 19:33:16 +02:00
|
|
|
END Enter;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
Enter(unit, "assert", stASSERT, idSTPROC);
|
|
|
|
Enter(unit, "dec", stDEC, idSTPROC);
|
|
|
|
Enter(unit, "excl", stEXCL, idSTPROC);
|
|
|
|
Enter(unit, "inc", stINC, idSTPROC);
|
|
|
|
Enter(unit, "incl", stINCL, idSTPROC);
|
|
|
|
Enter(unit, "new", stNEW, idSTPROC);
|
|
|
|
Enter(unit, "copy", stCOPY, idSTPROC);
|
|
|
|
|
|
|
|
Enter(unit, "abs", stABS, idSTFUNC);
|
|
|
|
Enter(unit, "asr", stASR, idSTFUNC);
|
|
|
|
Enter(unit, "chr", stCHR, idSTFUNC);
|
|
|
|
Enter(unit, "len", stLEN, idSTFUNC);
|
|
|
|
Enter(unit, "lsl", stLSL, idSTFUNC);
|
|
|
|
Enter(unit, "odd", stODD, idSTFUNC);
|
|
|
|
Enter(unit, "ord", stORD, idSTFUNC);
|
|
|
|
Enter(unit, "ror", stROR, idSTFUNC);
|
|
|
|
Enter(unit, "bits", stBITS, idSTFUNC);
|
|
|
|
Enter(unit, "lsr", stLSR, idSTFUNC);
|
|
|
|
Enter(unit, "length", stLENGTH, idSTFUNC);
|
|
|
|
Enter(unit, "min", stMIN, idSTFUNC);
|
|
|
|
Enter(unit, "max", stMAX, idSTFUNC);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.RealSize # 0 THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
Enter(unit, "pack", stPACK, idSTPROC);
|
|
|
|
Enter(unit, "unpk", stUNPK, idSTPROC);
|
|
|
|
Enter(unit, "floor", stFLOOR, idSTFUNC);
|
|
|
|
Enter(unit, "flt", stFLT, idSTFUNC)
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF TARGETS.BitDepth >= 32 THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
Enter(unit, "wchr", stWCHR, idSTFUNC)
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.Dispose THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
Enter(unit, "dispose", stDISPOSE, idSTPROC)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END enterStProcs;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE newUnit* (name: SCAN.IDENT): UNIT;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
unit: UNIT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NEW(unit);
|
|
|
|
|
|
|
|
unit.name := name;
|
|
|
|
unit.closed := FALSE;
|
2019-09-26 22:23:06 +02:00
|
|
|
unit.idents := LISTS.create(NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
unit.frwPointers := LISTS.create(NIL);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(openScope(unit, NIL));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
enterStTypes(unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
enterStProcs(unit);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(openScope(unit, NIL));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
unit.gscope := unit.idents.last(IDENT);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
LISTS.push(program.units, unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
unit.scopeLvl := 0;
|
|
|
|
unit.scopes[0] := NIL;
|
|
|
|
|
|
|
|
unit.sysimport := FALSE;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF unit.name.s = UTILS.RTL_NAME THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
program.rtl := unit
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN unit
|
2019-09-26 22:23:06 +02:00
|
|
|
END newUnit;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE getField* (self: _TYPE; name: SCAN.IDENT; unit: UNIT): FIELD;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
field: FIELD;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
ASSERT(self # NIL);
|
|
|
|
ASSERT(unit # NIL);
|
|
|
|
|
|
|
|
field := NIL;
|
|
|
|
WHILE (self # NIL) & (field = NIL) DO
|
|
|
|
|
|
|
|
field := self.fields.first(FIELD);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (field # NIL) & ~IdEq(field.name, name) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
field := field.next(FIELD)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF field = NIL THEN
|
|
|
|
self := self.base
|
|
|
|
END
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF (field # NIL) & (self.unit # unit) & ~field.export THEN
|
|
|
|
field := NIL
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN field
|
|
|
|
END getField;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE addField* (self: _TYPE; name: SCAN.IDENT; export: BOOLEAN): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
field: FIELD;
|
|
|
|
res: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := getField(self, name, self.unit) = NIL;
|
|
|
|
|
|
|
|
IF res THEN
|
|
|
|
NEW(field);
|
|
|
|
|
|
|
|
field.name := name;
|
|
|
|
field.export := export;
|
2020-10-13 09:58:51 +02:00
|
|
|
field._type := NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
field.offset := self.size;
|
|
|
|
|
|
|
|
LISTS.push(self.fields, field)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END addField;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE setFields* (self: _TYPE; _type: _TYPE): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: FIELD;
|
|
|
|
res: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(_type # NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
item := self.fields.first(FIELD);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
WHILE (item # NIL) & (item._type # NIL) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.next(FIELD)
|
|
|
|
END;
|
|
|
|
|
|
|
|
res := TRUE;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
WHILE res & (item # NIL) & (item._type = NIL) DO
|
|
|
|
item._type := _type;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ~self.noalign THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
res := UTILS.Align(self.size, _type.align)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
res := TRUE
|
|
|
|
END;
|
|
|
|
item.offset := self.size;
|
2020-10-13 09:58:51 +02:00
|
|
|
res := res & (UTILS.maxint - self.size >= _type.size);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF res THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(self.size, _type.size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
item := item.next(FIELD)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END setFields;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE getParam* (self: _TYPE; name: SCAN.IDENT): PARAM;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
item: PARAM;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
item := self.params.first(PARAM);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
WHILE (item # NIL) & ~IdEq(item.name, name) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.next(PARAM)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item
|
|
|
|
END getParam;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE addParam* (self: _TYPE; name: SCAN.IDENT; vPar: BOOLEAN): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
param: PARAM;
|
|
|
|
res: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
res := getParam(self, name) = NIL;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF res THEN
|
|
|
|
NEW(param);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
param.name := name;
|
|
|
|
param._type := NIL;
|
|
|
|
param.vPar := vPar;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
LISTS.push(self.params, param)
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END addParam;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE Dim* (t: _TYPE): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := 0;
|
|
|
|
WHILE isOpenArray(t) DO
|
|
|
|
t := t.base;
|
|
|
|
INC(res)
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
END Dim;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE OpenBase* (t: _TYPE): _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
WHILE isOpenArray(t) DO t := t.base END
|
|
|
|
RETURN t
|
|
|
|
END OpenBase;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE getFloatParamsPos* (self: _TYPE; maxoffs: INTEGER; VAR int, flt: INTEGER): SET;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: SET;
|
|
|
|
param: PARAM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
res := {};
|
|
|
|
int := 0;
|
|
|
|
flt := 0;
|
|
|
|
param := self.params.first(PARAM);
|
|
|
|
WHILE (param # NIL) & (param.offset <= maxoffs + STACK_FRAME) DO
|
2020-10-13 09:58:51 +02:00
|
|
|
IF ~param.vPar & (param._type.typ = tREAL) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
INCL(res, param.offset - STACK_FRAME);
|
|
|
|
INC(flt)
|
|
|
|
END;
|
|
|
|
param := param.next(PARAM)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
int := self.parSize - flt
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END getFloatParamsPos;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE setParams* (self: _TYPE; _type: _TYPE);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
item: LISTS.ITEM;
|
|
|
|
param: PARAM;
|
|
|
|
word, size: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(_type # NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
word := UTILS.target.bit_depth DIV 8;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
item := self.params.first;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
WHILE (item # NIL) & (item(PARAM)._type # NIL) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
item := item.next
|
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
WHILE (item # NIL) & (item(PARAM)._type = NIL) DO
|
2019-03-11 09:59:55 +01:00
|
|
|
param := item(PARAM);
|
2020-10-13 09:58:51 +02:00
|
|
|
param._type := _type;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF param.vPar THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _type.typ = tRECORD THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
size := 2
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF isOpenArray(_type) THEN
|
|
|
|
size := Dim(_type) + 1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
size := 1
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
param.offset := self.parSize + ORD(_type.typ = tRECORD) + Dim(_type) + STACK_FRAME;
|
2019-09-26 22:23:06 +02:00
|
|
|
INC(self.parSize, size)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF _type.typ IN {tRECORD, tARRAY} THEN
|
|
|
|
IF isOpenArray(_type) THEN
|
|
|
|
size := Dim(_type) + 1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
size := 1
|
|
|
|
END
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
size := _type.size;
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(UTILS.Align(size, word));
|
2019-03-11 09:59:55 +01:00
|
|
|
size := size DIV word
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
param.offset := self.parSize + Dim(_type) + STACK_FRAME;
|
2019-09-26 22:23:06 +02:00
|
|
|
INC(self.parSize, size)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
item := item.next
|
|
|
|
END
|
|
|
|
|
|
|
|
END setParams;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE enterType* (typ, size, length: INTEGER; unit: UNIT): _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
t: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NEW(t);
|
|
|
|
|
|
|
|
t.typ := typ;
|
|
|
|
t.size := size;
|
|
|
|
t.length := length;
|
|
|
|
t.align := 0;
|
|
|
|
t.base := NIL;
|
2019-09-26 22:23:06 +02:00
|
|
|
t.fields := LISTS.create(NIL);
|
|
|
|
t.params := LISTS.create(NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
t.unit := unit;
|
|
|
|
t.num := 0;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
CASE TARGETS.BitDepth OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|16: t.call := default16
|
|
|
|
|32: t.call := default32
|
|
|
|
|64: t.call := default64
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
t._import := FALSE;
|
2019-03-11 09:59:55 +01:00
|
|
|
t.noalign := FALSE;
|
2019-09-26 22:23:06 +02:00
|
|
|
t.parSize := 0;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF typ IN {tARRAY, tRECORD} THEN
|
|
|
|
t.closed := FALSE;
|
|
|
|
IF typ = tRECORD THEN
|
|
|
|
INC(program.recCount);
|
|
|
|
t.num := program.recCount
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
t.closed := TRUE
|
|
|
|
END;
|
|
|
|
|
|
|
|
LISTS.push(program.types, t)
|
|
|
|
|
|
|
|
RETURN t
|
|
|
|
END enterType;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE getType* (typ: INTEGER): _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-10-13 09:58:51 +02:00
|
|
|
res: _TYPE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
CASE typ OF
|
|
|
|
|ARITH.tINTEGER: res := program.stTypes.tINTEGER
|
|
|
|
|ARITH.tREAL: res := program.stTypes.tREAL
|
|
|
|
|ARITH.tSET: res := program.stTypes.tSET
|
|
|
|
|ARITH.tBOOLEAN: res := program.stTypes.tBOOLEAN
|
|
|
|
|ARITH.tCHAR: res := program.stTypes.tCHAR
|
|
|
|
|ARITH.tWCHAR: res := program.stTypes.tWCHAR
|
|
|
|
|ARITH.tSTRING: res := program.stTypes.tSTRING
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END getType;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE createSysUnit;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident: IDENT;
|
|
|
|
unit: UNIT;
|
2021-06-15 19:33:16 +02:00
|
|
|
name: SCAN.IDENT;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE EnterProc (sys: UNIT; nameStr: SCAN.IDSTR; idtyp, proc: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
ident: IDENT;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper: SCAN.IDSTR;
|
|
|
|
name: SCAN.IDENT;
|
2020-10-13 09:58:51 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF LowerCase THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, nameStr);
|
|
|
|
ident := addIdent(sys, name, idtyp);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident.stproc := proc;
|
|
|
|
ident._type := program.stTypes.tNONE;
|
|
|
|
ident.export := TRUE
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
upper := nameStr;
|
2020-10-13 09:58:51 +02:00
|
|
|
STRINGS.UpCase(upper);
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, upper);
|
|
|
|
ident := addIdent(sys, name, idtyp);
|
2019-03-11 09:59:55 +01:00
|
|
|
ident.stproc := proc;
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := program.stTypes.tNONE;
|
2019-03-11 09:59:55 +01:00
|
|
|
ident.export := TRUE
|
|
|
|
END EnterProc;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, "$SYSTEM");
|
|
|
|
unit := newUnit(name);
|
|
|
|
unit.fname := "SYSTEM";
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
EnterProc(unit, "adr", idSYSFUNC, sysADR);
|
|
|
|
EnterProc(unit, "size", idSYSFUNC, sysSIZE);
|
|
|
|
EnterProc(unit, "sadr", idSYSFUNC, sysSADR);
|
|
|
|
EnterProc(unit, "typeid", idSYSFUNC, sysTYPEID);
|
|
|
|
|
|
|
|
EnterProc(unit, "get", idSYSPROC, sysGET);
|
|
|
|
EnterProc(unit, "get8", idSYSPROC, sysGET8);
|
|
|
|
EnterProc(unit, "put", idSYSPROC, sysPUT);
|
|
|
|
EnterProc(unit, "put8", idSYSPROC, sysPUT8);
|
|
|
|
EnterProc(unit, "code", idSYSPROC, sysCODE);
|
|
|
|
EnterProc(unit, "move", idSYSPROC, sysMOVE);
|
2023-01-21 15:34:25 +01:00
|
|
|
EnterProc(unit, "val", idSYSPROC, sysVAL);
|
2019-09-26 22:23:06 +02:00
|
|
|
(*
|
|
|
|
IF program.target.sys = mConst.Target_iMSP430 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
EnterProc(unit, "nop", idSYSPROC, sysNOP);
|
|
|
|
EnterProc(unit, "eint", idSYSPROC, sysEINT);
|
|
|
|
EnterProc(unit, "dint", idSYSPROC, sysDINT)
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
|
|
|
*)
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.RealSize # 0 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
EnterProc(unit, "inf", idSYSFUNC, sysINF);
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF TARGETS.CPU IN {TARGETS.cpuX86, TARGETS.cpuAMD64} THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
EnterProc(unit, "copy", idSYSPROC, sysCOPY)
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF TARGETS.BitDepth >= 32 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
EnterProc(unit, "wsadr", idSYSFUNC, sysWSADR);
|
|
|
|
EnterProc(unit, "put16", idSYSPROC, sysPUT16);
|
|
|
|
EnterProc(unit, "put32", idSYSPROC, sysPUT32);
|
|
|
|
EnterProc(unit, "get16", idSYSPROC, sysGET16);
|
|
|
|
EnterProc(unit, "get32", idSYSPROC, sysGET32);
|
|
|
|
|
|
|
|
IF LowerCase THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, "card32");
|
|
|
|
ident := addIdent(unit, name, idTYPE);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := program.stTypes.tCARD32;
|
|
|
|
ident.export := TRUE
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
SCAN.setIdent(name, "CARD32");
|
|
|
|
ident := addIdent(unit, name, idTYPE);
|
2020-10-13 09:58:51 +02:00
|
|
|
ident._type := program.stTypes.tCARD32;
|
|
|
|
ident.export := TRUE;
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
closeUnit(unit);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
program.sysunit := unit
|
|
|
|
END createSysUnit;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE DelUnused* (DelImport: DELIMPORT);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
proc: PROC;
|
|
|
|
flag: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE process (proc: PROC);
|
|
|
|
VAR
|
|
|
|
used_proc: LISTS.ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
proc.processed := TRUE;
|
|
|
|
|
|
|
|
used_proc := proc.using.first;
|
|
|
|
WHILE used_proc # NIL DO
|
|
|
|
used_proc(USED_PROC).proc.used := TRUE;
|
|
|
|
used_proc := used_proc.next
|
|
|
|
END
|
|
|
|
|
|
|
|
END process;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
REPEAT
|
|
|
|
flag := FALSE;
|
|
|
|
proc := program.procs.first(PROC);
|
|
|
|
|
|
|
|
WHILE proc # NIL DO
|
|
|
|
IF proc.used & ~proc.processed THEN
|
|
|
|
process(proc);
|
|
|
|
flag := TRUE
|
|
|
|
END;
|
|
|
|
proc := proc.next(PROC)
|
|
|
|
END
|
|
|
|
|
|
|
|
UNTIL ~flag;
|
|
|
|
|
|
|
|
proc := program.procs.first(PROC);
|
|
|
|
|
|
|
|
WHILE proc # NIL DO
|
|
|
|
IF ~proc.used THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF proc._import = NIL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.delete2(proc.enter, proc.leave)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
DelImport(proc._import)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END;
|
|
|
|
proc := proc.next(PROC)
|
|
|
|
END
|
|
|
|
|
|
|
|
END DelUnused;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE ResetLocSize*;
|
|
|
|
BEGIN
|
|
|
|
program.locsize := 0
|
|
|
|
END ResetLocSize;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE create* (options: OPTIONS);
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
LowerCase := options.lower;
|
|
|
|
SCAN.init(options.lower);
|
2019-03-11 09:59:55 +01:00
|
|
|
idents := C.create();
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
UTILS.SetBitDepth(TARGETS.BitDepth, TARGETS.RealSize = 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
program.options := options;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
CASE TARGETS.OS OF
|
2022-06-21 22:32:43 +02:00
|
|
|
|TARGETS.osWIN32: program.sysflags := {sf_oberon, sf_windows, sf_stdcall, sf_cdecl, sf_ccall, sf_fastcall, sf_noalign}
|
|
|
|
|TARGETS.osLINUX32: program.sysflags := {sf_oberon, sf_linux, sf_stdcall, sf_cdecl, sf_ccall, sf_fastcall, sf_noalign}
|
|
|
|
|TARGETS.osKOS: program.sysflags := {sf_oberon, sf_stdcall, sf_cdecl, sf_ccall, sf_fastcall, sf_noalign}
|
2021-06-15 19:33:16 +02:00
|
|
|
|TARGETS.osWIN64: program.sysflags := {sf_oberon, sf_windows, sf_win64, sf_systemv, sf_ccall, sf_noalign}
|
|
|
|
|TARGETS.osLINUX64: program.sysflags := {sf_oberon, sf_linux, sf_win64, sf_systemv, sf_ccall, sf_noalign}
|
2020-05-25 22:48:33 +02:00
|
|
|
|TARGETS.osNONE: program.sysflags := {sf_code}
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
program.recCount := -1;
|
|
|
|
program.bss := 0;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
program.units := LISTS.create(NIL);
|
2019-03-11 09:59:55 +01:00
|
|
|
program.types := LISTS.create(NIL);
|
|
|
|
program.procs := LISTS.create(NIL);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
program.stTypes.tINTEGER := enterType(tINTEGER, TARGETS.WordSize, 0, NIL);
|
|
|
|
program.stTypes.tBYTE := enterType(tBYTE, 1, 0, NIL);
|
|
|
|
program.stTypes.tCHAR := enterType(tCHAR, 1, 0, NIL);
|
|
|
|
program.stTypes.tSET := enterType(tSET, TARGETS.WordSize, 0, NIL);
|
|
|
|
program.stTypes.tBOOLEAN := enterType(tBOOLEAN, 1, 0, NIL);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
program.stTypes.tINTEGER.align := TARGETS.WordSize;
|
|
|
|
program.stTypes.tBYTE.align := 1;
|
|
|
|
program.stTypes.tCHAR.align := 1;
|
|
|
|
program.stTypes.tSET.align := TARGETS.WordSize;
|
|
|
|
program.stTypes.tBOOLEAN.align := 1;
|
|
|
|
|
|
|
|
IF TARGETS.BitDepth >= 32 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
program.stTypes.tWCHAR := enterType(tWCHAR, 2, 0, NIL);
|
|
|
|
program.stTypes.tCARD32 := enterType(tCARD32, 4, 0, NIL);
|
2020-05-25 22:48:33 +02:00
|
|
|
program.stTypes.tWCHAR.align := 2;
|
|
|
|
program.stTypes.tCARD32.align := 4
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.RealSize # 0 THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
program.stTypes.tREAL := enterType(tREAL, TARGETS.RealSize, 0, NIL);
|
2023-01-21 15:34:25 +01:00
|
|
|
IF TARGETS.OS = TARGETS.osLINUX32 THEN
|
|
|
|
program.stTypes.tREAL.align := 4
|
|
|
|
ELSE
|
|
|
|
program.stTypes.tREAL.align := TARGETS.RealSize
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
program.stTypes.tSTRING := enterType(tSTRING, TARGETS.WordSize, 0, NIL);
|
|
|
|
program.stTypes.tNIL := enterType(tNIL, TARGETS.WordSize, 0, NIL);
|
|
|
|
program.stTypes.tNONE := enterType(tNONE, 0, 0, NIL);
|
|
|
|
program.stTypes.tANYREC := enterType(tRECORD, 0, 0, NIL);
|
2020-05-25 22:48:33 +02:00
|
|
|
program.stTypes.tANYREC.closed := TRUE;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
createSysUnit
|
2019-03-11 09:59:55 +01:00
|
|
|
END create;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END PROG.
|