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