summaryrefslogtreecommitdiff
path: root/compiler/avr/navrutil.pas
blob: 4a27d5853b116272d5b6c7d1f596310a64aeee78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
    Copyright (c) 2015 by Jeppe Johansen

    AVR version of some node tree helper routines

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
unit navrutil;

{$i fpcdefs.inc}

interface

  uses
    cclasses,
    node,nbas,
    ngenutil,
    symtype,symconst,symsym,symdef;


  type
    tavrnodeutils = class(tnodeutils)
    protected
      class procedure insert_init_final_table(entries:tfplist); override;
    end;

implementation

    uses
      verbose,cutils,globtype,globals,constexp,fmodule,
      aasmdata,aasmtai,aasmcpu,aasmcnst,aasmbase,
      cpubase,
      symbase,symcpu,symtable,defutil,
      ncnv,ncon,ninl,ncal,nld,nmem,
      systems,
      CPUInfo,
      ppu,
      pass_1;


  class procedure tavrnodeutils.insert_init_final_table(entries:tfplist);
    var
      op : TAsmOp;
      initList, finalList, header: TAsmList;
      entry : pinitfinalentry;
      i : longint;
    begin
      initList:=TAsmList.create;
      finalList:=TAsmList.create;

      if CPUAVR_HAS_JMP_CALL in cpu_capabilities[current_settings.cputype] then
        op:=A_CALL
      else
        op:=A_RCALL;

      for i:=0 to entries.count-1 do
        begin
          entry:=pinitfinalentry(entries[i]);
          if entry^.finifunc<>'' then
            finalList.Concat(taicpu.op_sym(op,current_asmdata.RefAsmSymbol(entry^.finifunc,AT_FUNCTION)));
          if entry^.initfunc<>'' then
            initList.Concat(taicpu.op_sym(op,current_asmdata.RefAsmSymbol(entry^.initfunc,AT_FUNCTION)));
        end;

      initList.Concat(taicpu.op_none(A_RET));
      finalList.Concat(taicpu.op_none(A_RET));

      begin
        header:=TAsmList.create;
        new_section(header, sec_code, 'FPC_INIT_FUNC_TABLE', 1);
        header.concat(tai_symbol.Createname_global('FPC_INIT_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));

        initList.insertList(header);
        header.free;

        current_asmdata.AsmLists[al_procedures].concatList(initList);
      end;

      begin
        header:=TAsmList.create;
        new_section(header, sec_code, 'FPC_FINALIZE_FUNC_TABLE', 1);
        header.concat(tai_symbol.Createname_global('FPC_FINALIZE_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));

        finalList.insertList(header);
        header.free;

        current_asmdata.AsmLists[al_procedures].concatList(finalList);
      end;

      initList.Free;
      finalList.Free;

      inherited insert_init_final_table(entries);
    end;

begin
  cnodeutils:=tavrnodeutils;
end.