hlcgcpu.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. symtype,symdef,
  27. parabase, hlcgobj, hlcg2ll;
  28. type
  29. thlcgmips = class(thlcg2ll)
  30. function a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; forceresdef: tdef; weak: boolean): tcgpara; 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. globals,
  40. cgobj,
  41. cpubase,
  42. cgcpu;
  43. function thlcgmips.a_call_name(list: TAsmList; pd: tprocdef; const s: TSymStr; forceresdef: tdef; weak: boolean): tcgpara;
  44. var
  45. ref : treference;
  46. begin
  47. if pd.proccalloption=pocall_cdecl then
  48. begin
  49. if (cs_create_pic in current_settings.moduleswitches) then
  50. begin
  51. reference_reset(ref,sizeof(aint));
  52. ref.symbol:=current_asmdata.RefAsmSymbol(s);
  53. cg.a_loadaddr_ref_reg(list,ref,NR_PIC_FUNC);
  54. end
  55. else
  56. begin
  57. { Use $gp/$t9 registers as the code might be in a shared library }
  58. reference_reset(ref,sizeof(aint));
  59. ref.symbol:=current_asmdata.RefAsmSymbol('_gp');
  60. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_name')));
  61. cg.a_loadaddr_ref_reg(list,ref,NR_GP);
  62. reference_reset(ref,sizeof(aint));
  63. ref.symbol:=current_asmdata.RefAsmSymbol(s);
  64. ref.base:=NR_GP;
  65. ref.refaddr:=addr_pic_call16;
  66. cg.a_loadaddr_ref_reg(list,ref,NR_PIC_FUNC);
  67. end;
  68. cg.a_call_reg(list,NR_PIC_FUNC);
  69. end
  70. else
  71. cg.a_call_name(list,s,weak);
  72. { set the result location }
  73. result:=get_call_result_cgpara(pd,forceresdef);
  74. end;
  75. procedure thlcgmips.a_call_reg(list: TAsmList; pd: tabstractprocdef; reg: tregister);
  76. begin
  77. if (pd.proccalloption=pocall_cdecl) and (reg<>NR_PIC_FUNC) then
  78. begin
  79. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_reg')));
  80. { Use $t9 register as the code might be in a shared library }
  81. cg.a_load_reg_reg(list,OS_32,OS_32,reg,NR_PIC_FUNC);
  82. cg.a_call_reg(list,NR_PIC_FUNC);
  83. end
  84. else
  85. cg.a_call_reg(list,reg);
  86. end;
  87. procedure thlcgmips.a_call_ref(list: TAsmList; pd: tabstractprocdef; const ref: treference);
  88. begin
  89. if pd.proccalloption =pocall_cdecl then
  90. begin
  91. { Use $t9 register as the code might be in a shared library }
  92. list.concat(tai_comment.create(strpnew('Using PIC code for a_call_ref')));
  93. cg.a_loadaddr_ref_reg(list,ref,NR_PIC_FUNC);
  94. cg.a_call_reg(list,NR_PIC_FUNC);
  95. end
  96. else
  97. cg.a_call_ref(list,ref);
  98. end;
  99. procedure create_hlcodegen;
  100. begin
  101. hlcg:=thlcgmips.create;
  102. create_codegen;
  103. end;
  104. end.