1 /*
2     cs_par_orc_sematics.h:
3 
4     Copyright (C) 2011 by John ffitch
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23 
24 #ifndef __CSOUND_ORC_SEMANTIC_ANALYSIS_H__
25 #define __CSOUND_ORC_SEMANTIC_ANALYSIS_H__
26 
27 /*
28  * This module maintains a list of instruments that have been parsed
29  * When parsing an instrument:
30  *  csp_orc_sa_instr_add
31  *          called first to setup instrument (when parsed the instrument
32                                               name/number)
33  *  csp_orc_sa_global_read_write_add_list
34  *          called to add globals to that instruments dependency lists
35  *  csp_orc_sa_instr_finalize
36  *          called when finished parsing that instrument
37  *
38  *  csp_orc_sa_instr_get_by_name or by_num
39  *          called to fetch an instrument later
40  */
41 
42 /* maintain information about insturments defined */
43 typedef struct instr_semantics_t {
44     char                        hdr[HDR_LEN];
45     char                        *name;
46     int32                       insno;
47     int32                       sanitized;
48     struct set_t                *read;
49     struct set_t                *write;
50     struct set_t                *read_write;
51     uint32_t                    weight;
52     struct instr_semantics_t    *next;
53 } INSTR_SEMANTICS;
54 
55 void csp_orc_sa_cleanup(CSOUND *csound);
56 void csp_orc_sa_print_list(CSOUND *csound);
57 
58 /* maintain state about the current instrument we are parsing */
59 /* add a new instrument */
60 void csp_orc_sa_instr_add(CSOUND *csound, char *name);
61 void csp_orc_sa_instr_add_tree(CSOUND *csound, TREE *x);
62 /* finish the current instrument */
63 #define csp_orc_sa_instr_finalize(csound) \
64   { csound->instCurr = NULL; csound->inInstr = 0; }
65 
66 /* add the globals read and written to the current instrument; second case
67  * if write and read contain the same global and size of both is 1 then
68  * that global is added to the read-write list of the current instrument */
69 void csp_orc_sa_global_read_write_add_list(CSOUND *csound,
70                                            struct set_t *write, struct set_t *read);
71 void csp_orc_sa_global_read_write_add_list1(CSOUND *csound,
72                                            struct set_t *write, struct set_t *read);
73 
74 /* add to the read and write lists of the current instrument */
75 void csp_orc_sa_global_write_add_list(CSOUND *csound, struct set_t *list);
76 void csp_orc_sa_global_read_add_list(CSOUND *csound, struct set_t *list);
77 
78 /* find all the globals contained in the sub-tree node */
79 struct set_t *csp_orc_sa_globals_find(CSOUND *csound, TREE *node);
80 
81 /* find an instrument from the instruments parsed */
82 struct instr_semantics_t
83     *csp_orc_sa_instr_get_by_name(CSOUND *csound, char *instr_name);
84 struct instr_semantics_t
85     *csp_orc_sa_instr_get_by_num(CSOUND *csound, int16 insno);
86 
87 /* interlocks */
88 void csp_orc_sa_interlocks(CSOUND *, ORCTOKEN *);
89 
90 void csp_orc_analyze_tree(CSOUND *, TREE*);
91 
92 #endif /* end of include guard: __CSOUND_ORC_SEMANTIC_ANALYSIS_H__ */
93