n8086tcon.pas 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {
  2. Copyright (c) 1998-2011 by Florian Klaempfl, Jonas Maebe
  3. Generates i8086 assembler for typed constant declarations
  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 n8086tcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,symdef,ngtcon;
  22. type
  23. { ti8086typedconstbuilder }
  24. ti8086typedconstbuilder = class(tasmlisttypedconstbuilder)
  25. protected
  26. procedure tc_emit_pointerdef(def: tpointerdef; var node: tnode);override;
  27. end;
  28. implementation
  29. uses
  30. ncon,ncnv,defcmp,defutil,aasmtai,symcpu;
  31. { ti8086typedconstbuilder }
  32. procedure ti8086typedconstbuilder.tc_emit_pointerdef(def: tpointerdef; var node: tnode);
  33. var
  34. hp: tnode;
  35. begin
  36. { remove equal typecasts for pointer/nil addresses }
  37. if (node.nodetype=typeconvn) then
  38. with Ttypeconvnode(node) do
  39. if (left.nodetype in [addrn,niln]) and equal_defs(def,node.resultdef) then
  40. begin
  41. hp:=left;
  42. left:=nil;
  43. node.free;
  44. node:=hp;
  45. end;
  46. { const pointer ? }
  47. if (node.nodetype = pointerconstn) then
  48. begin
  49. ftcb.queue_init(def);
  50. if is_farpointer(def) or is_hugepointer(def) then
  51. begin
  52. ftcb.queue_typeconvn(s32inttype,def);
  53. ftcb.queue_emit_ordconst(longint(tpointerconstnode(node).value),s32inttype);
  54. end
  55. else
  56. begin
  57. ftcb.queue_typeconvn(s16inttype,def);
  58. ftcb.queue_emit_ordconst(smallint(tpointerconstnode(node).value),s16inttype);
  59. end;
  60. end
  61. else if node.nodetype=niln then
  62. begin
  63. if is_farpointer(def) or is_hugepointer(def) then
  64. ftcb.emit_tai(Tai_const.Create_32bit(0),u32inttype)
  65. else
  66. ftcb.emit_tai(Tai_const.Create_16bit(0),u16inttype);
  67. end
  68. else
  69. inherited tc_emit_pointerdef(def, node);
  70. end;
  71. begin
  72. ctypedconstbuilder:=ti8086typedconstbuilder;
  73. end.