Files
mercury/bytecode/mb_module.h
Levi Cameron 0921310ca5 More work on the bytecode interpreter.
With these changes, it now passes all tests/general/* test cases
  except those with floats.

  Changes to the compiler:
  - Added extra argument to test instruction (string comparisons were
    being treated as integer comparisons; properly deals with different
    atomic type unifications now)
  - Changed bytecode stub functions

  Changes to the bytecode interpreter:
  - Cleaned up comments
  - Forked part of mb_machine to mb_exec
  - Added support for submodules
  - Added support for nondet procedures
  - Added support for cc_xxx procedures
  - Finished higher order calls
  - Added (very basic) debug interface
  - Added support for type information
  - Added memory corruption checking
  - Changed machine state dump formatting
  - Fixed bug in nested switches
  - Resolved builtin__unify and builtin_compare failures
  - Modified bytecode tags generation so .c & .m tag files are separate
  - Header usage rationalised

  Changes to test suite:
  - Added test cases for the bytecode interpreter.
  - More work on the bytecode interpreter.

bytecode/Mmakefile:
        Modified bytecode tags generation so .c & .m tag files are separate.
        mb_machine split into mb_exec.
        test file renamed to simple.m (copy over tests/simple??.m to test).

bytecode/TODO:
        Updated.

bytecode/mb_basetypes.h:
        Removed redundant MB_WORD_BITS (use MR_WORDBITS instead).

bytecode/mb_bytecode.h:
bytecode/mpb_bytecode.c:
        Formatting changes
        Third test instruction argument added.

bytecode/mb_disasm.h:
bytecode/mb_disasm.c:
        Formatting changes.
        Third test instruction argument added.
        Added MB_FMT_INTWIDE.

bytecode/mb_exec.h:
bytecode/mb_exec.c:
bytecode/mb_machine.h:
bytecode/mb_machine.c:
        mb_machine* split into mb_exec* and mb_machine*.
        Almost all instructions now work (see important changes above).

bytecode/mb_interface.h:
bytecode/mb_interface.c:
        Added nondet stub functions.
        Added functions to lookup builtin compiler procedures:
                do_redo, do_fail, __unify, __compare.
        Removed old debugging code.
        Stack layout changed to support nondet procedures.

bytecode/mb_interface_stub.c:
bytecode/mb_interface_stub.h:
        Split off bare minimum of includes for bytecode stubs.
        Added nondet stubs.

bytecode/mb_machine_show.c:
        Made code cleaner (added subfunctions for MB_show_state).
        Added variable names to machine state dump.

bytecode/mb_mem.h:
bytecode/mb_mem.c:
        Added limited memory corruption checking.

bytecode/mb_module.h:
bytecode/mb_module.c:
        Swapped order of temps & vars on stack.
        Fixed nested switches causing random crashes.
        Added nested module support.

bytecode/test/simple??.m:
        Various test files - just to check that it doesn't crash.
        (Most do not output anything & must be verified by stepping through
        manually).

compiler/bytecode.m:
compiler/bytecode_gen.m:
        Added extra argument to test instruction (otherwise
        string comparisons would be treated as integer comparisons).

compiler/code_gen.m:
        Changed call structure name in bytecode stub to resolve
        issues with illegal characters in C structure names.
        Changed bytecode stub header file name.
2001-02-19 02:05:59 +00:00

106 lines
3.1 KiB
C

/*
** Copyright (C) 2000-2001 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.
**
** Code module
**
*/
#ifndef MB_MODULE_H
#define MB_MODULE_H
#include <limits.h>
#include "mb_bytecode.h"
#include "mb_util.h"
struct MB_Module_Struct;
typedef struct MB_Module_Struct MB_Module;
/*
** Special code addresses. INVALID_ADR must be last as the asserts
** assume that any address above INVALID_ADR is a special code
**
** If you alter these, ensure MB_ip_special reflects this
*/
#define MB_CODE_DO_FAIL ((MB_Bytecode_Addr) (-1))
#define MB_CODE_DO_REDO ((MB_Bytecode_Addr) (-2))
#define MB_CODE_NATIVE_RETURN ((MB_Bytecode_Addr) (-3))
#define MB_CODE_INVALID_ADR ((MB_Bytecode_Addr) (-4))
/* Ensure a module is loaded */
MB_Module *MB_module_load_name(MB_CString_Const module_name);
MB_Module *MB_module_load(MB_CString_Const module_name, FILE *fp);
/* Unload a module */
void MB_module_unload(MB_Module *module);
/*
** Returns a pointer to a given module.
** If the module is not loaded, loads it.
*/
MB_Module *MB_module_get(MB_CString_Const module_name);
/* Return the number of bytecodes loaded so far */
MB_Unsigned MB_code_size(void);
/* Return the bytecode id of the bytecode at a given address */
MB_Byte MB_code_get_id(MB_Bytecode_Addr addr);
/* Get the procedure model that a bytecode at a given address is in */
#define MB_ISDET_NO 0 /* nondet */
#define MB_ISDET_YES 1 /* det, semidet */
MB_Byte MB_code_get_det(MB_Bytecode_Addr addr);
/* Get the bytecode argument at a given address */
MB_Bytecode_Arg *MB_code_get_arg(MB_Bytecode_Addr addr);
/* Get the predicate in which the following address resides */
MB_Bytecode_Addr MB_code_get_pred_addr(MB_Bytecode_Addr addr);
/* Get the procedure in which the following address resides */
MB_Bytecode_Addr MB_code_get_proc_addr(MB_Bytecode_Addr addr);
MB_Bytecode_Addr MB_code_find_proc(MB_CString_Const module,
MB_CString_Const pred,
MB_Word proc,
MB_Word arity,
MB_Bool is_func);
/* Returns a code address clipped into the valid code range */
MB_Bytecode_Addr MB_code_range_clamp(MB_Bytecode_Addr addr);
/* True if the code address is 'normal' (not invalid or one of MB_CODE_xxx) */
MB_Bool MB_ip_normal(MB_Bytecode_Addr ip);
/* True if the code address is one of MB_CODE_xxx */
MB_Bool MB_ip_special(MB_Bytecode_Addr ip);
/* True if a native code address */
MB_Bool MB_ip_native(MB_Bytecode_Addr ip);
/* Allocate memory in the code argument data array */
#define MB_CODE_DATA_ALLOC(type, number) \
((type *) (MB_code_data_alloc_words( \
MB_NUMBLOCKS(sizeof(type)*(number), sizeof(MB_Word))) \
) \
)
MB_Word *MB_code_data_alloc_words(MB_Word num_words);
/*
** This is only defined here so instruction pointers can be incremented; you should
** never need to use any of these fields: the MB_BCID_xxx wrappers in mb_module.c
** are the only things that should use them
*/
struct MB_BCId_Struct {
MB_Unsigned id : 7;
MB_Unsigned is_det : 1;
MB_Unsigned arg : MR_WORDBITS - (7 + 1);
};
#endif /* MB_MODULE_H */