nppcld.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate ppc assembler for nodes that handle loads and assignments
  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 nppcld;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgld;
  22. type
  23. tppcloadnode = class(tcgloadnode)
  24. procedure pass_2; override;
  25. procedure generate_picvaraccess;override;
  26. end;
  27. implementation
  28. uses
  29. verbose,
  30. systems,
  31. cpubase,
  32. cgutils,cgobj,
  33. aasmbase,aasmtai,
  34. symconst,symsym,
  35. procinfo,
  36. nld;
  37. procedure tppcloadnode.pass_2;
  38. var
  39. l : tasmsymbol;
  40. ref : treference;
  41. begin
  42. case target_info.system of
  43. system_powerpc_darwin:
  44. begin
  45. if (symtableentry.typ = procsym) and
  46. (tprocsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  47. (
  48. (not tprocsym(symtableentry).owner.iscurrentunit) or
  49. (po_external in tprocsym(symtableentry).procdef[1].procoptions)
  50. ) then
  51. begin
  52. l:=objectlibrary.getasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr');
  53. if not(assigned(l)) then
  54. begin
  55. l:=objectlibrary.newasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  56. asmlist[picdata].concat(tai_symbol.create(l,0));
  57. asmlist[picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tprocsym(symtableentry).procdef[1].mangledname,AB_EXTERNAL,AT_DATA)));
  58. asmlist[picdata].concat(tai_const.create_32bit(0));
  59. end;
  60. reference_reset_symbol(ref,l,0);
  61. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  62. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  63. end
  64. else
  65. inherited pass_2;
  66. end;
  67. else
  68. inherited pass_2;
  69. end;
  70. end;
  71. procedure tppcloadnode.generate_picvaraccess;
  72. var
  73. l : tasmsymbol;
  74. ref : treference;
  75. begin
  76. case target_info.system of
  77. system_powerpc_darwin:
  78. begin
  79. if ([vo_is_dll_var,vo_is_external] * tglobalvarsym(symtableentry).varoptions <> []) or
  80. ((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  81. not(tglobalvarsym(symtableentry).owner.iscurrentunit)) then
  82. begin
  83. l:=objectlibrary.getasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr');
  84. if not(assigned(l)) then
  85. begin
  86. l:=objectlibrary.newasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  87. asmlist[picdata].concat(tai_symbol.create(l,0));
  88. asmlist[picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA)));
  89. asmlist[picdata].concat(tai_const.create_32bit(0));
  90. end;
  91. reference_reset_symbol(ref,l,0);
  92. { ref.base:=current_procinfo.got;
  93. ref.relsymbol:=current_procinfo.gotlabel;}
  94. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  95. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  96. end
  97. else
  98. internalerror(200403021);
  99. end
  100. else
  101. internalerror(200402291);
  102. end;
  103. end;
  104. begin
  105. cloadnode:=tppcloadnode;
  106. end.