Pristine Ack-5.5
[Ack-5.5.git] / lang / pc / comp / progs.c
1 #include        "debug.h"
2
3 #include        <em.h>
4 #include        <assert.h>
5
6 #include        "LLlex.h"
7 #include        "def.h"
8 #include        "main.h"
9 #include        "scope.h"
10 #include        "type.h"
11
12 static int extflc;                      /* number of external files */
13 static int inpflag = 0;                 /* input mentioned in heading ? */
14 static int outpflag = 0;                /* output mentioned in heading ? */
15 static label extfl_label;               /* label of array of file pointers */
16
17 set_inp()
18 {
19         inpflag = 1;
20 }
21
22 set_outp()
23 {
24         outpflag = 1;
25 }
26
27 make_extfl()
28 {
29         if( err_occurred ) return; 
30
31         extfl_label = ++data_label;
32         C_df_dlb(extfl_label);
33
34         if( inpflag ) {
35                 C_ina_dnam(input);
36                 C_con_dnam(input, (arith) 0);
37         }
38         else
39                 C_con_ucon("0", pointer_size);
40
41         if( outpflag ) {
42                 C_ina_dnam(output);
43                 C_con_dnam(output, (arith) 0);
44         }
45         else
46                 C_con_ucon("0", pointer_size);
47
48         extflc = 2;
49
50         /* Process the identifiers in the global scope (at this point only
51          * the program parameters) in order of specification.
52          */
53         make_extfl_args( GlobalScope->sc_def );
54 }
55
56 make_extfl_args(df)
57         register struct def *df;
58 {
59         if( !df ) return;
60         make_extfl_args(df->df_nextinscope);
61         assert(df->df_flags & D_PROGPAR);
62         if( df->var_name != input && df->var_name != output ) {
63                 C_ina_dnam(df->var_name);
64                 C_con_dnam(df->var_name, (arith) 0);
65                 extflc++;
66         }
67 }
68
69 call_ini()
70 {
71         C_lxl((arith) 0);
72         if( extflc )
73                 C_lae_dlb(extfl_label, (arith) 0);
74         else
75                 C_zer(pointer_size);
76         C_loc((arith) extflc);
77         C_lxa((arith) 0);
78         C_cal("_ini");
79         C_asp(3 * pointer_size + word_size);
80 }