n8086cnv.pas 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate code for i8086 assembler for type converting nodes
  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 n8086cnv;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgcnv,nx86cnv,defutil,defcmp;
  22. type
  23. { t8086typeconvnode }
  24. t8086typeconvnode = class(tx86typeconvnode)
  25. protected
  26. function typecheck_int_to_int: tnode;override;
  27. function typecheck_proc_to_procvar: tnode;override;
  28. procedure second_proc_to_procvar;override;
  29. end;
  30. implementation
  31. uses
  32. verbose,systems,globals,globtype,
  33. aasmbase,aasmtai,aasmdata,aasmcpu,
  34. symconst,symdef,symcpu,
  35. cgbase,cga,procinfo,pass_1,pass_2,
  36. ncon,ncal,ncnv,nmem,n8086mem,
  37. cpubase,cpuinfo,
  38. cgutils,cgobj,hlcgobj,cgx86,ncgutil,
  39. tgobj;
  40. function t8086typeconvnode.typecheck_int_to_int: tnode;
  41. begin
  42. Result:=inherited typecheck_int_to_int;
  43. if (is_16bitint(totypedef) or is_8bitint(totypedef)) and (left.nodetype=addrn) then
  44. begin
  45. if left.nodetype=addrn then
  46. ti8086addrnode(left).get_offset_only:=true;
  47. end;
  48. end;
  49. function t8086typeconvnode.typecheck_proc_to_procvar: tnode;
  50. begin
  51. Result:=inherited typecheck_proc_to_procvar;
  52. if tcnf_proc_2_procvar_get_offset_only in convnodeflags then
  53. begin
  54. if resultdef.typ<>procvardef then
  55. internalerror(2018040401);
  56. if po_far in tprocvardef(resultdef).procoptions then
  57. resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_offset);
  58. end
  59. else if (tcnf_proc_2_procvar_2_voidpointer in convnodeflags) and
  60. (current_settings.x86memorymodel in x86_far_code_models) then
  61. begin
  62. if resultdef.typ<>procvardef then
  63. internalerror(2018040402);
  64. if not (po_far in tprocvardef(resultdef).procoptions) then
  65. resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_far_address);
  66. end;
  67. end;
  68. procedure t8086typeconvnode.second_proc_to_procvar;
  69. begin
  70. if (tcnf_proc_2_procvar_get_offset_only in convnodeflags) and
  71. is_proc_far(tabstractprocdef(resultdef)) then
  72. internalerror(2018040403);
  73. inherited;
  74. end;
  75. begin
  76. ctypeconvnode:=t8086typeconvnode
  77. end.