%-----------------------------------------------------------------------------% % Copyright (C) 1995 University of Melbourne. % This file may only be copied under the terms of the GNU General % Public License - see the file COPYING in the Mercury distribution. %-----------------------------------------------------------------------------% % This module defines predicates to produce the functions which are % exported to C via a pragma(export, ...) declaration. % XXX We don't handle floats or strings properly. % Main authors: dgj. %-----------------------------------------------------------------------------% :- module export. :- interface. :- import_module hlds_module. :- import_module io, list, string, term. % From the module_info, get a list of functions, each of which allows % a call to be made to a Mercury procedure from C :- pred export__get_pragma_exported_procs(module_info, list(string)). :- mode export__get_pragma_exported_procs(in, out) is det. % Produce a header file containing prototypes for the exported C % functions :- pred export__produce_header_file(module_info, string, io__state, io__state). :- mode export__produce_header_file(in, in, di, uo) is det. % Convert the term, which represents a type, to a string corresponding % to its C type. (Defaults to Word). :- pred export__term_to_type_string(term, string). :- mode export__term_to_type_string(in, out) is det. :- implementation. :- import_module code_gen, code_util, hlds_pred, llds, llds_out. :- import_module library, map, int, std_util, assoc_list. export__get_pragma_exported_procs(Module, ExportedProcsCode) :- module_info_get_pragma_exported_procs(Module, ExportedProcs), module_info_get_predicate_table(Module, PredicateTable), predicate_table_get_preds(PredicateTable, Preds), export__to_c(Preds, ExportedProcs, Module, ExportedProcsCode). % For each exported procedure, produce a C function. % The code we generate is in the form % % void % (Word Mercury__Argument1, Word *Mercury__Argument2...) % /* Word for input, Word* for output */ % { % /* restore Mercury's registers that were saved as */ % /* we entered C from Mercury (the process must */ % /* always start in Mercury so that we can */ % /* init_engine() etc.) */ % restore_registers(); % % /* save the registers which may be clobbered */ % /* by the C function call call_engine(). */ % save_transient_registers(); % { % Declare_entry(