Subversion Repositories Kolibri OS

Rev

Rev 7597 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7597 Rev 7693
Line 5... Line 5...
5
    All rights reserved.
5
    All rights reserved.
6
*)
6
*)
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
MODULE PROG;
8
MODULE PROG;
Line 9... Line 9...
9
 
9
 
Line 10... Line 10...
10
IMPORT SCAN, LISTS, ARITH, ERRORS, MACHINE, C := COLLECTIONS, mConst := CONSTANTS, CODE, UTILS;
10
IMPORT SCAN, LISTS, ARITH, ERRORS, C := COLLECTIONS, mConst := CONSTANTS, IL, UTILS;
Line 37... Line 37...
37
 
37
 
38
    stDISPOSE* = 23;  stLSR*     = 24;  stBITS*  = 25;  sysCODE*  = 26;
38
    stDISPOSE* = 23;  stLSR*     = 24;  stBITS*  = 25;  sysCODE*  = 26;
39
    sysMOVE*   = 27;  stLENGTH*  = 28;  stMIN*   = 29;  stMAX*    = 30;
39
    sysMOVE*   = 27;  stLENGTH*  = 28;  stMIN*   = 29;  stMAX*    = 30;
40
    sysSADR*   = 31;  sysTYPEID* = 32;  sysCOPY* = 33;  sysINF*   = 34;
40
    sysSADR*   = 31;  sysTYPEID* = 32;  sysCOPY* = 33;  sysINF*   = 34;
41
    sysPUT8*   = 35;  sysPUT16*  = 36;  stCOPY*  = 37;  stWCHR*   = 38;
41
    sysPUT8*   = 35;  sysPUT16*  = 36;  stCOPY*  = 37;  stWCHR*   = 38;
-
 
42
    sysWSADR*  = 39;  sysPUT32*  = 40;  (*sysNOP*  = 41;  sysEINT*  = 42;
Line 42... Line 43...
42
    sysWSADR*  = 39;  sysPUT32*  = 40;
43
    sysDINT*   = 43;*)
43
 
44
 
44
    default*   =  2;
45
    default32* =  2;
45
    stdcall*   =  4;  _stdcall*   = stdcall + 1;
46
    stdcall*   =  4;  _stdcall*   = stdcall + 1;
46
    ccall*     =  6;  _ccall*     = ccall + 1;
47
    ccall*     =  6;  _ccall*     = ccall + 1;
47
    ccall16*   =  8;  _ccall16*   = ccall16 + 1;
48
    ccall16*   =  8;  _ccall16*   = ccall16 + 1;
48
    win64*     = 10;  _win64*     = win64 + 1;
49
    win64*     = 10;  _win64*     = win64 + 1;
49
    stdcall64* = 12;  _stdcall64* = stdcall64 + 1;
50
    stdcall64* = 12;  _stdcall64* = stdcall64 + 1;
-
 
51
    default64* = 14;
-
 
52
    systemv*   = 16;  _systemv*   = systemv + 1;
Line 50... Line 53...
50
    default64* = 14;
53
    default16* = 18;
Line 51... Line 54...
51
    systemv*   = 16;  _systemv*   = systemv + 1;
54
    code*      = 20;  _code*      = code + 1;
-
 
55
 
52
 
56
    noalign* = 22;
53
    noalign* = 20;
57
 
-
 
58
    callee_clean_up* = {default32, stdcall, _stdcall, default64, stdcall64, _stdcall64};
-
 
59
 
-
 
60
    sf_stdcall* = 0; sf_stdcall64* = 1; sf_ccall*   = 2; sf_ccall16* = 3;
54
 
61
    sf_win64*   = 4; sf_systemv*   = 5; sf_windows* = 6; sf_linux*   = 7;
-
 
62
    sf_code*    = 8;
Line 55... Line 63...
55
    callee_clean_up* = {default, stdcall, _stdcall, default64, stdcall64, _stdcall64};
63
    sf_noalign* = 9;
Line 56... Line 64...
56
    caller_clean_up* = {ccall, ccall16, win64, systemv, _ccall, _ccall16, _win64, _systemv};
64
 
Line -... Line 65...
-
 
65
    proc_flags* = {sf_stdcall, sf_stdcall64, sf_ccall, sf_ccall16, sf_win64, sf_systemv, sf_windows, sf_linux, sf_code};
-
 
66
    rec_flags*  = {sf_noalign};
-
 
67
 
-
 
68
    STACK_FRAME = 2;
-
 
69
 
-
 
70
 
-
 
71
TYPE
-
 
72
 
57
    callconv32* = {default, stdcall, ccall, ccall16, _stdcall, _ccall, _ccall16};
73
    OPTIONS* = RECORD
Line 58... Line 74...
58
    callconv64* = {default64, win64, stdcall64, systemv, _win64, _stdcall64, _systemv};
74
 
Line 59... Line 75...
59
 
75
        version*, stack*, base*, ram*, rom*: INTEGER;
Line 79... Line 95...
79
        pos*:        SCAN.POSITION;
95
        pos*:        SCAN.POSITION;
80
        notRecord*:  BOOLEAN
96
        notRecord*:  BOOLEAN
Line 81... Line 97...
81
 
97
 
Line 82... Line -...
82
    END;
-
 
83
 
-
 
84
    IDENTS = POINTER TO RECORD (LISTS.LIST)
-
 
85
 
-
 
86
        add*:   PROCEDURE (unit: UNIT; ident: SCAN.IDENT; typ: INTEGER): IDENT;
-
 
87
        get*:   PROCEDURE (unit: UNIT; ident: SCAN.IDENT; currentScope: BOOLEAN): IDENT
-
 
88
 
-
 
89
    END;
98
    END;
Line 90... Line 99...
90
 
99
 
91
    PROC* = POINTER TO RECORD (LISTS.ITEM)
100
    PROC* = POINTER TO RECORD (LISTS.ITEM)
92
 
101
 
Line 108... Line 117...
108
 
117
 
Line 109... Line 118...
109
    rUNIT = RECORD (LISTS.ITEM)
118
    rUNIT = RECORD (LISTS.ITEM)
110
 
119
 
111
        program*:    PROGRAM;
120
        program*:    PROGRAM;
112
        name*:       SCAN.IDENT;
121
        name*:       SCAN.IDENT;
113
        idents*:     IDENTS;
122
        idents*:     LISTS.LIST;
114
        frwPointers: LISTS.LIST;
123
        frwPointers: LISTS.LIST;
115
        gscope:      IDENT;
124
        gscope:      IDENT;
116
        closed*:     BOOLEAN;
125
        closed*:     BOOLEAN;
117
        scopeLvl*:   INTEGER;
-
 
118
        sysimport*:  BOOLEAN;
126
        scopeLvl*:   INTEGER;
119
 
-
 
120
        scopes*:     ARRAY MAXSCOPE OF PROC;
-
 
121
 
-
 
122
        scope*:      RECORD
-
 
123
 
-
 
124
            open*:   PROCEDURE (unit: UNIT; proc: PROC): BOOLEAN;
-
 
125
            close*:  PROCEDURE (unit: UNIT; variables: LISTS.LIST)
-
 
126
 
-
 
127
        END;
-
 
128
 
-
 
129
        close*:      PROCEDURE (unit: UNIT);
-
 
130
        setvars*:    PROCEDURE (unit: UNIT; type: TYPE_);
-
 
131
 
-
 
132
        pointers*:   RECORD
-
 
133
 
-
 
134
            add*:    PROCEDURE (unit: UNIT; type: TYPE_; baseIdent: SCAN.IDENT; pos: SCAN.POSITION);
-
 
135
            link*:   PROCEDURE (unit: UNIT): FRWPTR
-
 
Line 136... Line 127...
136
 
127
        sysimport*:  BOOLEAN;
Line 137... Line 128...
137
        END
128
        scopes*:     ARRAY MAXSCOPE OF PROC
Line 138... Line 129...
138
 
129
 
Line 139... Line -...
139
    END;
-
 
140
 
-
 
141
    FIELD* = POINTER TO rFIELD;
-
 
142
 
-
 
143
    PARAM* = POINTER TO rPARAM;
-
 
144
 
-
 
145
    FIELDS = POINTER TO RECORD (LISTS.LIST)
-
 
146
 
-
 
147
        add*:        PROCEDURE (rec: TYPE_; name: SCAN.IDENT; export: BOOLEAN): BOOLEAN;
-
 
148
        get*:        PROCEDURE (rec: TYPE_; name: SCAN.IDENT; unit: UNIT): FIELD;
-
 
149
        set*:        PROCEDURE (rec: TYPE_; type: TYPE_): BOOLEAN
-
 
150
 
-
 
151
    END;
-
 
152
 
-
 
153
    PARAMS = POINTER TO RECORD (LISTS.LIST)
-
 
154
 
-
 
155
        size*:       INTEGER;
-
 
156
 
-
 
157
        add*:        PROCEDURE (proc: TYPE_; name: SCAN.IDENT; vPar: BOOLEAN): BOOLEAN;
-
 
158
        get*:        PROCEDURE (proc: TYPE_; name: SCAN.IDENT): PARAM;
130
    END;
Line 159... Line 131...
159
        set*:        PROCEDURE (proc: TYPE_; type: TYPE_);
131
 
160
        getfparams*: PROCEDURE (proc: TYPE_; maxparam: INTEGER; VAR int, flt: INTEGER): SET
132
    FIELD* = POINTER TO rFIELD;
-
 
133
 
161
 
134
    PARAM* = POINTER TO rPARAM;
162
    END;
135
 
163
 
136
    rTYPE_ = RECORD (LISTS.ITEM)
164
    rTYPE_ = RECORD (LISTS.ITEM)
137
 
165
 
138
        typ*:        INTEGER;
166
        typ*:        INTEGER;
139
        size*:       INTEGER;
167
        size*:       INTEGER;
140
        parSize*:    INTEGER;
168
        length*:     INTEGER;
141
        length*:     INTEGER;
169
        align*:      INTEGER;
142
        align*:      INTEGER;
170
        base*:       TYPE_;
143
        base*:       TYPE_;
Line 213... Line 186...
213
        proc*:       PROC;
186
        proc*:       PROC;
214
        pos*:        SCAN.POSITION
187
        pos*:        SCAN.POSITION
Line 215... Line 188...
215
 
188
 
Line 216... Line -...
216
    END;
-
 
217
 
-
 
218
    UNITS* = POINTER TO RECORD (LISTS.LIST)
-
 
219
 
-
 
220
        program:     PROGRAM;
-
 
221
 
-
 
222
        create*:     PROCEDURE (units: UNITS; name: SCAN.IDENT): UNIT;
-
 
223
        get*:        PROCEDURE (units: UNITS; name: SCAN.IDENT): UNIT
-
 
224
 
-
 
225
    END;
189
    END;
Line 226... Line 190...
226
 
190
 
227
    rPROGRAM = RECORD
191
    rPROGRAM = RECORD
228
 
192
 
229
        recCount:    INTEGER;
193
        recCount:    INTEGER;
230
        units*:      UNITS;
194
        units*:      LISTS.LIST;
231
        types*:      LISTS.LIST;
195
        types*:      LISTS.LIST;
232
        sysunit*:    UNIT;
196
        sysunit*:    UNIT;
Line 238... Line 202...
238
        dll*:        BOOLEAN;
202
        dll*:        BOOLEAN;
239
        obj*:        BOOLEAN;
203
        obj*:        BOOLEAN;
Line 240... Line 204...
240
 
204
 
Line 241... Line 205...
241
        stTypes*:     RECORD
205
        stTypes*:    RECORD
242
 
206
 
Line 243... Line 207...
243
            tINTEGER*, tBYTE*, tCHAR*, tWCHAR*, tSET*, tBOOLEAN*, tREAL*, tSTRING*, tNIL*,
207
            tINTEGER*, tBYTE*, tCHAR*, tWCHAR*, tSET*, tBOOLEAN*, tREAL*,
Line 244... Line 208...
244
            tCARD16*, tCARD32*, tANYREC*: TYPE_
208
            tSTRING*, tNIL*, tCARD16*, tCARD32*, tANYREC*: TYPE_
Line 245... Line 209...
245
 
209
 
246
        END;
210
        END;
247
 
211
 
248
        target*:     RECORD
212
        target*:     RECORD
-
 
213
 
-
 
214
            bit_depth*:  INTEGER;
Line 249... Line 215...
249
 
215
            word*:       INTEGER;
250
            bit_depth*:  INTEGER;
-
 
251
            word*:       INTEGER;
-
 
252
            adr*:        INTEGER;
-
 
Line 253... Line 216...
253
            sys*:        INTEGER
216
            adr*:        INTEGER;
Line 254... Line 217...
254
 
217
            sys*:        INTEGER;
Line 290... Line 253...
290
    size: INTEGER;
253
    size: INTEGER;
Line 291... Line 254...
291
 
254
 
292
BEGIN
255
BEGIN
293
    IF varIdent.offset = -1 THEN
256
    IF varIdent.offset = -1 THEN
294
        IF varIdent.global THEN
257
        IF varIdent.global THEN
295
            IF MACHINE.Align(program.bss, varIdent.type.align) THEN
258
            IF UTILS.Align(program.bss, varIdent.type.align) THEN
296
                IF UTILS.maxint - program.bss >= varIdent.type.size THEN
259
                IF UTILS.maxint - program.bss >= varIdent.type.size THEN
297
                    varIdent.offset := program.bss;
260
                    varIdent.offset := program.bss;
298
                    INC(program.bss, varIdent.type.size)
261
                    INC(program.bss, varIdent.type.size)
299
                END
262
                END
300
            END
263
            END
301
        ELSE
264
        ELSE
302
            word := program.target.word;
265
            word := program.target.word;
303
            size := varIdent.type.size;
266
            size := varIdent.type.size;
304
            IF MACHINE.Align(size, word) THEN
267
            IF UTILS.Align(size, word) THEN
305
                size := size DIV word;
268
                size := size DIV word;
306
                IF UTILS.maxint - program.locsize >= size THEN
269
                IF UTILS.maxint - program.locsize >= size THEN
307
                    INC(program.locsize, size);
270
                    INC(program.locsize, size);
308
                    varIdent.offset := program.locsize;
271
                    varIdent.offset := program.locsize;
Line 313... Line 276...
313
 
276
 
314
    RETURN varIdent.offset
277
    RETURN varIdent.offset
Line 315... Line 278...
315
END getOffset;
278
END getOffset;
316
 
279
 
317
 
280
 
318
PROCEDURE close (unit: UNIT);
281
PROCEDURE closeUnit* (unit: UNIT);
Line 319... Line 282...
319
VAR
282
VAR
320
    ident, prev: IDENT;
283
    ident, prev: IDENT;
321
    offset: INTEGER;
284
    offset: INTEGER;
322
 
285
 
323
BEGIN
286
BEGIN
324
    ident := unit.idents.last(IDENT);
287
    ident := unit.idents.last(IDENT);
325
    WHILE (ident # NIL) & (ident.typ # idGUARD) DO
288
    WHILE (ident # NIL) & (ident.typ # idGUARD) DO
326
        IF (ident.typ = idVAR) & (ident.offset = -1) THEN
289
        IF (ident.typ = idVAR) & (ident.offset = -1) THEN
327
            ERRORS.hintmsg(ident.name.s, ident.pos.line, ident.pos.col, 0);
290
            ERRORS.HintMsg(ident.name.s, ident.pos.line, ident.pos.col, 0);
328
            IF ident.export THEN
291
            IF ident.export THEN
Line 341... Line 304...
341
        END;
304
        END;
342
        ident := prev
305
        ident := prev
343
    END;
306
    END;
Line 344... Line 307...
344
 
307
 
345
    unit.closed := TRUE
308
    unit.closed := TRUE
Line 346... Line 309...
346
END close;
309
END closeUnit;
347
 
310
 
348
 
311
 
Line 360... Line 323...
360
 
323
 
361
    RETURN item.typ = idGUARD
324
    RETURN item.typ = idGUARD
Line 362... Line 325...
362
END unique;
325
END unique;
363
 
326
 
364
 
327
 
365
PROCEDURE addIdent (unit: UNIT; ident: SCAN.IDENT; typ: INTEGER): IDENT;
328
PROCEDURE addIdent* (unit: UNIT; ident: SCAN.IDENT; typ: INTEGER): IDENT;
366
VAR
329
VAR
367
    item:   IDENT;
330
    item:  IDENT;
Line 436... Line 399...
436
        END
399
        END
437
    END
400
    END
438
END UseProc;
401
END UseProc;
Line 439... Line 402...
439
 
402
 
440
 
403
 
441
PROCEDURE setvars (unit: UNIT; type: TYPE_);
404
PROCEDURE setVarsType* (unit: UNIT; type: TYPE_);
Line 442... Line 405...
442
VAR
405
VAR
443
    item: IDENT;
406
    item: IDENT;
Line 448... Line 411...
448
    item := unit.idents.last(IDENT);
411
    item := unit.idents.last(IDENT);
449
    WHILE (item # NIL) & (item.typ = idVAR) & (item.type = NIL) DO
412
    WHILE (item # NIL) & (item.typ = idVAR) & (item.type = NIL) DO
450
        item.type := type;
413
        item.type := type;
451
        item := item.prev(IDENT)
414
        item := item.prev(IDENT)
452
    END
415
    END
453
END setvars;
416
END setVarsType;
Line 454... Line 417...
454
 
417
 
455
 
418
 
456
PROCEDURE getIdent (unit: UNIT; ident: SCAN.IDENT; currentScope: BOOLEAN): IDENT;
419
PROCEDURE getIdent* (unit: UNIT; ident: SCAN.IDENT; currentScope: BOOLEAN): IDENT;
Line 457... Line 420...
457
VAR
420
VAR
458
    item: IDENT;
421
    item: IDENT;
Line 459... Line 422...
459
 
422
 
Line 460... Line 423...
460
BEGIN
423
BEGIN
Line 461... Line 424...
461
    ASSERT(ident # NIL);
424
    ASSERT(ident # NIL);
462
 
425
 
463
    item := unit.idents.last(IDENT);
426
    item := unit.idents.last(IDENT);
464
 
427
 
Line 475... Line 438...
475
        WHILE (item # NIL) & (item.name # ident) DO
438
            WHILE (item # NIL) & (item.name # ident) DO
476
            item := item.prev(IDENT)
439
                item := item.prev(IDENT)
477
        END
440
            END
478
    END
441
        END
Line -... Line 442...
-
 
442
 
-
 
443
    END
479
 
444
 
480
    RETURN item
445
    RETURN item
Line 481... Line 446...
481
END getIdent;
446
END getIdent;
482
 
447
 
483
 
448
 
484
PROCEDURE openScope (unit: UNIT; proc: PROC): BOOLEAN;
449
PROCEDURE openScope* (unit: UNIT; proc: PROC): BOOLEAN;
Line 485... Line 450...
485
VAR
450
VAR
Line 506... Line 471...
506
 
471
 
507
    RETURN res
472
    RETURN res
Line 508... Line 473...
508
END openScope;
473
END openScope;
509
 
474
 
510
 
475
 
511
PROCEDURE closeScope (unit: UNIT; variables: LISTS.LIST);
476
PROCEDURE closeScope* (unit: UNIT; variables: LISTS.LIST);
512
VAR
477
VAR
Line 513... Line 478...
513
    item: IDENT;
478
    item: IDENT;
514
    del:  IDENT;
479
    del:  IDENT;
Line 515... Line 480...
515
    lvar: CODE.LOCALVAR;
480
    lvar: IL.LOCALVAR;
516
 
481
 
517
BEGIN
482
BEGIN
518
    item := unit.idents.last(IDENT);
483
    item := unit.idents.last(IDENT);
519
 
484
 
520
    WHILE (item # NIL) & (item.typ # idGUARD) DO
485
    WHILE (item # NIL) & (item.typ # idGUARD) DO
521
        del  := item;
486
        del  := item;
522
        item := item.prev(IDENT);
487
        item := item.prev(IDENT);
523
        IF (del.typ = idVAR) & (del.offset = -1) THEN
488
        IF (del.typ = idVAR) & (del.offset = -1) THEN
524
            ERRORS.hintmsg(del.name.s, del.pos.line, del.pos.col, 0)
489
            ERRORS.HintMsg(del.name.s, del.pos.line, del.pos.col, 0)
525
        END;
490
        END;
526
        IF (variables # NIL) & (del.typ IN {idVAR, idPARAM}) & (del.offset # -1) THEN
491
        IF (variables # NIL) & (del.typ IN {idVAR, idPARAM}) & (del.offset # -1) THEN
527
            IF del.type.typ IN BASICTYPES - {tREAL} + {tPOINTER, tPROCEDURE} THEN
492
            IF del.type.typ IN BASICTYPES - {tREAL} + {tPOINTER, tPROCEDURE} THEN
528
                lvar := CODE.NewVar();
493
                lvar := IL.NewVar();
Line 546... Line 511...
546
    DEC(unit.scopeLvl)
511
    DEC(unit.scopeLvl)
Line 547... Line 512...
547
 
512
 
Line 548... Line 513...
548
END closeScope;
513
END closeScope;
549
 
514
 
550
 
515
 
Line 551... Line 516...
551
PROCEDURE frwptr (unit: UNIT; type: TYPE_; baseIdent: SCAN.IDENT; pos: SCAN.POSITION);
516
PROCEDURE frwPtr* (unit: UNIT; type: TYPE_; baseIdent: SCAN.IDENT; pos: SCAN.POSITION);
552
VAR
517
VAR
Line 564... Line 529...
564
    newptr.pos        := pos;
529
    newptr.pos       := pos;
565
    newptr.linked     := FALSE;
530
    newptr.linked    := FALSE;
566
    newptr.notRecord  := FALSE;
531
    newptr.notRecord := FALSE;
Line 567... Line 532...
567
 
532
 
568
    LISTS.push(unit.frwPointers, newptr)
533
    LISTS.push(unit.frwPointers, newptr)
Line 569... Line 534...
569
END frwptr;
534
END frwPtr;
570
 
535
 
571
 
536
 
572
PROCEDURE linkptr (unit: UNIT): FRWPTR;
537
PROCEDURE linkPtr* (unit: UNIT): FRWPTR;
573
VAR
538
VAR
Line 574... Line 539...
574
    item:  FRWPTR;
539
    item:  FRWPTR;
575
    ident: IDENT;
540
    ident: IDENT;
576
    res:   FRWPTR;
541
    res:   FRWPTR;
Line 577... Line 542...
577
 
542
 
578
BEGIN
543
BEGIN
Line 579... Line 544...
579
    res  := NIL;
544
    res  := NIL;
580
    item := unit.frwPointers.last(FRWPTR);
545
    item := unit.frwPointers.last(FRWPTR);
581
 
546
 
582
    WHILE (item # NIL) & ~item.linked & (res = NIL) DO
547
    WHILE (item # NIL) & ~item.linked & (res = NIL) DO
Line 597... Line 562...
597
 
562
 
598
        item := item.prev(FRWPTR)
563
        item := item.prev(FRWPTR)
Line 599... Line 564...
599
    END
564
    END
600
 
565
 
Line 601... Line 566...
601
    RETURN res
566
    RETURN res
602
END linkptr;
567
END linkPtr;
603
 
568
 
Line 615... Line 580...
615
    ELSIF (t1.typ = tPROCEDURE) & (t2.typ = tPROCEDURE) THEN
580
    ELSIF (t1.typ = tPROCEDURE) & (t2.typ = tPROCEDURE) THEN
Line 616... Line 581...
616
 
581
 
617
        param1 := t1.params.first;
582
        param1 := t1.params.first;
Line 618... Line 583...
618
        param2 := t2.params.first;
583
        param2 := t2.params.first;
Line 619... Line 584...
619
 
584
 
620
        res := (t1.call = t2.call) & ((param1 # NIL) = (param2 # NIL));
585
        res := ((t1.call = t2.call) OR (t1.call IN {code, _code}) OR (t2.call IN {code, _code})) & ((param1 # NIL) = (param2 # NIL));
621
 
586
 
622
        WHILE res & (param1 # NIL) & (param2 # NIL) DO
587
        WHILE res & (param1 # NIL) & (param2 # NIL) DO
Line 641... Line 606...
641
PROCEDURE isBaseOf* (t0, t1: TYPE_): BOOLEAN;
606
PROCEDURE isBaseOf* (t0, t1: TYPE_): BOOLEAN;
642
VAR
607
VAR
643
    res: BOOLEAN;
608
    res: BOOLEAN;
Line 644... Line 609...
644
 
609
 
645
BEGIN
610
BEGIN
Line 646... Line 611...
646
    res := ((t0.typ = tPOINTER) & (t1.typ = tPOINTER)) OR ((t0.typ = tRECORD) & (t1.typ = tRECORD));
611
    res := (t0.typ = t1.typ) & (t0.typ IN {tPOINTER, tRECORD});
647
 
612
 
648
    IF (t0.typ = tPOINTER) & (t1.typ = tPOINTER) THEN
613
    IF res & (t0.typ = tPOINTER) THEN
649
        t0 := t0.base;
614
        t0 := t0.base;
Line -... Line 615...
-
 
615
        t1 := t1.base
650
        t1 := t1.base
616
    END;
651
    END;
617
 
-
 
618
    IF res THEN
-
 
619
        WHILE (t1 # NIL) & (t1 # t0) DO
652
 
620
            t1 := t1.base
Line 653... Line 621...
653
    WHILE res & (t1 # NIL) & (t1 # t0) DO
621
        END;
654
        t1 := t1.base
622
        res := t1 # NIL
Line 655... Line 623...
655
    END
623
    END
656
 
624
 
657
    RETURN res & (t1 = t0)
625
    RETURN res
Line 658... Line 626...
658
END isBaseOf;
626
END isBaseOf;
659
 
627
 
660
 
628
 
Line 661... Line 629...
661
PROCEDURE isOpenArray* (t: TYPE_): BOOLEAN;
629
PROCEDURE isOpenArray* (t: TYPE_): BOOLEAN;
662
    RETURN (t.typ = tARRAY) & (t.length = 0)
630
    RETURN (t.typ = tARRAY) & (t.length = 0)
Line 663... Line 631...
663
END isOpenArray;
631
END isOpenArray;
Line 664... Line 632...
664
 
632
 
665
 
633
 
666
PROCEDURE getunit (units: UNITS; name: SCAN.IDENT): UNIT;
634
PROCEDURE getUnit* (program: PROGRAM; name: SCAN.IDENT): UNIT;
Line 667... Line 635...
667
VAR
635
VAR
668
    item: UNIT;
636
    item: UNIT;
669
 
637
 
Line 670... Line 638...
670
BEGIN
638
BEGIN
671
    ASSERT(name # NIL);
639
    ASSERT(name # NIL);
Line 672... Line 640...
672
 
640
 
673
    item := units.first(UNIT);
641
    item := program.units.first(UNIT);
674
 
642
 
675
    WHILE (item # NIL) & (item.name # name) DO
-
 
Line 676... Line 643...
676
        item := item.next(UNIT)
643
    WHILE (item # NIL) & (item.name # name) DO
677
    END;
-
 
678
 
-
 
679
    IF (item = NIL) & (name.s = "SYSTEM") THEN
644
        item := item.next(UNIT)
680
        item := units.program.sysunit
645
    END;
Line 681... Line -...
681
    END
-
 
682
 
646
 
683
    RETURN item
647
    IF (item = NIL) & (name.s = "SYSTEM") THEN
Line 684... Line -...
684
END getunit;
-
 
685
 
648
        item := program.sysunit
686
 
649
    END
Line 687... Line -...
687
PROCEDURE enterStTypes (unit: UNIT; program: PROGRAM);
-
 
688
VAR
650
 
689
    ident:   IDENT;
-
 
690
    stName:  SCAN.IDENT;
-
 
691
 
-
 
692
BEGIN
-
 
693
 
651
    RETURN item
Line 694... Line -...
694
    stName     := SCAN.enterid("INTEGER");
-
 
695
    ident      := addIdent(unit, stName, idTYPE);
652
END getUnit;
696
    ident.type := program.stTypes.tINTEGER;
653
 
Line 697... Line 654...
697
 
654
 
698
    stName     := SCAN.enterid("BYTE");
655
PROCEDURE enterStTypes (unit: UNIT; program: PROGRAM);
699
    ident      := addIdent(unit, stName, idTYPE);
656
VAR
Line -... Line 657...
-
 
657
    ident: IDENT;
-
 
658
 
-
 
659
BEGIN
-
 
660
    ident      := addIdent(unit, SCAN.enterid("INTEGER"), idTYPE);
700
    ident.type := program.stTypes.tBYTE;
661
    ident.type := program.stTypes.tINTEGER;
Line 701... Line 662...
701
 
662
 
Line 702... Line 663...
702
    stName     := SCAN.enterid("CHAR");
663
    ident      := addIdent(unit, SCAN.enterid("BYTE"), idTYPE);
703
    ident      := addIdent(unit, stName, idTYPE);
664
    ident.type := program.stTypes.tBYTE;
704
    ident.type := program.stTypes.tCHAR;
665
 
705
 
666
    ident      := addIdent(unit, SCAN.enterid("CHAR"), idTYPE);
706
    stName     := SCAN.enterid("WCHAR");
667
    ident.type := program.stTypes.tCHAR;
707
    ident      := addIdent(unit, stName, idTYPE);
668
 
708
    ident.type := program.stTypes.tWCHAR;
669
    ident      := addIdent(unit, SCAN.enterid("SET"), idTYPE);
Line -... Line 670...
-
 
670
    ident.type := program.stTypes.tSET;
-
 
671
 
-
 
672
    ident      := addIdent(unit, SCAN.enterid("BOOLEAN"), idTYPE);
-
 
673
    ident.type := program.stTypes.tBOOLEAN;
-
 
674
 
-
 
675
    IF program.target.sys # mConst.Target_iMSP430 THEN
-
 
676
        ident      := addIdent(unit, SCAN.enterid("REAL"), idTYPE);
-
 
677
        ident.type := program.stTypes.tREAL;
-
 
678
 
709
 
679
        ident      := addIdent(unit, SCAN.enterid("WCHAR"), idTYPE);
710
    stName     := SCAN.enterid("SET");
680
        ident.type := program.stTypes.tWCHAR
711
    ident      := addIdent(unit, stName, idTYPE);
681
    END
712
    ident.type := program.stTypes.tSET;
682
 
713
 
683
END enterStTypes;
714
    stName     := SCAN.enterid("BOOLEAN");
684
 
715
    ident      := addIdent(unit, stName, idTYPE);
685
 
716
    ident.type := program.stTypes.tBOOLEAN;
686
PROCEDURE enterStProcs (unit: UNIT);
-
 
687
 
717
 
688
 
718
    stName     := SCAN.enterid("REAL");
689
    PROCEDURE EnterProc (unit: UNIT; name: SCAN.LEXSTR; proc: INTEGER);
719
    ident      := addIdent(unit, stName, idTYPE);
690
    VAR
720
    ident.type := program.stTypes.tREAL;
-
 
721
 
691
        ident: IDENT;
722
END enterStTypes;
692
    BEGIN
723
 
693
        ident := addIdent(unit, SCAN.enterid(name), idSTPROC);
724
 
694
        ident.stproc := proc
725
PROCEDURE enterStProcs (unit: UNIT);
695
    END EnterProc;
726
 
696
 
727
 
697
 
728
    PROCEDURE EnterProc (unit: UNIT; name: SCAN.LEXSTR; idtyp, proc: INTEGER);
698
    PROCEDURE EnterFunc (unit: UNIT; name: SCAN.LEXSTR; func: INTEGER);
729
    VAR
699
    VAR
730
        ident: IDENT;
700
        ident: IDENT;
-
 
701
    BEGIN
-
 
702
        ident := addIdent(unit, SCAN.enterid(name), idSTFUNC);
731
    BEGIN
703
        ident.stproc := func
732
        ident := addIdent(unit, SCAN.enterid(name), idtyp);
704
    END EnterFunc;
733
        ident.stproc := proc
705
 
-
 
706
 
734
    END EnterProc;
707
BEGIN
735
 
708
    EnterProc(unit, "ASSERT", stASSERT);
736
 
709
    EnterProc(unit, "DEC",    stDEC);
-
 
710
    EnterProc(unit, "EXCL",   stEXCL);
-
 
711
    EnterProc(unit, "INC",    stINC);
737
BEGIN
712
    EnterProc(unit, "INCL",   stINCL);
Line 738... Line 713...
738
    EnterProc(unit, "ASSERT",   idSTPROC,  stASSERT);
713
    EnterProc(unit, "NEW",    stNEW);
739
    EnterProc(unit, "DEC",      idSTPROC,  stDEC);
714
    EnterProc(unit, "COPY",   stCOPY);
740
    EnterProc(unit, "EXCL",     idSTPROC,  stEXCL);
715
 
741
    EnterProc(unit, "INC",      idSTPROC,  stINC);
-
 
Line 742... Line 716...
742
    EnterProc(unit, "INCL",     idSTPROC,  stINCL);
716
    EnterFunc(unit, "ABS",    stABS);
743
    EnterProc(unit, "NEW",      idSTPROC,  stNEW);
717
    EnterFunc(unit, "ASR",    stASR);
744
    EnterProc(unit, "PACK",     idSTPROC,  stPACK);
718
    EnterFunc(unit, "CHR",    stCHR);
Line 745... Line 719...
745
    EnterProc(unit, "UNPK",     idSTPROC,  stUNPK);
719
    EnterFunc(unit, "LEN",    stLEN);
Line 746... Line -...
746
    EnterProc(unit, "DISPOSE",  idSTPROC,  stDISPOSE);
-
 
747
    EnterProc(unit, "COPY",     idSTPROC,  stCOPY);
-
 
748
 
-
 
749
    EnterProc(unit, "ABS",      idSTFUNC,  stABS);
-
 
750
    EnterProc(unit, "ASR",      idSTFUNC,  stASR);
-
 
751
    EnterProc(unit, "CHR",      idSTFUNC,  stCHR);
-
 
752
    EnterProc(unit, "WCHR",     idSTFUNC,  stWCHR);
720
    EnterFunc(unit, "LSL",    stLSL);
753
    EnterProc(unit, "FLOOR",    idSTFUNC,  stFLOOR);
721
    EnterFunc(unit, "ODD",    stODD);
754
    EnterProc(unit, "FLT",      idSTFUNC,  stFLT);
722
    EnterFunc(unit, "ORD",    stORD);
755
    EnterProc(unit, "LEN",      idSTFUNC,  stLEN);
723
    EnterFunc(unit, "ROR",    stROR);
756
    EnterProc(unit, "LSL",      idSTFUNC,  stLSL);
724
    EnterFunc(unit, "BITS",   stBITS);
Line 757... Line -...
757
    EnterProc(unit, "ODD",      idSTFUNC,  stODD);
-
 
758
    EnterProc(unit, "ORD",      idSTFUNC,  stORD);
-
 
759
    EnterProc(unit, "ROR",      idSTFUNC,  stROR);
-
 
760
    EnterProc(unit, "BITS",     idSTFUNC,  stBITS);
-
 
761
    EnterProc(unit, "LSR",      idSTFUNC,  stLSR);
-
 
762
    EnterProc(unit, "LENGTH",   idSTFUNC,  stLENGTH);
-
 
763
    EnterProc(unit, "MIN",      idSTFUNC,  stMIN);
-
 
764
    EnterProc(unit, "MAX",      idSTFUNC,  stMAX);
725
    EnterFunc(unit, "LSR",    stLSR);
Line 765... Line 726...
765
END enterStProcs;
726
    EnterFunc(unit, "LENGTH", stLENGTH);
766
 
727
    EnterFunc(unit, "MIN",    stMIN);
Line 767... Line 728...
767
 
728
    EnterFunc(unit, "MAX",    stMAX);
Line 768... Line 729...
768
PROCEDURE newunit (units: UNITS; name: SCAN.IDENT): UNIT;
729
 
Line 769... Line 730...
769
VAR
730
    IF unit.program.target.sys # mConst.Target_iMSP430 THEN
Line 770... Line 731...
770
    unit:    UNIT;
731
        EnterProc(unit, "PACK",    stPACK);
771
    idents:  IDENTS;
732
        EnterProc(unit, "UNPK",    stUNPK);
Line 772... Line 733...
772
 
733
        EnterProc(unit, "DISPOSE", stDISPOSE);
Line 773... Line 734...
773
BEGIN
734
 
774
    ASSERT(units # NIL);
735
        EnterFunc(unit, "WCHR",    stWCHR);
775
    ASSERT(name # NIL);
736
        EnterFunc(unit, "FLOOR",   stFLOOR);
Line 776... Line 737...
776
 
737
        EnterFunc(unit, "FLT",     stFLT)
777
    NEW(unit);
738
    END
Line 778... Line 739...
778
 
739
 
779
    NEW(idents);
740
END enterStProcs;
780
    ASSERT(LISTS.create(idents) = idents);
741
 
Line 781... Line 742...
781
 
742
 
782
    idents.add       := addIdent;
743
PROCEDURE newUnit* (program: PROGRAM; name: SCAN.IDENT): UNIT;
Line 849... Line 810...
849
 
810
 
850
    RETURN field
811
    RETURN field
Line 851... Line 812...
851
END getField;
812
END getField;
852
 
813
 
853
 
814
 
854
PROCEDURE addField (self: TYPE_; name: SCAN.IDENT; export: BOOLEAN): BOOLEAN;
815
PROCEDURE addField* (self: TYPE_; name: SCAN.IDENT; export: BOOLEAN): BOOLEAN;
Line 855... Line 816...
855
VAR
816
VAR
Line 874... Line 835...
874
 
835
 
875
    RETURN res
836
    RETURN res
Line 876... Line 837...
876
END addField;
837
END addField;
877
 
838
 
878
 
839
 
879
PROCEDURE setFields (self: TYPE_; type: TYPE_): BOOLEAN;
840
PROCEDURE setFields* (self: TYPE_; type: TYPE_): BOOLEAN;
Line 880... Line 841...
880
VAR
841
VAR
Line 893... Line 854...
893
    res := TRUE;
854
    res := TRUE;
Line 894... Line 855...
894
 
855
 
895
    WHILE res & (item # NIL) & (item.type = NIL) DO
856
    WHILE res & (item # NIL) & (item.type = NIL) DO
896
        item.type := type;
857
        item.type := type;
897
        IF ~self.noalign THEN
858
        IF ~self.noalign THEN
898
            res := MACHINE.Align(self.size, type.align)
859
            res := UTILS.Align(self.size, type.align)
899
        ELSE
860
        ELSE
900
            res := TRUE
861
            res := TRUE
901
        END;
862
        END;
902
        item.offset := self.size;
863
        item.offset := self.size;
Line 909... Line 870...
909
 
870
 
910
    RETURN res
871
    RETURN res
Line 911... Line 872...
911
END setFields;
872
END setFields;
912
 
873
 
913
 
874
 
Line 914... Line 875...
914
PROCEDURE getParam (self: TYPE_; name: SCAN.IDENT): PARAM;
875
PROCEDURE getParam* (self: TYPE_; name: SCAN.IDENT): PARAM;
915
VAR
876
VAR
Line 926... Line 887...
926
 
887
 
927
    RETURN item
888
    RETURN item
Line 928... Line 889...
928
END getParam;
889
END getParam;
929
 
890
 
930
 
891
 
931
PROCEDURE addParam (self: TYPE_; name: SCAN.IDENT; vPar: BOOLEAN): BOOLEAN;
892
PROCEDURE addParam* (self: TYPE_; name: SCAN.IDENT; vPar: BOOLEAN): BOOLEAN;
Line 932... Line 893...
932
VAR
893
VAR
933
    param:  PARAM;
894
    param: PARAM;
Line 934... Line 895...
934
    res:    BOOLEAN;
895
    res:   BOOLEAN;
Line 935... Line 896...
935
 
896
 
936
BEGIN
897
BEGIN
Line 937... Line 898...
937
    ASSERT(name # NIL);
898
    ASSERT(name # NIL);
Line 971... Line 932...
971
    WHILE isOpenArray(t) DO t := t.base END
932
    WHILE isOpenArray(t) DO t := t.base END
972
    RETURN t
933
    RETURN t
973
END OpenBase;
934
END OpenBase;
Line 974... Line 935...
974
 
935
 
975
 
936
 
976
PROCEDURE getFloatParamsPos (self: TYPE_; maxoffs: INTEGER; VAR int, flt: INTEGER): SET;
937
PROCEDURE getFloatParamsPos* (self: TYPE_; maxoffs: INTEGER; VAR int, flt: INTEGER): SET;
977
VAR
938
VAR
Line 978... Line 939...
978
    res: SET;
939
    res: SET;
Line 989... Line 950...
989
            INC(flt)
950
            INC(flt)
990
        END;
951
        END;
991
        param := param.next(PARAM)
952
        param := param.next(PARAM)
992
    END;
953
    END;
Line 993... Line 954...
993
 
954
 
Line 994... Line 955...
994
    int := self.params.size - flt
955
    int := self.parSize - flt
995
 
956
 
Line 996... Line 957...
996
    RETURN res
957
    RETURN res
997
END getFloatParamsPos;
958
END getFloatParamsPos;
998
 
959
 
999
 
960
 
1000
PROCEDURE setParams (self: TYPE_; type: TYPE_);
961
PROCEDURE setParams* (self: TYPE_; type: TYPE_);
Line 1001... Line 962...
1001
VAR
962
VAR
1002
    item: LISTS.ITEM;
963
    item: LISTS.ITEM;
Line 1003... Line 964...
1003
    param: PARAM;
964
    param: PARAM;
Line 1004... Line 965...
1004
    word, size: INTEGER;
965
    word, size: INTEGER;
Line 1005... Line 966...
1005
 
966
 
1006
BEGIN
967
BEGIN
Line 1023... Line 984...
1023
            ELSIF isOpenArray(type) THEN
984
            ELSIF isOpenArray(type) THEN
1024
                size := Dim(type) + 1
985
                size := Dim(type) + 1
1025
            ELSE
986
            ELSE
1026
                size := 1
987
                size := 1
1027
            END;
988
            END;
1028
            param.offset := self.params.size + ORD(type.typ = tRECORD) + Dim(type) + STACK_FRAME;
989
            param.offset := self.parSize + ORD(type.typ = tRECORD) + Dim(type) + STACK_FRAME;
1029
            INC(self.params.size, size)
990
            INC(self.parSize, size)
1030
        ELSE
991
        ELSE
1031
            IF type.typ IN {tRECORD, tARRAY} THEN
992
            IF type.typ IN {tRECORD, tARRAY} THEN
1032
                IF isOpenArray(type) THEN
993
                IF isOpenArray(type) THEN
1033
                    size := Dim(type) + 1
994
                    size := Dim(type) + 1
1034
                ELSE
995
                ELSE
1035
                    size := 1
996
                    size := 1
1036
                END
997
                END
1037
            ELSE
998
            ELSE
1038
                size := type.size;
999
                size := type.size;
1039
                ASSERT(MACHINE.Align(size, word));
1000
                ASSERT(UTILS.Align(size, word));
1040
                size := size DIV word
1001
                size := size DIV word
1041
            END;
1002
            END;
1042
            param.offset := self.params.size + Dim(type) + STACK_FRAME;
1003
            param.offset := self.parSize + Dim(type) + STACK_FRAME;
1043
            INC(self.params.size, size)
1004
            INC(self.parSize, size)
1044
        END;
1005
        END;
Line 1045... Line 1006...
1045
 
1006
 
1046
        item := item.next
1007
        item := item.next
Line 1047... Line 1008...
1047
    END
1008
    END
Line 1048... Line 1009...
1048
 
1009
 
1049
END setParams;
1010
END setParams;
1050
 
1011
 
1051
 
-
 
1052
PROCEDURE enterType (program: PROGRAM; typ, size, length: INTEGER; unit: UNIT): TYPE_;
-
 
Line 1053... Line 1012...
1053
VAR
1012
 
1054
    t:        TYPE_;
1013
PROCEDURE enterType* (program: PROGRAM; typ, size, length: INTEGER; unit: UNIT): TYPE_;
Line 1055... Line -...
1055
    fields:   FIELDS;
-
 
1056
    params:   PARAMS;
-
 
1057
 
-
 
1058
BEGIN
-
 
1059
    NEW(t);
-
 
1060
 
-
 
1061
    NEW(fields);
1014
VAR
1062
    ASSERT(LISTS.create(fields) = fields);
1015
    t: TYPE_;
1063
 
1016
 
1064
    NEW(params);
1017
BEGIN
1065
    ASSERT(LISTS.create(params) = params);
1018
    NEW(t);
1066
 
1019
 
1067
    t.typ     := typ;
1020
    t.typ     := typ;
1068
    t.size    := size;
1021
    t.size    := size;
1069
    t.length  := length;
1022
    t.length  := length;
-
 
1023
    t.align   := 0;
1070
    t.align   := 0;
1024
    t.base    := NIL;
1071
    t.base    := NIL;
1025
    t.fields  := LISTS.create(NIL);
1072
    t.fields  := fields;
1026
    t.params  := LISTS.create(NIL);
1073
    t.params  := params;
1027
    t.unit    := unit;
1074
    t.unit    := unit;
1028
    t.num     := 0;
-
 
1029
 
1075
    t.num     := 0;
1030
    CASE program.target.bit_depth OF
1076
    IF program.target.bit_depth = 32 THEN
1031
    |16: t.call := default16
1077
        t.call := default
-
 
1078
    ELSIF program.target.bit_depth = 64 THEN
-
 
1079
        t.call := default64
-
 
1080
    END;
-
 
1081
    t.import  := FALSE;
-
 
1082
    t.noalign := FALSE;
-
 
1083
 
-
 
1084
    t.fields.add := addField;
-
 
1085
    t.fields.get := getField;
-
 
1086
    t.fields.set := setFields;
1032
    |32: t.call := default32
Line 1087... Line 1033...
1087
 
1033
    |64: t.call := default64
1088
    t.params.add := addParam;
1034
    END;
1089
    t.params.get := getParam;
1035
 
1090
    t.params.getfparams := getFloatParamsPos;
1036
    t.import  := FALSE;
Line 1105... Line 1051...
1105
 
1051
 
1106
    RETURN t
1052
    RETURN t
Line 1107... Line 1053...
1107
END enterType;
1053
END enterType;
1108
 
1054
 
1109
 
1055
 
Line 1110... Line 1056...
1110
PROCEDURE getType (program: PROGRAM; typ: INTEGER): TYPE_;
1056
PROCEDURE getType* (program: PROGRAM; typ: INTEGER): TYPE_;
Line 1152... Line 1098...
1152
        ident.export := TRUE
1098
        ident.export := TRUE
1153
    END EnterProc;
1099
    END EnterProc;
Line 1154... Line 1100...
1154
 
1100
 
1155
 
1101
 
Line 1156... Line 1102...
1156
BEGIN
1102
BEGIN
1157
    unit := program.units.create(program.units, SCAN.enterid("$SYSTEM"));
1103
    unit := newUnit(program, SCAN.enterid("$SYSTEM"));
1158
 
1104
 
1159
    EnterProc(unit, "ADR",    idSYSFUNC, sysADR);
-
 
1160
    EnterProc(unit, "SIZE",   idSYSFUNC, sysSIZE);
1105
    EnterProc(unit, "ADR",    idSYSFUNC, sysADR);
1161
    EnterProc(unit, "SADR",   idSYSFUNC, sysSADR);
-
 
Line 1162... Line 1106...
1162
    EnterProc(unit, "WSADR",  idSYSFUNC, sysWSADR);
1106
    EnterProc(unit, "SIZE",   idSYSFUNC, sysSIZE);
1163
    EnterProc(unit, "TYPEID", idSYSFUNC, sysTYPEID);
-
 
1164
    EnterProc(unit, "INF",    idSYSFUNC, sysINF);
1107
    EnterProc(unit, "SADR",   idSYSFUNC, sysSADR);
1165
 
-
 
1166
    EnterProc(unit, "GET",    idSYSPROC, sysGET);
1108
    EnterProc(unit, "TYPEID", idSYSFUNC, sysTYPEID);
1167
    EnterProc(unit, "PUT",    idSYSPROC, sysPUT);
1109
 
1168
    EnterProc(unit, "PUT8",   idSYSPROC, sysPUT8);
1110
    EnterProc(unit, "GET",    idSYSPROC, sysGET);
-
 
1111
    EnterProc(unit, "PUT8",   idSYSPROC, sysPUT8);
-
 
1112
    EnterProc(unit, "PUT",    idSYSPROC, sysPUT);
-
 
1113
    EnterProc(unit, "CODE",   idSYSPROC, sysCODE);
-
 
1114
    EnterProc(unit, "MOVE",   idSYSPROC, sysMOVE);
-
 
1115
           (*
-
 
1116
    IF program.target.sys = mConst.Target_iMSP430 THEN
-
 
1117
        EnterProc(unit, "NOP",  idSYSPROC, sysNOP);
-
 
1118
        EnterProc(unit, "EINT", idSYSPROC, sysEINT);
-
 
1119
        EnterProc(unit, "DINT", idSYSPROC, sysDINT)
-
 
1120
    END;
-
 
1121
         *)
-
 
1122
    IF program.target.sys # mConst.Target_iMSP430 THEN
1169
    EnterProc(unit, "PUT16",  idSYSPROC, sysPUT16);
1123
        EnterProc(unit, "WSADR",  idSYSFUNC, sysWSADR);
Line 1170... Line 1124...
1170
    EnterProc(unit, "PUT32",  idSYSPROC, sysPUT32);
1124
        EnterProc(unit, "INF",    idSYSFUNC, sysINF);
1171
    EnterProc(unit, "CODE",   idSYSPROC, sysCODE);
1125
        EnterProc(unit, "PUT32",  idSYSPROC, sysPUT32);
1172
    EnterProc(unit, "MOVE",   idSYSPROC, sysMOVE);
1126
        EnterProc(unit, "PUT16",  idSYSPROC, sysPUT16);
Line 1173... Line 1127...
1173
    EnterProc(unit, "COPY",   idSYSPROC, sysCOPY);
1127
        EnterProc(unit, "COPY",   idSYSPROC, sysCOPY);
1174
 
1128
 
1175
    ident := addIdent(unit, SCAN.enterid("CARD16"), idTYPE);
1129
        ident := addIdent(unit, SCAN.enterid("CARD16"), idTYPE);
-
 
1130
        ident.type := program.stTypes.tCARD16;
Line 1176... Line 1131...
1176
    ident.type := program.stTypes.tCARD16;
1131
        ident.export := TRUE;
Line 1177... Line 1132...
1177
    ident.export := TRUE;
1132
 
1178
 
1133
        ident := addIdent(unit, SCAN.enterid("CARD32"), idTYPE);
Line 1209... Line 1164...
1209
 
1164
 
Line 1210... Line 1165...
1210
 
1165
 
1211
BEGIN
-
 
1212
 
1166
BEGIN
1213
    REPEAT
1167
 
Line 1214... Line 1168...
1214
 
1168
    REPEAT
1215
        flag := FALSE;
1169
        flag := FALSE;
Line 1228... Line 1182...
1228
    proc := program.procs.first(PROC);
1182
    proc := program.procs.first(PROC);
Line 1229... Line 1183...
1229
 
1183
 
1230
    WHILE proc # NIL DO
1184
    WHILE proc # NIL DO
1231
        IF ~proc.used THEN
1185
        IF ~proc.used THEN
1232
            IF proc.import = NIL THEN
1186
            IF proc.import = NIL THEN
1233
                CODE.delete2(proc.enter, proc.leave)
1187
                IL.delete2(proc.enter, proc.leave)
1234
            ELSE
1188
            ELSE
1235
                DelImport(proc.import)
1189
                DelImport(proc.import)
1236
            END
1190
            END
1237
        END;
1191
        END;
1238
        proc := proc.next(PROC)
1192
        proc := proc.next(PROC)
Line 1239... Line 1193...
1239
    END
1193
    END
Line 1240... Line 1194...
1240
 
1194
 
1241
END DelUnused;
1195
END DelUnused;
1242
 
1196
 
1243
 
-
 
Line 1244... Line 1197...
1244
PROCEDURE create* (bit_depth, sys: INTEGER): PROGRAM;
1197
 
1245
VAR
1198
PROCEDURE create* (bit_depth, target: INTEGER; options: OPTIONS): PROGRAM;
Line 1246... Line 1199...
1246
    program: PROGRAM;
1199
VAR
1247
    units:   UNITS;
1200
    program: PROGRAM;
1248
 
-
 
1249
BEGIN
-
 
Line 1250... Line 1201...
1250
    idents := C.create();
1201
 
1251
 
1202
BEGIN
1252
    MACHINE.SetBitDepth(bit_depth);
1203
    idents := C.create();
1253
    NEW(program);
1204
 
-
 
1205
    UTILS.SetBitDepth(bit_depth);
-
 
1206
    NEW(program);
-
 
1207
 
-
 
1208
    program.target.bit_depth := bit_depth;
-
 
1209
    program.target.word      := bit_depth DIV 8;
-
 
1210
    program.target.adr       := bit_depth DIV 8;
-
 
1211
    program.target.sys       := target;
-
 
1212
    program.target.options   := options;
-
 
1213
 
-
 
1214
    CASE target OF
-
 
1215
    |mConst.Target_iConsole,
-
 
1216
     mConst.Target_iGUI,
-
 
1217
     mConst.Target_iDLL:        program.target.sysflags := {sf_windows, sf_stdcall, sf_ccall, sf_ccall16, sf_noalign}
-
 
1218
 
-
 
1219
    |mConst.Target_iELF32,
-
 
1220
     mConst.Target_iELFSO32:    program.target.sysflags := {sf_linux, sf_stdcall, sf_ccall, sf_ccall16, sf_noalign}
-
 
1221
 
-
 
1222
    |mConst.Target_iKolibri,
-
 
1223
     mConst.Target_iObject:     program.target.sysflags := {sf_stdcall, sf_ccall, sf_ccall16, sf_noalign}
-
 
1224
 
-
 
1225
    |mConst.Target_iConsole64,
-
 
1226
     mConst.Target_iGUI64,
Line 1254... Line 1227...
1254
    NEW(units);
1227
     mConst.Target_iDLL64:      program.target.sysflags := {sf_windows, sf_stdcall64, sf_win64, sf_systemv, sf_noalign}
1255
    ASSERT(LISTS.create(units) = units);
1228
 
Line 1256... Line 1229...
1256
 
1229
    |mConst.Target_iELF64,
1257
    program.target.bit_depth := bit_depth;
1230
     mConst.Target_iELFSO64:    program.target.sysflags := {sf_linux, sf_stdcall64, sf_win64, sf_systemv, sf_noalign}
1258
    program.target.word      := bit_depth DIV 8;
-
 
1259
    program.target.adr       := bit_depth DIV 8;
1231
 
Line 1260... Line -...
1260
    program.target.sys       := sys;
-
 
1261
 
-
 
1262
    program.recCount := -1;
-
 
1263
    program.bss := 0;
1232
    |mConst.Target_iMSP430:     program.target.sysflags := {sf_code}
1264
 
1233
    END;
1265
    program.units := units;
1234
 
1266
    program.types := LISTS.create(NIL);
-
 
1267
 
1235
    program.recCount := -1;
1268
    program.procs := LISTS.create(NIL);
1236
    program.bss := 0;
-
 
1237
 
-
 
1238
    program.units := LISTS.create(NIL);
-
 
1239
    program.types := LISTS.create(NIL);
1269
 
1240
    program.procs := LISTS.create(NIL);
-
 
1241
 
-
 
1242
    program.stTypes.tINTEGER := enterType(program, tINTEGER,  program.target.word, 0, NIL);
-
 
1243
    program.stTypes.tBYTE    := enterType(program, tBYTE,                       1, 0, NIL);
-
 
1244
    program.stTypes.tCHAR    := enterType(program, tCHAR,                       1, 0, NIL);
1270
    program.enterType := enterType;
1245
    program.stTypes.tSET     := enterType(program, tSET,      program.target.word, 0, NIL);
1271
    program.getType   := getType;
1246
    program.stTypes.tBOOLEAN := enterType(program, tBOOLEAN,                    1, 0, NIL);
1272
 
-
 
1273
    program.stTypes.tINTEGER := enterType(program, tINTEGER,  program.target.word, 0, NIL);
-
 
-
 
1247
 
1274
    program.stTypes.tBYTE    := enterType(program, tBYTE,                       1, 0, NIL);
1248
    IF target # mConst.Target_iMSP430 THEN
1275
    program.stTypes.tCHAR    := enterType(program, tCHAR,                       1, 0, NIL);
1249
        program.stTypes.tWCHAR   := enterType(program, tWCHAR,  2, 0, NIL);
Line 1276... Line 1250...
1276
    program.stTypes.tWCHAR   := enterType(program, tWCHAR,                      2, 0, NIL);
1250
        program.stTypes.tREAL    := enterType(program, tREAL,   8, 0, NIL);
1277
    program.stTypes.tSET     := enterType(program, tSET,      program.target.word, 0, NIL);
1251
        program.stTypes.tCARD16  := enterType(program, tCARD16, 2, 0, NIL);
1278
    program.stTypes.tBOOLEAN := enterType(program, tBOOLEAN,                    1, 0, NIL);
1252
        program.stTypes.tCARD32  := enterType(program, tCARD32, 4, 0, NIL)
1279
    program.stTypes.tREAL    := enterType(program, tREAL,                       8, 0, NIL);
-
 
1280
    program.stTypes.tSTRING  := enterType(program, tSTRING,   program.target.word, 0, NIL);
1253
    END;
1281
    program.stTypes.tNIL     := enterType(program, tNIL,      program.target.word, 0, NIL);
1254
 
-
 
1255
    program.stTypes.tSTRING  := enterType(program, tSTRING, program.target.word, 0, NIL);
-
 
1256
    program.stTypes.tNIL     := enterType(program, tNIL,    program.target.word, 0, NIL);
-
 
1257
 
1282
    program.stTypes.tCARD16  := enterType(program, tCARD16,                     2, 0, NIL);
1258
    program.stTypes.tANYREC  := enterType(program, tRECORD, 0, 0, NIL);
1283
    program.stTypes.tCARD32  := enterType(program, tCARD32,                     4, 0, NIL);
1259
    program.stTypes.tANYREC.closed := TRUE;
1284
    program.stTypes.tANYREC  := enterType(program, tRECORD,                     0, 0, NIL);
1260
 
1285
    program.stTypes.tANYREC.closed := TRUE;
-
 
1286
 
-
 
1287
    program.stTypes.tINTEGER.align := program.stTypes.tINTEGER.size;
-
 
1288
    program.stTypes.tBYTE.align    := 1;
-
 
1289
    program.stTypes.tCHAR.align    := program.stTypes.tCHAR.size;
1261
    program.stTypes.tINTEGER.align := program.stTypes.tINTEGER.size;
Line 1290... Line 1262...
1290
    program.stTypes.tWCHAR.align   := program.stTypes.tWCHAR.size;
1262
    program.stTypes.tBYTE.align    := 1;
1291
    program.stTypes.tSET.align     := program.stTypes.tSET.size;
1263
    program.stTypes.tCHAR.align    := program.stTypes.tCHAR.size;
Line 1292... Line 1264...
1292
    program.stTypes.tBOOLEAN.align := program.stTypes.tBOOLEAN.size;
1264
    program.stTypes.tSET.align     := program.stTypes.tSET.size;