n8086con.pas 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 pass_generate_code;override;
  27. end;
  28. implementation
  29. uses
  30. systems,globals,
  31. symconst,symdef,symcpu,
  32. defutil,
  33. cpubase,
  34. cga,cgx86,cgobj,cgbase,cgutils;
  35. {*****************************************************************************
  36. T8086POINTERCONSTNODE
  37. *****************************************************************************}
  38. constructor ti8086pointerconstnode.create(v: TConstPtrUInt; def: tdef);
  39. begin
  40. { truncate near pointers }
  41. if (def.typ<>pointerdef) or not (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  42. v := Word(v);
  43. inherited create(v, def);
  44. end;
  45. procedure ti8086pointerconstnode.pass_generate_code;
  46. begin
  47. { far pointer? }
  48. if (typedef.typ=pointerdef) and (tcpupointerdef(typedef).x86pointertyp in [x86pt_far,x86pt_huge]) then
  49. begin
  50. location_reset(location,LOC_CONSTANT,OS_32);
  51. location.value:=longint(value);
  52. end
  53. else
  54. begin
  55. { an integer const. behaves as a memory reference }
  56. location_reset(location,LOC_CONSTANT,OS_ADDR);
  57. location.value:=aint(value);
  58. end;
  59. end;
  60. begin
  61. cpointerconstnode:=ti8086pointerconstnode;
  62. end.