navrutil.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {
  2. Copyright (c) 2015 by Jeppe Johansen
  3. AVR version of some node tree helper routines
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit navrutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. fmodule,
  23. node,nbas,
  24. ngenutil,
  25. symtype,symconst,symsym,symdef;
  26. type
  27. tavrnodeutils = class(tnodeutils)
  28. protected
  29. class procedure insert_init_final_table(main: tmodule; entries:tfplist); override;
  30. end;
  31. implementation
  32. uses
  33. verbose,cutils,globtype,globals,constexp,
  34. aasmdata,aasmtai,aasmcpu,aasmcnst,aasmbase,
  35. cpubase,
  36. symbase,symcpu,symtable,defutil,
  37. ncnv,ncon,ninl,ncal,nld,nmem,
  38. systems,
  39. CPUInfo,
  40. ppu,
  41. pass_1;
  42. class procedure tavrnodeutils.insert_init_final_table(main: tmodule; entries:tfplist);
  43. var
  44. op : TAsmOp;
  45. initList, finalList, header: TAsmList;
  46. entry : pinitfinalentry;
  47. i : longint;
  48. begin
  49. initList:=TAsmList.create;
  50. finalList:=TAsmList.create;
  51. if CPUAVR_HAS_JMP_CALL in cpu_capabilities[current_settings.cputype] then
  52. op:=A_CALL
  53. else
  54. op:=A_RCALL;
  55. for i:=0 to entries.count-1 do
  56. begin
  57. entry:=pinitfinalentry(entries[i]);
  58. if entry^.finifunc<>'' then
  59. finalList.Concat(taicpu.op_sym(op,current_asmdata.RefAsmSymbol(entry^.finifunc,AT_FUNCTION)));
  60. if entry^.initfunc<>'' then
  61. initList.Concat(taicpu.op_sym(op,current_asmdata.RefAsmSymbol(entry^.initfunc,AT_FUNCTION)));
  62. end;
  63. initList.Concat(taicpu.op_none(A_RET));
  64. finalList.Concat(taicpu.op_none(A_RET));
  65. begin
  66. header:=TAsmList.create;
  67. new_section(header, sec_code, 'FPC_INIT_FUNC_TABLE', 1);
  68. header.concat(tai_symbol.Createname_global('FPC_INIT_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));
  69. initList.insertList(header);
  70. header.free;
  71. current_asmdata.AsmLists[al_procedures].concatList(initList);
  72. end;
  73. begin
  74. header:=TAsmList.create;
  75. new_section(header, sec_code, 'FPC_FINALIZE_FUNC_TABLE', 1);
  76. header.concat(tai_symbol.Createname_global('FPC_FINALIZE_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));
  77. finalList.insertList(header);
  78. header.free;
  79. current_asmdata.AsmLists[al_procedures].concatList(finalList);
  80. end;
  81. initList.Free;
  82. finalList.Free;
  83. inherited insert_init_final_table(main,entries);
  84. end;
  85. begin
  86. cnodeutils:=tavrnodeutils;
  87. end.