n8086con.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. Copyright (c) 1998-2012 by Florian Klaempfl and others
  3. Generate i8086 assembler for constants
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit n8086con;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,symtype,ncon,ncgcon,nx86con;
  22. type
  23. { ti8086pointerconstnode }
  24. ti8086pointerconstnode = class(tcgpointerconstnode)
  25. constructor create(v : TConstPtrUInt;def:tdef);override;
  26. procedure printnodedata(var t: text);override;
  27. procedure pass_generate_code;override;
  28. end;
  29. implementation
  30. uses
  31. systems,globals,
  32. symconst,symdef,symcpu,
  33. defutil,
  34. cpubase,
  35. cga,cgx86,cgobj,cgbase,cgutils,
  36. node;
  37. {*****************************************************************************
  38. T8086POINTERCONSTNODE
  39. *****************************************************************************}
  40. constructor ti8086pointerconstnode.create(v: TConstPtrUInt; def: tdef);
  41. begin
  42. { truncate near pointers }
  43. if (def.typ<>pointerdef) or not (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  44. v := Word(v);
  45. inherited create(v, def);
  46. end;
  47. procedure ti8086pointerconstnode.printnodedata(var t: text);
  48. begin
  49. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  50. writeln(t,printnodeindention,'value = $',hexstr(word(value shr 16),4),':',hexstr(word(value),4))
  51. else
  52. inherited printnodedata(t);
  53. end;
  54. procedure ti8086pointerconstnode.pass_generate_code;
  55. begin
  56. { far pointer? }
  57. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  58. begin
  59. location_reset(location,LOC_CONSTANT,OS_32);
  60. location.value:=longint(value);
  61. end
  62. else
  63. begin
  64. { an integer const. behaves as a memory reference }
  65. location_reset(location,LOC_CONSTANT,OS_ADDR);
  66. location.value:=aint(value);
  67. end;
  68. end;
  69. begin
  70. cpointerconstnode:=ti8086pointerconstnode;
  71. end.