Next: , Up: Compilation details   [Contents][Index]


5.1 Creating target and object code files

If you use Mmake or ‘mmc --make’, then you do not need to understand the details of how the Mercury implementation goes about building programs. Thus you may wish to skip this chapter.

To compile a Mercury source file to C code, use a command such as

mmc --grade asm_fast.gc -C module_name.m

On that command line, the --grade asm_fast.gc part obviously specifies the grade, while the -C option, whose long name is --target-code-only, tells the compiler to stop after generating the target language file (in this case, module_name.c).

You can then compile module_name.c to module_name.o, or you can tell the Mercury compiler to do this for you. To compile a source file not just to C code but to object code, use the command

mmc --grade asm_fast.gc -c module_name.m

The -c option, whose long name is --compile-only, tells the compiler to stop after compiling the Mercury code into object code. (In grades that target Java, it tells the compiler to stop after generating module_name.class, and In grades that target C#, it tells the compiler to stop after generating module_name.dll, since these file types are the equivalents of object files for these target languages.)

If the source file contains nested modules, then both the main module in the file, and all the submodules nested inside it, directly or indirectly, will all get compiled first to separate .c (or .java, or .cs files, and then to separate .o (or .class, or .dll files.

However, before you can compile a module, you must first make the interface files for the modules that it imports, either directly or indirectly. And if you want to compile the program with intermodule optimization, then you must first also create the files that enable that. The next two sections cover these in turn.


Next: , Up: Compilation details   [Contents][Index]