mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 21:04:00 +00:00
Estimated hours taken: 12 Branches: main Support nested modules in the GCC back-end. (TO DO: Mmake support for nested modules is still not yet implemented.) compiler/mlds_to_gcc.m: compiler/maybe_mlds_to_gcc.pp: In mlds_to_gcc.m, split compile_to_asm into two procedures, an outer one called run_gcc_backend and an inner one still called compile_to_asm. Likewise for the wrapper in maybe_mlds_to_gcc.m. compiler/mercury_compile.m: For --target asm, invoke run_gcc_backend at the top-level of the compilation, to avoid problems that occur with the gcc back-end. The problem was that the gcc back-end can only be invoked once per process, but previously, when processing nested modules or multiple modules on the command line, we were invoking it multiple times. With the new approach, we always invoke the gcc back-end once, and generate a single assembler file, regardless of how many modules are being compiled. This required changing the computation of the set of modules to link for --target asm. I also fixed a bug where it wasn't linking in the object files generated for C foreign code with --target asm.
72 lines
2.5 KiB
ObjectPascal
72 lines
2.5 KiB
ObjectPascal
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2001 The 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.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% maybe_mlds_to_gcc - Convert MLDS to the GCC back-end representation,
|
|
% if the GCC back-end interface has been enabled.
|
|
% Main author: fjh.
|
|
|
|
% This is just a wrapper around mlds_to_gcc.m to enable that
|
|
% file to be included iff we were configured with the
|
|
% gcc back-end interface enabled.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module maybe_mlds_to_gcc.
|
|
:- interface.
|
|
|
|
:- import_module mlds, bool.
|
|
:- use_module io.
|
|
|
|
:- type frontend_callback(T) == pred(T, io__state, io__state).
|
|
:- inst frontend_callback == (pred(out, di, uo) is det).
|
|
|
|
% Invoke the callback either via gcc__run_backend, or directly,
|
|
% depending on whether the gcc back-end interface has
|
|
% been enabled.
|
|
:- pred maybe_mlds_to_gcc__run_gcc_backend(mercury_module_name,
|
|
frontend_callback(T), T, io__state, io__state).
|
|
:- mode maybe_mlds_to_gcc__run_gcc_backend(in, in(frontend_callback), out,
|
|
di, uo) is det.
|
|
|
|
% Either invoke mlds_to_gcc__compile_to_asm, or report an error
|
|
% message, depending on whether the gcc back-end interface has
|
|
% been enabled. In the former case,
|
|
% the bool returned is `yes' iff the module contained C code.
|
|
:- pred maybe_mlds_to_gcc__compile_to_asm(mlds__mlds, bool,
|
|
io__state, io__state).
|
|
:- mode maybe_mlds_to_gcc__compile_to_asm(in, out, di, uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
#if ENABLE_GCC_BACK_END
|
|
|
|
:- use_module mlds_to_gcc.
|
|
|
|
maybe_mlds_to_gcc__run_gcc_backend(ModuleName, CallBack, CallBackOutput) -->
|
|
mlds_to_gcc__run_gcc_backend(ModuleName, CallBack, CallBackOutput).
|
|
|
|
maybe_mlds_to_gcc__compile_to_asm(MLDS, ContainsCCode) -->
|
|
mlds_to_gcc__compile_to_asm(MLDS, ContainsCCode).
|
|
|
|
#else
|
|
|
|
:- import_module passes_aux.
|
|
:- import_module string.
|
|
|
|
maybe_mlds_to_gcc__run_gcc_backend(_ModuleName, CallBack, CallBackOutput) -->
|
|
CallBack(CallBackOutput).
|
|
|
|
maybe_mlds_to_gcc__compile_to_asm(_MLDS, no) -->
|
|
report_error(
|
|
"Sorry, `--target asm' not supported: this installation of the Mercury\n" ++
|
|
"compiler was built without support for the GCC back-end interface.").
|
|
|
|
#endif
|
|
|
|
%-----------------------------------------------------------------------------%
|