nppcld.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. globtype,globals,
  32. cpubase,
  33. cgutils,cgobj,
  34. aasmbase,aasmtai,
  35. symconst,symsym,
  36. procinfo,
  37. nld;
  38. procedure tppcloadnode.pass_2;
  39. var
  40. l : tasmsymbol;
  41. ref : treference;
  42. begin
  43. case target_info.system of
  44. system_powerpc_darwin:
  45. begin
  46. if (symtableentry.typ = procsym) and
  47. (tprocsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  48. (
  49. (not tprocsym(symtableentry).owner.iscurrentunit) or
  50. (po_external in tprocsym(symtableentry).procdef[1].procoptions)
  51. ) then
  52. begin
  53. l:=objectlibrary.getasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr');
  54. if not(assigned(l)) then
  55. begin
  56. l:=objectlibrary.newasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  57. asmlist[al_picdata].concat(tai_symbol.create(l,0));
  58. asmlist[al_picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tprocsym(symtableentry).procdef[1].mangledname,AB_EXTERNAL,AT_DATA)));
  59. asmlist[al_picdata].concat(tai_const.create_32bit(0));
  60. end;
  61. reference_reset_symbol(ref,l,0);
  62. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  63. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  64. end
  65. else
  66. inherited pass_2;
  67. end;
  68. else
  69. inherited pass_2;
  70. end;
  71. end;
  72. procedure tppcloadnode.generate_picvaraccess;
  73. var
  74. l : tasmsymbol;
  75. ref : treference;
  76. begin
  77. case target_info.system of
  78. system_powerpc_darwin:
  79. begin
  80. if ([vo_is_dll_var,vo_is_external] * tglobalvarsym(symtableentry).varoptions <> []) or
  81. ((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  82. (not(tglobalvarsym(symtableentry).owner.iscurrentunit) or
  83. (cs_create_pic in aktmoduleswitches))) then
  84. begin
  85. l:=objectlibrary.getasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr');
  86. if not(assigned(l)) then
  87. begin
  88. l:=objectlibrary.newasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  89. asmlist[al_picdata].concat(tai_symbol.create(l,0));
  90. asmlist[al_picdata].concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA)));
  91. asmlist[al_picdata].concat(tai_const.create_32bit(0));
  92. end;
  93. reference_reset_symbol(ref,l,0);
  94. { ref.base:=current_procinfo.got;
  95. ref.relsymbol:=current_procinfo.gotlabel;}
  96. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  97. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  98. end
  99. else
  100. internalerror(200403021);
  101. end
  102. else
  103. internalerror(200402291);
  104. end;
  105. end;
  106. begin
  107. cloadnode:=tppcloadnode;
  108. end.