hlcgx86.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. {$ifdef I8086}
  44. cpuinfo,
  45. {$endif I8086}
  46. cpubase,aasmcpu;
  47. { thlcgx86 }
  48. procedure thlcgx86.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  49. begin
  50. { the caller will pop a value from the fpu stack }
  51. if assigned(resloc.location) and
  52. (resloc.location^.loc=LOC_FPUREGISTER) then
  53. list.concat(taicpu.op_none(A_FLDZ));
  54. end;
  55. procedure thlcgx86.a_jmp_external_name(list: TAsmList; const externalname: TSymStr);
  56. var
  57. ref : treference;
  58. sym : tasmsymbol;
  59. begin
  60. if (target_info.system = system_i386_darwin) then
  61. begin
  62. { a_jmp_name jumps to a stub which is always pic-safe on darwin }
  63. inherited;
  64. exit;
  65. end;
  66. sym:=current_asmdata.RefAsmSymbol(externalname,AT_FUNCTION);
  67. reference_reset_symbol(ref,sym,0,sizeof(pint),[]);
  68. { create pic'ed? }
  69. if (cs_create_pic in current_settings.moduleswitches) and
  70. { darwin/x86_64's assembler doesn't want @PLT after call symbols }
  71. not(target_info.system in [system_x86_64_darwin,system_i386_iphonesim,system_x86_64_iphonesim]) then
  72. ref.refaddr:=addr_pic
  73. else
  74. ref.refaddr:=addr_full;
  75. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  76. end;
  77. procedure thlcgx86.a_load_undefined_cgpara(list: TAsmList; size: tdef; const cgpara: TCGPara);
  78. begin
  79. if not (cgpara.Location^.Loc in [LOC_REGISTER,LOC_CREGISTER]) and
  80. (cgpara.size=OS_ADDR) then
  81. a_load_reg_cgpara(list,size,NR_FRAME_POINTER_REG,cgpara)
  82. else
  83. inherited;
  84. end;
  85. procedure thlcgx86.a_bit_set_reg_reg(list: TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber, dest: tregister);
  86. const
  87. bit_set_clr_instr: array[boolean] of tasmop = (A_BTR,A_BTS);
  88. begin
  89. {$ifdef I8086}
  90. { BTR/BTS is only supportd by 80386 CPU or later }
  91. if not(CPUX86_HAS_BTX in cpu_capabilities[current_settings.optimizecputype]) then
  92. inherited
  93. else
  94. {$endif I8086}
  95. list.concat(taicpu.op_reg_reg(bit_set_clr_instr[doset],S_NO,bitnumber,dest));
  96. end;
  97. end.