123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- {****************************************************************}
- { CODE GENERATOR TEST PROGRAM }
- {****************************************************************}
- { NODE TESTED : secondvecn() }
- {****************************************************************}
- { PRE-REQUISITES: secondload() }
- { secondassign() }
- { secondfor() }
- { secondderef() }
- { Free Pascal compiler }
- { secondnew() }
- { seconddispose() }
- { secondinline() length() }
- {****************************************************************}
- { DEFINES: }
- {****************************************************************}
- { REMARKS: }
- { Missing tests : openarray tests }
- {****************************************************************}
- program tvec;
- { things to test : }
- { array/record offset with index = 0 }
- { array/record offset with index < MAX_CPU_DISP }
- { non-aligned word/dword access to record field }
- { ansistring }
- { LOC_REFERENCE, LOC_REGISTER }
- { string }
- { right (index value) }
- { LOC_REGISTER }
- { LOC_FLAGS }
- { LOC_JUMP }
- { LOC_REFERENCE, LOC_MEM }
- const
- min_small_neg_array = -127;
- max_small_neg_array = 255;
- min_small_array = 0;
- max_small_array = 255;
- min_big_neg_array = -77000;
- max_big_neg_array = 77000;
- min_big_array = 0;
- max_big_array = 77000;
- min_big_odd_array = 0;
- max_big_odd_array = 255;
- alphabet_size = ord('Z')-ord('A')+1;
- alphabet : array[1..alphabet_size] of char =
- (
- 'A','B','C','D','E','F','G','H','I',
- 'J','K','L','M','N','O','P','Q','R',
- 'S','T','U','V','W','X','Y','Z');
- type
- { alignment requirements are checked }
- { in tsubscript.pp not here }
- { so all elements are byte for easy }
- { testing. }
- toddelement = packed record
- _b0 : array[1..8] of byte;
- _b1 : byte;
- _b2 : byte;
- end;
- psmallnegarray = ^smallnegarray;
- smallnegarray = array[min_small_neg_array..max_small_neg_array] of word;
- psmallarray = ^smallarray;
- smallarray = array[min_small_array..max_small_array] of word;
- pbignegarray = ^bignegarray;
- bignegarray = array[min_big_neg_array..max_big_neg_array] of word;
- pbigarray = ^bigarray;
- bigarray = array[min_big_array..max_big_array] of word;
- { in the case of odd addresses }
- { call multiply in calculating offset }
- pbigoddarray = ^bigoddarray;
- bigoddarray = array[min_big_odd_array..max_big_odd_array] of toddelement;
- boolarray = array[boolean] of boolean;
- var
- globalsmallnegarray : smallnegarray;
- globalsmallarray : smallarray;
- globalbignegarray : bignegarray;
- globalbigarray : bigarray;
- globaloddarray : bigoddarray;
- globalindex : longint;
- globalansi : ansistring;
- globalboolarray : boolarray;
- procedure checkpassed(passed: boolean);
- begin
- if passed then
- begin
- writeln('Passed!');
- end
- else
- begin
- writeln('Failure.');
- halt(1);
- end;
- end;
- { this routine clears all arrays }
- { without calling secondvecn() first }
- procedure clearglobalarrays;
- begin
- FillChar(globalsmallnegarray,sizeof(globalsmallnegarray),0);
- FillChar(globalsmallarray,sizeof(globalsmallarray),0);
- FillChar(globalbignegarray,sizeof(globalbignegarray),0);
- FillChar(globalbignegarray,sizeof(globalbignegarray),0);
- FillChar(globalbigarray,sizeof(globalbigarray),0);
- FillChar(globaloddarray,sizeof(globaloddarray),0);
- FillChar(globalboolarray,sizeof(globalboolarray),0);
- end;
- { left: array definition }
- { right : index constant }
- { NOT OPEN ARRAY }
- { (current): LOC_MEM, LOC_REFERENCE (symbol) }
- { (current): LOC_REFERENCE (with index register) }
- { (current): LOC_REFERENCE (without index register) }
- { (current): LOC_REFERENCE (without base register) }
- procedure testarrayglobal;
- var
- i : longint;
- passed : boolean;
- b1: boolean;
- b2: boolean;
- p : pointer;
- begin
- passed := true;
- ClearGlobalArrays;
- Write('Testing subscriptn() global variables...');
- { RIGHT : LOC_JUMP }
- { (current) : LOC_MEM (symbol) }
- b1 := true;
- b2 := false;
- globalboolarray[b1 or b2] := TRUE;
- if globalboolarray[true] <> TRUE then
- passed := false;
- { RIGHT : LOC_FLAGS }
- { (current) : LOC_MEM (symbol) }
- { IF ASSIGNED DOES NOT HAVE }
- { A RESULT IN FLAGS THIS WILL }
- { NOT WORK (LOC_FLAGS = OK) }
- { for FPC v1.0.x }
- p:= nil;
- globalboolarray[assigned(p)]:=true;
- if globalboolarray[false] <> true then
- passed := false;
- { RIGHT : LOC_REFERENCE }
- { (current) : LOC_MEM (symbol) }
- globalindex := max_big_array;
- globalbigarray[globalindex] := $F0F0;
- if globalbigarray[globalindex] <> $F0F0 then
- passed := false;
- { RIGHT : ordconstn }
- { (current) : LOC_MEM (symbol) }
- { index 1 : 1 }
- globalbigarray[max_big_array] := $FF;
- if globalbigarray[max_big_array] <> $FF then
- passed := false;
- { RIGHT : LOC_REGISTER }
- { (current) : LOC_MEM (symbol) }
- for i:=min_small_neg_array to max_small_neg_array do
- begin
- globalsmallnegarray[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_small_neg_array to max_small_neg_array do
- begin
- if globalsmallnegarray[i] <> word(i) then
- passed := false;
- end;
- for i:=min_small_array to max_small_array do
- begin
- globalsmallarray[i] := i;
- end;
- { now compare if the values are correct }
- for i:=min_small_array to max_small_array do
- begin
- if globalsmallarray[i] <> i then
- passed := false;
- end;
- for i:=min_big_neg_array to max_big_neg_array do
- begin
- globalbignegarray[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_big_neg_array to max_big_neg_array do
- begin
- if globalbignegarray[i] <> word(i) then
- passed := false;
- end;
- for i:=min_big_array to max_big_array do
- begin
- globalbigarray[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_big_array to max_big_array do
- begin
- if globalbigarray[i] <> word(i) then
- passed := false;
- end;
- for i:=min_big_odd_array to max_big_odd_array do
- begin
- globaloddarray[i]._b1 := byte(i);
- end;
- { now compare if the values are correct }
- for i:=min_big_odd_array to max_big_odd_array do
- begin
- if globaloddarray[i]._b1 <> byte(i) then
- passed := false;
- end;
- checkpassed(passed);
- end;
- { left: array definition }
- { right : index constant }
- { OPEN ARRAY }
- { (current): LOC_MEM, LOC_REFERENCE (symbol) }
- { (current): LOC_REFERENCE (with index register) }
- { (current): LOC_REFERENCE (without index register) }
- { (current): LOC_REFERENCE (without base register) }
- procedure testarraylocal;
- var
- localsmallnegarray : psmallnegarray;
- localsmallarray : psmallarray;
- localbignegarray : pbignegarray;
- localbigarray : pbigarray;
- localindex : longint;
- localboolarray: boolarray;
- i : longint;
- passed : boolean;
- b1, b2: boolean;
- p : pointer;
- begin
- Write('Testing subscriptn() local variables...');
- new(localsmallnegarray);
- new(localsmallarray);
- new(localbignegarray);
- new(localbigarray);
- passed := true;
- FillChar(localsmallnegarray^,sizeof(smallnegarray),0);
- FillChar(localsmallarray^,sizeof(smallarray),0);
- FillChar(localbignegarray^,sizeof(bignegarray),0);
- FillChar(localbignegarray^,sizeof(bignegarray),0);
- FillChar(localbigarray^,sizeof(bigarray),0);
- FillChar(localboolarray, sizeof(localboolarray),0);
- { RIGHT : LOC_JUMP }
- { (current) : LOC_MEM (symbol) }
- b1 := true;
- b2 := true;
- localboolarray[b1 and b2] := TRUE;
- if localboolarray[true] <> TRUE then
- passed := false;
- { RIGHT : LOC_FLAGS }
- { (current) : LOC_MEM (symbol) }
- { IF ASSIGNED DOES NOT HAVE }
- { A RESULT IN FLAGS THIS WILL }
- { NOT WORK (LOC_FLAGS = OK) }
- { for FPC v1.0.x }
- p := nil;
- localboolarray[assigned(p)]:=true;
- if localboolarray[false] <> true then
- passed := false;
- { RIGHT : LOC_REFERENCE }
- { (current) : LOC_MEM () }
- localindex := max_big_array;
- localbigarray^[localindex] := $F0F0;
- if localbigarray^[localindex] <> $F0F0 then
- passed := false;
- { RIGHT : ordconstn }
- { (current) : LOC_MEM () }
- { index 1 : 1 }
- localbigarray^[max_big_array] := $FF;
- if localbigarray^[max_big_array] <> $FF then
- passed := false;
- { RIGHT : LOC_REGISTER }
- { (current) : LOC_MEM () }
- for i:=min_small_neg_array to max_small_neg_array do
- begin
- localsmallnegarray^[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_small_neg_array to max_small_neg_array do
- begin
- if localsmallnegarray^[i] <> word(i) then
- passed := false;
- end;
- for i:=min_small_array to max_small_array do
- begin
- localsmallarray^[i] := i;
- end;
- { now compare if the values are correct }
- for i:=min_small_array to max_small_array do
- begin
- if localsmallarray^[i] <> i then
- passed := false;
- end;
- for i:=min_big_neg_array to max_big_neg_array do
- begin
- localbignegarray^[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_big_neg_array to max_big_neg_array do
- begin
- if localbignegarray^[i] <> word(i) then
- passed := false;
- end;
- for i:=min_big_array to max_big_array do
- begin
- localbigarray^[i] := word(i);
- end;
- { now compare if the values are correct }
- for i:=min_big_array to max_big_array do
- begin
- if localbigarray^[i] <> word(i) then
- passed := false;
- end;
- checkpassed(passed);
- dispose(localbigarray);
- dispose(localbignegarray);
- dispose(localsmallarray);
- dispose(localsmallnegarray);
- end;
- { (current): LOC_MEM, LOC_REFERENCE (symbol) }
- { (current): LOC_REFERENCE (with index register) }
- { (current): LOC_REFERENCE (without index register) }
- { (current): LOC_REFERENCE (without base register) }
- procedure testansistring;
- var
- localansi : ansistring;
- passed : boolean;
- i : longint;
- begin
- Write('Testing subscriptn() ansistring()...');
- passed := true;
- localansi := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- { RIGHT : LOC_REFERENCE }
- { (current) : LOC_REFERENCE () }
- for i:=1 to length(localansi) do
- begin
- if localansi[i]<>alphabet[i] then
- passed := false;
- end;
- { RIGHT : LOC_REFERENCE
- (current) : LOC_REGISTER ()
- for i:=0 to length(localansi) do
- begin
- if ansistring(getansistr)[i]<>alphabet[i] then
- passed := false;
- end;
- }
- checkpassed(passed);
- end;
- { left: array definition }
- { right : + operator }
- { right right : index constant }
- { With -Or switch only }
- { left: array definition }
- { right : - operator }
- { right right : index constant }
- { With -Or switch only }
- var
- i: integer;
- b1,b2: boolean;
- p: pointer;
- begin
- globalansi := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- testarrayglobal;
- testarraylocal;
- testansistring;
- end.
|