| | @@ -45,6 +45,7 @@ |
| 45 | 45 | |
| 46 | 46 | var |
| 47 | 47 | labelAt: longint; { the last place a jump was made to land } |
| 48 | + listing: boolean; { -S: each instruction's text is kept, for List } |
| 48 | 49 | |
| 49 | 50 | function Here: TMem; |
| 50 | 51 | function Mem(base: longint; disp: int64): TMem; |
| | @@ -120,6 +121,9 @@ |
| 120 | 121 | 'be', 'a', 's', 'ns', 'p', 'np', 'l', 'ge', 'le', 'g'); |
| 121 | 122 | |
| 122 | 123 | procedure Assemble(constExpr: TConstFn); |
| 124 | +procedure Say(const s: shortstring); |
| 125 | +procedure Restate(at: longint; const s: shortstring); |
| 126 | +procedure List(module: longint); |
| 123 | 127 | |
| 124 | 128 | implementation |
| 125 | 129 | |
| | @@ -216,15 +220,107 @@ |
| 216 | 220 | Prefix(pfx, w, reg, NoIndex, rm, byteReg and ((reg in [4..7]) or (rm in [4..7]))); |
| 217 | 221 | Opcode(op); |
| 218 | 222 | Put1($C0 or (reg and 7) shl 3 or (rm and 7)); |
| 223 | +end; |
| 224 | + |
| 225 | +{ The listing: the text of each instruction, as it is made } |
| 226 | + |
| 227 | +type |
| 228 | + TSaid = record |
| 229 | + at: longint; { where the instruction starts in code } |
| 230 | + text: string[63]; |
| 231 | + end; |
| 232 | + |
| 233 | +var |
| 234 | + said: ^TSaid; |
| 235 | + numSaid, saidCap: longint; |
| 236 | + |
| 237 | +procedure SayAt(at: longint; const s: shortstring); |
| 238 | +begin |
| 239 | + if not listing then exit; |
| 240 | + if numSaid = saidCap then begin |
| 241 | + saidCap := saidCap * 2 + 1024; |
| 242 | + said := ReAllocMem(said, saidCap * SizeOf(TSaid)); |
| 243 | + end; |
| 244 | + said[numSaid].at := at; |
| 245 | + said[numSaid].text := s; |
| 246 | + inc(numSaid); |
| 219 | 247 | end; |
| 220 | 248 | |
| 249 | +{ The text of the instruction about to be written } |
| 250 | +procedure Say(const s: shortstring); |
| 251 | +begin |
| 252 | + SayAt(pc, s); |
| 253 | +end; |
| 254 | + |
| 255 | +{ The text of the instruction at at, said again, as when its operand is |
| 256 | + patched } |
| 257 | +procedure Restate(at: longint; const s: shortstring); |
| 258 | +var i: longint; |
| 259 | +begin |
| 260 | + i := numSaid - 1; |
| 261 | + while (i >= 0) and (said[i].at <> at) do dec(i); |
| 262 | + if i >= 0 then said[i].text := s; |
| 263 | +end; |
| 264 | + |
| 265 | +function RN(r: longint; size: longint = 8): shortstring; |
| 266 | +begin |
| 267 | + case size of |
| 268 | + 1: RN := RegNames[3, r]; |
| 269 | + 2: RN := RegNames[2, r]; |
| 270 | + 4: RN := RegNames[1, r]; |
| 271 | + else RN := RegNames[0, r]; |
| 272 | + end; |
| 273 | +end; |
| 274 | + |
| 275 | +function XN(x: longint): shortstring; |
| 276 | +begin |
| 277 | + XN := 'xmm' + IntStr(x); |
| 278 | +end; |
| 279 | + |
| 280 | +function ChunkName(c: longint): shortstring; |
| 281 | +begin |
| 282 | + with chunks^[c] do |
| 283 | + if name < 0 then ChunkName := 'data' + IntStr(c) |
| 284 | + else if module < 0 then ChunkName := NameOf(name) |
| 285 | + else ChunkName := NameOf(module) + '.' + NameOf(name); |
| 286 | +end; |
| 287 | + |
| 288 | +{ A memory operand, with the size of what it holds, as the assembler |
| 289 | + reads it } |
| 290 | +function MN(const m: TMem; size: longint = 0): shortstring; |
| 291 | +var s: shortstring; |
| 292 | +begin |
| 293 | + case size of |
| 294 | + 1: s := 'byte '; |
| 295 | + 2: s := 'word '; |
| 296 | + 4: s := 'dword '; |
| 297 | + 8: s := 'qword '; |
| 298 | + else s := ''; |
| 299 | + end; |
| 300 | + if m.base = RIP then s := s + '[' + ChunkName(m.chunk) |
| 301 | + else s := s + '[' + RN(m.base); |
| 302 | + if m.index <> NoIndex then s := s + ' + ' + RN(m.index) + ' * ' + IntStr(m.scale); |
| 303 | + if m.disp > 0 then s := s + ' + ' + IntStr(m.disp) |
| 304 | + else if m.disp < 0 then s := s + ' - ' + IntStr(-m.disp); |
| 305 | + MN := s + ']'; |
| 306 | +end; |
| 307 | + |
| 308 | +const |
| 309 | + AluNames: array[0..7] of string[3] = ('add', 'or', 'adc', 'sbb', 'and', 'sub', 'xor', 'cmp'); |
| 310 | + ShiftNames: array[0..7] of string[3] = ('rol', 'ror', 'rcl', 'rcr', 'shl', 'shr', 'sal', 'sar'); |
| 311 | + UnaryNames: array[2..7] of string[4] = ('not', 'neg', 'mul', 'imul', 'div', 'idiv'); |
| 312 | + |
| 221 | 313 | procedure MovRR(dst, src: longint); |
| 222 | 314 | begin |
| 315 | + if listing then Say('mov ' + RN(dst) + ', ' + RN(src)); |
| 223 | 316 | OpR(0, true, $89, src, dst); |
| 224 | 317 | end; |
| 225 | 318 | |
| 226 | 319 | procedure MovRI(r: longint; v: int64); |
| 227 | 320 | begin |
| 321 | + if not listing then |
| 322 | + else if v = 0 then Say('xor ' + RN(r, 4) + ', ' + RN(r, 4)) |
| 323 | + else Say('mov ' + RN(r) + ', ' + IntStr(v)); |
| 228 | 324 | if (v >= low(longint)) and (v <= high(longint)) then begin |
| 229 | 325 | if v = 0 then OpR(0, false, $31, r, r) { xor r32, r32 } |
| 230 | 326 | else if v > 0 then begin { mov r32, imm32 } |
| | @@ -241,6 +337,12 @@ |
| 241 | 337 | |
| 242 | 338 | procedure Load(r: longint; const m: TMem; size: longint; signed: boolean); |
| 243 | 339 | begin |
| 340 | + if not listing then |
| 341 | + else if size = 8 then Say('mov ' + RN(r) + ', ' + MN(m)) |
| 342 | + else if (size = 4) and not signed then Say('mov ' + RN(r, 4) + ', ' + MN(m)) |
| 343 | + else if size = 4 then Say('movsxd ' + RN(r) + ', ' + MN(m, 4)) |
| 344 | + else if signed then Say('movsx ' + RN(r) + ', ' + MN(m, size)) |
| 345 | + else Say('movzx ' + RN(r, 4) + ', ' + MN(m, size)); |
| 244 | 346 | case size of |
| 245 | 347 | 1: if signed then OpM(0, true, $BE0F, r, m) else OpM(0, false, $B60F, r, m); |
| 246 | 348 | 2: if signed then OpM(0, true, $BF0F, r, m) else OpM(0, false, $B70F, r, m); |
| | @@ -251,6 +353,7 @@ |
| 251 | 353 | |
| 252 | 354 | procedure Store(const m: TMem; r: longint; size: longint); |
| 253 | 355 | begin |
| 356 | + if listing then Say('mov ' + MN(m) + ', ' + RN(r, size)); |
| 254 | 357 | case size of |
| 255 | 358 | 1: OpM(0, false, $88, r, m, true); |
| 256 | 359 | 2: OpM($66, false, $89, r, m); |
| | @@ -261,16 +364,19 @@ |
| 261 | 364 | |
| 262 | 365 | procedure Lea(r: longint; const m: TMem); |
| 263 | 366 | begin |
| 367 | + if listing then Say('lea ' + RN(r) + ', ' + MN(m)); |
| 264 | 368 | OpM(0, true, $8D, r, m); |
| 265 | 369 | end; |
| 266 | 370 | |
| 267 | 371 | procedure Alu(op, dst, src: longint); |
| 268 | 372 | begin |
| 373 | + if listing then Say(AluNames[op] + ' ' + RN(dst) + ', ' + RN(src)); |
| 269 | 374 | OpR(0, true, op shl 3 or 1, src, dst); |
| 270 | 375 | end; |
| 271 | 376 | |
| 272 | 377 | procedure AluI(op, r: longint; v: longint); |
| 273 | 378 | begin |
| 379 | + if listing then Say(AluNames[op] + ' ' + RN(r) + ', ' + IntStr(v)); |
| 274 | 380 | if (v >= -128) and (v <= 127) then begin |
| 275 | 381 | OpR(0, true, $83, op, r); Put1(v) |
| 276 | 382 | end else begin |
| | @@ -281,44 +387,56 @@ |
| 281 | 387 | { op r, [m] } |
| 282 | 388 | procedure AluM(op, r: longint; const m: TMem); |
| 283 | 389 | begin |
| 390 | + if listing then Say(AluNames[op] + ' ' + RN(r) + ', ' + MN(m)); |
| 284 | 391 | OpM(0, true, op shl 3 or 3, r, m); |
| 285 | 392 | end; |
| 286 | 393 | |
| 287 | 394 | procedure Imul(dst, src: longint); |
| 288 | 395 | begin |
| 396 | + if listing then Say('imul ' + RN(dst) + ', ' + RN(src)); |
| 289 | 397 | OpR(0, true, $AF0F, dst, src); |
| 290 | 398 | end; |
| 291 | 399 | |
| 292 | 400 | procedure ImulI(r: longint; v: longint); |
| 293 | 401 | begin |
| 402 | + if listing then Say('imul ' + RN(r) + ', ' + RN(r) + ', ' + IntStr(v)); |
| 294 | 403 | OpR(0, true, $69, r, r); |
| 295 | 404 | Put4(v); |
| 296 | 405 | end; |
| 297 | 406 | |
| 298 | 407 | procedure Shift(op, r: longint); |
| 299 | 408 | begin |
| 409 | + if listing then Say(ShiftNames[op] + ' ' + RN(r) + ', cl'); |
| 300 | 410 | OpR(0, true, $D3, op, r); |
| 301 | 411 | end; |
| 302 | 412 | |
| 303 | 413 | procedure ShiftI(op, r, n: longint); |
| 304 | 414 | begin |
| 415 | + if listing then Say(ShiftNames[op] + ' ' + RN(r) + ', ' + IntStr(n)); |
| 305 | 416 | OpR(0, true, $C1, op, r); |
| 306 | 417 | Put1(n); |
| 307 | 418 | end; |
| 308 | 419 | |
| 309 | 420 | procedure Unary(ext, r: longint); |
| 310 | 421 | begin |
| 422 | + if listing then Say(UnaryNames[ext] + ' ' + RN(r)); |
| 311 | 423 | OpR(0, true, $F7, ext, r); |
| 312 | 424 | end; |
| 313 | 425 | |
| 314 | 426 | procedure Cqo; |
| 315 | 427 | begin |
| 428 | + if listing then Say('cqo'); |
| 316 | 429 | Put1($48); Put1($99); |
| 317 | 430 | end; |
| 318 | 431 | |
| 319 | 432 | { Brings a value of size bytes in r to 64 bits, by its sign or zeros. } |
| 320 | 433 | procedure Extend(r, size: longint; signed: boolean); |
| 321 | 434 | begin |
| 435 | + if not listing then |
| 436 | + else if size = 4 then begin |
| 437 | + if signed then Say('movsxd ' + RN(r) + ', ' + RN(r, 4)) else Say('mov ' + RN(r, 4) + ', ' + RN(r, 4)) |
| 438 | + end else if signed then Say('movsx ' + RN(r) + ', ' + RN(r, size)) |
| 439 | + else Say('movzx ' + RN(r, 4) + ', ' + RN(r, size)); |
| 322 | 440 | case size of |
| 323 | 441 | 1: if signed then OpR(0, true, $BE0F, r, r) else OpR(0, false, $B60F, r, r); |
| 324 | 442 | 2: if signed then OpR(0, true, $BF0F, r, r) else OpR(0, false, $B70F, r, r); |
| | @@ -329,29 +447,35 @@ |
| 329 | 447 | { r := 1 if the condition holds, else 0 } |
| 330 | 448 | procedure SetCC(cc, r: longint); |
| 331 | 449 | begin |
| 450 | + if listing then Say('set' + CondNames[cc] + ' ' + RN(r, 1)); |
| 332 | 451 | OpR(0, false, $900F + cc shl 8, 0, r); |
| 452 | + if listing then Say('movzx ' + RN(r, 4) + ', ' + RN(r, 1)); |
| 333 | 453 | OpR(0, false, $B60F, r, r); |
| 334 | 454 | end; |
| 335 | 455 | |
| 336 | 456 | procedure TestRR(a, b: longint); |
| 337 | 457 | begin |
| 458 | + if listing then Say('test ' + RN(a) + ', ' + RN(b)); |
| 338 | 459 | OpR(0, true, $85, b, a); |
| 339 | 460 | end; |
| 340 | 461 | |
| 341 | 462 | procedure Push(r: longint); |
| 342 | 463 | begin |
| 464 | + if listing then Say('push ' + RN(r)); |
| 343 | 465 | if r >= 8 then Put1($41); |
| 344 | 466 | Put1($50 + r and 7); |
| 345 | 467 | end; |
| 346 | 468 | |
| 347 | 469 | procedure Pop(r: longint); |
| 348 | 470 | begin |
| 471 | + if listing then Say('pop ' + RN(r)); |
| 349 | 472 | if r >= 8 then Put1($41); |
| 350 | 473 | Put1($58 + r and 7); |
| 351 | 474 | end; |
| 352 | 475 | |
| 353 | 476 | procedure CallChunk(c: longint); |
| 354 | 477 | begin |
| 478 | + if listing then Say('call ' + ChunkName(c)); |
| 355 | 479 | Put1($E8); |
| 356 | 480 | AddFixup(pc, c, 0); |
| 357 | 481 | Put4(0); |
| | @@ -359,91 +483,117 @@ |
| 359 | 483 | |
| 360 | 484 | procedure CallBack(target: longint); |
| 361 | 485 | begin |
| 486 | + if listing then Say('call'); |
| 362 | 487 | Put1($E8); |
| 363 | 488 | Put4(target - (pc + 4)); |
| 364 | 489 | end; |
| 365 | 490 | |
| 366 | 491 | procedure CallR(r: longint); |
| 367 | 492 | begin |
| 493 | + if listing then Say('call ' + RN(r)); |
| 368 | 494 | OpR(0, false, $FF, 2, r); |
| 369 | 495 | end; |
| 370 | 496 | |
| 371 | 497 | procedure CallM(const m: TMem); |
| 372 | 498 | begin |
| 499 | + if listing then Say('call ' + MN(m)); |
| 373 | 500 | OpM(0, false, $FF, 2, m); |
| 374 | 501 | end; |
| 375 | 502 | |
| 376 | | -procedure Ret; begin Put1($C3) end; |
| 377 | | -procedure Leave; begin Put1($C9) end; |
| 378 | | -procedure Syscall; begin Put1($0F); Put1($05) end; |
| 379 | | -procedure Mfence; begin Put1($0F); Put1($AE); Put1($F0) end; |
| 380 | | -procedure Ud2; begin Put1($0F); Put1($0B) end; |
| 381 | | -procedure RepMovsb; begin Put1($F3); Put1($A4) end; |
| 382 | | -procedure RepStosb; begin Put1($F3); Put1($AA) end; |
| 383 | | -procedure RepeCmpsb; begin Put1($F3); Put1($A6) end; |
| 503 | +procedure Ret; begin if listing then Say('ret'); Put1($C3) end; |
| 504 | +procedure Leave; begin Say('leave'); Put1($C9) end; |
| 505 | +procedure Syscall; begin Say('syscall'); Put1($0F); Put1($05) end; |
| 506 | +procedure Mfence; begin Say('mfence'); Put1($0F); Put1($AE); Put1($F0) end; |
| 507 | +procedure Ud2; begin Say('ud2'); Put1($0F); Put1($0B) end; |
| 508 | +procedure RepMovsb; begin Say('rep movsb'); Put1($F3); Put1($A4) end; |
| 509 | +procedure RepStosb; begin Say('rep stosb'); Put1($F3); Put1($AA) end; |
| 510 | +procedure RepeCmpsb; begin Say('repe cmpsb'); Put1($F3); Put1($A6) end; |
| 384 | 511 | |
| 385 | 512 | procedure LockCmpxchg(const m: TMem; r: longint); |
| 386 | 513 | begin |
| 514 | + if listing then Say('lock cmpxchg ' + MN(m) + ', ' + RN(r)); |
| 387 | 515 | Put1($F0); |
| 388 | 516 | OpM(0, true, $B10F, r, m); |
| 389 | 517 | end; |
| 390 | 518 | |
| 391 | 519 | procedure Xchg(const m: TMem; r: longint); |
| 392 | 520 | begin |
| 521 | + if listing then Say('xchg ' + MN(m) + ', ' + RN(r)); |
| 393 | 522 | OpM(0, true, $87, r, m); |
| 394 | 523 | end; |
| 395 | 524 | |
| 396 | 525 | procedure LockXadd(const m: TMem; r: longint); |
| 397 | 526 | begin |
| 527 | + if listing then Say('lock xadd ' + MN(m) + ', ' + RN(r)); |
| 398 | 528 | Put1($F0); |
| 399 | 529 | OpM(0, true, $C10F, r, m); |
| 400 | 530 | end; |
| 401 | 531 | |
| 402 | 532 | procedure MovqXR(x, r: longint); |
| 403 | 533 | begin |
| 534 | + if listing then Say('movq ' + XN(x) + ', ' + RN(r)); |
| 404 | 535 | OpR($66, true, $6E0F, x, r); |
| 405 | 536 | end; |
| 406 | 537 | |
| 407 | 538 | procedure MovqRX(r, x: longint); |
| 408 | 539 | begin |
| 540 | + if listing then Say('movq ' + RN(r) + ', ' + XN(x)); |
| 409 | 541 | OpR($66, true, $7E0F, x, r); |
| 410 | 542 | end; |
| 411 | 543 | |
| 412 | 544 | procedure MovsdXM(x: longint; const m: TMem); |
| 413 | 545 | begin |
| 546 | + if listing then Say('movsd ' + XN(x) + ', ' + MN(m)); |
| 414 | 547 | OpM($F2, false, $100F, x, m); |
| 415 | 548 | end; |
| 416 | 549 | |
| 417 | 550 | procedure MovsdMX(const m: TMem; x: longint); |
| 418 | 551 | begin |
| 552 | + if listing then Say('movsd ' + MN(m) + ', ' + XN(x)); |
| 419 | 553 | OpM($F2, false, $110F, x, m); |
| 420 | 554 | end; |
| 421 | 555 | |
| 422 | 556 | const |
| 423 | 557 | RealPfx: array[boolean] of longint = ($F2, $F3); |
| 558 | + RealEnd: array[boolean] of string[2] = ('sd', 'ss'); |
| 424 | 559 | |
| 425 | 560 | procedure Sse(op, x, y: longint; single: boolean); |
| 561 | +var s: shortstring; |
| 426 | 562 | begin |
| 563 | + if listing then begin |
| 564 | + case op of |
| 565 | + $58: s := 'add' + RealEnd[single]; |
| 566 | + $59: s := 'mul' + RealEnd[single]; |
| 567 | + $5C: s := 'sub' + RealEnd[single]; |
| 568 | + $5E: s := 'div' + RealEnd[single]; |
| 569 | + else s := 'cvt' + RealEnd[single] + '2' + RealEnd[not single]; |
| 570 | + end; |
| 571 | + Say(s + ' ' + XN(x) + ', ' + XN(y)); |
| 572 | + end; |
| 427 | 573 | OpR(RealPfx[single], false, $0F or op shl 8, x, y); |
| 428 | 574 | end; |
| 429 | 575 | |
| 430 | 576 | procedure Ucomis(x, y: longint; single: boolean); |
| 431 | 577 | begin |
| 578 | + if listing then Say('ucomi' + RealEnd[single] + ' ' + XN(x) + ', ' + XN(y)); |
| 432 | 579 | if single then OpR(0, false, $2E0F, x, y) else OpR($66, false, $2E0F, x, y); |
| 433 | 580 | end; |
| 434 | 581 | |
| 435 | 582 | procedure Cvtsi2s(x, r: longint; single: boolean); |
| 436 | 583 | begin |
| 584 | + if listing then Say('cvtsi2' + RealEnd[single] + ' ' + XN(x) + ', ' + RN(r)); |
| 437 | 585 | OpR(RealPfx[single], true, $2A0F, x, r); |
| 438 | 586 | end; |
| 439 | 587 | |
| 440 | 588 | procedure Cvtts2si(r, x: longint; single: boolean); |
| 441 | 589 | begin |
| 590 | + if listing then Say('cvtt' + RealEnd[single] + '2si ' + RN(r) + ', ' + XN(x)); |
| 442 | 591 | OpR(RealPfx[single], true, $2C0F, r, x); |
| 443 | 592 | end; |
| 444 | 593 | |
| 445 | 594 | procedure Btc(r, bit: longint); |
| 446 | 595 | begin |
| 596 | + if listing then Say('btc ' + RN(r) + ', ' + IntStr(bit)); |
| 447 | 597 | OpR(0, true, $BA0F, 7, r); |
| 448 | 598 | Put1(bit); |
| 449 | 599 | end; |
| | @@ -454,6 +604,7 @@ |
| 454 | 604 | |
| 455 | 605 | procedure Jmp(var L: longint); |
| 456 | 606 | begin |
| 607 | + if listing then Say('jmp'); |
| 457 | 608 | Put1($E9); |
| 458 | 609 | Put4(L); |
| 459 | 610 | L := pc - 4; |
| | @@ -461,6 +612,7 @@ |
| 461 | 612 | |
| 462 | 613 | procedure Jcc(cc: longint; var L: longint); |
| 463 | 614 | begin |
| 615 | + if listing then Say('j' + CondNames[cc]); |
| 464 | 616 | Put1($0F); Put1($80 + cc); |
| 465 | 617 | Put4(L); |
| 466 | 618 | L := pc - 4; |
| | @@ -468,12 +620,14 @@ |
| 468 | 620 | |
| 469 | 621 | procedure JmpBack(target: longint); |
| 470 | 622 | begin |
| 623 | + if listing then Say('jmp'); |
| 471 | 624 | Put1($E9); |
| 472 | 625 | Put4(target - (pc + 4)); |
| 473 | 626 | end; |
| 474 | 627 | |
| 475 | 628 | procedure JccBack(cc, target: longint); |
| 476 | 629 | begin |
| 630 | + if listing then Say('j' + CondNames[cc]); |
| 477 | 631 | Put1($0F); Put1($80 + cc); |
| 478 | 632 | Put4(target - (pc + 4)); |
| 479 | 633 | end; |
| | @@ -635,7 +789,7 @@ |
| 635 | 789 | $90F3, $90, $0B0F, $CC, $F4, $9948, $99, $F0AE0F, $E8AE0F, $F8AE0F); |
| 636 | 790 | var |
| 637 | 791 | w: shortstring; o: array[0..2] of TOpd; n, i, k, size, pfx, cc: longint; |
| 638 | | - wide, byteOp: boolean; at, start: TPos; v: int64; |
| 792 | + wide, byteOp, wasListing: boolean; at, start: TPos; v: int64; first: longint; |
| 639 | 793 | names, places, chains: array[0..63] of longint; numLabels: longint; |
| 640 | 794 | usedAt: array[0..63] of TPos; |
| 641 | 795 | |
| | @@ -687,6 +841,7 @@ |
| 687 | 841 | if w = '' then Mark('expected an instruction'); |
| 688 | 842 | Next; |
| 689 | 843 | if tok = sColon then begin |
| 844 | + SayAt(pc, w + ':'); |
| 690 | 845 | k := Lab(Intern(@w[1], length(w))); |
| 691 | 846 | if places[k] >= 0 then MarkAt(at, 'label ' + w + ' is defined twice'); |
| 692 | 847 | places[k] := pc; |
| | @@ -694,6 +849,9 @@ |
| 694 | 849 | Next; |
| 695 | 850 | continue; |
| 696 | 851 | end; |
| 852 | + first := pc; |
| 853 | + wasListing := listing; |
| 854 | + listing := false; { the instruction is said as it is written } |
| 697 | 855 | if w = 'lock' then begin |
| 698 | 856 | Put1($F0); |
| 699 | 857 | w := AsmWord; |
| | @@ -825,10 +983,57 @@ |
| 825 | 983 | end; |
| 826 | 984 | end; |
| 827 | 985 | if tok <> sSemicolon then Mark('expected ";"'); |
| 986 | + listing := wasListing; |
| 987 | + SayAt(first, Source(SpanFrom(at))); |
| 828 | 988 | Next; |
| 829 | 989 | end; |
| 830 | 990 | for k := 0 to numLabels - 1 do |
| 831 | 991 | if places[k] < 0 then MarkAt(usedAt[k], 'label ' + NameOf(names[k]) + ' isn''t defined'); |
| 992 | +end; |
| 993 | + |
| 994 | +{ The listing, raz -S: each live procedure of the module in the order |
| 995 | + it was made, each line of source it comes from, and under it the |
| 996 | + instructions made for it, at their offsets in the procedure; a jump |
| 997 | + within it says where to by its offset too. } |
| 998 | +procedure List(module: longint); |
| 999 | +var order: ^longint; n, i, j, k, c, t, line: longint; text: shortstring; |
| 1000 | +begin |
| 1001 | + order := GetMem(numChunks * SizeOf(longint)); |
| 1002 | + n := 0; |
| 1003 | + for c := 0 to numChunks - 1 do |
| 1004 | + if chunks^[c].live and (chunks^[c].sec = secText) and (chunks^[c].module = module) then begin |
| 1005 | + i := n; |
| 1006 | + while (i > 0) and (chunks^[order[i - 1]].start > chunks^[c].start) do begin |
| 1007 | + order[i] := order[i - 1]; |
| 1008 | + dec(i); |
| 1009 | + end; |
| 1010 | + order[i] := c; |
| 1011 | + inc(n); |
| 1012 | + end; |
| 1013 | + i := 0; j := 0; |
| 1014 | + for k := 0 to n - 1 do begin |
| 1015 | + c := order[k]; |
| 1016 | + writeln; |
| 1017 | + writeln(ChunkName(c), ':'); |
| 1018 | + line := -1; |
| 1019 | + while (i < numSaid) and (said[i].at < chunks^[c].start) do inc(i); |
| 1020 | + while (i < numSaid) and (said[i].at < chunks^[c].start + chunks^[c].size) do begin |
| 1021 | + while (j < numLines) and (lines^[j].at <= said[i].at) do begin |
| 1022 | + if (lines^[j].chunk = c) and (lines^[j].line <> line) then begin |
| 1023 | + line := lines^[j].line; |
| 1024 | + writeln(line: 6, ' ', LineText(NameOf(lines^[j].path), line)); |
| 1025 | + end; |
| 1026 | + inc(j); |
| 1027 | + end; |
| 1028 | + text := said[i].text; |
| 1029 | + t := said[i].at; |
| 1030 | + if (text = 'jmp') or (text = 'call') then text := text + ' ' + IntStr(t + 5 + Get4At(t + 1) - chunks^[c].start) |
| 1031 | + else if (text[1] = 'j') and (pos(' ', text) = 0) then text := text + ' ' + IntStr(t + 6 + Get4At(t + 2) - chunks^[c].start); |
| 1032 | + writeln(t - chunks^[c].start: 14, ' ', text); |
| 1033 | + inc(i); |
| 1034 | + end; |
| 1035 | + end; |
| 1036 | + FreeMem(order); |
| 832 | 1037 | end; |
| 833 | 1038 | |
| 834 | 1039 | end. |