module.c

Include dependency graph for module.c:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "3" [label="stdbool.h" tooltip="stdbool.h"]
    "32" [label="bif.h" tooltip="bif.h"]
    "34" [label="iff.h" tooltip="iff.h"]
    "5" [label="atom.h" tooltip="atom.h"]
    "13" [label="assert.h" tooltip="assert.h"]
    "18" [label="synclist.h" tooltip="synclist.h"]
    "4" [label="stdint.h" tooltip="stdint.h"]
    "6" [label="stdlib.h" tooltip="stdlib.h"]
    "31" [label="valueshashtable.h" tooltip="valueshashtable.h"]
    "30" [label="exportedfunction.h" tooltip="exportedfunction.h"]
    "9" [label="context.h" tooltip="context.h"]
    "24" [label="utils.h" tooltip="utils.h"]
    "16" [label="ets.h" tooltip="ets.h"]
    "7" [label="atom_table.h" tooltip="atom_table.h"]
    "12" [label="term_typedef.h" tooltip="term_typedef.h"]
    "25" [label="stddef.h" tooltip="stddef.h"]
    "14" [label="limits.h" tooltip="limits.h"]
    "26" [label="refc_binary.h" tooltip="refc_binary.h"]
    "22" [label="string.h" tooltip="string.h"]
    "28" [label="mailbox.h" tooltip="mailbox.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c" fillcolor="#BFBFBF"]
    "2" [label="module.h" tooltip="module.h"]
    "21" [label="term.h" tooltip="term.h"]
    "11" [label="erl_nif.h" tooltip="erl_nif.h"]
    "38" [label="opcodesswitch.h" tooltip="opcodesswitch.h"]
    "37" [label="time.h" tooltip="time.h"]
    "27" [label="resources.h" tooltip="resources.h"]
    "20" [label="smp.h" tooltip="smp.h"]
    "36" [label="sys.h" tooltip="sys.h"]
    "8" [label="atomshashtable.h" tooltip="atomshashtable.h"]
    "35" [label="nifs.h" tooltip="nifs.h"]
    "10" [label="globalcontext.h" tooltip="globalcontext.h"]
    "23" [label="memory.h" tooltip="memory.h"]
    "19" [label="stdio.h" tooltip="stdio.h"]
    "29" [label="timer_list.h" tooltip="timer_list.h"]
    "17" [label="list.h" tooltip="list.h"]
    "15" [label="inttypes.h" tooltip="inttypes.h"]
    "33" [label="externalterm.h" tooltip="externalterm.h"]
    "32" -> "3" [dir=forward tooltip="include"]
    "32" -> "5" [dir=forward tooltip="include"]
    "32" -> "9" [dir=forward tooltip="include"]
    "32" -> "30" [dir=forward tooltip="include"]
    "32" -> "2" [dir=forward tooltip="include"]
    "34" -> "3" [dir=forward tooltip="include"]
    "34" -> "4" [dir=forward tooltip="include"]
    "5" -> "4" [dir=forward tooltip="include"]
    "5" -> "6" [dir=forward tooltip="include"]
    "18" -> "19" [dir=forward tooltip="include"]
    "18" -> "17" [dir=forward tooltip="include"]
    "18" -> "20" [dir=forward tooltip="include"]
    "30" -> "21" [dir=forward tooltip="include"]
    "9" -> "10" [dir=forward tooltip="include"]
    "9" -> "17" [dir=forward tooltip="include"]
    "9" -> "28" [dir=forward tooltip="include"]
    "9" -> "20" [dir=forward tooltip="include"]
    "9" -> "21" [dir=forward tooltip="include"]
    "9" -> "29" [dir=forward tooltip="include"]
    "24" -> "25" [dir=forward tooltip="include"]
    "24" -> "19" [dir=forward tooltip="include"]
    "24" -> "6" [dir=forward tooltip="include"]
    "16" -> "17" [dir=forward tooltip="include"]
    "16" -> "18" [dir=forward tooltip="include"]
    "16" -> "21" [dir=forward tooltip="include"]
    "7" -> "3" [dir=forward tooltip="include"]
    "7" -> "5" [dir=forward tooltip="include"]
    "12" -> "13" [dir=forward tooltip="include"]
    "12" -> "14" [dir=forward tooltip="include"]
    "12" -> "15" [dir=forward tooltip="include"]
    "12" -> "4" [dir=forward tooltip="include"]
    "26" -> "3" [dir=forward tooltip="include"]
    "26" -> "6" [dir=forward tooltip="include"]
    "26" -> "17" [dir=forward tooltip="include"]
    "26" -> "27" [dir=forward tooltip="include"]
    "28" -> "3" [dir=forward tooltip="include"]
    "28" -> "17" [dir=forward tooltip="include"]
    "28" -> "12" [dir=forward tooltip="include"]
    "28" -> "24" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "5" [dir=forward tooltip="include"]
    "1" -> "32" [dir=forward tooltip="include"]
    "1" -> "9" [dir=forward tooltip="include"]
    "1" -> "33" [dir=forward tooltip="include"]
    "1" -> "10" [dir=forward tooltip="include"]
    "1" -> "34" [dir=forward tooltip="include"]
    "1" -> "17" [dir=forward tooltip="include"]
    "1" -> "35" [dir=forward tooltip="include"]
    "1" -> "21" [dir=forward tooltip="include"]
    "1" -> "24" [dir=forward tooltip="include"]
    "1" -> "36" [dir=forward tooltip="include"]
    "1" -> "20" [dir=forward tooltip="include"]
    "1" -> "19" [dir=forward tooltip="include"]
    "1" -> "6" [dir=forward tooltip="include"]
    "1" -> "38" [dir=forward tooltip="include"]
    "2" -> "3" [dir=forward tooltip="include"]
    "2" -> "4" [dir=forward tooltip="include"]
    "2" -> "5" [dir=forward tooltip="include"]
    "2" -> "7" [dir=forward tooltip="include"]
    "2" -> "8" [dir=forward tooltip="include"]
    "2" -> "9" [dir=forward tooltip="include"]
    "2" -> "30" [dir=forward tooltip="include"]
    "2" -> "10" [dir=forward tooltip="include"]
    "2" -> "21" [dir=forward tooltip="include"]
    "2" -> "31" [dir=forward tooltip="include"]
    "21" -> "3" [dir=forward tooltip="include"]
    "21" -> "4" [dir=forward tooltip="include"]
    "21" -> "19" [dir=forward tooltip="include"]
    "21" -> "6" [dir=forward tooltip="include"]
    "21" -> "22" [dir=forward tooltip="include"]
    "21" -> "23" [dir=forward tooltip="include"]
    "21" -> "26" [dir=forward tooltip="include"]
    "21" -> "24" [dir=forward tooltip="include"]
    "21" -> "12" [dir=forward tooltip="include"]
    "11" -> "12" [dir=forward tooltip="include"]
    "27" -> "6" [dir=forward tooltip="include"]
    "27" -> "11" [dir=forward tooltip="include"]
    "27" -> "17" [dir=forward tooltip="include"]
    "27" -> "23" [dir=forward tooltip="include"]
    "20" -> "3" [dir=forward tooltip="include"]
    "36" -> "10" [dir=forward tooltip="include"]
    "36" -> "2" [dir=forward tooltip="include"]
    "36" -> "4" [dir=forward tooltip="include"]
    "36" -> "37" [dir=forward tooltip="include"]
    "8" -> "5" [dir=forward tooltip="include"]
    "35" -> "5" [dir=forward tooltip="include"]
    "35" -> "9" [dir=forward tooltip="include"]
    "35" -> "30" [dir=forward tooltip="include"]
    "10" -> "4" [dir=forward tooltip="include"]
    "10" -> "5" [dir=forward tooltip="include"]
    "10" -> "7" [dir=forward tooltip="include"]
    "10" -> "11" [dir=forward tooltip="include"]
    "10" -> "16" [dir=forward tooltip="include"]
    "10" -> "17" [dir=forward tooltip="include"]
    "10" -> "28" [dir=forward tooltip="include"]
    "10" -> "20" [dir=forward tooltip="include"]
    "10" -> "18" [dir=forward tooltip="include"]
    "10" -> "21" [dir=forward tooltip="include"]
    "10" -> "29" [dir=forward tooltip="include"]
    "23" -> "4" [dir=forward tooltip="include"]
    "23" -> "6" [dir=forward tooltip="include"]
    "23" -> "11" [dir=forward tooltip="include"]
    "23" -> "12" [dir=forward tooltip="include"]
    "23" -> "24" [dir=forward tooltip="include"]
    "29" -> "3" [dir=forward tooltip="include"]
    "29" -> "4" [dir=forward tooltip="include"]
    "29" -> "17" [dir=forward tooltip="include"]
    "17" -> "3" [dir=forward tooltip="include"]
    "33" -> "21" [dir=forward tooltip="include"]
}

Defines

LITT_UNCOMPRESSED_SIZE_OFFSET 8
LITT_HEADER_SIZE 12
TAG_COMPACT_INT 0x01
TAG_COMPACT_ATOM 0x02
TAG_EXTENDED_INT 0x09
TAG_EXTENDED_ATOM 0x0A
CHECK_FREE_SPACE(space, error)

if ((size_t) ((pos + space) - data) > len) { \

fprintf(stderr, error);                  \

return;                                  \

}


IMPL_CODE_LOADER 1

Functions

static struct LiteralEntry *module_build_literals_table(const void *literalsBuf)
static void module_add_label(Module *mod, int index, const uint8_t *ptr)
static enum ModuleLoadResult module_build_imported_functions_table(Module *this_module, uint8_t *table_data, GlobalContext *glb)
static void parse_line_table(uint16_t **line_refs, struct ModuleFilename **filenames, uint8_t *data, size_t len)
static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, uint8_t *table_data, GlobalContext *glb)
void module_get_imported_function_module_and_name(const Module *this_module, int index, AtomString *module_atom, AtomString *function_atom, GlobalContext *glb)
bool module_get_function_from_label(Module *this_module, int label, AtomString *function_name, int *arity, GlobalContext *glb)
size_t module_get_exported_functions_count(Module *this_module)

Count exported functions of a given module.

Get the number of exported functions. This function is used to compute the required heap size of the list of exported functions.

Parameters:
  • this_module – the module to count exported functions of

Returns:

the number of exported functions

uint32_t module_search_exported_function(Module *this_module, AtomString func_name, int func_arity, GlobalContext *glb)

Gets exported function index by searching it by function name and arity.

Gets exported function index by searching it by function name and arity

Parameters:
  • this_module – the module on which the function will be searched.

  • func_name – function name atom string.

  • func_arity – function arity.

  • glb – the global context

term module_get_exported_functions(Module *this_module, Heap *heap, GlobalContext *glb)

Get the list of exported functions.

Create a list of exported functions of the form {FunctionName, Arity} To create this list, the heap must be grown by module_get_exported_functions_list_size terms.

Parameters:
  • this_module – the module to count exported functions of

  • heap – heap to allocate tuples

  • global – global context to fetch atoms

Returns:

a list of exported functions

Module *module_new_from_iff_binary(GlobalContext *global, const void *iff_binary, unsigned long size)

Parse a BEAM file and returns a Module.

Parse a BEAM file a returns a newly allocated and initialized Module struct.

Parameters:
  • global – the global context.

  • iff_binary – the IFF file data.

  • size – the size of the buffer containing the IFF data.

void module_destroy(Module *module)
term module_load_literal(Module *mod, int index, Context *ctx)

Gets a literal stored on the literal table of the specified module.

Loads and deserialize a term stored in the literal table and returns a term.

Parameters:
  • mod – The module that owns that is going to be loaded.

  • index – a valid literal index.

  • ctx – the target context.

const struct ExportedFunction *module_resolve_function0(Module *mod, int import_table_index, struct UnresolvedFunctionCall *unresolved, GlobalContext *glb)
static uint16_t *parse_line_refs(uint8_t **data, size_t num_refs, size_t len)
struct ModuleFilename *parse_filename_table(uint8_t **data, size_t num_filenames, size_t len)
void module_insert_line_ref_offset(Module *mod, int line_ref, int offset)
int module_find_line(Module *mod, unsigned int offset)