hlcgx86.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 hlcgx86;
  20. interface
  21. {$i fpcdefs.inc}
  22. uses
  23. globtype,
  24. aasmdata,
  25. cgbase,
  26. symtype,symdef,
  27. parabase,
  28. hlcgobj, hlcg2ll;
  29. type
  30. thlcgx86 = class(thlcg2ll)
  31. protected
  32. procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara); override;
  33. procedure a_jmp_external_name(list: TAsmList; const externalname: TSymStr); override;
  34. public
  35. procedure a_load_undefined_cgpara(list: TAsmList; size: tdef; const cgpara: TCGPara); override;
  36. procedure a_bit_set_reg_reg(list: TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber, dest: tregister); override;
  37. end;
  38. implementation
  39. uses
  40. globals,systems,
  41. aasmbase,
  42. cgutils,
  43. cpubase,aasmcpu;
  44. { thlcgx86 }
  45. procedure thlcgx86.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  46. begin
  47. { the caller will pop a value from the fpu stack }
  48. if assigned(resloc.location) and
  49. (resloc.location^.loc=LOC_FPUREGISTER) then
  50. list.concat(taicpu.op_none(A_FLDZ));
  51. end;
  52. procedure thlcgx86.a_jmp_external_name(list: TAsmList; const externalname: TSymStr);
  53. var
  54. ref : treference;
  55. sym : tasmsymbol;
  56. begin
  57. if (target_info.system = system_i386_darwin) then
  58. begin
  59. { a_jmp_name jumps to a stub which is always pic-safe on darwin }
  60. inherited;
  61. exit;
  62. end;
  63. sym:=current_asmdata.RefAsmSymbol(externalname,AT_FUNCTION);
  64. reference_reset_symbol(ref,sym,0,sizeof(pint),[]);
  65. { create pic'ed? }
  66. if (cs_create_pic in current_settings.moduleswitches) and
  67. { darwin/x86_64's assembler doesn't want @PLT after call symbols }
  68. not(target_info.system in [system_x86_64_darwin,system_i386_iphonesim,system_x86_64_iphonesim]) then
  69. ref.refaddr:=addr_pic
  70. else
  71. ref.refaddr:=addr_full;
  72. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  73. end;
  74. procedure thlcgx86.a_load_undefined_cgpara(list: TAsmList; size: tdef; const cgpara: TCGPara);
  75. begin
  76. if not (cgpara.Location^.Loc in [LOC_REGISTER,LOC_CREGISTER]) and
  77. (cgpara.size=OS_ADDR) then
  78. a_load_reg_cgpara(list,size,NR_FRAME_POINTER_REG,cgpara)
  79. else
  80. inherited;
  81. end;
  82. procedure thlcgx86.a_bit_set_reg_reg(list: TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber, dest: tregister);
  83. const
  84. bit_set_clr_instr: array[boolean] of tasmop = (A_BTR,A_BTS);
  85. begin
  86. list.concat(taicpu.op_reg_reg(bit_set_clr_instr[doset],S_NO,bitnumber,dest));
  87. end;
  88. end.