1
{****************************************************************}
2
{ CODE GENERATOR TEST PROGRAM }
3
{ By Carl Eric Codere }
4
{****************************************************************}
5
{ NODE TESTED : secondcallparan() }
6
{****************************************************************}
7
{ PRE-REQUISITES: secondload() }
13
{****************************************************************}
15
{ FPC = Target is FreePascal compiler }
16
{****************************************************************}
17
{ REMARKS: This tests a subset of the secondcalln() node }
18
{ (const parameters) }
19
{****************************************************************}
31
{ REAL should map to single or double }
32
{ so it is not checked, since single }
33
{ double nodes are checked. }
35
{ assumes that enumdef is the same as orddef (same storage format) }
38
{ should be defined depending on CPU target }
45
SMALL_INDEX = 13; { value should not be aligned! }
49
SMALL_INDEX = 13; { value should not be aligned! }
52
RESULT_U16BIT = $500F;
53
RESULT_S32BIT = $500F0000;
54
RESULT_S64BIT = $500F0000;
55
RESULT_S32REAL = 1777.12;
56
RESULT_S64REAL = 3444.24;
60
RESULT_PCHAR = 'Hello world';
61
RESULT_BIGSTRING = 'Hello world';
62
RESULT_SMALLSTRING = 'H';
64
RESULT_BOOLEAN = TRUE;
74
tprocedure = procedure;
77
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
79
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
85
tlargerecord = packed record
86
b: array[1..BIG_INDEX] of byte;
89
tsmallarray = packed array[1..SMALL_INDEX] of byte;
94
tsmallset = set of tsmallsetenum;
95
tlargeset = set of char;
97
tsmallstring = string[2];
105
global_u16bit : word;
106
global_s32bit : longint;
107
global_s32real : single;
108
global_s64real : double;
110
global_proc : tprocedure;
111
global_bigstring : shortstring;
112
global_boolean : boolean;
116
value_s32bit : longint;
118
global_class : tclass1;
119
global_s64bit : int64;
120
value_s64bit : int64;
121
value_class : tclass1;
123
value_s32real : single;
124
value_s64real : double;
125
value_proc : tprocedure;
127
value_smallrec : tsmallrecord;
128
value_largerec : tlargerecord;
129
value_smallset : tsmallset;
130
value_smallstring : tsmallstring;
131
value_bigstring : shortstring;
132
value_largeset : tlargeset;
133
value_smallarray : tsmallarray;
134
value_boolean : boolean;
144
procedure clear_globals;
149
global_s32real := 0.0;
150
global_s64real := 0.0;
153
global_bigstring := '';
154
global_boolean := false;
163
procedure clear_values;
168
value_s32real := 0.0;
169
value_s64real := 0.0;
176
fillchar(value_smallrec, sizeof(value_smallrec), #0);
177
fillchar(value_largerec, sizeof(value_largerec), #0);
178
value_smallset := [];
179
value_smallstring := '';
180
value_bigstring := '';
181
value_largeset := [];
182
fillchar(value_smallarray, sizeof(value_smallarray), #0);
183
value_boolean := false;
188
procedure testprocedure;
192
function getu8bit : byte;
194
getu8bit:=RESULT_U8BIT;
197
function getu16bit: word;
199
getu16bit:=RESULT_U16BIT;
202
function gets32bit: longint;
204
gets32bit:=RESULT_S32BIT;
207
function gets64bit: int64;
209
gets64bit:=RESULT_S64BIT;
213
function gets32real: single;
215
gets32real:=RESULT_S32REAL;
218
function gets64real: double;
220
gets64real:=RESULT_S64REAL;
223
{************************************************************************}
225
{************************************************************************}
226
procedure proc_const_s32bit(const v : longint);
232
procedure proc_const_s64bit(const v: int64);
237
procedure proc_const_smallarray_const_1(const arr : array of const);
241
for i:=0 to high(arr) do
244
vtInteger : global_u8bit := arr[i].vinteger and $ff;
245
vtBoolean : global_boolean := arr[i].vboolean;
246
vtChar : global_char := arr[i].vchar;
247
vtExtended : global_s64real := arr[i].VExtended^;
248
vtString : global_bigstring := arr[i].VString^;
250
vtPChar : global_ptr := arr[i].VPchar;
252
{ vtClass : global_class := (arr[i].VClass) as tclass1;}
254
vtInt64 : global_s64bit := arr[i].vInt64^;
262
procedure proc_const_smallarray_const_2(const arr : array of const);
267
global_u8bit := RESULT_U8BIT;
273
procedure proc_const_smallrecord(const smallrec : tsmallrecord);
275
if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
276
global_u8bit := RESULT_U8BIT;
280
procedure proc_const_largerecord(const largerec : tlargerecord);
282
if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
283
global_u8bit := RESULT_U8BIT;
286
procedure proc_const_smallset(const smallset : tsmallset);
288
if A_D in smallset then
289
global_u8bit := RESULT_U8BIT;
293
procedure proc_const_largeset(const largeset : tlargeset);
295
if 'I' in largeset then
296
global_u8bit := RESULT_U8BIT;
300
procedure proc_const_smallstring(const s:tsmallstring);
302
if s = RESULT_SMALLSTRING then
303
global_u8bit := RESULT_u8BIT;
307
procedure proc_const_bigstring(const s:shortstring);
309
if s = RESULT_BIGSTRING then
310
global_u8bit := RESULT_u8BIT;
314
procedure proc_const_smallarray(const arr : tsmallarray);
316
if arr[SMALL_INDEX] = RESULT_U8BIT then
317
global_u8bit := RESULT_U8BIT;
320
procedure proc_const_smallarray_open(const arr : array of byte);
322
{ form 0 to N-1 indexes in open arrays }
323
if arr[SMALL_INDEX-1] = RESULT_U8BIT then
324
global_u8bit := RESULT_U8BIT;
330
procedure proc_const_formaldef_array(const buf);
334
{ array is indexed from 1 }
336
global_u8bit := byte(p[SMALL_INDEX-1]);
340
{************************************************************************}
341
{ MIXED CONST PARAMETERS }
342
{************************************************************************}
343
procedure proc_const_s32bit_mixed(b1: byte; const v : longint; b2: byte);
350
procedure proc_const_s64bit_mixed(b1 : byte; const v: int64; b2: byte);
356
procedure proc_const_smallarray_const_1_mixed(b1 : byte; const arr : array of const; b2: byte);
360
for i:=0 to high(arr) do
363
vtInteger : global_u8bit := arr[i].vinteger and $ff;
364
vtBoolean : global_boolean := arr[i].vboolean;
365
vtChar : global_char := arr[i].vchar;
366
vtExtended : global_s64real := arr[i].VExtended^;
367
vtString : global_bigstring := arr[i].VString^;
369
vtPChar : global_ptr := arr[i].VPchar;
371
{ vtClass : global_class := (arr[i].VClass) as tclass1;}
373
vtInt64 : global_s64bit := arr[i].vInt64^;
382
procedure proc_const_smallarray_const_2_mixed(b1: byte; const arr : array of const; b2: byte);
387
global_u8bit := RESULT_U8BIT;
393
procedure proc_const_smallrecord_mixed(b1 : byte; const smallrec : tsmallrecord; b2: byte);
395
if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
396
global_u8bit := RESULT_U8BIT;
401
procedure proc_const_largerecord_mixed(b1: byte; const largerec : tlargerecord; b2: byte);
403
if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
404
global_u8bit := RESULT_U8BIT;
408
procedure proc_const_smallset_mixed(b1: byte; const smallset : tsmallset; b2: byte);
410
if A_D in smallset then
411
global_u8bit := RESULT_U8BIT;
416
procedure proc_const_largeset_mixed(b1: byte; const largeset : tlargeset; b2: byte);
418
if 'I' in largeset then
419
global_u8bit := RESULT_U8BIT;
424
procedure proc_const_smallstring_mixed(b1: byte; const s:tsmallstring; b2: byte);
426
if s = RESULT_SMALLSTRING then
427
global_u8bit := RESULT_u8BIT;
432
procedure proc_const_bigstring_mixed(b1: byte; const s:shortstring; b2: byte);
434
if s = RESULT_BIGSTRING then
435
global_u8bit := RESULT_u8BIT;
440
procedure proc_const_smallarray_mixed(b1: byte; const arr : tsmallarray; b2: byte);
442
if arr[SMALL_INDEX] = RESULT_U8BIT then
443
global_u8bit := RESULT_U8BIT;
447
procedure proc_const_smallarray_open_mixed(b1: byte; const arr : array of byte; b2: byte);
449
{ form 0 to N-1 indexes in open arrays }
450
if arr[high(arr)] = RESULT_U8BIT then
451
global_u8bit := RESULT_U8BIT;
458
procedure proc_const_formaldef_array_mixed(b1: byte; const buf; b2: byte);
462
{ array is indexed from 1 }
464
global_u8bit := byte(p[SMALL_INDEX-1]);
473
{***************************** NORMAL TESTS *******************************}
474
write('Const parameter test (src : LOC_REGISTER (orddef)))...');
479
proc_const_s32bit(gets32bit);
480
if global_s32bit <> RESULT_S32BIT then
483
proc_const_s64bit(gets64bit);
484
if global_s64bit <> RESULT_S64BIT then
493
write('Const parameter test (src : LOC_REFERENCE (recorddef)))...');
498
value_smallrec.b := RESULT_U8BIT;
499
value_smallrec.w := RESULT_U16BIT;
500
proc_const_smallrecord(value_smallrec);
501
if global_u8bit <> RESULT_U8BIT then
506
fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
507
proc_const_largerecord(value_largerec);
508
if global_u8bit <> RESULT_U8BIT then
518
write('const parameter test (src : LOC_REFERENCE (setdef)))...');
523
value_smallset := [A_A,A_D];
524
proc_const_smallset(value_smallset);
525
if global_u8bit <> RESULT_U8BIT then
530
value_largeset := ['I'];
531
proc_const_largeset(value_largeset);
532
if global_u8bit <> RESULT_U8BIT then
544
write('const parameter test (src : LOC_REFERENCE (stringdef)))...');
548
value_smallstring := RESULT_SMALLSTRING;
550
proc_const_smallstring(value_smallstring);
551
if global_u8bit <> RESULT_U8BIT then
556
value_bigstring := RESULT_BIGSTRING;
557
proc_const_bigstring(value_bigstring);
558
if global_u8bit <> RESULT_U8BIT then
569
write('Const parameter test (src : LOC_REFERENCE (formaldef)))...');
574
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
575
proc_const_formaldef_array(value_smallarray);
576
if global_u8bit <> RESULT_U8BIT then
586
write('Const parameter test (src : LOC_REFERENCE (arraydef)))...');
592
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
593
proc_const_smallarray(value_smallarray);
594
if global_u8bit <> RESULT_U8BIT then
600
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
601
proc_const_smallarray_open(value_smallarray);
602
if global_u8bit <> RESULT_U8BIT then
609
value_u8bit := RESULT_U8BIT;
610
value_ptr := RESULT_PCHAR;
611
value_s64bit := RESULT_S64BIT;
612
value_smallstring := RESULT_SMALLSTRING;
613
value_class := tclass1.create;
614
value_boolean := RESULT_BOOLEAN;
615
value_char := RESULT_CHAR;
616
value_s64real:=RESULT_S64REAL;
617
proc_const_smallarray_const_1([value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,value_s64real,
618
value_boolean,value_class]);
620
if global_u8bit <> RESULT_U8BIT then
623
if global_char <> RESULT_CHAR then
625
if global_boolean <> RESULT_BOOLEAN then
627
if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
629
if global_bigstring <> RESULT_SMALLSTRING then
631
if global_ptr <> value_ptr then
633
{ if value_class <> global_class then
634
failed := true;!!!!!!!!!!!!!!!!!!!!}
635
if global_s64bit <> RESULT_S64BIT then
637
if assigned(value_class) then
641
proc_const_smallarray_const_2([]);
642
if global_u8bit <> RESULT_U8BIT then
652
{***************************** MIXED TESTS *******************************}
653
write('Mixed const parameter test (src : LOC_REGISTER (orddef)))...');
658
proc_const_s32bit_mixed(RESULT_U8BIT,gets32bit,RESULT_U8BIT);
659
if global_s32bit <> RESULT_S32BIT then
661
if value_u8bit <> RESULT_U8BIT then
664
proc_const_s64bit_mixed(RESULT_U8BIT,gets64bit,RESULT_U8BIT);
665
if global_s64bit <> RESULT_S64BIT then
667
if value_u8bit <> RESULT_U8BIT then
675
write('Mixed const parameter test (src : LOC_REFERENCE (recorddef)))...');
680
value_smallrec.b := RESULT_U8BIT;
681
value_smallrec.w := RESULT_U16BIT;
682
proc_const_smallrecord_mixed(RESULT_U8BIT,value_smallrec,RESULT_U8BIT);
683
if global_u8bit <> RESULT_U8BIT then
685
if value_u8bit <> RESULT_U8BIT then
690
fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
691
proc_const_largerecord_mixed(RESULT_U8BIT,value_largerec,RESULT_U8BIT);
692
if global_u8bit <> RESULT_U8BIT then
694
if value_u8bit <> RESULT_U8BIT then
704
write('Mixed const parameter test (src : LOC_REFERENCE (setdef)))...');
709
value_smallset := [A_A,A_D];
710
proc_const_smallset_mixed(RESULT_U8BIT,value_smallset,RESULT_U8BIT);
711
if global_u8bit <> RESULT_U8BIT then
713
if value_u8bit <> RESULT_U8BIT then
718
value_largeset := ['I'];
719
proc_const_largeset_mixed(RESULT_U8BIT,value_largeset,RESULT_U8BIT);
720
if global_u8bit <> RESULT_U8BIT then
722
if value_u8bit <> RESULT_U8BIT then
731
write('Mixed const parameter test (src : LOC_REFERENCE (stringdef)))...');
735
value_smallstring := RESULT_SMALLSTRING;
737
proc_const_smallstring_mixed(RESULT_U8BIT,value_smallstring,RESULT_U8BIT);
738
if global_u8bit <> RESULT_U8BIT then
740
if value_u8bit <> RESULT_U8BIT then
745
value_bigstring := RESULT_BIGSTRING;
746
proc_const_bigstring_mixed(RESULT_U8BIT,value_bigstring,RESULT_U8BIT);
747
if global_u8bit <> RESULT_U8BIT then
749
if value_u8bit <> RESULT_U8BIT then
757
write('Mixed const parameter test (src : LOC_REFERENCE (formaldef)))...');
762
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
763
proc_const_formaldef_array_mixed(RESULT_U8BIT,value_smallarray,RESULT_U8BIT);
764
if global_u8bit <> RESULT_U8BIT then
766
if value_u8bit <> RESULT_U8BIT then
776
write('Mixed const parameter test (src : LOC_REFERENCE (arraydef)))...');
782
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
783
proc_const_smallarray_mixed(RESULT_U8BIt,value_smallarray,RESULT_U8BIT);
784
if global_u8bit <> RESULT_U8BIT then
786
if value_u8bit <> RESULT_U8BIT then
792
value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
793
proc_const_smallarray_open_mixed(RESULT_U8BIT,value_smallarray,RESULT_U8BIT);
794
if global_u8bit <> RESULT_U8BIT then
796
if value_u8bit <> RESULT_U8BIT then
803
value_u8bit := RESULT_U8BIT;
804
value_ptr := RESULT_PCHAR;
805
value_s64bit := RESULT_S64BIT;
806
value_smallstring := RESULT_SMALLSTRING;
807
value_class := tclass1.create;
808
value_boolean := RESULT_BOOLEAN;
809
value_char := RESULT_CHAR;
810
value_s64real:=RESULT_S64REAL;
811
proc_const_smallarray_const_1_mixed(RESULT_U8BIT, [value_u8bit,value_ptr,value_s64bit,value_char,value_smallstring,
812
value_s64real,value_boolean,value_class],RESULT_U8BIT);
814
if global_u8bit <> RESULT_U8BIT then
817
if global_char <> RESULT_CHAR then
819
if global_boolean <> RESULT_BOOLEAN then
821
if trunc(global_s64real) <> trunc(RESULT_S64REAL) then
823
if global_bigstring <> RESULT_SMALLSTRING then
825
if global_ptr <> value_ptr then
827
{ if value_class <> global_class then
828
failed := true;!!!!!!!!!!!!!!!!!!!!}
829
if global_s64bit <> RESULT_S64BIT then
831
if assigned(value_class) then
833
if value_u8bit <> RESULT_U8BIT then
837
proc_const_smallarray_const_2_mixed(RESULT_U8BIT,[],RESULT_U8BIT);
838
if global_u8bit <> RESULT_U8BIT then
840
if value_u8bit <> RESULT_U8BIT then