[m-rev.] For review: Fix dummy type handling in the IL backend
Julien Fischer
juliensf at csse.unimelb.edu.au
Mon Oct 23 16:24:32 AEST 2006
Pete, could you please take a look at this one.
(That's Peter Ross - not any of the other Peters).
Cheers,
Julien.
On Wed, 27 Sep 2006, Jonathan Morgan wrote:
> With the below patch mercury-0.13 handles the IL backend correctly (as
> well as it ever did). I cannot test the patch on main, as
> foreign_export does not yet work properly with the IL backend, but it
> should work without change.
>
> Jon
> ================================================================
> Branches: release, main
>
> Previously in the IL backend dummy variables were assigned to
> private_builtin.dummy_var, which did not work when values were
> assigned to it using the high-level data representation, as their type
> was not the low-level object[]. This change changes the
> representation of dummy variables from object[] (the low-level
> representation) to object (suitable for high-level data), and causes
> the IL backend to detect assignments to dummy_var and cast them to
> type object before assigning to them.
>
> compiler/mlds_to_il.m:
> Detect when an object is constructed and assigned to
> private_builtin.dummy_var, and cast to il_generic_type (object) before
> assigning the constructed object.
>
> library/private_builtin.m:
> Change dummy_var's type from object[] to object.
>
> Index: compiler/mlds_to_il.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
> retrieving revision 1.161
> diff -u -u -r1.161 mlds_to_il.m
> --- compiler/mlds_to_il.m 29 Mar 2006 08:07:05 -0000 1.161
> +++ compiler/mlds_to_il.m 27 Sep 2006 11:06:28 -0000
> @@ -2056,7 +2056,23 @@
> ILArgTypes = list.map(mlds_type_to_ilds_type(DataRep), ArgTypes),
> list.map_foldl(load, Args, ArgsLoadInstrsTrees, !Info),
> ArgsLoadInstrs = tree_list(ArgsLoadInstrsTrees),
> - get_load_store_lval_instrs(Target, LoadMemRefInstrs,
> + % check if it's assigning to private_builtin.dummy_var
> + % If so, then it needs to be cast to il_generic_type.
> + (
> + Target = var(qual(MLDS_Module, QualKind, VarName), _),
> + VarName = mlds_var_name("dummy_var", _),
> + mercury_private_builtin_module(PrivateBuiltin),
> + MLDS_PrivateBuiltin =
> mercury_module_name_to_mlds(PrivateBuiltin),
> + mlds_append_wrapper_class(MLDS_PrivateBuiltin) = MLDS_Module
> + ->
> + MaybeCastInstrs = node([castclass(il_generic_type)]),
> + Target1 = var(qual(MLDS_Module, QualKind, VarName),
> + mlds_generic_type)
> + ;
> + MaybeCastInstrs = empty,
> + Target1 = Target
> + ),
> + get_load_store_lval_instrs(Target1, LoadMemRefInstrs,
> StoreLvalInstrs, !Info),
> CallCtor = newobj_constructor(ClassName, ILArgTypes),
> Instrs = tree_list([
> @@ -2064,6 +2080,7 @@
> comment_node("new object (call constructor)"),
> ArgsLoadInstrs,
> instr_node(CallCtor),
> + MaybeCastInstrs,
> StoreLvalInstrs
> ])
> ;
> @@ -3112,7 +3129,7 @@
> il_object_array_type.
> mlds_mercury_type_to_ilds_type(_, _, type_cat_tuple) = il_object_array_type.
> mlds_mercury_type_to_ilds_type(_, _, type_cat_enum) = il_object_array_type.
> -mlds_mercury_type_to_ilds_type(_, _, type_cat_dummy) =
> il_object_array_type.
> +mlds_mercury_type_to_ilds_type(_, _, type_cat_dummy) = il_generic_type.
> mlds_mercury_type_to_ilds_type(_, _, type_cat_variable) = il_generic_type.
> mlds_mercury_type_to_ilds_type(DataRep, MercuryType, type_cat_type_info) =
> mlds_mercury_type_to_ilds_type(DataRep, MercuryType, type_cat_user_ctor).
> Index: library/private_builtin.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
> retrieving revision 1.154.2.3
> diff -u -u -r1.154.2.3 private_builtin.m
> --- library/private_builtin.m 21 Aug 2006 05:37:25 -0000 1.154.2.3
> +++ library/private_builtin.m 27 Sep 2006 11:07:54 -0000
> @@ -124,7 +124,7 @@
> // will be used by the code generator as an lval, so we use
> // private_builtin:dummy_var as that lval.
>
> -public static object[] dummy_var;
> +public static object dummy_var;
>
> ").
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
>
--------------------------------------------------------------------------
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