[m-rev.] for review: add infrastructure for Erlang backend

Julien Fischer juliensf at csse.unimelb.edu.au
Mon May 7 14:05:28 AEST 2007


On Mon, 7 May 2007, Peter Wang wrote:

> Estimated hours take: 4
> Branches: main
>
> Add some preliminary infrastructure for an HLDS->Erlang code generator.
>
> compiler/globals.m:
> compiler/options.m:
>        Recognise "erlang" as a valid compilation target.
>
>        Add new options: `--erlang' and `--erlang-only' as synonyms
>        for `--target erlang' and `--target erlang --target-code-only'.
>        XXX the new options are currently undocumented.
>
> compiler/hlds_data.m:
> compiler/prog_data.m:
> compiler/prog_io_pragma.m:
> 	Recognise "Erlang" as a valid language for foreign code.
>
> compiler/add_pragma.m:
> compiler/add_type.m:
> compiler/code_gen.m:
> compiler/compile_target_code.m:
> compiler/export.m:
> compiler/foreign.m:
> compiler/granularity.m:
> compiler/handle_options.m:
> compiler/intermod.m:
> compiler/llds_out.m:
> compiler/make.module_target.m:
> compiler/make.program_target.m:
> compiler/make_hlds_passes.m:
> compiler/mercury_compile.m:
> compiler/mercury_to_mercury.m:
> compiler/ml_code_gen.m:
> compiler/ml_optimize.m:
> compiler/ml_switch_gen.m:
> compiler/ml_type_gen.m:
> compiler/ml_unify_gen.m:
> compiler/mlds.m:
> compiler/mlds_to_c.m:
> compiler/mlds_to_il.m:
> compiler/mlds_to_ilasm.m:
> compiler/mlds_to_java.m:
> compiler/modules.m:
> compiler/pragma_c_gen.m:
> compiler/prog_foreign.m:
> compiler/simplify.m:
> 	Conform to the above changes.
>

> Index: compiler/handle_options.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/handle_options.m,v
> retrieving revision 1.297
> diff -u -r1.297 handle_options.m
> --- compiler/handle_options.m	13 Apr 2007 04:56:39 -0000	1.297
> +++ compiler/handle_options.m	7 May 2007 02:39:04 -0000
> @@ -536,6 +536,7 @@
>             ; Target = target_java
>             ; Target = target_asm
>             ; Target = target_x86_64
> +            ; Target = target_erlang
>             )
>         ),
>
> @@ -625,6 +626,7 @@
>             ; Target = target_il
>             ; Target = target_asm
>             ; Target = target_x86_64
> +            ; Target = target_erlang
>             )
>         ),
>         % Generating assembler via the gcc back-end requires
> @@ -637,6 +639,7 @@
>             ; Target = target_il
>             ; Target = target_java
>             ; Target = target_x86_64
> +            ; Target = target_erlang
>             )
>         ),
>
> @@ -664,6 +667,7 @@
>             ; Target = target_c
>             ; Target = target_il
>             ; Target = target_java
> +            ; Target = target_erlang
>             )
>         ),
>
> @@ -1160,6 +1164,7 @@
>                     ; Target = target_java
>                     ; Target = target_asm
>                     ; Target = target_x86_64
> +                    ; Target = target_erlang
>                     )
>                 )
>             ;
> @@ -1827,6 +1832,9 @@
>         ;
>             Target = target_x86_64,
>             BackendForeignLanguages = ["c"]
> +        ;
> +            Target = target_erlang,
> +            BackendForeignLanguages = ["erlang"]
>         ),
>
>         % Only set the backend foreign languages if they are unset.
> @@ -2353,6 +2361,14 @@
>         highlevel_code          - bool(yes),
>         highlevel_data          - bool(yes)],
>         yes([string("java")]), yes).
> +grade_component_table("erlang", comp_gcc_ext, [
> +        asm_labels              - bool(no),
> +        gcc_non_local_gotos     - bool(no),
> +        gcc_global_registers    - bool(no),
> +        gcc_nested_functions    - bool(no),
> +        highlevel_code          - bool(yes),    % XXX ?

That option really says, use the MLDS backend instead of the LLDS.
It won't really matter since you're generating erlang directly from
the HLDS, apart from the fact that if --high-level-code is enabled
then it affects whether certain optimizations are enabled.


> +        highlevel_data          - bool(yes)],
> +        yes([string("erlang")]), yes).
>
>     % Parallelism/multithreading components.
> grade_component_table("par", comp_par, [parallel - bool(yes)], no, yes).

> Index: compiler/ml_switch_gen.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_switch_gen.m,v
> retrieving revision 1.29
> diff -u -r1.29 ml_switch_gen.m
> --- compiler/ml_switch_gen.m	8 Jan 2007 03:03:12 -0000	1.29
> +++ compiler/ml_switch_gen.m	7 May 2007 02:39:05 -0000
> @@ -275,6 +275,7 @@
> % target_supports_int_switch_2(c_sharp) = yes.
> target_supports_int_switch_2(target_x86_64) =
>     unexpected(this_file, "target x86_64 with --high-level code").
> +target_supports_int_switch_2(target_erlang) = yes.

You should call unexpecyted there, unless you are also planning to
write an MLDS->Erlang code generator.

> target_supports_goto_2(target_x86_64) =
>     unexpected(this_file, "target x86_64 with --high-level code").
> +target_supports_goto_2(target_erlang) = no.

Likewise.

...

> Index: compiler/ml_type_gen.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_type_gen.m,v
> retrieving revision 1.64
> diff -u -r1.64 ml_type_gen.m
> --- compiler/ml_type_gen.m	8 Jan 2007 03:03:12 -0000	1.64
> +++ compiler/ml_type_gen.m	7 May 2007 02:39:05 -0000
> @@ -727,6 +727,8 @@
> target_uses_constructors(target_asm) = no.
> target_uses_constructors(target_x86_64) =
>     unexpected(this_file, "target_x86_64 and --high-level-code").
> +target_uses_constructors(target_erlang) =
> +    unexpected(this_file, "target erlang").
>
> :- func target_uses_empty_base_classes(compilation_target) = bool.
>
> @@ -736,6 +738,8 @@
> target_uses_empty_base_classes(target_asm) = no.
> target_uses_empty_base_classes(target_x86_64) =
>     unexpected(this_file, "target_x86_64 and --high-level-code").
> +target_uses_empty_base_classes(target_erlang) =
> +    unexpected(this_file, "target erlang").
>
>     % This should return yes if references to function parameters in
>     % constructor functions must be qualified with the module name,
> @@ -753,6 +757,7 @@
> target_requires_module_qualified_params(target_asm) = no.
> target_requires_module_qualified_params(target_x86_64) =
>     unexpected(this_file, "target_x86_64 with --high-level-code").
> +target_requires_module_qualified_params(target_erlang) = no.

Likewise.

You should also set gc_automatic when compiling to erlang.  (Have a look
at post_process_options_2).

You should also disable tabling when compiling to erlang, as is done for
the other grades that don't support it.

The rest looks fine.

Julien.


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list