hlcgcpu.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit contains routines to create a pass-through high-level code
  5. generator. This is used by most regular code generators.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit hlcgcpu;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,
  24. aasmbase, aasmdata,
  25. cgbase, cgutils,
  26. symdef,
  27. hlcgobj, hlcg2ll;
  28. type
  29. thlcg2mips = class(thlcg2ll)
  30. procedure a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; weak: boolean);override;
  31. procedure a_call_reg(list : TAsmList;pd : tabstractprocdef;reg : tregister);override;
  32. procedure a_call_ref(list : TAsmList;pd : tabstractprocdef;const ref : treference);override;
  33. end;
  34. procedure create_hlcodegen;
  35. implementation
  36. uses
  37. aasmtai,
  38. cutils,
  39. cgobj,
  40. cpubase,
  41. cgcpu;
  42. procedure thlcg2mips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; weak: boolean);
  43. var
  44. ref : treference;
  45. begin
  46. if pd.proccalloption=pocall_cdecl then
  47. begin
  48. { Use $gp/$t9 registers as the code might be in a shared library }
  49. reference_reset(ref,sizeof(aint));
  50. ref.symbol:=current_asmdata.RefAsmSymbol('_gp');
  51. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));
  52. cg.a_loadaddr_ref_reg(list,ref,NR_GP);
  53. reference_reset(ref,sizeof(aint));
  54. ref.symbol:=current_asmdata.RefAsmSymbol(s);
  55. ref.base:=NR_GP;
  56. ref.refaddr:=addr_pic;
  57. cg.a_loadaddr_ref_reg(list,ref,NR_PIC_FUNC);
  58. cg.a_call_reg(list,NR_PIC_FUNC);
  59. end
  60. else
  61. cg.a_call_name(list,s,weak);
  62. end;
  63. procedure thlcg2mips.a_call_reg(list: TAsmList; pd: tabstractprocdef; reg: tregister);
  64. begin
  65. if (pd.proccalloption=pocall_cdecl) and (reg<>NR_PIC_FUNC) then
  66. begin
  67. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_reg')));
  68. { Use $t9 register as the code might be in a shared library }
  69. cg.a_load_reg_reg(list,OS_32,OS_32,reg,NR_PIC_FUNC);
  70. cg.a_call_reg(list,NR_PIC_FUNC);
  71. end
  72. else
  73. cg.a_call_reg(list,reg);
  74. end;
  75. procedure thlcg2mips.a_call_ref(list: TAsmList; pd: tabstractprocdef; const ref: treference);
  76. begin
  77. if pd.proccalloption =pocall_cdecl then
  78. begin
  79. { Use $t9 register as the code might be in a shared library }
  80. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_ref')));
  81. cg.a_loadaddr_ref_reg(list,ref,NR_PIC_FUNC);
  82. cg.a_call_reg(list,NR_PIC_FUNC);
  83. end
  84. else
  85. cg.a_call_ref(list,ref);
  86. end;
  87. procedure create_hlcodegen;
  88. begin
  89. hlcg:=thlcg2mips.create;
  90. create_codegen;
  91. end;
  92. end.