|
| 1 | +#include "cmplrs/usys.h" |
| 2 | +#include "cmplrs/ucode.h" |
| 3 | + |
| 4 | +procedure uputinit(var ObjectName : Filename); external; |
| 5 | +procedure uputint(i: integer); external; |
| 6 | +procedure uputkill(); external; |
| 7 | +procedure uputclose(); external; |
| 8 | + |
| 9 | +var |
| 10 | + dtyname: Array [first(Datatype)..last(Datatype)] of char; |
| 11 | + mtyname: Array [first(Memtype)..last(Memtype)] of char; |
| 12 | + noerrorsyet: boolean; |
| 13 | + u_indent: integer; |
| 14 | + Utab: extern array[first(Uopcode)..last(Uopcode)] of Utabrec; |
| 15 | + |
| 16 | +procedure inituwrite(var arg0: Filename); |
| 17 | +begin |
| 18 | + noerrorsyet := true; |
| 19 | + uputinit(arg0); |
| 20 | + |
| 21 | + dtyname[Cdt] := 'C'; |
| 22 | + dtyname[Fdt] := 'F'; |
| 23 | + dtyname[Gdt] := 'G'; |
| 24 | + dtyname[Hdt] := 'H'; |
| 25 | + dtyname[Zdt] := 'Z'; |
| 26 | + dtyname[Adt] := 'A'; |
| 27 | + dtyname[Jdt] := 'J'; |
| 28 | + dtyname[Ldt] := 'L'; |
| 29 | + dtyname[Mdt] := 'M'; |
| 30 | + dtyname[Ndt] := 'N'; |
| 31 | + dtyname[Pdt] := 'P'; |
| 32 | + dtyname[Qdt] := 'Q'; |
| 33 | + dtyname[Rdt] := 'R'; |
| 34 | + dtyname[Sdt] := 'S'; |
| 35 | + dtyname[Xdt] := 'X'; |
| 36 | + dtyname[Idt] := 'I'; |
| 37 | + dtyname[Kdt] := 'K'; |
| 38 | + dtyname[Wdt] := 'W'; |
| 39 | + |
| 40 | + mtyname[Zmt] := 'Z'; |
| 41 | + mtyname[Mmt] := 'M'; |
| 42 | + mtyname[Rmt] := 'R'; |
| 43 | + mtyname[Smt] := 'S'; |
| 44 | + mtyname[Pmt] := 'P'; |
| 45 | + mtyname[Amt] := 'A'; |
| 46 | + |
| 47 | + u_indent := 0; |
| 48 | +end; |
| 49 | + |
| 50 | +function idlen(var id: Identname): integer; |
| 51 | +var |
| 52 | + len: integer; |
| 53 | +begin |
| 54 | + for len := Identlength downto 1 do begin |
| 55 | + if (id[len] <> ' ') then begin |
| 56 | + return len; |
| 57 | + end; |
| 58 | + end; |
| 59 | + return 0; |
| 60 | +end; |
| 61 | + |
| 62 | +function fnamelen(fname: Filename): integer; |
| 63 | +var |
| 64 | + len: integer; |
| 65 | +begin |
| 66 | + len := 0; |
| 67 | + |
| 68 | + while (len < Filenamelen) do begin |
| 69 | + if (fname[len + 1] = ' ') then begin |
| 70 | + return len; |
| 71 | + end; |
| 72 | + len := len + 1; |
| 73 | + end; |
| 74 | + |
| 75 | + return Filenamelen; |
| 76 | +end; |
| 77 | + |
| 78 | +procedure uwrite(var u: Bcrec); |
| 79 | +var |
| 80 | + i: integer; |
| 81 | + pad: integer; |
| 82 | + urec: UtabRec; |
| 83 | + strlength: integer; |
| 84 | + str: Stringtextptr; |
| 85 | +begin |
| 86 | + if noerrorsyet then begin |
| 87 | + urec := utab[u.Opc]; |
| 88 | + i := 1; |
| 89 | + while (i <> (urec.instlength + 1)) do begin |
| 90 | + uputint(u.Intarray[i]); |
| 91 | + uputint(u.Intarray[i + 1]); |
| 92 | + i := i + 2; |
| 93 | + end; |
| 94 | + |
| 95 | + if (urec.hasconst) then begin |
| 96 | + uputint(u.Intarray[urec.instlength + 1]); |
| 97 | + uputint(u.Intarray[urec.instlength + 2]); |
| 98 | + if ((u.Dtype in [Mdt, Qdt, Rdt, Sdt, Xdt]) or (u.Opc = Ucomm)) then begin |
| 99 | + if (u.Opc = Uinit) then begin |
| 100 | + strlength := (u.Initval.Ival + 3) div 4; |
| 101 | + end else begin |
| 102 | + strlength := (u.Constval.Ival + 3) div 4; |
| 103 | + end; |
| 104 | + |
| 105 | + if (strlength & 1 <> 0) then begin |
| 106 | + strlength := strlength + 1; |
| 107 | + end; |
| 108 | + |
| 109 | + if (u.Opc = Uinit) then begin |
| 110 | + str := u.Initval.Chars; |
| 111 | + end else begin |
| 112 | + str := u.Constval.Chars; |
| 113 | + end; |
| 114 | + |
| 115 | + i := 1; |
| 116 | + while (i <> (strlength + 1)) do begin |
| 117 | + uputint(str^.ssarray[i]); |
| 118 | + uputint(str^.ssarray[i + 1]); |
| 119 | + i := i + 2; |
| 120 | + end; |
| 121 | + end; |
| 122 | + end; |
| 123 | + end; |
| 124 | +end; |
| 125 | + |
| 126 | +function getdtyname(Dtyp: Datatype): char; |
| 127 | +begin |
| 128 | + getdtyname := dtyname[Dtyp]; |
| 129 | +end; |
| 130 | + |
| 131 | +function getmtyname(Mtyp: Memtype): char; |
| 132 | +begin |
| 133 | + getmtyname := mtyname[Mtyp]; |
| 134 | +end; |
| 135 | + |
| 136 | +procedure ucoid(Tag: Identname); |
| 137 | +var |
| 138 | + i: integer; |
| 139 | + u: Bcrec; |
| 140 | +begin |
| 141 | + for i := 1 to Maxinstlength do begin |
| 142 | + u.Intarray[i] := 0; |
| 143 | + end; |
| 144 | + |
| 145 | + new(u.Constval.Chars); |
| 146 | + |
| 147 | + { Skip end spaces } |
| 148 | + while ((u.Constval.Ival > 0) and (Tag[u.Constval.Ival] = ' ')) do begin |
| 149 | + u.Constval.Ival := u.Constval.Ival - 1; |
| 150 | + end; |
| 151 | + |
| 152 | + for i := 1 to u.Constval.Ival do begin |
| 153 | + u.Constval.Chars^.ss[i] := Tag[i]; |
| 154 | + end; |
| 155 | + |
| 156 | + u.Opc := Ucomm; |
| 157 | + u.Dtype := Mdt; |
| 158 | + uwrite(u); |
| 159 | + dispose(u.Constval.Chars); |
| 160 | +end; |
| 161 | + |
| 162 | +procedure ucofname(fname: Filename); |
| 163 | +var |
| 164 | + i: integer; |
| 165 | + u: Bcrec; |
| 166 | +begin |
| 167 | + for i := 1 to Maxinstlength do begin |
| 168 | + u.Intarray[i] := 0; |
| 169 | + end; |
| 170 | + |
| 171 | + new(u.Constval.Chars); |
| 172 | + u.Constval.Ival := fnamelen(fname); |
| 173 | + |
| 174 | + if (u.Constval.Ival >= (Filenamelen + 1)) then begin |
| 175 | + u.Constval.Ival := Filenamelen; |
| 176 | + end; |
| 177 | + |
| 178 | + for i := 1 to u.Constval.Ival do begin |
| 179 | + u.Constval.Chars^.ss[i] := fname[i]; |
| 180 | + end; |
| 181 | + |
| 182 | + u.Opc := Ucomm; |
| 183 | + u.Dtype := Mdt; |
| 184 | + uwrite(u); |
| 185 | + dispose(u.Constval.Chars); |
| 186 | +end; |
| 187 | + |
| 188 | +procedure stopucode(); |
| 189 | +begin |
| 190 | + uputkill(); |
| 191 | + noerrorsyet := false; |
| 192 | +end; |
| 193 | + |
| 194 | +procedure ubittobyte(var u: Bcrec); |
| 195 | +begin |
| 196 | + if (u.Opc in [Uadj, Uisld, Uisst, Ulod, Umpmv, Upar, Updef, Upmov, Uregs, Urlda, Urpar, Ustr, Uvreg]) then begin |
| 197 | + u.Offset := u.Offset div 8; |
| 198 | + u.Length := u.Length div 8; |
| 199 | + return; |
| 200 | + end; |
| 201 | + |
| 202 | + if (u.Opc in [Uildv, Uilod, Uistr, Uistv, Urldc]) then begin |
| 203 | + u.I1 := u.I1 div 8; |
| 204 | + u.Length := u.Length div 8; |
| 205 | + return; |
| 206 | + end; |
| 207 | + |
| 208 | + if (u.Opc in [Uilda, Ulda, Urlod, Urstr]) then begin |
| 209 | + u.Offset := u.Offset div 8; |
| 210 | + u.Length := u.Length div 8; |
| 211 | + u.Offset2 := u.Offset2 div 8; |
| 212 | + return; |
| 213 | + end; |
| 214 | + |
| 215 | + if (u.Opc in [Uidx, Uixa]) then begin |
| 216 | + u.I1 := u.I1 div 8; |
| 217 | + return; |
| 218 | + end; |
| 219 | + |
| 220 | + if (u.Opc in [Udef, Udif, Ufill, Uiequ, Uigeq, Uigrt, Uileq, Uiles, Uineq, Uinn, Uint, Ulca, Uldc, Umov, Umus, Usdef, Usgs, Uuni]) then begin |
| 221 | + u.Length := u.Length div 8; |
| 222 | + end else if (u.Opc = Uinit) then begin |
| 223 | + u.Offset := u.Offset div 8; |
| 224 | + u.Length := u.Length div 8; |
| 225 | + u.Offset2 := u.Offset2 div 8; |
| 226 | + u.Constval.dwval_l := u.Constval.dwval_l div 8; |
| 227 | + end else if (u.Opc = Uoptn) and (u.I1 = 1) then begin |
| 228 | + u.Length := u.Length div 8; |
| 229 | + end; |
| 230 | +end; |
| 231 | + |
| 232 | +procedure set_u_indent(ident: integer); |
| 233 | +begin |
| 234 | + {u_ident := ident} (* Possible implementation of this 'useless' function *) |
| 235 | +end; |
0 commit comments