aasmdef.pas 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. function TAsmDataDef.DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  36. var
  37. symind: tasmsymbol;
  38. ptrdef: tdef;
  39. tcb: ttai_typedconstbuilder;
  40. wasdefined: boolean;
  41. begin
  42. result:=DefineAsmSymbolByClassBase(symclass,s,_bind,_typ,def,wasdefined);
  43. { define the indirect asmsymbol if necessary }
  44. if not wasdefined and
  45. (_bind in [AB_GLOBAL,AB_COMMON]) and
  46. (((_typ=AT_DATA) and
  47. (tf_supports_packages in target_info.flags) and
  48. (target_info.system in systems_indirect_var_imports)
  49. ) or
  50. (_typ=AT_DATA_FORCEINDIRECT)
  51. ) then
  52. begin
  53. ptrdef:=cpointerdef.getreusable(def);
  54. symind:=current_asmdata.DefineAsmSymbol(s,AB_INDIRECT,AT_DATA,ptrdef);
  55. tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable,tcalo_new_section]);
  56. tcb.emit_tai(Tai_const.Create_sym_offset(result,0),ptrdef);
  57. current_asmdata.AsmLists[al_exports].concatlist(tcb.get_final_asmlist(
  58. symind,ptrdef,
  59. sec_rodata,
  60. lower(symind.name),
  61. const_align(ptrdef.alignment)));
  62. tcb.free;
  63. end;
  64. end;
  65. begin
  66. casmdata:=TAsmDataDef;
  67. end.