Skip to content

Commit 9750ad2

Browse files
committed
introduced global variables for vtable
1 parent 4e04e85 commit 9750ad2

19 files changed

+2011
-1305
lines changed

compiler/plc_driver/src/pipelines/participant.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,14 @@ impl PipelineParticipantMut for VTableIndexer {
289289

290290
let vtables_pou = VTableIndexer::create_vtables_for_pous(&index);
291291
let vtables_intf = VTableIndexer::create_vtables_for_interfaces(&index);
292+
let (internal, external) = VTableIndexer::create_global_variables_for_vtable(&index);
292293

294+
//FIXME: should we create the vtable in the unit of its pou?
293295
if let Some(unit) = project.units.first_mut() {
294296
unit.user_types.extend(vtables_pou);
295297
unit.user_types.extend(vtables_intf);
298+
unit.global_vars.push(internal);
299+
unit.global_vars.push(external);
296300
}
297301

298302
project.index(self.id_provider.clone())

libs/stdlib/src/bistable_functionblocks.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ impl SetResetParams {
1313
}
1414
}
1515

16+
pub struct EmptyVTable;
17+
18+
#[allow(non_upper_case_globals)]
19+
#[no_mangle]
20+
#[used]
21+
pub static __vtable_SR: EmptyVTable = EmptyVTable {};
1622
///.
1723
/// Bistable function, set dominant
1824
///
@@ -22,6 +28,10 @@ pub extern "C" fn SR(params: &mut SetResetParams) {
2228
params.set_output(params.set | (!params.reset & params.output));
2329
}
2430

31+
#[allow(non_upper_case_globals)]
32+
#[no_mangle]
33+
#[used]
34+
pub static __vtable_RS: EmptyVTable = EmptyVTable {};
2535
///.
2636
/// Bistable function, reset dominant
2737
///

libs/stdlib/src/counters.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct CTUParams<T> {
1414
internal: Signal,
1515
}
1616

17+
pub struct EmptyVTable {}
18+
1719
impl<T> CTUParams<T>
1820
where
1921
T: Integer + Copy,
@@ -47,6 +49,10 @@ where
4749
params.update_q();
4850
}
4951

52+
#[allow(non_upper_case_globals)]
53+
#[no_mangle]
54+
#[used]
55+
pub static __vtable_CTU: EmptyVTable = EmptyVTable {};
5056
///.
5157
/// Counter up for INT
5258
///
@@ -56,6 +62,10 @@ pub extern "C" fn CTU(params: &mut CTUParams<i16>) {
5662
ctu(params);
5763
}
5864

65+
#[allow(non_upper_case_globals)]
66+
#[no_mangle]
67+
#[used]
68+
pub static __vtable_CTU_INT: EmptyVTable = EmptyVTable {};
5969
///.
6070
/// Counter up for INT
6171
///
@@ -65,6 +75,10 @@ pub extern "C" fn CTU_INT(params: &mut CTUParams<i16>) {
6575
ctu(params);
6676
}
6777

78+
#[allow(non_upper_case_globals)]
79+
#[no_mangle]
80+
#[used]
81+
pub static __vtable_CTU_DINT: EmptyVTable = EmptyVTable {};
6882
///.
6983
/// Counter up for DINT
7084
///
@@ -74,6 +88,10 @@ pub extern "C" fn CTU_DINT(params: &mut CTUParams<i32>) {
7488
ctu(params);
7589
}
7690

91+
#[allow(non_upper_case_globals)]
92+
#[no_mangle]
93+
#[used]
94+
pub static __vtable_CTU_UDINT: EmptyVTable = EmptyVTable {};
7795
///.
7896
/// Counter up for DINT
7997
///
@@ -83,6 +101,10 @@ pub extern "C" fn CTU_UDINT(params: &mut CTUParams<u32>) {
83101
ctu(params);
84102
}
85103

104+
#[allow(non_upper_case_globals)]
105+
#[no_mangle]
106+
#[used]
107+
pub static __vtable_CTU_LINT: EmptyVTable = EmptyVTable {};
86108
///.
87109
/// Counter up for LINT
88110
///
@@ -92,6 +114,10 @@ pub extern "C" fn CTU_LINT(params: &mut CTUParams<i64>) {
92114
ctu(params);
93115
}
94116

117+
#[allow(non_upper_case_globals)]
118+
#[no_mangle]
119+
#[used]
120+
pub static __vtable_CTU_ULINT: EmptyVTable = EmptyVTable {};
95121
///.
96122
/// Counter up for ULINT
97123
///
@@ -146,6 +172,10 @@ where
146172
params.update_q();
147173
}
148174

175+
#[allow(non_upper_case_globals)]
176+
#[no_mangle]
177+
#[used]
178+
pub static __vtable_CTD: EmptyVTable = EmptyVTable {};
149179
///.
150180
/// Counter down for INT
151181
///
@@ -155,6 +185,10 @@ pub extern "C" fn CTD(params: &mut CTDParams<i16>) {
155185
ctd(params);
156186
}
157187

188+
#[allow(non_upper_case_globals)]
189+
#[no_mangle]
190+
#[used]
191+
pub static __vtable_CTD_INT: EmptyVTable = EmptyVTable {};
158192
///.
159193
/// Counter down for INT
160194
///
@@ -164,6 +198,10 @@ pub extern "C" fn CTD_INT(params: &mut CTDParams<i16>) {
164198
ctd(params);
165199
}
166200

201+
#[allow(non_upper_case_globals)]
202+
#[no_mangle]
203+
#[used]
204+
pub static __vtable_CTD_DINT: EmptyVTable = EmptyVTable {};
167205
///.
168206
/// Counter down for DINT
169207
///
@@ -173,6 +211,10 @@ pub extern "C" fn CTD_DINT(params: &mut CTDParams<i32>) {
173211
ctd(params);
174212
}
175213

214+
#[allow(non_upper_case_globals)]
215+
#[no_mangle]
216+
#[used]
217+
pub static __vtable_CTD_UDINT: EmptyVTable = EmptyVTable {};
176218
///.
177219
/// Counter down for UDINT
178220
///
@@ -182,6 +224,10 @@ pub extern "C" fn CTD_UDINT(params: &mut CTDParams<u32>) {
182224
ctd(params);
183225
}
184226

227+
#[allow(non_upper_case_globals)]
228+
#[no_mangle]
229+
#[used]
230+
pub static __vtable_CTD_LINT: EmptyVTable = EmptyVTable {};
185231
///.
186232
/// Counter down for LINT
187233
///
@@ -191,6 +237,10 @@ pub extern "C" fn CTD_LINT(params: &mut CTDParams<i64>) {
191237
ctd(params);
192238
}
193239

240+
#[allow(non_upper_case_globals)]
241+
#[no_mangle]
242+
#[used]
243+
pub static __vtable_CTD_ULINT: EmptyVTable = EmptyVTable {};
194244
///.
195245
/// Counter down for ULINT
196246
///
@@ -276,6 +326,10 @@ where
276326
params.update_qd();
277327
}
278328

329+
#[allow(non_upper_case_globals)]
330+
#[no_mangle]
331+
#[used]
332+
pub static __vtable_CTUD: EmptyVTable = EmptyVTable {};
279333
///.
280334
/// Counter up and down for INT
281335
///
@@ -285,6 +339,10 @@ pub extern "C" fn CTUD(params: &mut CTUDParams<i16>) {
285339
ctud(params);
286340
}
287341

342+
#[allow(non_upper_case_globals)]
343+
#[no_mangle]
344+
#[used]
345+
pub static __vtable_CTUD_INT: EmptyVTable = EmptyVTable {};
288346
///.
289347
/// Counter up and down for INT
290348
///
@@ -294,6 +352,10 @@ pub extern "C" fn CTUD_INT(params: &mut CTUDParams<i16>) {
294352
ctud(params);
295353
}
296354

355+
#[allow(non_upper_case_globals)]
356+
#[no_mangle]
357+
#[used]
358+
pub static __vtable_CTUD_DINT: EmptyVTable = EmptyVTable {};
297359
///.
298360
/// Counter up and down for DINT
299361
///
@@ -303,6 +365,10 @@ pub extern "C" fn CTUD_DINT(params: &mut CTUDParams<i32>) {
303365
ctud(params);
304366
}
305367

368+
#[allow(non_upper_case_globals)]
369+
#[no_mangle]
370+
#[used]
371+
pub static __vtable_CTUD_UDINT: EmptyVTable = EmptyVTable {};
306372
///.
307373
/// Counter up and down for UDINT
308374
///
@@ -312,6 +378,10 @@ pub extern "C" fn CTUD_UDINT(params: &mut CTUDParams<u32>) {
312378
ctud(params);
313379
}
314380

381+
#[allow(non_upper_case_globals)]
382+
#[no_mangle]
383+
#[used]
384+
pub static __vtable_CTUD_LINT: EmptyVTable = EmptyVTable {};
315385
///.
316386
/// Counter up and down for LINT
317387
///
@@ -321,6 +391,10 @@ pub extern "C" fn CTUD_LINT(params: &mut CTUDParams<i64>) {
321391
ctud(params);
322392
}
323393

394+
#[allow(non_upper_case_globals)]
395+
#[no_mangle]
396+
#[used]
397+
pub static __vtable_CTUD_ULINT: EmptyVTable = EmptyVTable {};
324398
///.
325399
/// Counter up and down for ULINT
326400
///

libs/stdlib/src/flanks.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ impl Trigger {
1515
}
1616
}
1717

18+
pub struct EmtpyVTable;
19+
20+
#[allow(non_upper_case_globals)]
21+
#[no_mangle]
22+
#[used]
23+
pub static __vtable_R_TRIG: EmtpyVTable = EmtpyVTable {};
1824
#[allow(non_snake_case)]
1925
#[no_mangle]
2026
pub extern "C" fn R_TRIG(trigger: &mut Trigger) {
2127
let res = trigger.internal.rising_edge(trigger.clk);
2228
trigger.set_output(res);
2329
}
2430

31+
#[allow(non_upper_case_globals)]
32+
#[no_mangle]
33+
#[used]
34+
pub static __vtable_F_TRIG: EmtpyVTable = EmtpyVTable {};
2535
#[allow(non_snake_case)]
2636
#[no_mangle]
2737
pub extern "C" fn F_TRIG(trigger: &mut Trigger) {

libs/stdlib/src/timers.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct TimerParams {
2525
start_time: Option<Instant>,
2626
}
2727

28+
pub struct EmptyVTable {}
29+
2830
impl TimerParams {
2931
/// This method returns true if the timer has already started
3032
/// It does not take into consideration the preset/range for the timer
@@ -81,6 +83,11 @@ impl TimerParams {
8183
}
8284
}
8385

86+
#[allow(non_upper_case_globals)]
87+
#[no_mangle]
88+
#[used]
89+
pub static __vtable_TP: EmptyVTable = EmptyVTable {};
90+
8491
#[allow(non_snake_case)]
8592
#[no_mangle]
8693
pub extern "C" fn TP(timer: &mut TimerParams) {
@@ -106,6 +113,10 @@ pub extern "C" fn TP(timer: &mut TimerParams) {
106113
timer.input_edge.set(timer.input);
107114
}
108115

116+
#[allow(non_upper_case_globals)]
117+
#[no_mangle]
118+
#[used]
119+
pub static __vtable_TON: EmptyVTable = EmptyVTable {};
109120
#[allow(non_snake_case)]
110121
#[no_mangle]
111122
pub extern "C" fn TON(timer: &mut TimerParams) {
@@ -132,6 +143,10 @@ pub extern "C" fn TON(timer: &mut TimerParams) {
132143
timer.input_edge.set(timer.input);
133144
}
134145

146+
#[allow(non_upper_case_globals)]
147+
#[no_mangle]
148+
#[used]
149+
pub static __vtable_TOF: EmptyVTable = EmptyVTable {};
135150
#[allow(non_snake_case)]
136151
#[no_mangle]
137152
pub extern "C" fn TOF(timer: &mut TimerParams) {
@@ -154,36 +169,60 @@ pub extern "C" fn TOF(timer: &mut TimerParams) {
154169
}
155170

156171
// Aliases
172+
#[allow(non_upper_case_globals)]
173+
#[no_mangle]
174+
#[used]
175+
pub static __vtable_TP_TIME: EmptyVTable = EmptyVTable {};
157176
#[allow(non_snake_case)]
158177
#[no_mangle]
159178
pub extern "C" fn TP_TIME(timer: &mut TimerParams) {
160179
TP(timer)
161180
}
162181

182+
#[allow(non_upper_case_globals)]
183+
#[no_mangle]
184+
#[used]
185+
pub static __vtable_TP_LTIME: EmptyVTable = EmptyVTable {};
163186
#[allow(non_snake_case)]
164187
#[no_mangle]
165188
pub extern "C" fn TP_LTIME(timer: &mut TimerParams) {
166189
TP(timer)
167190
}
168191

192+
#[allow(non_upper_case_globals)]
193+
#[no_mangle]
194+
#[used]
195+
pub static __vtable_TON_TIME: EmptyVTable = EmptyVTable {};
169196
#[allow(non_snake_case)]
170197
#[no_mangle]
171198
pub extern "C" fn TON_TIME(timer: &mut TimerParams) {
172199
TON(timer)
173200
}
174201

202+
#[allow(non_upper_case_globals)]
203+
#[no_mangle]
204+
#[used]
205+
pub static __vtable_TON_LTIME: EmptyVTable = EmptyVTable {};
175206
#[allow(non_snake_case)]
176207
#[no_mangle]
177208
pub extern "C" fn TON_LTIME(timer: &mut TimerParams) {
178209
TON(timer)
179210
}
180211

212+
#[allow(non_upper_case_globals)]
213+
#[no_mangle]
214+
#[used]
215+
pub static __vtable_TOF_TIME: EmptyVTable = EmptyVTable {};
181216
#[allow(non_snake_case)]
182217
#[no_mangle]
183218
pub extern "C" fn TOF_TIME(timer: &mut TimerParams) {
184219
TOF(timer)
185220
}
186221

222+
#[allow(non_upper_case_globals)]
223+
#[no_mangle]
224+
#[used]
225+
pub static __vtable_TOF_LTIME: EmptyVTable = EmptyVTable {};
187226
#[allow(non_snake_case)]
188227
#[no_mangle]
189228
pub extern "C" fn TOF_LTIME(timer: &mut TimerParams) {

0 commit comments

Comments
 (0)