1 /*
2  * Copyright (c) 2004 - 2010, Nils R. Weller
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef FUNCTIONS_H
28 #define FUNCTIONS_H
29 
30 struct decl;
31 struct function;
32 struct icode;
33 struct vreg;
34 
35 
36 extern struct function	*curfunc;
37 
38 struct statement {
39 	int			type;
40 	int			debug;
41 #define ST_DECL		1 /* struct decl */
42 #define ST_CODE		2 /* struct icode */
43 #define ST_COMP		3 /* struct scope */
44 #define ST_CTRL		4 /* struct control */
45 #define ST_LABEL	5 /* struct label */
46 #define ST_ASM		6 /* struct inline_asm_stmt */
47 #define ST_EXPRSTMT	7 /* same as ST_COMP */
48 
49 	void			*data;
50 	struct statement	*next;
51 };
52 
53 #include <stddef.h>
54 
55 struct stack_block;
56 
57 struct function {
58 	struct decl		*proto;
59 	struct type		*rettype;
60 	struct ty_func	*fty; /* XXX remove proto?!?! */
61 	struct statement	*code;
62 	struct statement	*code_tail;
63 	struct scope		*scope;
64 	struct icode_list	*icode;
65 	struct function		*next;
66 	struct label		*labels_head; /* function scope */
67 	struct label		*labels_tail;
68 	size_t			total_allocated;
69 	size_t			callee_save_offset;
70 	int			callee_save_used;
71 	int			gotframe; /* MIPS */
72 	int			max_bytes_pushed; /* PowerPC */
73 
74 	/*
75 	 * 03/26/08: Checkpoint of last static initialized variable
76 	 * that was present before the function definition was
77 	 * encountered. This gives us the info we need to output all
78 	 * initialized static variables belonging to this function
79 	 */
80 	struct decl		*static_init_vars_checkpoint;
81 
82 	/*
83 	 * 02/05/08: New variable that tells us whether PIC support
84 	 * has already been set up (e.g. loading ebx on x86)
85 	 */
86 	int			pic_initialized;
87 	/*
88 	 * 02/15/08: New variable to hold vreg for PIC register IF
89 	 * that must be saved across function calls (e.g. on SPARC...
90 	 * and it's cheaper to save instead of recomputing it
91 	 */
92 	struct vreg		*pic_vreg;
93 	/*
94 	 * 02/05/09: Name of PIC label to get program counter.
95 	 * Currently only used for OSX
96 	 */
97 	char			*pic_label;
98 	struct vreg		*hidden_pointer; /* MIPS */
99 	void			*patchme; /* AMD64 :-( */
100 
101 	struct stack_block	*alloca_head;
102 	struct stack_block	*alloca_tail;
103 	struct stack_block	*alloca_regs;
104 
105 	struct stack_block	*vla_head;
106 	struct stack_block	*vla_tail;
107 	struct stack_block	*vla_regs;
108 
109 	struct stack_block	*regs_head;
110 	struct stack_block	*regs_tail;
111 	struct stack_block	*free_list;
112 };
113 
114 extern struct function	*funclist;
115 extern struct function	*funclist_tail;
116 
117 void				append_statement(
118 						struct statement **,
119 						struct statement **,
120 						struct statement *);
121 struct statement	*alloc_statement(void);
122 struct function		*alloc_function(void);
123 struct label		*lookup_label(struct function *f, const char *name);
124 
125 #endif
126 
127