summaryrefslogtreecommitdiffstats
path: root/gst/goom/goomsl_private.h
blob: 8be151577d554606187593cca3d5a484809022b7 (plain)
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
#ifndef _GSL_PRIVATE_H
#define _GSL_PRIVATE_H

/* -- internal use -- */

#include "goomsl.h"

#ifdef USE_JITC_X86
#include "jitc_x86.h"
#endif

#include "goomsl_heap.h"

/* {{{ type of nodes */
#define EMPTY_NODE 0
#define CONST_INT_NODE 1
#define CONST_FLOAT_NODE 2
#define CONST_PTR_NODE 3
#define VAR_NODE 4
#define PARAM_NODE 5
#define READ_PARAM_NODE 6
#define OPR_NODE 7
/* }}} */
/* {{{ type of operations */
#define OPR_SET 1
#define OPR_IF 2
#define OPR_WHILE 3
#define OPR_BLOCK 4
#define OPR_ADD 5
#define OPR_MUL 6
#define OPR_EQU 7
#define OPR_NOT 8
#define OPR_LOW 9
#define OPR_DIV 10
#define OPR_SUB 11
#define OPR_FUNC_INTRO 12
#define OPR_FUNC_OUTRO 13
#define OPR_CALL 14
#define OPR_EXT_CALL 15
#define OPR_PLUS_EQ 16
#define OPR_SUB_EQ 17
#define OPR_MUL_EQ 18
#define OPR_DIV_EQ 19
#define OPR_CALL_EXPR 20
#define OPR_AFFECT_LIST 21
#define OPR_FOREACH 22
#define OPR_VAR_LIST 23

/* }}} */

typedef struct _ConstIntNodeType { /* {{{ */
    int val;
} ConstIntNodeType; /* }}} */
typedef struct _ConstFloatNodeType { /* {{{ */
    float val;
} ConstFloatNodeType; /* }}} */
typedef struct _ConstPtrNodeType { /* {{{ */
    int id;
} ConstPtrNodeType; /* }}} */
typedef struct _OprNodeType { /* {{{ */
    int type;
    int nbOp;
    struct _NODE_TYPE *op[3]; /* maximal number of operand needed */
    struct _NODE_TYPE *next;
} OprNodeType; /* }}} */
typedef struct _NODE_TYPE { /* {{{ */
    int type;
    char *str;
    GoomHash *vnamespace;
    int line_number;
    union {
        ConstIntNodeType constInt;
        ConstFloatNodeType constFloat;
        ConstPtrNodeType constPtr;
        OprNodeType opr;
    } unode;
} NodeType; /* }}} */
typedef struct _INSTRUCTION_DATA { /* {{{ */
  
  union {
    void  *var;
    int   *var_int;
    int   *var_ptr;
    float *var_float;
    int    jump_offset;
    struct _ExternalFunctionStruct *external_function;
  } udest;

  union {
    void  *var;
    int   *var_int;
    int   *var_ptr;
    float *var_float;
    int    value_int;
    int    value_ptr;
    float  value_float;
  } usrc;
} InstructionData;
/* }}} */
typedef struct _INSTRUCTION { /* {{{ */

    int id;
    InstructionData data;
    GoomSL *parent;
    const char *name; /* name of the instruction */

    char     **params; /* parametres de l'instruction */
    GoomHash **vnamespace;
    int       *types;  /* type des parametres de l'instruction */
    int cur_param;
    int nb_param;

    int address;
    char *jump_label;
    char *nop_label;

    int line_number;

} Instruction;
/* }}} */
typedef struct _INSTRUCTION_FLOW { /* {{{ */

    Instruction **instr;
    int number;
    int tabsize;
    GoomHash *labels;
} InstructionFlow;
/* }}} */
typedef struct _FAST_INSTRUCTION { /* {{{ */
  int id;
  InstructionData data;
  Instruction *proto;
} FastInstruction;
/* }}} */
typedef struct _FastInstructionFlow { /* {{{ */
  int number;
  FastInstruction *instr;
  void *mallocedInstr;
} FastInstructionFlow;
/* }}} */
typedef struct _ExternalFunctionStruct { /* {{{ */
  GoomSL_ExternalFunction function;
  GoomHash *vars;
  int is_extern;
} ExternalFunctionStruct;
/* }}} */
typedef struct _Block {
  int    data;
  int    size;
} Block;
typedef struct _GSL_StructField { /* {{{ */
  int  type;
  char name[256];
  int  offsetInStruct; /* Where this field is stored... */
} GSL_StructField;
 /* }}} */
typedef struct _GSL_Struct { /* {{{ */
  int nbFields;
  GSL_StructField *fields[64];
  int size;
  Block iBlock[64];
  Block fBlock[64];
} GSL_Struct;
 /* }}} */
struct _GoomSL { /* {{{ */
    int num_lines;
    Instruction *instr;     /* instruction en cours de construction */

    InstructionFlow     *iflow;  /* flow d'instruction 'normal' */
    FastInstructionFlow *fastiflow; /* flow d'instruction optimise */
    
    GoomHash *vars;         /* table de variables */
    int currentNS;
    GoomHash *namespaces[16];
    
    GoomHash *functions;    /* table des fonctions externes */

    GoomHeap *data_heap; /* GSL Heap-like memory space */
    
    int nbStructID;
    GoomHash   *structIDS;
    GSL_Struct **gsl_struct;
    int gsl_struct_size;
    
    int    nbPtr;
    int    ptrArraySize;
    void **ptrArray;
    
    int compilationOK;
#ifdef USE_JITC_X86
    JitcX86Env *jitc;
    JitcFunc    jitc_func;
#endif
}; /* }}} */

extern GoomSL *currentGoomSL;

Instruction *gsl_instr_init(GoomSL *parent, const char *name, int id, int nb_param, int line_number);
void gsl_instr_add_param(Instruction *_this, char *param, int type);
void gsl_instr_set_namespace(Instruction *_this, GoomHash *ns);

void gsl_declare_task(const char *name);
void gsl_declare_external_task(const char *name);

int gsl_type_of_var(GoomHash *namespace, const char *name);

void gsl_enternamespace(const char *name);
void gsl_reenternamespace(GoomHash *ns);
GoomHash *gsl_leavenamespace(void);
GoomHash *gsl_find_namespace(const char *name);

void gsl_commit_compilation(void);

/* #define TYPE_PARAM    1 */

#define FIRST_RESERVED 0x80000

#define TYPE_INTEGER  0x90001
#define TYPE_FLOAT    0x90002
#define TYPE_VAR      0x90003
#define TYPE_PTR      0x90004
#define TYPE_LABEL    0x90005

#define TYPE_OP_EQUAL 6
#define TYPE_IVAR     0xa0001
#define TYPE_FVAR     0xa0002
#define TYPE_PVAR     0xa0003
#define TYPE_SVAR     0xa0004

#define INSTR_JUMP     6
#define INSTR_JZERO    29
#define INSTR_CALL     36 
#define INSTR_RET      37
#define INSTR_EXT_CALL 38
#define INSTR_JNZERO   40

#define INSTR_SET     0x80001
#define INSTR_INT     0x80002
#define INSTR_FLOAT   0x80003
#define INSTR_PTR     0x80004
#define INSTR_LABEL   0x80005
#define INSTR_ISLOWER 0x80006
#define INSTR_ADD     0x80007
#define INSTR_MUL     0x80008
#define INSTR_DIV     0x80009
#define INSTR_SUB     0x80010
#define INSTR_ISEQUAL 0x80011
#define INSTR_NOT     0x80012


#endif