-
Notifications
You must be signed in to change notification settings - Fork 21
/
exec.h
303 lines (264 loc) · 10.5 KB
/
exec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
* A compiled program consists of several data blocks, all allocated
* contiguos in memory to enhance the working set. At the compilation,
* the blocks will be allocated separately, as the final size is
* unknow. When compilation is done, the blocks will be copied into
* the one big area.
*
* There are 5 different blocks of information for each program:
* 1. The program itself. Consists of machine code instructions for a virtual
* stack machine. The size of the program must not be bigger than
* 65535 bytes, as 16 bit pointers are used. Who would ever need a bigger
* program :-)
* 2. Function names. All local functions that has been defined or called,
* with the address of the function in the program. Inherited functions
* will be found here too, with information of how far up the inherit
* chain that the function was defined.
* 3. String table. All strings used in the program. They are all pointers
* into the shared string area. Thus, they are easily found and deallocated
* when the object is destructed.
* 4. Table of variable names. They all point into the shared string table.
* 5. Line number information. A table which tells at what address every
* line belongs to. The table has the same number of entries as the
* programs has source lines. This is used at errors, to find out the
* line number of the error.
* 6. List of inherited objects.
* Includes indirect inherits.
* F_CALL_DOWN gets an index to this table.
*/
#include "config.h"
#include <bits/stdint-uintn.h>
#include <stdint.h>
#ifndef EXEC_H
#define EXEC_H
typedef uint32_t offset_t;
#define OFFSET_MAX (UINT32_MAX)
struct reloc
{
char *name;
int value;
offset_t address;
char type;
char modifier;
};
struct cfun_desc
{
short inh;
short idx;
};
#define R_VAR 1 /* Global variable reference */
#define R_CALL 2
struct function {
#if defined(PROFILE_LPC)
unsigned long long num_calls; /* Number of times this function called */
double time_spent; /* cpu spent inside this function */
double tot_time_spent; /* cpu spent inside this function and those called by it */
double avg_time;
double avg_tot_time;
double avg_calls;
double last_call_update;
#endif
char *name;
short hash_idx;
unsigned short type_flags; /* Return type of function. See below. */
/* NAME_ . See above. */
offset_t offset; /* Address of function or inherit table index when inherited. */
unsigned char num_local; /* Number of local variables */
char num_arg; /* Number of arguments needed.
* -1 arguments means function not defined
* in this object. Probably inherited */
char first_default;
};
struct function_hash {
char *name;
short next_hashed_function;
short func_index;
};
struct variable {
char *name;
unsigned short type; /* Type of variable. See below. TYPE_ */
};
struct inherit {
struct program *prog;
char *name;
unsigned short variable_index_offset;
/* Only TYPE_MOD_PRIVATE, TYPE_MOD_STATIC, TYPE_MOD_NO_MASK, and
TYPE_MOD_PUBLIC apply. */
unsigned short type; /* Type of inherit. See below. TYPE_ */
};
struct segment_desc
{
int ptr_offset;
int swap_idx_offset;
int size_offset;
struct section_desc
{
int section;
int ptr_offset;
int num_offset;
int ent_size;
} *sections;
};
extern struct segment_desc segm_desc[];
#define A_HEADER 0
#define A_PROGRAM 1
#define A_FUNCTIONS 2
#define A_RODATA 3
#define A_VARIABLES 4
#define A_LINENUMBERS 5
#define A_INHERITS 6
#define A_ARGUMENT_TYPES 7
#define A_ARGUMENT_INDEX 8
#define A_INCLUDES 9
#define A_RELOC 10
#define A_FUNC_HASH 11
#define A_CFUN 12
#define NUMPAREAS 13
#define A_CASE_NUMBERS (NUMPAREAS + 0)
#define A_CASE_STRINGS (NUMPAREAS + 1)
#define A_CASE_LABELS (NUMPAREAS + 2)
#define A_STRTAB (NUMPAREAS + 3)
#define A_LABELS (NUMPAREAS + 4)
#define A_JUMPS (NUMPAREAS + 5)
#define NUMAREAS (NUMPAREAS + 6)
#define A_NUM NUMAREAS
#define S_HDR 0
#define S_EXEQ 1
#define S_DBG 2
#define S_NULL 3
#define S_NUM 4
struct lineno {
unsigned short code;
unsigned short file;
unsigned int lineno;
};
struct program {
char *program; /* The binary instructions */
char *name; /* Name of file that defined prog */
struct program *next_all, *prev_all; /* pointers in the list of all
programs. */
struct lineno *line_numbers; /* Line number information
This is not stored in memory
but swapped in when needed.
*/
struct function *functions;
struct function_hash *func_hash;
char *rodata; /* All strings uses by the program */
struct variable *variable_names; /* All variables defined */
struct inherit *inherit; /* List of inherited prgms */
struct cfun_desc *cfuns;
/*
* The types of function arguments are saved where 'argument_types'
* points. It can be a variable number of arguments, so allocation
* is done dynamically. To know where first argument is found for
* function 'n' (number of function), use 'type_start[n]'.
* These two arrays will only be allocated if '#pragma save_types' has
* been specified. This #pragma should be specified in files that are
* commonly used for inheritance. There are several lines of code
* that depends on the type length (16 bits) of 'type_start' (sorry !).
*/
unsigned short *argument_types;
#define INDEX_START_NONE 65535
unsigned short *type_start;
char *include_files;
struct object *clones;
#if defined(PROFILE_LPC)
double cpu; /* The amount of cpu taken up */
double cpu_avg;
double last_avg_update;
#endif
int ref; /* Reference count */
int swap_num;
long num_clones;
unsigned int time_of_ref;
#ifdef DEBUG
int extra_ref; /* Used to verify ref count */
#endif
offset_t total_size; /* Sum of all data in this struct */
offset_t debug_size;
offset_t exec_size;
int load_time; /* Time of loding of the program */
int id_number; /* used to associate information with
this prog block without needing to
increase the reference count */
int swap_lineno_index; /* Index in swapfile for lineno info */
int mod_time; /* (simulate.c) last time of modification of the */
/* corrseponding file /lib_entry */
unsigned short dtor_index; /* destructor */
unsigned short ctor_index; /* constructor */
unsigned short debug_flags;
/*
* And now some general size information.
*/
/* SEC_EXE */
offset_t program_size; /* size of this instruction code */
offset_t rodata_size;
offset_t num_functions;
offset_t num_variables;
/* SEC_HDR */
offset_t num_inherited;
/* SEC_DBG */
offset_t sizeof_line_numbers;
offset_t sizeof_include_files;
/* NOT IMPLEMENETED */
offset_t sizeof_argument_types;
char flags; /* some useful flags */
#define PRAGMA_NO_CLONE 1
#define PRAGMA_NO_INHERIT 2
#define PRAGMA_NO_SHADOW 4
#define PRAGMA_RESIDENT 8
};
extern struct program *current_prog;
extern int inh_offset;
/*
* Types available. The number '0' is valid as any type. These types
* are only used by the compiler, when type checks are enabled. Compare with
* the run-time types, named T_ interpret.h.
*/
#define TYPE_UNKNOWN 0 /* This type must be casted */
#define TYPE_NUMBER 1
#define TYPE_STRING 2
#define TYPE_VOID 3
#define TYPE_OBJECT 4
#define TYPE_ANY 5 /* Will match any type */
#define TYPE_MAPPING 6
#define TYPE_FLOAT 7
#define TYPE_FUNCTION 8
#define TYPE_NONE 9
#define TYPE_LVALUE 0x10 /* or'ed in temporarily */
/*
* These are or'ed in on top of the basic type.
*/
#define TYPE_MOD_STATIC 0x0100 /* Static function or variable */
#define TYPE_MOD_NO_MASK 0x0200 /* The nomask => not redefineable */
#define TYPE_MOD_POINTER 0x0400 /* Pointer to a basic type */
#define TYPE_MOD_PRIVATE 0x0800 /* Can't be inherited */
#define TYPE_MOD_PUBLIC 0x1000 /* Force inherit through private */
#define TYPE_MOD_VARARGS 0x2000 /* Used for type checking */
#define TYPE_MOD_TRUE_VARARGS 0x4000 /* The new true varargs */
#define TYPE_MOD_SECOND 0x0080 /* Muliple inheritance (only valid for inherit) */
/*
* When an new object inherits from another, all function definitions
* are copied, and all variable definitions.
* Flags below can't explicitly declared. Flags that can be declared,
* are found with TYPE_ above.
*
* When an object is compiled with type testing NAME_STRICT_TYPES, all
* types are saved of the arguments for that function during compilation.
* If the #pragma save_types is specified, then the types are saved even
* after compilation, to be used when the object is inherited.
*
* Functions in a compiled program can only have the NAME_STRICT_TYPES flag.
*/
#define NAME_STRICT_TYPES 0x10 /* Compiled with type testing */
#define NAME_PROTOTYPE 0x20 /* Defined by a prototype only */
#define NAME_ABSTRACT 0x40 /* Function is implemented in C */
#define TYPE_MASK (~(TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\
TYPE_MOD_PRIVATE | TYPE_MOD_PUBLIC |\
TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS |\
NAME_ABSTRACT | NAME_STRICT_TYPES |\
NAME_PROTOTYPE))
#define TYPE_MOD_MASK (TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\
TYPE_MOD_PRIVATE | TYPE_MOD_PUBLIC |\
TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS)
#endif