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, 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #ifndef LONG_TYPE_SIZE
32 #define LONG_TYPE_SIZE BITS_PER_WORD
35 /* set non-zero if input text is forced to lowercase */
36 extern int ignore_case;
38 /* set non-zero if special words are to be entered in uppercase */
39 extern int special_UC;
42 tree abs_timing_type_node;
43 tree duration_timing_type_node;
46 static tree rtstime_type_node = NULL_TREE;
48 /* the stack for AFTER primval [ DELAY ] IN
49 and has following layout
51 TREE_VALUE (TREE_VALUE (after_stack)) = current time or NULL_TREE (if DELAY specified)
52 TREE_PURPOSE (TREE_VALUE (after_stack)) = the duration location
53 TREE_VALUE (TREE_PURPOSE (after_stack)) = label at TIMEOUT
54 TREE_PURPOSE (TREE_PURPOSE (after_stack)) = label at the end of AFTER action
56 tree after_stack = NULL_TREE;
58 /* in pass 1 we need a seperate list for the labels */
59 static tree after_stack_pass_1 = NULL_TREE;
60 static tree after_help;
65 tree ptr_ftype_durt_ptr_int;
66 tree int_ftype_abst_ptr_int;
68 tree long_ftype_int_int_int_int_int_int_int_ptr_int;
69 tree void_ftype_abstime_ptr;
70 tree int_ftype_ptr_durt_ptr;
71 tree void_ftype_durt_ptr;
72 tree void_ftype_ptr_durt_ptr_int;
77 ulong_type = TREE_TYPE (lookup_name (
78 get_identifier ((ignore_case || ! special_UC ) ?
81 /* build modes for TIME and DURATION */
82 duration_timing_type_node = make_unsigned_type (LONG_TYPE_SIZE);
83 temp = pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_DURATION],
84 duration_timing_type_node));
85 SET_CH_NOVELTY_NONNIL (duration_timing_type_node, temp);
86 abs_timing_type_node = make_unsigned_type (LONG_TYPE_SIZE);
87 temp = pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_TIME],
88 abs_timing_type_node));
89 SET_CH_NOVELTY_NONNIL (abs_timing_type_node, temp);
91 /* the mode of time the runtimesystem returns */
92 if (rtstime_type_node == NULL_TREE)
94 tree decl1, decl2, result;
96 decl1 = build_decl (FIELD_DECL,
97 get_identifier ("secs"),
99 DECL_INITIAL (decl1) = NULL_TREE;
100 decl2 = build_decl (FIELD_DECL,
101 get_identifier ("nsecs"),
103 DECL_INITIAL (decl2) = NULL_TREE;
104 TREE_CHAIN (decl2) = NULL_TREE;
105 TREE_CHAIN (decl1) = decl2;
107 result = build_chill_struct_type (decl1);
108 pushdecl (temp = build_decl (TYPE_DECL,
109 get_identifier ("__tmp_rtstime"), result));
110 DECL_SOURCE_LINE (temp) = 0;
111 satisfy_decl (temp, 0);
112 rtstime_type_node = TREE_TYPE (temp);
115 endlink = void_list_node;
117 ptr_ftype_durt_ptr_int
118 = build_function_type (ptr_type_node,
119 tree_cons (NULL_TREE, duration_timing_type_node,
120 tree_cons (NULL_TREE, ptr_type_node,
121 tree_cons (NULL_TREE, integer_type_node,
124 int_ftype_abst_ptr_int
125 = build_function_type (integer_type_node,
126 tree_cons (NULL_TREE, abs_timing_type_node,
127 tree_cons (NULL_TREE, ptr_type_node,
128 tree_cons (NULL_TREE, integer_type_node,
132 = build_function_type (void_type_node,
133 tree_cons (NULL_TREE, ptr_type_node,
136 long_ftype_int_int_int_int_int_int_int_ptr_int
137 = build_function_type (abs_timing_type_node,
138 tree_cons (NULL_TREE, integer_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, ptr_type_node,
146 tree_cons (NULL_TREE, integer_type_node,
149 void_ftype_abstime_ptr
150 = build_function_type (void_type_node,
151 tree_cons (NULL_TREE, abs_timing_type_node,
152 tree_cons (NULL_TREE, ptr_type_node,
155 int_ftype_ptr_durt_ptr
156 = build_function_type (integer_type_node,
157 tree_cons (NULL_TREE, ptr_type_node,
158 tree_cons (NULL_TREE, duration_timing_type_node,
159 tree_cons (NULL_TREE, ptr_type_node,
163 = build_function_type (void_type_node,
164 tree_cons (NULL_TREE, duration_timing_type_node,
165 tree_cons (NULL_TREE, ptr_type_node,
168 void_ftype_ptr_durt_ptr_int
169 = build_function_type (void_type_node,
170 tree_cons (NULL_TREE, ptr_type_node,
171 tree_cons (NULL_TREE, duration_timing_type_node,
172 tree_cons (NULL_TREE, ptr_type_node,
173 tree_cons (NULL_TREE, integer_type_node,
176 builtin_function ("_abstime", long_ftype_int_int_int_int_int_int_int_ptr_int,
177 NOT_BUILT_IN, NULL_PTR);
178 builtin_function ("__check_cycle", void_ftype_ptr_durt_ptr_int,
179 NOT_BUILT_IN, NULL_PTR);
180 builtin_function ("__convert_duration_rtstime", void_ftype_durt_ptr,
181 NOT_BUILT_IN, NULL_PTR);
182 builtin_function ("__define_timeout", ptr_ftype_durt_ptr_int,
183 NOT_BUILT_IN, NULL_PTR);
184 builtin_function ("_inttime", void_ftype_abstime_ptr,
185 NOT_BUILT_IN, NULL_PTR);
186 builtin_function ("__remaintime", int_ftype_ptr_durt_ptr,
187 NOT_BUILT_IN, NULL_PTR);
188 builtin_function ("__rtstime", void_ftype_ptr,
189 NOT_BUILT_IN, NULL_PTR);
190 builtin_function ("__wait_until", int_ftype_abst_ptr_int,
191 NOT_BUILT_IN, NULL_PTR);
206 * if (__wait_until (primval) == 0)
217 tree abstime, expr, filename, fcall;
219 if (t == NULL_TREE || TREE_CODE (t) == ERROR_MARK)
220 abstime = convert (abs_timing_type_node, build_int_2 (0, 0));
224 if (TREE_TYPE (abstime) != abs_timing_type_node)
226 error ("absolute time value must be of mode TIME.");
227 abstime = convert (abs_timing_type_node, build_int_2 (0, 0));
229 filename = force_addr_of (get_chill_filename ());
230 fcall = build_chill_function_call (
231 lookup_name (get_identifier ("__wait_until")),
232 tree_cons (NULL_TREE, abstime,
233 tree_cons (NULL_TREE, filename,
234 tree_cons (NULL_TREE, get_chill_linenumber (), NULL_TREE))));
235 expr = build (EQ_EXPR, integer_type_node, fcall, integer_zero_node);
236 expand_start_cond (expr, 0);
237 emit_line_note (input_filename, lineno);
255 * __check_cycle (&now, primval, filename, lineno);
262 build_cycle_start (t)
265 tree purpose = build_tree_list (NULL_TREE, NULL_TREE);
266 tree toid = build_tree_list (purpose, NULL_TREE);
268 /* define the label. Note: define_label needs to be called in
269 pass 1 and pass 2. */
270 TREE_VALUE (toid) = define_label (input_filename, lineno,
271 get_unique_identifier ("CYCLE_label"));
274 tree duration_value, now_location;
276 if (t == NULL_TREE || TREE_CODE (t) == ERROR_MARK)
277 duration_value = convert (duration_timing_type_node, build_int_2 (0,0));
281 if (TREE_TYPE (duration_value) != duration_timing_type_node)
283 error ("duration primitive value must be of mode DURATION.");
284 duration_value = convert (duration_timing_type_node, build_int_2 (0,0));
286 TREE_PURPOSE (TREE_PURPOSE (toid)) = duration_value;
287 /* define the variable */
288 now_location = decl_temp1 (get_unique_identifier ("CYCLE_var"),
289 rtstime_type_node, 0,
291 TREE_VALUE (TREE_PURPOSE (toid)) = force_addr_of (now_location);
293 /* build the call to __rtstime */
295 build_chill_function_call (lookup_name (get_identifier ("__rtstime")),
296 build_tree_list (NULL_TREE, TREE_VALUE (TREE_PURPOSE (toid)))));
303 build_cycle_end (toid)
306 tree filename, linenumber;
308 /* here we call __check_cycle and then jump to beginning of this
310 filename = force_addr_of (get_chill_filename ());
311 linenumber = get_chill_linenumber ();
313 build_chill_function_call (
314 lookup_name (get_identifier ("__check_cycle")),
315 tree_cons (NULL_TREE, TREE_VALUE (TREE_PURPOSE (toid)),
316 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_PURPOSE (toid)),
317 tree_cons (NULL_TREE, filename,
318 tree_cons (NULL_TREE, linenumber, NULL_TREE))))));
319 expand_goto (TREE_VALUE (toid));
326 * AFTER primval [ DELAY ] IN
335 * struct chill_time __now;
336 * duration dur = primval;
337 * if (! delay_spceified)
338 * __rts_time (&__now);
351 build_after_start (duration, delay_flag)
359 value = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
360 purpose = after_stack_pass_1;
361 after_stack_pass_1 = TREE_CHAIN (after_stack_pass_1);
362 after_stack = tree_cons (purpose, value, after_stack);
364 if (TREE_TYPE (duration) != duration_timing_type_node)
366 error ("duration primitive value must be of mode DURATION.");
367 duration = convert (duration_timing_type_node, build_int_2 (0,0));
369 TREE_PURPOSE (value) = decl_temp1 (get_identifier ("AFTER_duration"),
370 duration_timing_type_node, 0,
375 /* in this case we have to get the current time */
376 TREE_VALUE (value) = decl_temp1 (get_unique_identifier ("AFTER_now"),
377 rtstime_type_node, 0,
379 /* build the function call to initialize the variable */
381 build_chill_function_call (lookup_name (get_identifier ("__rtstime")),
382 build_tree_list (NULL_TREE, force_addr_of (TREE_VALUE (value)))));
387 /* in pass 1 we just save the labels */
388 after_help = tree_cons (NULL_TREE, NULL_TREE, after_help);
389 after_stack_pass_1 = chainon (after_stack_pass_1, after_help);
394 build_after_timeout_start ()
400 /* jump to the end of AFTER action */
401 lookup_and_expand_goto (TREE_PURPOSE (TREE_PURPOSE (after_stack)));
402 label_name = TREE_VALUE (TREE_PURPOSE (after_stack));
403 /* mark we are in TIMEOUT part of AFTER action */
404 TREE_VALUE (TREE_PURPOSE (after_stack)) = NULL_TREE;
408 label_name = get_unique_identifier ("AFTER_tolabel");
409 TREE_VALUE (after_help) = label_name;
411 define_label (input_filename, lineno, label_name);
419 /* define the end label */
422 label_name = TREE_PURPOSE (TREE_PURPOSE (after_stack));
423 after_stack = TREE_CHAIN (after_stack);
427 label_name = get_unique_identifier ("AFTER_endlabel");
428 TREE_PURPOSE (after_help) = label_name;
429 after_help = TREE_CHAIN (after_help);
431 define_label (input_filename, lineno, label_name);
435 build_timeout_preface ()
437 tree timeout_value = null_pointer_node;
439 if (after_stack != NULL_TREE &&
440 TREE_VALUE (TREE_PURPOSE (after_stack)) != NULL_TREE)
444 to_loc = decl_temp1 (get_unique_identifier ("TOloc"),
445 rtstime_type_node, 0, NULL_TREE, 0, 0);
446 timeout_value = force_addr_of (to_loc);
448 if (TREE_VALUE (TREE_VALUE (after_stack)) == NULL_TREE)
450 /* DELAY specified -- just call __convert_duration_rtstime for
451 given duration value */
453 build_chill_function_call (
454 lookup_name (get_identifier ("__convert_duration_rtstime")),
455 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_VALUE (after_stack)),
456 tree_cons (NULL_TREE, timeout_value, NULL_TREE))));
460 /* delay not specified -- call __remaintime which returns the
461 remaining time of duration in rtstime format and check the
464 build_chill_function_call (
465 lookup_name (get_identifier ("__remaintime")),
466 tree_cons (NULL_TREE, force_addr_of (TREE_VALUE (TREE_VALUE (after_stack))),
467 tree_cons (NULL_TREE, TREE_PURPOSE (TREE_VALUE (after_stack)),
468 tree_cons (NULL_TREE, timeout_value, NULL_TREE))));
469 tree expr = build (NE_EXPR, integer_type_node,
470 fcall, integer_zero_node);
471 expand_start_cond (expr, 0);
472 lookup_and_expand_goto (TREE_VALUE (TREE_PURPOSE (after_stack)));
476 return timeout_value;
480 build_timesupervised_call (fcall, to_loc)
484 if (to_loc == null_pointer_node)
485 expand_expr_stmt (fcall);
488 tree expr = build (NE_EXPR, integer_type_node, fcall, integer_zero_node);
489 expand_start_cond (expr, 0);
490 lookup_and_expand_goto (TREE_VALUE (TREE_PURPOSE (after_stack)));