for review: generate type parameter locations
Tyson Dowd
trd at cs.mu.OZ.AU
Mon Feb 9 17:04:41 AEDT 1998
Hi,
Here's a change that will output the type parameter location vector
for execution tracing.
Zoltan might want to review this.
===================================================================
Estimated hours taken: 15
Put type parameter locations into stack layouts.
compiler/code_gen.m:
Generate typeinfos for entry and exit points.
compiler/stack_layout.m:
Output the type parameters vector.
Index: compiler/code_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/code_gen.m,v
retrieving revision 1.46
diff -u -r1.46 code_gen.m
--- code_gen.m 1998/02/03 08:18:12 1.46
+++ code_gen.m 1998/02/09 05:55:25
@@ -421,7 +421,8 @@
{ code_gen__select_args_with_mode(Args, top_in, InVars,
InLvals) },
- code_gen__generate_var_infos(InVars, InLvals, VarInfos,
+ code_gen__generate_var_infos(InVars, InLvals, VarInfos),
+ code_gen__generate_typeinfos_on_entry(InVars, InLvals,
TypeInfos),
code_info__get_continuation_info(ContInfo0),
@@ -615,7 +616,9 @@
trace_stack_layout, yes) }
->
code_gen__generate_var_infos(OutVars, OutLvals,
- VarInfos, TypeInfos),
+ VarInfos),
+ code_gen__generate_typeinfos_on_exit(OutVars,
+ TypeInfos),
code_info__get_continuation_info(ContInfo0),
code_info__get_pred_id(PredId),
code_info__get_proc_id(ProcId),
@@ -695,35 +698,86 @@
%---------------------------------------------------------------------------%
- % Generate the list of lval - live_value_type pairs and the
- % typeinfo variable - lval pairs for any type variables in
- % the types of the given variables.
+ % Generate the list of lval - live_value_type pairs for the
+ % the given variables.
:- pred code_gen__generate_var_infos(list(var), list(lval),
- list(var_info), assoc_list(var, lval), code_info, code_info).
-:- mode code_gen__generate_var_infos(in, in, out, out, in, out) is det.
-
-code_gen__generate_var_infos(Vars, Lvals, VarInfos, TypeInfos) -->
- { assoc_list__from_corresponding_lists(Vars, Lvals, VarLvals) },
- code_info__get_proc_info(ProcInfo),
- { proc_info_vartypes(ProcInfo, VarTypes) },
- code_info__get_instmap(InstMap),
+ list(var_info), code_info, code_info).
+:- mode code_gen__generate_var_infos(in, in, out, in, out) is det.
+code_gen__generate_var_infos(Vars, Lvals, VarInfos) -->
+ % Add the variable names, insts, types and lvals.
code_info__get_varset(VarSet),
- { MakeVarInfo = lambda([VarLval::in, VarInfo::out] is det, (
- VarLval = Var - Lval,
- map__lookup(VarTypes, Var, Type),
+ code_info__get_instmap(InstMap),
+ { map__from_corresponding_lists(Vars, Lvals, VarLvalMap) },
+ =(CodeInfo),
+ { MakeVarInfo = lambda([Var::in, VarInfo::out] is det, (
+ map__lookup(VarLvalMap, Var, Lval),
+ code_info__variable_type(Var, Type, CodeInfo, _),
instmap__lookup_var(InstMap, Var, Inst),
LiveType = var(Type, Inst),
varset__lookup_name(VarSet, Var, "V_", Name),
VarInfo = var_info(Lval, LiveType, Name)
)) },
- { list__map(MakeVarInfo, VarLvals, VarInfos) },
+ { list__map(MakeVarInfo, Vars, VarInfos) }.
+
- % XXX This doesn't work yet.
- % { list__map(type_util__vars, Types, TypeVarsList) },
- % { list__condense(TypeVarsList, TypeVars) },
- % code_info__find_type_infos(TypeVars, TypeInfos),
- { TypeInfos = [] }.
+ % Generate the tvar - lval pairs for the typeinfos of the
+ % given variables on entry to the procedure (we find the
+ % lval location by looking in the input registers).
+
+:- pred code_gen__generate_typeinfos_on_entry(list(var), list(lval),
+ assoc_list(tvar, lval), code_info, code_info).
+:- mode code_gen__generate_typeinfos_on_entry(in, in, out, in, out) is det.
+code_gen__generate_typeinfos_on_entry(Vars, Lvals, TypeInfos) -->
+
+ code_gen__find_typeinfos_for_vars(Vars, TVars, TypeInfoVars),
+
+ % Find the locations of the TypeInfoVars.
+ { map__from_corresponding_lists(Vars, Lvals, VarLvalMap) },
+ { map__apply_to_list(TypeInfoVars, VarLvalMap, TypeInfoLvals) },
+ { assoc_list__from_corresponding_lists(TVars, TypeInfoLvals,
+ TypeInfos) }.
+
+ % Generate the tvar - lval pairs for the typeinfos of the
+ % given variables on exit from the procedure (we use code_exprn
+ % to find the lvals).
+
+:- pred code_gen__generate_typeinfos_on_exit(list(var), assoc_list(var, lval),
+ code_info, code_info).
+:- mode code_gen__generate_typeinfos_on_exit(in, out, in, out) is det.
+code_gen__generate_typeinfos_on_exit(Vars, TypeInfos) -->
+
+ code_gen__find_typeinfos_for_vars(Vars, TVars, TypeInfoVars),
+
+ % Find the locations of the TypeInfoVars.
+ code_info__variable_locations(VarLocs),
+ { map__apply_to_list(TypeInfoVars, VarLocs, TypeInfoLvalSets) },
+ { FindSingleLval = lambda([Set::in, Lval::out] is det, (
+ (
+ set__remove_least(Set, Value, _),
+ Value = lval(Lval0)
+ ->
+ Lval = Lval0
+ ;
+ error("code_gen__generate_typeinfos_on_exit: typeinfo var not available")
+ ))) },
+ { list__map(FindSingleLval, TypeInfoLvalSets, TypeInfoLvals) },
+ { assoc_list__from_corresponding_lists(TVars, TypeInfoLvals,
+ TypeInfos) }.
+
+:- pred code_gen__find_typeinfos_for_vars(list(var), list(tvar), list(var),
+ code_info, code_info).
+:- mode code_gen__find_typeinfos_for_vars(in, out, out, in, out) is det.
+code_gen__find_typeinfos_for_vars(Vars, TypeVars, TypeInfoVars) -->
+ % Find the TypeInfo variables
+ list__map_foldl(code_info__variable_type, Vars, Types),
+ { list__map(type_util__vars, Types, TypeVarsList) },
+ { list__condense(TypeVarsList, TypeVars0) },
+ { list__sort_and_remove_dups(TypeVars0, TypeVars) },
+ code_info__get_proc_info(ProcInfo),
+ { proc_info_typeinfo_varmap(ProcInfo, TypeInfoMap) },
+ { map__apply_to_list(TypeVars, TypeInfoMap, TypeInfoLocns) },
+ { list__map(type_info_locn_var, TypeInfoLocns, TypeInfoVars) }.
%---------------------------------------------------------------------------%
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/stack_layout.m,v
retrieving revision 1.6
diff -u -r1.6 stack_layout.m
--- stack_layout.m 1998/02/03 08:18:33 1.6
+++ stack_layout.m 1998/02/09 05:04:51
@@ -351,7 +351,7 @@
ExitRvals),
{ list__append(EntryRvals, ExitRvals, RvalList) }
;
- { error("stack_layout__construct_agc_rvals: entry or exit information not available.") }
+ { error("stack_layout__construct_trace_rvals: entry or exit information not available.") }
).
% Construct the rvals required for accurate GC.
@@ -394,27 +394,39 @@
%---------------------------------------------------------------------------%
- % XXX Should also create Tvars.
-
:- pred stack_layout__construct_livelval_rvals(set(var_info),
set(pair(tvar, lval)), list(maybe(rval)),
stack_layout_info, stack_layout_info).
:- mode stack_layout__construct_livelval_rvals(in, in, out, in, out) is det.
-stack_layout__construct_livelval_rvals(LiveLvalSet, _TVars, RvalList) -->
+stack_layout__construct_livelval_rvals(LiveLvalSet, TVarSet, RvalList) -->
{ set__to_sorted_list(LiveLvalSet, LiveLvals) },
{ list__length(LiveLvals, Length) },
{ LengthRval = const(int_const(Length)) },
stack_layout__construct_liveval_pairs(LiveLvals, LiveValRval,
NamesRval),
- % XXX We don't yet generate tvars, so we use 0 as
- % a dummy value.
- { TVarRval = const(int_const(0)) },
+ { set__to_sorted_list(TVarSet, TVars) },
+ { assoc_list__values(TVars, TypeParamLvals) },
+ stack_layout__construct_type_parameter_locn_vector(TypeParamLvals,
+ TypeParamRval),
+
{ RvalList = [yes(LengthRval), yes(LiveValRval),
- yes(NamesRval), yes(TVarRval)] }.
+ yes(NamesRval), yes(TypeParamRval)] }.
%---------------------------------------------------------------------------%
+
+:- pred stack_layout__construct_type_parameter_locn_vector(list(lval)::in,
+ rval::out, stack_layout_info::in, stack_layout_info::out) is det.
+
+stack_layout__construct_type_parameter_locn_vector(TypeParamLvals,
+ TypeParamVector) -->
+ { MakeLval = lambda([Lval::in, yes(Rval)::out] is det, (
+ stack_layout__represent_lval(Lval, Rval))) },
+ { list__map(MakeLval, TypeParamLvals, TypeParamLocs) },
+ stack_layout__get_next_cell_number(CNum1),
+ { TypeParamVector = create(0, TypeParamLocs, no, CNum1,
+ "stack_layout_type_parameter_locn_vector") }.
% Construct a vector of (lval, live_value_type) pairs,
% and a corresponding vector of variable names.
--
Tyson Dowd # There isn't any reason why Linux can't be
# implemented as an enterprise computing solution.
trd at cs.mu.oz.au # Find out what you've been missing while you've
http://www.cs.mu.oz.au/~trd # been rebooting Windows NT. -- InfoWorld, 1998.
More information about the developers
mailing list