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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
|
/*
** Copyright (C) 1997 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
**
** $Id: bytecode.h,v 1.12 1997/07/27 14:59:19 fjh Exp $
*/
/*
** This file defines the bytecode format.
** The definitions here must match those in compiler/bytecode.m.
*/
#ifndef MB_BYTECODE_H
#define MB_BYTECODE_H
#include "conf.h"
#include "mercury_types.h"
#include "mercury_float.h"
#include "gc.h"
/*
* XXX: We should make bytecode portable from platform to platform.
*
* We require the following:
* sizeof(MB_Byte) = 1
* sizeof(MB_Short16) = 2 (2's complement)
* sizeof(MB_Integer64) = 8 (2's complement)
* sizeof(Float64) = 8 (IEEE) // We don't really need float.
* Each of the above is big-endian in the bytecode file.
* That is, we read the byte at the big end first.
*
* We should have platform-dependent #defines to ensure that each of
* these types has identical size on all platforms.
*/
typedef unsigned char
MB_Byte;
typedef short
MB_Short;
typedef char*
MB_CString;
typedef struct MB_Tag_struct {
MB_Byte id;
union {
MB_Byte primary;
struct {
MB_Byte primary;
Word secondary;
} pair;
MB_Byte enum_tag;
} opt;
} MB_Tag;
/*
* Possible values for Tag.id ...
*/
#define MB_TAG_SIMPLE 0
#define MB_TAG_COMPLICATED 1
#define MB_TAG_COMPLICATED_CONSTANT 2
#define MB_TAG_ENUM 3
#define MB_TAG_NONE 4
typedef MB_Byte
MB_Determinism;
/*
* Possible values for Determinism ...
*/
#define MB_DET_DET 0
#define MB_DET_SEMIDET 1
#define MB_DET_MULTIDET 2
#define MB_DET_NONDET 3
#define MB_DET_CC_MULTIDET 4
#define MB_DET_CC_NONDET 5
#define MB_DET_ERRONEOUS 6
#define MB_DET_FAILURE 7
typedef struct MB_Op_arg_struct {
MB_Byte id;
union {
MB_Short var;
Integer int_const;
Float float_const;
} opt;
} MB_Op_arg;
/*
* Possible values for Op_arg.id
*/
#define MB_ARG_VAR 0
#define MB_ARG_INT_CONST 1
#define MB_ARG_FLOAT_CONST 2
typedef MB_Byte
MB_Direction;
typedef struct MB_Var_dir_struct {
MB_Short var;
MB_Direction dir;
} MB_Var_dir;
/*
* Possible values for Direction ...
*/
#define MB_DIR_TO_ARG 0
#define MB_DIR_TO_VAR 1
#define MB_DIR_TO_NONE 2
typedef struct MB_Cons_id_struct {
MB_Byte id;
union {
struct {
MB_CString module_id;
MB_CString string;
MB_Short arity;
MB_Tag tag;
} cons;
Integer int_const;
MB_CString string_const;
Float float_const;
struct {
MB_CString module_id;
MB_CString pred_id;
MB_Short arity;
MB_Byte proc_id;
} pred_const;
struct {
MB_CString module_id;
MB_CString pred_id;
MB_Short arity;
MB_Byte proc_id;
} code_addr_const;
struct {
MB_CString module_id;
MB_CString type_name;
MB_Byte type_arity;
} base_type_info_const;
struct {
MB_Byte ch;
} char_const;
} opt;
} MB_Cons_id;
/*
* Possible values for Cons_id.id ...
*/
#define MB_CONSID_CONS 0
#define MB_CONSID_INT_CONST 1
#define MB_CONSID_STRING_CONST 2
#define MB_CONSID_FLOAT_CONST 3
#define MB_CONSID_PRED_CONST 4
#define MB_CONSID_CODE_ADDR_CONST 5
#define MB_CONSID_BASE_TYPE_INFO_CONST 6
#define MB_CONSID_CHAR_CONST 7
typedef struct MB_Bytecode_struct {
MB_Byte id; /* Which bytecode instruction. e.g. BC_fail */
union {
struct {
MB_CString pred_name; /* XXX: malloc */
MB_Short proc_count;
} enter_pred;
/* endof_pred */
struct {
MB_Byte proc_id;
MB_Determinism det;
MB_Short label_count;
MB_Short temp_count;
MB_Short list_length;
MB_CString *var_info_list; /* XXX: malloc */
} enter_proc;
struct {
MB_Short label;
} label;
struct {
MB_Short end_label;
} enter_disjunction;
/* endof_disjunction */
struct {
MB_Short next_label;
} enter_disjunct;
struct {
MB_Short label; /* XXX: what's label for? */
} endof_disjunct;
struct {
MB_Short var;
MB_Short end_label;
} enter_switch;
/* endof_switch */
struct {
MB_Cons_id cons_id;
MB_Short next_label;
} enter_switch_arm;
struct {
MB_Short label; /* XXX: what's this label for? */
} endof_switch_arm;
struct {
MB_Short else_label;
MB_Short end_label;
MB_Short frame_ptr_tmp;
} enter_if;
struct {
MB_Short frame_ptr_tmp;
} enter_then;
struct {
MB_Short follow_label;
} endof_then; /* XXX: should rename to enter_else */
/* endof_if */
struct {
MB_Short end_label;
} enter_negation;
/* endof_negation */
struct {
MB_Short temp;
} enter_commit;
struct {
MB_Short temp;
} endof_commit;
struct {
MB_Short to_var;
MB_Short from_var;
} assign;
struct {
MB_Short var1;
MB_Short var2;
} test;
struct {
MB_Short to_var;
MB_Cons_id consid;
MB_Short list_length;
MB_Short *var_list; /* XXX: malloc */
} construct;
struct {
MB_Short from_var;
MB_Cons_id consid;
MB_Short list_length;
MB_Short *var_list; /* XXX: malloc */
} deconstruct;
struct {
MB_Short to_var;
MB_Cons_id consid;
MB_Short list_length;
MB_Var_dir *var_dir_list;/* XXX: malloc */
} complex_construct;
struct {
MB_Short from_var;
MB_Cons_id consid;
MB_Short list_length;
MB_Var_dir *var_dir_list;/* XXX: malloc */
} complex_deconstruct;
struct {
MB_Byte to_reg;
MB_Short from_var;
} place_arg;
struct {
MB_Byte from_reg;
MB_Short to_var;
} pickup_arg;
struct {
MB_CString module_id; /* XXX: malloc */
MB_CString pred_id; /* XXX: malloc */
MB_Short arity;
MB_Byte proc_id;
} call;
struct {
MB_Short pred_var;
MB_Short in_var_count;
MB_Short out_var_count;
MB_Determinism det;
} higher_order_call;
struct {
MB_Byte binop;
MB_Op_arg arg1;
MB_Op_arg arg2;
MB_Short to_var;
} builtin_binop;
struct {
MB_Byte unop;
MB_Op_arg arg;
MB_Short to_var;
} builtin_unop;
struct {
MB_Byte binop;
MB_Op_arg arg1;
MB_Op_arg arg2;
} builtin_bintest;
struct {
MB_Byte unop;
MB_Op_arg arg;
} builtin_untest;
/* semidet_succeed */
/* semidet_success_check */
/* fail */
struct {
/* XXX: is this int or short?? */
MB_Short line_number;
} context;
/* not_supported */
} opt;
} MB_Bytecode;
/*
* Possible values for Bytecode.id ...
*
* We use #defines rather than an enumeration here since
* C enumeration constant must be of type int whereas we
* want byte (unsigned char). XXX the preceding comment is
* a bogus explanation, because the constants are #defines
* for integerliterals, which are of type int anyway.
*/
#define MB_BC_enter_pred 0
#define MB_BC_endof_pred 1
#define MB_BC_enter_proc 2
#define MB_BC_endof_proc 3
#define MB_BC_label 4
#define MB_BC_enter_disjunction 5
#define MB_BC_endof_disjunction 6
#define MB_BC_enter_disjunct 7
#define MB_BC_endof_disjunct 8
#define MB_BC_enter_switch 9
#define MB_BC_endof_switch 10
#define MB_BC_enter_switch_arm 11
#define MB_BC_endof_switch_arm 12
#define MB_BC_enter_if 13
#define MB_BC_enter_then 14
/* XXX: enter_else would be a better name than endof_then */
#define MB_BC_endof_then 15
#define MB_BC_endof_if 16
#define MB_BC_enter_negation 17
#define MB_BC_endof_negation 18
#define MB_BC_enter_commit 19
#define MB_BC_endof_commit 20
#define MB_BC_assign 21
#define MB_BC_test 22
#define MB_BC_construct 23
#define MB_BC_deconstruct 24
#define MB_BC_complex_construct 25
#define MB_BC_complex_deconstruct 26
#define MB_BC_place_arg 27
#define MB_BC_pickup_arg 28
#define MB_BC_call 29
#define MB_BC_higher_order_call 30
#define MB_BC_builtin_binop 31
#define MB_BC_builtin_unop 32
#define MB_BC_builtin_bintest 33
#define MB_BC_builtin_untest 34
#define MB_BC_semidet_succeed 35
#define MB_BC_semidet_success_check 36
#define MB_BC_fail 37
#define MB_BC_context 38
#define MB_BC_not_supported 39
#define MB_BC_noop 255
/*
* Read the next bytecode from the stream fp.
* If no bytecode can be read, return FALSE.
* Otherwise, return TRUE.
*/
MB_Bool
MB_read_bytecode(FILE *fp, MB_Bytecode *bc_p);
/*
* Read the bytecode version number from the stream fp.
* If the version number cannot be read, return FALSE.
* Otherwise, return TRUE.
*/
MB_Bool
MB_read_bytecode_version_number(FILE *fp, MB_Short *version_number_p);
#endif /* MB_BYTECODE_H */
|