1 /* Implement timing-related actions for CHILL.
2 Copyright (C) 1992, 93, 1994, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC 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, or (at your option)
11 GNU CC 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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
32 #ifndef LONG_TYPE_SIZE
33 #define LONG_TYPE_SIZE BITS_PER_WORD
36 /* set non-zero if input text is forced to lowercase */
37 extern int ignore_case;
39 /* set non-zero if special words are to be entered in uppercase */
40 extern int special_UC;
43 tree abs_timing_type_node;
44 tree duration_timing_type_node;
47 static tree rtstime_type_node = NULL_TREE;
49 /* the stack for AFTER primval [ DELAY ] IN
50 and has following layout
52 TREE_VALUE (TREE_VALUE (after_stack)) = current time or NULL_TREE (if DELAY specified)
53 TREE_PURPOSE (TREE_VALUE (after_stack)) = the duration location
54 TREE_VALUE (TREE_PURPOSE (after_stack)) = label at TIMEOUT
55 TREE_PURPOSE (TREE_PURPOSE (after_stack)) = label at the end of AFTER action
57 tree after_stack = NULL_TREE;
59 /* in pass 1 we need a separate list for the labels */
60 static tree after_stack_pass_1 = NULL_TREE;
61 static tree after_help;
66 tree ptr_ftype_durt_ptr_int;
67 tree int_ftype_abst_ptr_int;
69 tree long_ftype_int_int_int_int_int_int_int_ptr_int;
70 tree void_ftype_abstime_ptr;
71 tree int_ftype_ptr_durt_ptr;
72 tree void_ftype_durt_ptr;
73 tree void_ftype_ptr_durt_ptr_int;
78 ulong_type = TREE_TYPE (lookup_name (
79 get_identifier ((ignore_case || ! special_UC ) ?
82 /* build modes for TIME and DURATION */
83 duration_timing_type_node = make_unsigned_type (LONG_TYPE_SIZE);
84 temp = pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_DURATION],
85 duration_timing_type_node));
86 SET_CH_NOVELTY_NONNIL (duration_timing_type_node, temp);
87 abs_timing_type_node = make_unsigned_type (LONG_TYPE_SIZE);
88 temp = pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_TIME],
89 abs_timing_type_node));
90 SET_CH_NOVELTY_NONNIL (abs_timing_type_node, temp);
92 /* the mode of time the runtimesystem returns */
93 if (rtstime_type_node == NULL_TREE)
95 tree decl1, decl2, result;
97 decl1 = build_decl (FIELD_DECL,
98 get_identifier ("secs"),
100 DECL_INITIAL (decl1) = NULL_TREE;
101 decl2 = build_decl (FIELD_DECL,
102 get_identifier ("nsecs"),
104 DECL_INITIAL (decl2) = NULL_TREE;
105 TREE_CHAIN (decl2) = NULL_TREE;
106 TREE_CHAIN (decl1) = decl2;
108 result = build_chill_struct_type (decl1);
109 pushdecl (temp = build_decl (TYPE_DECL,
110 get_identifier ("__tmp_rtstime"), result));
111 DECL_SOURCE_LINE (temp) = 0;
112 satisfy_decl (temp, 0);
113 rtstime_type_node = TREE_TYPE (temp);
116 endlink = void_list_node;
118 ptr_ftype_durt_ptr_int
119 = build_function_type (ptr_type_node,
120 tree_cons (NULL_TREE, duration_timing_type_node,
121 tree_cons (NULL_TREE, ptr_type_node,
122 tree_cons (NULL_TREE, integer_type_node,
125 int_ftype_abst_ptr_int
126 = build_function_type (integer_type_node,
127 tree_cons (NULL_TREE, abs_timing_type_node,
128 tree_cons (NULL_TREE, ptr_type_node,
129 tree_cons (NULL_TREE, integer_type_node,
133 = build_function_type (void_type_node,
134 tree_cons (NULL_TREE, ptr_type_node,
137 long_ftype_int_int_int_int_int_int_int_ptr_int
138 = build_function_type (abs_timing_type_node,
139 tree_cons (NULL_TREE, integer_type_node,
140 tree_cons (NULL_TREE, integer_type_node,
141 tree_cons (NULL_TREE, integer_type_node,
142 tree_cons (NULL_TREE, integer_type_node,
143 tree_cons (NULL_TREE, integer_type_node,
144 tree_cons (NULL_TREE, integer_type_node,
145 tree_cons (NULL_TREE, integer_type_node,
146 tree_cons (NULL_TREE, ptr_type_node,
147 tree_cons (NULL_TREE, integer_type_node,
150 void_ftype_abstime_ptr
151 = build_function_type (void_type_node,
152 tree_cons (NULL_TREE, abs_timing_type_node,
153 tree_cons (NULL_TREE, ptr_type_node,
156 int_ftype_ptr_durt_ptr
157 = build_function_type (integer_type_node,
158 tree_cons (NULL_TREE, ptr_type_node,
159 tree_cons (NULL_TREE, duration_timing_type_node,
160 tree_cons (NULL_TREE, ptr_type_node,
164 = build_function_type (void_type_node,
165 tree_cons (NULL_TREE, duration_timing_type_node,
166 tree_cons (NULL_TREE, ptr_type_node,
169 void_ftype_ptr_durt_ptr_int
170 = build_function_type (void_type_node,
171 tree_cons (NULL_TREE, ptr_type_node,
172 tree_cons (NULL_TREE, duration_timing_type_node,
173 tree_cons (NULL_TREE, ptr_type_node,
174 tree_cons (NULL_TREE, integer_type_node,
177 builtin_function ("_abstime", long_ftype_int_int_int_int_int_int_int_ptr_int,
178 0, NOT_BUILT_IN, NULL_PTR);
179 builtin_function ("__check_cycle", void_ftype_ptr_durt_ptr_int,
180 0, NOT_BUILT_IN, NULL_PTR);
181 builtin_function ("__convert_duration_rtstime", void_ftype_durt_ptr,
182 0, NOT_BUILT_IN, NULL_PTR);
183 builtin_function ("__define_timeout", ptr_ftype_durt_ptr_int,
184 0, NOT_BUILT_IN, NULL_PTR);
185 builtin_function ("_inttime", void_ftype_abstime_ptr,
186 0, NOT_BUILT_IN, NULL_PTR);
187 builtin_function ("__remaintime", int_ftype_ptr_durt_ptr,
188 0, NOT_BUILT_IN, NULL_PTR);
189 builtin_function ("__rtstime", void_ftype_ptr,
190 0, NOT_BUILT_IN, NULL_PTR);
191 builtin_function ("__wait_until", int_ftype_abst_ptr_int,
192 0, NOT_BUILT_IN, NULL_PTR);
207 * if (__wait_until (primval) == 0)
218 tree abstime, expr, filename, fcall;
220 if (t == NULL_TREE || TREE_CODE (t) == ERROR_MARK)
221 abstime = convert (abs_timing_type_node, build_int_2 (0, 0));
225 if (TREE_TYPE (abstime) != abs_timing_type_node)
227 error ("absolute time value must be of mode TIME.");
228 abstime = convert (abs_timing_type_node, build_int_2 (0, 0));
230 filename = force_addr_of (get_chill_filename ());
231 fcall = build_chill_function_call (
232 lookup_name (get_identifier ("__wait_until")),
233 tree_cons (NULL_TREE, abstime,
234 tree_cons (NULL_TREE, filename,
235 tree_cons (NULL_TREE, get_chill_linenumber (), NULL_TREE))));
236 expr = build (EQ_EXPR, integer_type_node, fcall, integer_zero_node);
237 expand_start_cond (expr, 0);
238 emit_line_note (input_filename, lineno);
256 * __check_cycle (&now, primval, filename, lineno);
263 build_cycle_start (t)
266 tree purpose = build_tree_list (NULL_TREE, NULL_TREE);
267 tree toid = build_tree_list (purpose, NULL_TREE);
269 /* define the label. Note: define_label needs to be called in
270 pass 1 and pass 2. */
271 TREE_VALUE (toid) = define_label (input_filename, lineno,
272 get_unique_identifier ("CYCLE_label"));
275 tree duration_value, now_location;
277 if (t == NULL_TREE || TREE_CODE (t) == ERROR_MARK)
278 duration_value = convert (duration_timing_type_node, build_int_2 (0,0));
282 if (TREE_TYPE (duration_value) != duration_timing_type_node)
284 error ("duration primitive value must be of mode DURATION.");
285 duration_value = convert (duration_timing_type_node, build_int_2 (0,0));
287 TREE_PURPOSE (TREE_PURPOSE (toid)) = duration_value;
288 /* define the variable */
289 now_location = decl_temp1 (get_unique_identifier ("CYCLE_var"),
290 rtstime_type_node, 0,
292 TREE_VALUE (TREE_PURPOSE (toid)) = force_addr_of (now_location);
294 /* build the call to __rtstime */
296 build_chill_function_call (lookup_name (get_identifier ("__rtstime")),
297 build_tree_list (NULL_TREE, TREE_VALUE (TREE_PURPOSE (toid)))));
304 build_cycle_end (toid)
307 tree filename, linenumber;
309 /* here we call __check_cycle and then jump to beginning of this
311 filename = force_addr_of (get_chill_filename ());
312 linenumber = get_chill_linenumber ();
314 build_chill_function_call (
315 lookup_name (get_identifier ("__check_cycle")),
316 tree_cons (NULL_TREE, TREE_VALUE (TREE_PURPOSE (toid)),
317 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_PURPOSE (toid)),
318 tree_cons (NULL_TREE, filename,
319 tree_cons (NULL_TREE, linenumber, NULL_TREE))))));
320 expand_goto (TREE_VALUE (toid));
327 * AFTER primval [ DELAY ] IN
336 * struct chill_time __now;
337 * duration dur = primval;
338 * if (! delay_spceified)
339 * __rts_time (&__now);
352 build_after_start (duration, delay_flag)
360 value = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
361 purpose = after_stack_pass_1;
362 after_stack_pass_1 = TREE_CHAIN (after_stack_pass_1);
363 after_stack = tree_cons (purpose, value, after_stack);
365 if (TREE_TYPE (duration) != duration_timing_type_node)
367 error ("duration primitive value must be of mode DURATION.");
368 duration = convert (duration_timing_type_node, build_int_2 (0,0));
370 TREE_PURPOSE (value) = decl_temp1 (get_identifier ("AFTER_duration"),
371 duration_timing_type_node, 0,
376 /* in this case we have to get the current time */
377 TREE_VALUE (value) = decl_temp1 (get_unique_identifier ("AFTER_now"),
378 rtstime_type_node, 0,
380 /* build the function call to initialize the variable */
382 build_chill_function_call (lookup_name (get_identifier ("__rtstime")),
383 build_tree_list (NULL_TREE, force_addr_of (TREE_VALUE (value)))));
388 /* in pass 1 we just save the labels */
389 after_help = tree_cons (NULL_TREE, NULL_TREE, after_help);
390 after_stack_pass_1 = chainon (after_stack_pass_1, after_help);
395 build_after_timeout_start ()
401 /* jump to the end of AFTER action */
402 lookup_and_expand_goto (TREE_PURPOSE (TREE_PURPOSE (after_stack)));
403 label_name = TREE_VALUE (TREE_PURPOSE (after_stack));
404 /* mark we are in TIMEOUT part of AFTER action */
405 TREE_VALUE (TREE_PURPOSE (after_stack)) = NULL_TREE;
409 label_name = get_unique_identifier ("AFTER_tolabel");
410 TREE_VALUE (after_help) = label_name;
412 define_label (input_filename, lineno, label_name);
420 /* define the end label */
423 label_name = TREE_PURPOSE (TREE_PURPOSE (after_stack));
424 after_stack = TREE_CHAIN (after_stack);
428 label_name = get_unique_identifier ("AFTER_endlabel");
429 TREE_PURPOSE (after_help) = label_name;
430 after_help = TREE_CHAIN (after_help);
432 define_label (input_filename, lineno, label_name);
436 build_timeout_preface ()
438 tree timeout_value = null_pointer_node;
440 if (after_stack != NULL_TREE &&
441 TREE_VALUE (TREE_PURPOSE (after_stack)) != NULL_TREE)
445 to_loc = decl_temp1 (get_unique_identifier ("TOloc"),
446 rtstime_type_node, 0, NULL_TREE, 0, 0);
447 timeout_value = force_addr_of (to_loc);
449 if (TREE_VALUE (TREE_VALUE (after_stack)) == NULL_TREE)
451 /* DELAY specified -- just call __convert_duration_rtstime for
452 given duration value */
454 build_chill_function_call (
455 lookup_name (get_identifier ("__convert_duration_rtstime")),
456 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_VALUE (after_stack)),
457 tree_cons (NULL_TREE, timeout_value, NULL_TREE))));
461 /* delay not specified -- call __remaintime which returns the
462 remaining time of duration in rtstime format and check the
465 build_chill_function_call (
466 lookup_name (get_identifier ("__remaintime")),
467 tree_cons (NULL_TREE, force_addr_of (TREE_VALUE (TREE_VALUE (after_stack))),
468 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_VALUE (after_stack)),
469 tree_cons (NULL_TREE, timeout_value, NULL_TREE))));
470 tree expr = build (NE_EXPR, integer_type_node,
471 fcall, integer_zero_node);
472 expand_start_cond (expr, 0);
473 lookup_and_expand_goto (TREE_VALUE (TREE_PURPOSE (after_stack)));
477 return timeout_value;
481 build_timesupervised_call (fcall, to_loc)
485 if (to_loc == null_pointer_node)
486 expand_expr_stmt (fcall);
489 tree expr = build (NE_EXPR, integer_type_node, fcall, integer_zero_node);
490 expand_start_cond (expr, 0);
491 lookup_and_expand_goto (TREE_VALUE (TREE_PURPOSE (after_stack)));