2
0

aasmdef.pas 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. Copyright (c) 2016 by Jonas Maebe, member of the Free Pascal
  3. development team
  4. Contains asmsymbol functionality that depends on symdef (to avoid creating
  5. circular dependencies between symdef and aasmdata via aasmtai)
  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 aasmdef;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,
  24. aasmbase,aasmdata,
  25. symtype;
  26. type
  27. TAsmDataDef = class(TAsmData)
  28. function DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol; override;
  29. end;
  30. implementation
  31. uses
  32. globals,cutils,systems,
  33. aasmtai,aasmcnst,
  34. symdef,
  35. fmodule;
  36. function TAsmDataDef.DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  37. var
  38. symind: tasmsymbol;
  39. ptrdef: tdef;
  40. tcb: ttai_typedconstbuilder;
  41. wasdefined: boolean;
  42. begin
  43. result:=DefineAsmSymbolByClassBase(symclass,s,_bind,_typ,def,wasdefined);
  44. { define the indirect asmsymbol if necessary }
  45. if not wasdefined and
  46. (_bind in [AB_GLOBAL,AB_COMMON]) and
  47. (_typ<>AT_DATA_NOINDIRECT) and
  48. (((_typ=AT_DATA) and
  49. (tf_supports_packages in target_info.flags) and
  50. (target_info.system in systems_indirect_var_imports)
  51. ) or
  52. (_typ=AT_DATA_FORCEINDIRECT)
  53. ) then
  54. begin
  55. ptrdef:=cpointerdef.getreusable(def);
  56. symind:=current_asmdata.DefineAsmSymbol(s,AB_INDIRECT,AT_DATA,ptrdef);
  57. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable,tcalo_new_section]);
  58. tcb.emit_tai(Tai_const.Create_sym_offset(result,0),ptrdef);
  59. current_asmdata.AsmLists[al_indirectglobals].concatlist(tcb.get_final_asmlist(
  60. symind,ptrdef,
  61. sec_rodata,
  62. lower(symind.name),
  63. ptrdef.alignment));
  64. tcb.free;
  65. if (_typ=AT_DATA_FORCEINDIRECT) and not (target_info.system in systems_indirect_var_imports) then
  66. current_module.add_public_asmsym(symind.name,AB_INDIRECT,AT_DATA);
  67. end;
  68. end;
  69. begin
  70. { Do not overwrite if already set, by powerpc specific code for example }
  71. if not assigned(casmdata) then
  72. casmdata:=TAsmDataDef;
  73. end.