hlcgcpu.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. aasmdata,
  24. symdef,
  25. hlcg2ll;
  26. type
  27. thlcgcpu = class(thlcg2ll)
  28. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  29. end;
  30. implementation
  31. uses
  32. verbose,
  33. cpubase,
  34. symconst,
  35. aasmbase,aasmtai,aasmcpu,
  36. procinfo,
  37. fmodule,
  38. hlcgobj,
  39. cgcpu;
  40. procedure thlcgcpu.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  41. var
  42. make_global: boolean;
  43. begin
  44. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  45. Internalerror(2024091401);
  46. if not assigned(procdef.struct) or
  47. (procdef.procoptions*[po_classmethod, po_staticmethod,
  48. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  49. Internalerror(2024091402);
  50. if procdef.owner.symtabletype<>ObjectSymtable then
  51. Internalerror(2024091403);
  52. make_global:=false;
  53. if (not current_module.is_unit) or
  54. create_smartlink or
  55. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  56. make_global:=true;
  57. if make_global then
  58. list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
  59. else
  60. list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
  61. { the wrapper might need aktlocaldata for the additional data to
  62. load the constant }
  63. current_procinfo:=cprocinfo.create(nil);
  64. //{ set param1 interface to self }
  65. //g_adjust_self_value(list,procdef,ioffset);
  66. //
  67. //{ case 4 }
  68. //if (po_virtualmethod in procdef.procoptions) and
  69. // not is_objectpascal_helper(procdef.struct) then
  70. // begin
  71. // loadvmttor12;
  72. // op_onr12methodaddr;
  73. // end
  74. //{ case 0 }
  75. //else if GenerateThumbCode then
  76. // begin
  77. // { bl cannot be used here because it destroys lr }
  78. //
  79. // list.concat(taicpu.op_regset(A_PUSH,R_INTREGISTER,R_SUBWHOLE,[RS_R0]));
  80. //
  81. // { create consts entry }
  82. // reference_reset(tmpref,4,[]);
  83. // current_asmdata.getjumplabel(l);
  84. // current_procinfo.aktlocaldata.Concat(tai_align.Create(4));
  85. // cg.a_label(current_procinfo.aktlocaldata,l);
  86. // tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  87. // current_procinfo.aktlocaldata.concat(tai_const.Create_sym(current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION)));
  88. //
  89. // tmpref.symbol:=l;
  90. // tmpref.base:=NR_PC;
  91. // cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,tmpref,NR_R0);
  92. // list.concat(taicpu.op_reg_reg(A_MOV,NR_R12,NR_R0));
  93. // list.concat(taicpu.op_regset(A_POP,R_INTREGISTER,R_SUBWHOLE,[RS_R0]));
  94. // list.concat(taicpu.op_reg(A_BX,NR_R12));
  95. // end
  96. //else
  97. // list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION)));
  98. list.concatlist(current_procinfo.aktlocaldata);
  99. { dummy so far }
  100. list.concat(taicpu.op_none(A_RET));
  101. current_procinfo.Free;
  102. current_procinfo:=nil;
  103. list.concat(Tai_symbol_end.Createname(labelname));
  104. end;
  105. procedure create_hlcodegen_cpu;
  106. begin
  107. hlcg:=thlcgcpu.create;
  108. create_codegen;
  109. end;
  110. begin
  111. chlcgobj:=thlcgcpu;
  112. create_hlcodegen:=@create_hlcodegen_cpu;
  113. end.