Commit | Line | Data |
---|---|---|
4a71579b | 1 | /* |
79bfeef6 | 2 | * Copyright (C) 2015-2023 Free Software Foundation, Inc. |
4a71579b PC |
3 | * |
4 | * This file is part of GNU lightning. | |
5 | * | |
6 | * GNU lightning is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU Lesser General Public License as published | |
8 | * by the Free Software Foundation; either version 3, or (at your option) | |
9 | * any later version. | |
10 | * | |
11 | * GNU lightning is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
14 | * License for more details. | |
15 | * | |
16 | * Authors: | |
17 | * Paulo Cesar Pereira de Andrade | |
18 | */ | |
19 | ||
20 | #include <lightning.h> | |
21 | #include <lightning/jit_private.h> | |
22 | ||
23 | #if PROTO | |
24 | # define free_synth_list(node) _free_synth_list(_jit,node) | |
25 | static jit_node_t *_free_synth_list(jit_state_t*,jit_node_t*); | |
26 | #define rewind_prolog() _rewind_prolog(_jit) | |
27 | static void _rewind_prolog(jit_state_t*); | |
28 | #define rewind_prepare() _rewind_prepare(_jit) | |
29 | static void _rewind_prepare(jit_state_t*); | |
30 | #endif | |
31 | ||
32 | #if CODE | |
33 | /* | |
34 | * Implementation | |
35 | */ | |
36 | static jit_node_t * | |
37 | _free_synth_list(jit_state_t *_jit, jit_node_t *node) | |
38 | { | |
39 | jit_node_t *next; | |
40 | next = node->next; | |
41 | free_node(node); | |
42 | for (node = next; node && (node->flag & jit_flag_synth); node = next) { | |
43 | next = node->next; | |
44 | free_node(node); | |
45 | } | |
46 | return (next); | |
47 | } | |
48 | ||
49 | static void | |
50 | _rewind_prolog(jit_state_t *_jit) | |
51 | { | |
52 | jit_node_t *node; | |
53 | jit_node_t *next; | |
54 | _jitc->function->self.size = stack_framesize; | |
55 | #if __arm__ | |
56 | assert(jit_cpu.abi); | |
79bfeef6 PC |
57 | _jitc->function->alist = NULL; |
58 | #elif __mips__ | |
59 | _jitc->function->alist = NULL; | |
4a71579b PC |
60 | #endif |
61 | _jitc->function->self.argi = | |
62 | _jitc->function->self.argf = _jitc->function->self.argn = 0; | |
63 | _jitc->tail = _jitc->function->prolog; | |
64 | node = _jitc->tail->next; | |
65 | _jitc->tail->next = (jit_node_t *)0; | |
66 | _jitc->tail->link = (jit_node_t *)0; | |
67 | for (; node; node = next) { | |
68 | next = node->next; | |
69 | switch (node->code) { | |
79bfeef6 PC |
70 | case jit_code_arg_c: case jit_code_arg_s: |
71 | case jit_code_arg_i: case jit_code_arg_l: | |
4a71579b | 72 | node->next = (jit_node_t *)0; |
79bfeef6 | 73 | jit_make_arg(node, node->code); |
4a71579b PC |
74 | break; |
75 | case jit_code_arg_f: | |
76 | node->next = (jit_node_t *)0; | |
77 | jit_make_arg_f(node); | |
78 | break; | |
79 | case jit_code_arg_d: | |
80 | node->next = (jit_node_t *)0; | |
81 | jit_make_arg_d(node); | |
82 | break; | |
83 | case jit_code_getarg_c: | |
84 | jit_getarg_c(node->u.w, node->v.n); | |
85 | next = free_synth_list(node); | |
86 | break; | |
87 | case jit_code_getarg_uc: | |
88 | jit_getarg_uc(node->u.w, node->v.n); | |
89 | next = free_synth_list(node); | |
90 | break; | |
91 | case jit_code_getarg_s: | |
92 | jit_getarg_s(node->u.w, node->v.n); | |
93 | next = free_synth_list(node); | |
94 | break; | |
95 | case jit_code_getarg_us: | |
96 | jit_getarg_us(node->u.w, node->v.n); | |
97 | next = free_synth_list(node); | |
98 | break; | |
99 | case jit_code_getarg_i: | |
100 | jit_getarg_i(node->u.w, node->v.n); | |
101 | next = free_synth_list(node); | |
102 | break; | |
103 | case jit_code_getarg_f: | |
104 | jit_getarg_f(node->u.w, node->v.n); | |
105 | next = free_synth_list(node); | |
106 | break; | |
107 | case jit_code_getarg_d: | |
108 | jit_getarg_d(node->u.w, node->v.n); | |
109 | next = free_synth_list(node); | |
110 | break; | |
111 | case jit_code_putargr: | |
112 | jit_putargr(node->u.w, node->v.n); | |
113 | next = free_synth_list(node); | |
114 | break; | |
115 | case jit_code_putargi: | |
116 | jit_putargi(node->u.w, node->v.n); | |
117 | next = free_synth_list(node); | |
118 | break; | |
119 | case jit_code_putargr_f: | |
120 | jit_putargr_f(node->u.w, node->v.n); | |
121 | next = free_synth_list(node); | |
122 | break; | |
123 | case jit_code_putargi_f: | |
124 | jit_putargi_f(node->u.f, node->v.n); | |
125 | next = free_synth_list(node); | |
126 | break; | |
127 | case jit_code_putargr_d: | |
128 | jit_putargr_d(node->u.w, node->v.n); | |
129 | next = free_synth_list(node); | |
130 | break; | |
131 | case jit_code_putargi_d: | |
132 | jit_putargi_d(node->u.d, node->v.n); | |
133 | next = free_synth_list(node); | |
134 | break; | |
135 | default: | |
136 | node->next = (jit_node_t *)0; | |
137 | link_node(node); | |
138 | break; | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | static void | |
144 | _rewind_prepare(jit_state_t *_jit) | |
145 | { | |
146 | jit_node_t *node; | |
147 | jit_node_t *next; | |
148 | _jitc->function->call.argi = | |
149 | _jitc->function->call.argf = | |
150 | _jitc->function->call.size = 0; | |
151 | _jitc->tail = _jitc->prepare; | |
152 | node = _jitc->tail->next; | |
153 | _jitc->tail->next = (jit_node_t *)0; | |
154 | _jitc->tail->link = (jit_node_t *)0; | |
155 | for (; node; node = next) { | |
156 | next = node->next; | |
157 | switch (node->code) { | |
158 | case jit_code_pushargr: | |
159 | jit_pushargr(node->u.w); | |
160 | next = free_synth_list(node); | |
161 | break; | |
162 | case jit_code_pushargi: | |
163 | jit_pushargi(node->u.w); | |
164 | next = free_synth_list(node); | |
165 | break; | |
166 | case jit_code_pushargr_f: | |
167 | jit_pushargr_f(node->u.w); | |
168 | next = free_synth_list(node); | |
169 | break; | |
170 | case jit_code_pushargi_f: | |
171 | jit_pushargi_f(node->u.f); | |
172 | next = free_synth_list(node); | |
173 | break; | |
174 | case jit_code_pushargr_d: | |
175 | jit_pushargr_d(node->u.w); | |
176 | next = free_synth_list(node); | |
177 | break; | |
178 | case jit_code_pushargi_d: | |
179 | jit_pushargi_d(node->u.d); | |
180 | next = free_synth_list(node); | |
181 | break; | |
182 | default: | |
183 | node->next = (jit_node_t *)0; | |
184 | link_node(node); | |
185 | break; | |
186 | } | |
187 | } | |
188 | } | |
189 | #endif |