n8086con.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. {$ifdef DEBUG_NODE_XML}
  28. procedure XMLPrintNodeData(var T: Text); override;
  29. {$endif DEBUG_NODE_XML}
  30. procedure pass_generate_code;override;
  31. end;
  32. implementation
  33. uses
  34. systems,globals,
  35. symconst,symdef,symcpu,
  36. defutil,
  37. cpubase,
  38. cga,cgx86,cgobj,cgbase,cgutils,
  39. node;
  40. {*****************************************************************************
  41. T8086POINTERCONSTNODE
  42. *****************************************************************************}
  43. constructor ti8086pointerconstnode.create(v: TConstPtrUInt; def: tdef);
  44. begin
  45. { truncate near pointers }
  46. if (def.typ<>pointerdef) or not (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  47. v := Word(v);
  48. inherited create(v, def);
  49. end;
  50. procedure ti8086pointerconstnode.printnodedata(var t: text);
  51. begin
  52. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  53. writeln(t,printnodeindention,'value = $',hexstr(word(value shr 16),4),':',hexstr(word(value),4))
  54. else
  55. inherited printnodedata(t);
  56. end;
  57. {$ifdef DEBUG_NODE_XML}
  58. procedure Ti8086PointerConstNode.XMLPrintNodeData(var T: Text);
  59. begin
  60. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  61. WriteLn(T, PrintNodeIndention, '<value>$', hexstr(word(value shr 16),4),':',hexstr(word(value),4), '</value>')
  62. else
  63. inherited XMLPrintNodeData(T);
  64. end;
  65. {$endif DEBUG_NODE_XML}
  66. procedure ti8086pointerconstnode.pass_generate_code;
  67. begin
  68. { far pointer? }
  69. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  70. begin
  71. location_reset(location,LOC_CONSTANT,OS_32);
  72. location.value:=longint(value);
  73. end
  74. else
  75. begin
  76. { an integer const. behaves as a memory reference }
  77. location_reset(location,LOC_CONSTANT,OS_ADDR);
  78. location.value:=aint(value);
  79. end;
  80. end;
  81. begin
  82. cpointerconstnode:=ti8086pointerconstnode;
  83. end.