[m-rev.] diff: more compactifications
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon May 3 22:03:07 AEST 2004
Generate even more compact output.
NEWS:
Mention the reductions in disk space required by generated .c files.
compiler/layout_out.m:
Refer to labels' layout structures without using unnecessary prefixes.
Emit less unnecessary white space.
compiler/llds_out.m:
Declare more than one common structure when possible.
Print procedure start comments only with --auto-comments.
Recognize common special forms of tests and generate more compact
code for them.
Use shorter macros to refer to stackvars and framevars.
In many cases, use macros that allow unnecessary prefixes to be
omitted.
Emit less unnecessary white space.
compiler/trace.m:
Use shorter macros to refer to stackvars and framevars.
Zoltan.
cvs server: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.331
diff -u -b -r1.331 NEWS
--- NEWS 10 Apr 2004 13:05:59 -0000 1.331
+++ NEWS 3 May 2004 08:41:56 -0000
@@ -43,6 +43,7 @@
Changes to the compiler back-ends:
* The .NET CLR back-end now bootstraps.
* Major improvements to the Java back-end.
+* The cost in disk space of enabling debugging is now much smaller.
Numerous minor improvements to the Mercury standard library.
@@ -863,5 +864,17 @@
See <http://www.cs.mu.oz.au/mercury/dotnet.html> and/or
<http://www.cs.mu.oz.au/mercury/information/dotnet/mercury_and_dotnet.html>.
+
+* The cost in disk space of enabling debugging is now much smaller.
+
+ When debugging is enabled, the compiler creates several data structures
+ for use by the Mercury debugger mdb, and includes the definitions of these
+ data structures in the generated C file. These definitions could be very
+ large (several megabytes), because readable C code is an inherently verbose
+ medium for expressing e.g. the values of pointers. By generating denser,
+ less readable C code, we have greatly reduced the size of these definitions,
+ and the sizes of the references to them in the executable code. The sizes
+ of the C files generated by the compiler with debugging enabled are now
+ typically between a quarter and a third of their previous sizes.
For news about earlier versions, see the HISTORY file.
cvs server: Diffing analysis
cvs server: Diffing bindist
cvs server: Diffing boehm_gc
cvs server: Diffing boehm_gc/Mac_files
cvs server: Diffing boehm_gc/cord
cvs server: Diffing boehm_gc/cord/private
cvs server: Diffing boehm_gc/doc
cvs server: Diffing boehm_gc/include
cvs server: Diffing boehm_gc/include/private
cvs server: Diffing boehm_gc/tests
cvs server: Diffing browser
cvs server: Diffing bytecode
cvs server: Diffing compiler
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.30
diff -u -b -r1.30 layout_out.m
--- compiler/layout_out.m 8 Apr 2004 05:35:02 -0000 1.30
+++ compiler/layout_out.m 3 May 2004 08:41:57 -0000
@@ -540,7 +540,7 @@
io__write_string("(", !IO),
break_up_local_label(Label, ProcLabel, LabelNum),
output_proc_label(ProcLabel, no, !IO),
- io__write_string(",\n ", !IO),
+ io__write_string(",\n", !IO),
io__write_int(LabelNum, !IO),
io__write_string(", ", !IO),
(
@@ -583,7 +583,7 @@
io__write_string(" &", !IO),
output_data_addr(DataAddr, !IO)
;
- io__write_string("\n\t\t", !IO),
+ io__write_string("\n", !IO),
output_rval(Rval, !IO)
).
@@ -705,7 +705,7 @@
output_layout_traversal_group(Traversal, !IO) :-
Traversal = proc_layout_stack_traversal(MaybeEntryLabel,
MaybeSuccipSlot, StackSlotCount, Detism),
- io__write_string("\t{\n\t", !IO),
+ io__write_string("{\n", !IO),
(
MaybeEntryLabel = yes(EntryLabel),
output_code_addr(label(EntryLabel), !IO)
@@ -715,7 +715,7 @@
% by module initialization code.
io__write_string("NULL", !IO)
),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
(
MaybeSuccipSlot = yes(SuccipSlot),
io__write_int(SuccipSlot, !IO)
@@ -723,11 +723,11 @@
MaybeSuccipSlot = no,
io__write_int(-1, !IO)
),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(StackSlotCount, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_string(detism_to_c_detism(Detism), !IO),
- io__write_string("\n\t},\n", !IO).
+ io__write_string("\n},\n", !IO).
:- func detism_to_c_detism(determinism) = string.
@@ -743,14 +743,14 @@
:- pred output_layout_proc_id_group(proc_label::in, io::di, io::uo) is det.
output_layout_proc_id_group(ProcLabel) -->
- io__write_string("\t{\n"),
+ io__write_string("{\n"),
output_proc_id(ProcLabel),
- io__write_string("\t},\n").
+ io__write_string("},\n").
:- pred output_layout_no_proc_id_group(io::di, io::uo) is det.
output_layout_no_proc_id_group -->
- io__write_string("\t-1\n").
+ io__write_string("-1\n").
:- pred output_layout_exec_trace_decls(proc_label::in,
proc_layout_exec_trace::in, decl_set::in, decl_set::out,
@@ -786,12 +786,16 @@
MaybeTableInfo, HeadVarNums, _VarNames, MaxVarNum,
MaxRegNum, MaybeFromFullSlot, MaybeIoSeqSlot, MaybeTrailSlot,
MaybeMaxfrSlot, EvalMethod, MaybeCallTableSlot) },
- io__write_string("\t{\n\t(const MR_Label_Layout *) &"),
- output_layout_name(CallLabelLayout),
- io__write_string(",\n\t(const MR_Module_Layout *) &"),
+ io__write_string("{\nMR_LABEL_LAYOUT_REF("),
+ ( { CallLabelLayout = label_layout(CallLabel, _) } ->
+ output_label(CallLabel, no)
+ ;
+ { error("output_layout_exec_trace_group: bad call layout") }
+ ),
+ io__write_string("),\n(const MR_Module_Layout *) &"),
{ ModuleName = get_defining_module_name(ProcLabel) },
output_layout_name(module_layout(ModuleName)),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
(
{ MaybeProcBody = yes(ProcBody) },
output_rval(ProcBody)
@@ -799,7 +803,7 @@
{ MaybeProcBody = no },
io__write_int(0)
),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
(
{ MaybeCallTableSlot = yes(_) },
io__write_string("&"),
@@ -808,7 +812,7 @@
{ MaybeCallTableSlot = no },
io__write_string("NULL")
),
- io__write_string(",\n\t{ "),
+ io__write_string(",\n{ "),
(
{ MaybeTableInfo = yes(TableInfo) },
io__write_string("(const void *) &"),
@@ -817,29 +821,29 @@
{ MaybeTableInfo = no },
io__write_string("NULL")
),
- io__write_string(" },\n\t"),
+ io__write_string(" },\n"),
output_layout_name(proc_layout_head_var_nums(ProcLabel)),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
output_layout_name(proc_layout_var_names(ProcLabel)),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(list__length(HeadVarNums)),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(MaxVarNum),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(MaxRegNum),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
write_maybe_slot_num(MaybeFromFullSlot),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
write_maybe_slot_num(MaybeIoSeqSlot),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
write_maybe_slot_num(MaybeTrailSlot),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
write_maybe_slot_num(MaybeMaxfrSlot),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_string(eval_method_to_c_string(EvalMethod)),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
write_maybe_slot_num(MaybeCallTableSlot),
- io__write_string("\n\t}\n").
+ io__write_string("\n}\n").
:- pred write_maybe_slot_num(maybe(int)::in, io::di, io::uo) is det.
@@ -884,7 +888,7 @@
( { HeadVarNums = [] } ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\t0\n")
+ io__write_string("0\n")
;
list__foldl(output_number_in_vector, HeadVarNums)
),
@@ -908,7 +912,7 @@
( { VarNames = [] } ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\t0\n")
+ io__write_string("0\n")
;
list__foldl(output_number_in_vector, VarNames)
),
@@ -920,7 +924,7 @@
:- pred output_layout_no_exec_trace_group(io::di, io::uo) is det.
output_layout_no_exec_trace_group -->
- io__write_string("\t0\n").
+ io__write_string("0\n").
%-----------------------------------------------------------------------------%
@@ -935,16 +939,16 @@
{ LayoutName = closure_proc_id(CallerProcLabel, SeqNo,
ClosureProcLabel) },
output_layout_name_storage_type_name(LayoutName, yes),
- io__write_string(" = {\n\t{\n"),
+ io__write_string(" = {\n{\n"),
output_proc_id(ClosureProcLabel),
- io__write_string("\t},\n\t"),
+ io__write_string("},\n"),
{ prog_out__sym_name_to_string(ModuleName, ModuleNameStr) },
quote_and_write_string(ModuleNameStr),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(FileName),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(LineNumber),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(GoalPath),
io__write_string("\n};\n"),
{ decl_set_insert(data_addr(layout_addr(LayoutName)),
@@ -961,17 +965,16 @@
{ prog_out__sym_name_to_string(DeclaringModule,
DeclaringModuleStr) },
{ proc_id_to_int(Mode, ModeInt) },
- io__write_string("\t"),
output_pred_or_func(PredOrFunc),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(DeclaringModuleStr),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(DefiningModuleStr),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(Name),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(Arity),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(ModeInt),
io__write_string("\n")
;
@@ -981,19 +984,18 @@
DefiningModuleStr) },
{ prog_out__sym_name_to_string(TypeModule, TypeModuleStr) },
{ proc_id_to_int(Mode, ModeInt) },
- io__write_string("\t"),
quote_and_write_string(TypeName),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(TypeModuleStr),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
quote_and_write_string(DefiningModuleStr),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
{ TypeCtor = qualified(TypeModule, TypeName) - TypeArity },
{ PredName = special_pred_name(SpecialPredId, TypeCtor) },
quote_and_write_string(PredName),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(TypeArity),
- io__write_string(",\n\t"),
+ io__write_string(",\n"),
io__write_int(ModeInt),
io__write_string("\n")
).
@@ -1020,27 +1022,27 @@
ModuleLayoutName = module_layout(ModuleName),
io__write_string("\n", !IO),
output_layout_name_storage_type_name(ModuleLayoutName, yes, !IO),
- io__write_string(" = {\n\t", !IO),
+ io__write_string(" = {\n", !IO),
prog_out__sym_name_to_string(ModuleName, ModuleNameStr),
quote_and_write_string(ModuleNameStr, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(StringTableSize, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
ModuleStringTableName = module_layout_string_table(ModuleName),
output_layout_name(ModuleStringTableName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
list__length(ProcLayoutNames, ProcLayoutVectorLength),
io__write_int(ProcLayoutVectorLength, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(ProcVectorName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
list__length(FileLayouts, FileLayoutVectorLength),
io__write_int(FileLayoutVectorLength, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(FileVectorName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_string(trace_level_rep(TraceLevel), !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(SuppressedEvents, !IO),
io__write_string("\n};\n", !IO),
decl_set_insert(data_addr(layout_addr(ModuleLayoutName)), !DeclSet).
@@ -1059,7 +1061,7 @@
( ProcLayoutNames = [] ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\tNULL\n", !IO)
+ io__write_string("NULL\n", !IO)
;
list__foldl(output_proc_layout_name_in_vector, ProcLayoutNames,
!IO)
@@ -1125,7 +1127,7 @@
output_module_string_table_chars(CurIndex, MaxIndex, StringWithNulls) -->
( { CurIndex mod 10 = 0 } ->
- io__write_string("\n\t")
+ io__write_string("\n")
;
[]
),
@@ -1158,7 +1160,7 @@
( FileLayoutNames = [] ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\tNULL\n", !IO)
+ io__write_string("NULL\n", !IO)
;
list__foldl(output_layout_name_in_vector("&"), FileLayoutNames,
!IO)
@@ -1198,13 +1200,13 @@
FileLayoutName = file_layout(ModuleName, FileNum),
io__write_string("\n", !IO),
output_layout_name_storage_type_name(FileLayoutName, yes, !IO),
- io__write_string(" = {\n\t", !IO),
+ io__write_string(" = {\n", !IO),
quote_and_write_string(FileName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(VectorLengths, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(LineNumberVectorName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(LabelVectorName, !IO),
io__write_string("\n};\n", !IO),
decl_set_insert(data_addr(layout_addr(FileLayoutName)), !DeclSet).
@@ -1222,7 +1224,7 @@
( LineNumbers = [] ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\t0\n", !IO)
+ io__write_string("0\n", !IO)
;
list__foldl(output_number_in_vector, LineNumbers, !IO)
),
@@ -1242,7 +1244,7 @@
( LabelAddrs = [] ->
% ANSI/ISO C doesn't allow empty arrays, so
% place a dummy value in the array.
- io__write_string("\tNULL\n", !IO)
+ io__write_string("NULL\n", !IO)
;
list__map(project_label_layout, LabelAddrs, Labels),
output_label_layout_addrs_in_vector(Labels, !IO)
@@ -1327,7 +1329,6 @@
:- pred output_number_in_vector(int::in, io::di, io::uo) is det.
output_number_in_vector(Num) -->
- io__write_string("\t"),
io__write_int(Num),
io__write_string(",\n").
@@ -1335,7 +1336,6 @@
io::di, io::uo) is det.
output_layout_name_in_vector(Prefix, Name) -->
- io__write_string("\t"),
io__write_string(Prefix),
output_layout_name(Name),
io__write_string(",\n").
@@ -1344,7 +1344,6 @@
io::di, io::uo) is det.
output_data_addr_in_vector(Prefix, DataAddr) -->
- io__write_string("\t"),
io__write_string(Prefix),
output_data_addr(DataAddr),
io__write_string(",\n").
@@ -1365,11 +1364,10 @@
io__write_string(" = {\n", !IO),
ProcLabel = make_proc_label_from_rtti(RttiProcLabel),
output_layout_proc_id_group(ProcLabel, !IO),
- io__write_string("\t", !IO),
quote_and_write_string(FileName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(LineNumber, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
(
IsInInterface = yes,
io__write_string("MR_TRUE", !IO)
@@ -1377,15 +1375,15 @@
IsInInterface = no,
io__write_string("MR_FALSE", !IO)
),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(list__length(CallSites), !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
CallSitesLayoutName = proc_static_call_sites(RttiProcLabel),
output_layout_name(CallSitesLayoutName, !IO),
io__write_string(",\n#ifdef MR_USE_ACTIVATION_COUNTS\n", !IO),
- io__write_string("\t0,\n", !IO),
+ io__write_string("0,\n", !IO),
io__write_string("#endif\n", !IO),
- io__write_string("\tNULL\n};\n", !IO),
+ io__write_string("NULL\n};\n", !IO),
decl_set_insert(data_addr(layout_addr(LayoutName)), !DeclSet).
:- pred output_call_site_static_array(rtti_proc_label::in,
@@ -1405,36 +1403,36 @@
io::di, io::uo) is det.
output_call_site_static(CallSiteStatic, Index, Index + 1, !IO) :-
- io__write_string("\t{ /* ", !IO),
+ io__write_string("{ /* ", !IO),
io__write_int(Index, !IO),
io__write_string(" */ ", !IO),
(
CallSiteStatic = normal_call(Callee, TypeSubst,
FileName, LineNumber, GoalPath),
- io__write_string("MR_normal_call, (MR_ProcStatic *)\n\t &",
+ io__write_string("MR_normal_call, (MR_ProcStatic *)\n&",
!IO),
output_layout_name(proc_static(Callee), !IO),
( TypeSubst = "" ->
- io__write_string(",\n\t NULL, ", !IO)
+ io__write_string(", NULL, ", !IO)
;
- io__write_string(",\n\t """, !IO),
+ io__write_string(",\n""", !IO),
io__write_string(TypeSubst, !IO),
io__write_string(""", ", !IO)
)
;
CallSiteStatic = special_call(FileName, LineNumber,
GoalPath),
- io__write_string("MR_special_call, NULL,\n\t NULL, ", !IO)
+ io__write_string("MR_special_call, NULL, NULL, ", !IO)
;
CallSiteStatic = higher_order_call(FileName, LineNumber,
GoalPath),
- io__write_string("MR_higher_order_call, NULL,\n\t NULL, ", !IO)
+ io__write_string("MR_higher_order_call, NULL, NULL, ", !IO)
;
CallSiteStatic = method_call(FileName, LineNumber, GoalPath),
- io__write_string("MR_method_call, NULL,\n\t NULL, ", !IO)
+ io__write_string("MR_method_call, NULL, NULL, ", !IO)
;
CallSiteStatic = callback(FileName, LineNumber, GoalPath),
- io__write_string("MR_callback, NULL,\n\t NULL, ", !IO)
+ io__write_string("MR_callback, NULL, NULL, ", !IO)
),
io__write_string("""", !IO),
io__write_string(FileName, !IO),
@@ -1479,13 +1477,13 @@
io__write_string("\n", !IO),
output_layout_name_storage_type_name(LayoutName, yes, !IO),
- io__write_string(" = {\n\t(const MR_Proc_Layout *) &", !IO),
+ io__write_string(" = {\n(const MR_Proc_Layout *) &", !IO),
output_layout_name(ProcLayoutName, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(NumPTIs, !IO),
- io__write_string(",\n\t(const MR_PseudoTypeInfo *) ", !IO),
+ io__write_string(",\n(const MR_PseudoTypeInfo *) ", !IO),
output_rval(PTIVectorRval, !IO),
- io__write_string(",\n\t(const MR_Type_Param_Locns *) ", !IO),
+ io__write_string(",\n(const MR_Type_Param_Locns *) ", !IO),
output_rval(TypeParamsRval, !IO),
io__write_string("\n};\n", !IO),
decl_set_insert(data_addr(layout_addr(LayoutName)), !DeclSet).
@@ -1504,17 +1502,17 @@
LayoutName = table_gen_info(RttiProcLabel),
io__write_string("\n", !IO),
output_layout_name_storage_type_name(LayoutName, yes, !IO),
- io__write_string(" = {\n\t", !IO),
+ io__write_string(" = {\n", !IO),
io__write_int(NumInputs, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
io__write_int(NumOutputs, !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(table_gen_steps(RttiProcLabel), !IO),
- io__write_string(",\n\t", !IO),
+ io__write_string(",\n", !IO),
output_layout_name(table_gen_enum_params(RttiProcLabel), !IO),
- io__write_string(",\n\t(const MR_PseudoTypeInfo *)\n\t\t", !IO),
+ io__write_string(",\n(const MR_PseudoTypeInfo *)\n", !IO),
output_rval(PTIVectorRval, !IO),
- io__write_string(",\n\t(const MR_Type_Param_Locns *)\n\t\t", !IO),
+ io__write_string(",\n(const MR_Type_Param_Locns *)\n", !IO),
output_rval(TypeParamsRval, !IO),
io__write_string("\n};\n", !IO),
decl_set_insert(data_addr(layout_addr(LayoutName)), !DeclSet).
@@ -1568,7 +1566,6 @@
StepType = "MR_TABLE_STEP_POLY",
MaybeEnumParam = no
),
- io__write_string("\t", !IO),
io__write_string(StepType, !IO),
io__write_string(",\n", !IO),
output_table_gen_steps(Steps, MaybeEnumParams, !IO).
@@ -1592,7 +1589,6 @@
output_table_gen_enum_params([], !IO).
output_table_gen_enum_params([MaybeEnumParam | MaybeEnumParams], !IO) :-
- io__write_string("\t", !IO),
(
MaybeEnumParam = no,
io__write_int(-1, !IO)
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.225
diff -u -b -r1.225 llds_out.m
--- compiler/llds_out.m 10 Apr 2004 08:11:26 -0000 1.225
+++ compiler/llds_out.m 3 May 2004 08:41:58 -0000
@@ -109,6 +109,10 @@
:- pred output_label(label::in, io::di, io::uo) is det.
+ % Output a label without the standard mercury__ prefix.
+
+:- pred output_label(label::in, bool::in, io::di, io::uo) is det.
+
% Convert a label to a C string. The boolean controls whether
% a prefix ("mercury__") is added to the string.
@@ -816,20 +820,6 @@
decl_set::in, decl_set::out, io::di, io::uo) is det.
output_common_decl_group(TypeNum - CommonDatas, !DeclSet, !IO) :-
- % ChunkSize should be as large as possible to reduce the size of the
- % file being generated, but small enough not to overload the fixed
- % limits of our target C compilers.
- ChunkSize = 20,
- % The process of creating the multi_map reverses the order of
- % CommonDatas, we now undo this reversal.
- list__chunk(list__reverse(CommonDatas), ChunkSize, CommonDataChunks),
- list__foldl2(output_common_decl_chunk(TypeNum), CommonDataChunks,
- !DeclSet, !IO).
-
-:- pred output_common_decl_chunk(int::in, list(common_data)::in,
- decl_set::in, decl_set::out, io::di, io::uo) is det.
-
-output_common_decl_chunk(TypeNum, CommonDatas, !DeclSet, !IO) :-
io__write_string("\n", !IO),
globals__io_lookup_bool_option(split_c_files, SplitFiles, !IO),
ExportedFromFile = SplitFiles,
@@ -850,12 +840,68 @@
decl_set_insert(TypeDeclId, !DeclSet)
),
(
+ ExportedFromFile = no,
+ % There should be a macro MR_DEF_COMMON<n> for every n up to
+ % ChunkSize.
+ ChunkSize = 10,
+ list__chunk(list__reverse(CommonDatas), ChunkSize,
+ CommonDataChunks),
+ list__foldl2(output_common_decl_shorthand_chunk(TypeNum),
+ CommonDataChunks, !DeclSet, !IO)
+ ;
ExportedFromFile = yes,
- io__write_string("const struct ", !IO)
+ % ChunkSize should be as large as possible to reduce the size
+ % of the file being generated, but small enough not to overload
+ % the fixed limits of our target C compilers.
+ ChunkSize = 20,
+ % The process of creating the multi_map reverses the order of
+ % CommonDatas, we now undo this reversal.
+ list__chunk(list__reverse(CommonDatas), ChunkSize,
+ CommonDataChunks),
+ list__foldl2(output_common_decl_chunk(ModuleName, TypeNum),
+ CommonDataChunks, !DeclSet, !IO)
+ ).
+
+:- pred output_common_decl_shorthand_chunk(int::in, list(common_data)::in,
+ decl_set::in, decl_set::out, io::di, io::uo) is det.
+
+output_common_decl_shorthand_chunk(TypeNum, CommonDatas, !DeclSet, !IO) :-
+ io__write_string("MR_DEF_COMMON", !IO),
+ io__write_int(list__length(CommonDatas), !IO),
+ io__write_string("(", !IO),
+ io__write_int(TypeNum, !IO),
+ io__write_string(",", !IO),
+ output_common_decl_shorthand_chunk_entries(CommonDatas, !DeclSet, !IO),
+ io__write_string(")\n", !IO).
+
+:- pred output_common_decl_shorthand_chunk_entries(list(common_data)::in,
+ decl_set::in, decl_set::out, io::di, io::uo) is det.
+
+output_common_decl_shorthand_chunk_entries([], !DeclSet, !IO) :-
+ error("output_common_decl_shorthand_chunk_entries: empty list").
+output_common_decl_shorthand_chunk_entries([CommonData | CommonDatas],
+ !DeclSet, !IO) :-
+ CommonData = common_data(ModuleName, CellNum, TypeAndValue),
+ TypeNum = common_cell_get_type_num(TypeAndValue),
+ VarName = common(CellNum, TypeNum),
+ VarDeclId = data_addr(data_addr(ModuleName, VarName)),
+ decl_set_insert(VarDeclId, !DeclSet),
+ io__write_int(CellNum, !IO),
+ (
+ CommonDatas = [_ | _],
+ io__write_string(",", !IO),
+ output_common_decl_shorthand_chunk_entries(CommonDatas,
+ !DeclSet, !IO)
;
- ExportedFromFile = no,
- io__write_string("static const struct ", !IO)
- ),
+ CommonDatas = []
+ ).
+
+:- pred output_common_decl_chunk(module_name::in, int::in,
+ list(common_data)::in, decl_set::in, decl_set::out, io::di, io::uo)
+ is det.
+
+output_common_decl_chunk(ModuleName, TypeNum, CommonDatas, !DeclSet, !IO) :-
+ io__write_string("const struct ", !IO),
output_common_cell_type_name(ModuleName, TypeNum, !IO),
io__nl(!IO),
output_common_decl_chunk_entries(CommonDatas, !DeclSet, !IO).
@@ -1297,7 +1343,8 @@
:- pred output_c_label_init_group(string::in,
pair(proc_label, list(int))::in, io::di, io::uo) is det.
-output_c_label_init_group(Suffix, ProcLabel - LabelNums, !IO) :-
+output_c_label_init_group(Suffix, ProcLabel - RevLabelNums, !IO) :-
+ list__reverse(RevLabelNums, LabelNums),
% There must be macros of the form MR_init_label<n> and
% MR_init_label_sl<n> for every <n> up to MaxChunkSize.
MaxChunkSize = 8,
@@ -1394,15 +1441,21 @@
;
true
),
+ (
+ PrintComments = yes,
io__write_string("/* code for predicate '", !IO),
- % Now that we have unused_args.m mangling predicate names,
- % we should probably demangle them here.
+ % Now that we have unused_args.m mangling predicate
+ % names, we should probably demangle them here.
io__write_string(Name, !IO),
io__write_string("'/", !IO),
io__write_int(Arity, !IO),
io__write_string(" in mode ", !IO),
io__write_int(ModeNum, !IO),
- io__write_string(" */\n", !IO),
+ io__write_string(" */\n", !IO)
+ ;
+ PrintComments = no
+ ),
+
llds_out__find_caller_label(Instrs, CallerLabel),
llds_out__find_cont_labels(Instrs, bintree_set__init, ContLabelSet),
( EmitCLoops = yes ->
@@ -1688,7 +1741,7 @@
WhileSet, !IO)
; Instr0 = if_val(Rval, label(Label)) ->
io__write_string("\tif (", !IO),
- output_rval(Rval, !IO),
+ output_test_rval(Rval, !IO),
io__write_string(")\n\t\tcontinue;\n", !IO),
(
PrintComments = yes,
@@ -1865,7 +1918,7 @@
output_instruction(if_val(Rval, Target), ProfInfo, !IO) :-
ProfInfo = CallerLabel - _,
io__write_string("\tif (", !IO),
- output_rval_as_type(Rval, bool, !IO),
+ output_test_rval(Rval, !IO),
io__write_string(") {\n\t\t", !IO),
output_goto(Target, CallerLabel, !IO),
io__write_string("\t}\n", !IO).
@@ -2067,8 +2120,8 @@
output_pragma_c_component(pragma_c_raw_code(C_Code, _), !IO) :-
io__write_string(C_Code, !IO).
output_pragma_c_component(pragma_c_fail_to(Label), !IO) :-
- io__write_string("if (!MR_r1) MR_GOTO_LABEL(", !IO),
- output_label(Label, !IO),
+ io__write_string("if (!MR_r1) MR_GOTO_LAB(", !IO),
+ output_label(Label, no, !IO),
io__write_string(");\n", !IO).
output_pragma_c_component(pragma_c_noop, !IO).
@@ -2669,10 +2722,10 @@
io__write_string(" =\n{\n", !IO),
(
TypeAndValue = plain_type_and_value(_, ArgsTypes),
- output_cons_args(ArgsTypes, "\t", !IO)
+ output_cons_args(ArgsTypes, !IO)
;
TypeAndValue = grouped_type_and_value(_, ArgGroups),
- output_cons_arg_groups(ArgGroups, "\t", !IO)
+ output_cons_arg_groups(ArgGroups, !IO)
),
io__write_string(LaterIndent, !IO),
io__write_string("};\n", !IO)
@@ -2795,12 +2848,11 @@
% Output the arguments, each on its own line prefixing with Indent,
% and with a cast appropriate to its type if necessary.
-:- pred output_cons_args(assoc_list(rval, llds_type)::in, string::in,
- io::di, io::uo) is det.
+:- pred output_cons_args(assoc_list(rval, llds_type)::in, io::di, io::uo)
+ is det.
-output_cons_args([], _Indent, !IO).
-output_cons_args([Rval - Type | RvalsTypes], Indent, !IO) :-
- io__write_string(Indent, !IO),
+output_cons_args([], !IO).
+output_cons_args([Rval - Type | RvalsTypes], !IO) :-
(
direct_field_int_constant(Type) = yes,
Rval = const(int_const(N))
@@ -2811,59 +2863,54 @@
),
( RvalsTypes \= [] ->
io__write_string(",\n", !IO),
- output_cons_args(RvalsTypes, Indent, !IO)
+ output_cons_args(RvalsTypes, !IO)
;
io__write_string("\n", !IO)
).
-:- pred output_cons_arg_groups(list(common_cell_arg_group)::in, string::in,
- io::di, io::uo) is det.
+:- pred output_cons_arg_groups(list(common_cell_arg_group)::in, io::di, io::uo)
+ is det.
-output_cons_arg_groups([], _Indent, !IO).
-output_cons_arg_groups([Group | Groups], Indent, !IO) :-
+output_cons_arg_groups([], !IO).
+output_cons_arg_groups([Group | Groups], !IO) :-
Group = common_cell_arg_group(Type, _, Rvals),
- io__write_string(Indent, !IO),
io__write_string("{\n", !IO),
(
direct_field_int_constant(Type) = yes,
list__map(project_int_constant, Rvals, Ints)
->
- output_cons_arg_group_ints(Ints, Indent, !IO)
+ output_cons_arg_group_ints(Ints, !IO)
;
- output_cons_arg_group_elements(Type, Rvals, Indent, !IO)
+ output_cons_arg_group_elements(Type, Rvals, !IO)
),
- io__write_string(Indent, !IO),
( Groups \= [] ->
io__write_string("},\n", !IO),
- output_cons_arg_groups(Groups, Indent, !IO)
+ output_cons_arg_groups(Groups, !IO)
;
io__write_string("}\n", !IO)
).
:- pred output_cons_arg_group_elements(llds_type::in, list(rval)::in,
- string::in, io::di, io::uo) is det.
+ io::di, io::uo) is det.
-output_cons_arg_group_elements(_, [], _Indent, !IO).
-output_cons_arg_group_elements(Type, [Rval | Rvals], Indent, !IO) :-
- io__write_string(Indent, !IO),
+output_cons_arg_group_elements(_, [], !IO).
+output_cons_arg_group_elements(Type, [Rval | Rvals], !IO) :-
output_rval_as_type(Rval, Type, !IO),
( Rvals \= [] ->
io__write_string(",\n", !IO),
- output_cons_arg_group_elements(Type, Rvals, Indent, !IO)
+ output_cons_arg_group_elements(Type, Rvals, !IO)
;
io__write_string("\n", !IO)
).
-:- pred output_cons_arg_group_ints(list(int)::in, string::in,
- io::di, io::uo) is det.
+:- pred output_cons_arg_group_ints(list(int)::in, io::di, io::uo) is det.
-output_cons_arg_group_ints([], _Indent, !IO).
-output_cons_arg_group_ints([Int | Ints], Indent, !IO) :-
- io__write_string(Indent, !IO),
+output_cons_arg_group_ints([], !IO).
+output_cons_arg_group_ints([Int | Ints], !IO) :-
io__write_int(Int, !IO),
( Ints \= [] ->
io__write_string(",\n", !IO),
- output_cons_arg_group_ints(Ints, Indent, !IO)
+ output_cons_arg_group_ints(Ints, !IO)
;
io__write_string("\n", !IO)
).
@@ -3030,8 +3077,8 @@
:- pred output_label_as_code_addr_decls(label::in, io::di, io::uo) is det.
output_label_as_code_addr_decls(exported(ProcLabel), !IO) :-
- io__write_string("MR_declare_entry(", !IO),
- output_label(exported(ProcLabel), !IO),
+ io__write_string("MR_decl_entry(", !IO),
+ output_label(exported(ProcLabel), no, !IO),
io__write_string(");\n", !IO).
output_label_as_code_addr_decls(local(ProcLabel), !IO) :-
globals__io_lookup_bool_option(split_c_files, SplitFiles, !IO),
@@ -3180,9 +3227,9 @@
bintree_set__is_member(Label, ContLabelSet),
ProfileTime = yes
->
- io__write_string("\tMR_update_prof_current_proc(MR_LABEL(",
+ io__write_string("\tMR_update_prof_current_proc(MR_LABEL_AP(",
!IO),
- output_label(CallerLabel, !IO),
+ output_label(CallerLabel, no, !IO),
io__write_string("));\n", !IO)
;
true
@@ -3210,8 +3257,8 @@
io__write_string(");\n", !IO)
;
ProfileCalls = no,
- io__write_string("MR_noprof_tailcall(", !IO),
- output_label_as_code_addr(Label, !IO),
+ io__write_string("MR_np_tailcall_ent(", !IO),
+ output_label(Label, no, !IO),
io__write_string(");\n", !IO)
)
;
@@ -3227,8 +3274,8 @@
io__write_string(");\n", !IO)
;
ProfileCalls = no,
- io__write_string("MR_noprof_tailcall(", !IO),
- output_label_as_code_addr(Label, !IO),
+ io__write_string("MR_np_tailcall_ent(", !IO),
+ output_label(Label, no, !IO),
io__write_string(");\n", !IO)
)
;
@@ -3244,14 +3291,14 @@
io__write_string(");\n", !IO)
;
ProfileCalls = no,
- io__write_string("MR_noprof_localtailcall(", !IO),
- output_label(Label, !IO),
+ io__write_string("MR_np_localtailcall(", !IO),
+ output_label(Label, no, !IO),
io__write_string(");\n", !IO)
)
;
Label = local(_, _),
- io__write_string("MR_GOTO_LABEL(", !IO),
- output_label(Label, !IO),
+ io__write_string("MR_GOTO_LAB(", !IO),
+ output_label(Label, no, !IO),
io__write_string(");\n", !IO)
).
output_goto(imported(ProcLabel), CallerLabel, !IO) :-
@@ -3265,9 +3312,9 @@
io__write_string(");\n", !IO)
;
ProfileCalls = no,
- io__write_string("MR_noprof_tailcall(MR_ENTRY(", !IO),
- output_proc_label(ProcLabel, !IO),
- io__write_string("));\n", !IO)
+ io__write_string("MR_np_tailcall_ent(", !IO),
+ output_proc_label(ProcLabel, no, !IO),
+ io__write_string(");\n", !IO)
).
output_goto(succip, _, !IO) :-
io__write_string("MR_proceed();\n", !IO).
@@ -3308,25 +3355,28 @@
io__write_string("MR_set_prof_ho_caller_proc(", !IO),
output_label_as_code_addr(CallerLabel, !IO),
io__write_string(");\n\t\t", !IO),
- io__write_string("MR_noprof_tailcall(" ++
- "MR_ENTRY(mercury__do_call_closure_compact));\n", !IO).
+ io__write_string("MR_np_tailcall_ent(do_call_closure_compact);\n",
+ !IO).
output_goto(do_call_class_method, CallerLabel, !IO) :-
% see comment in output_call for why we use `noprof_' etc. here
io__write_string("MR_set_prof_ho_caller_proc(", !IO),
output_label_as_code_addr(CallerLabel, !IO),
io__write_string(");\n\t\t", !IO),
- io__write_string("MR_noprof_tailcall(" ++
- "MR_ENTRY(mercury__do_call_class_method_compact));\n", !IO).
+ io__write_string("MR_np_tailcall(do_call_class_method_compact));\n",
+ !IO).
output_goto(do_not_reached, CallerLabel, !IO) :-
io__write_string("MR_tailcall(MR_ENTRY(MR_do_not_reached),\n\t\t",
!IO),
output_label_as_code_addr(CallerLabel, !IO),
io__write_string(");\n", !IO).
- % Note that we also do some optimization here by
- % outputting `localcall' rather than `call' for
- % calls to local labels, or `call_localret' for
+ % Note that we also do some optimization here by outputting `localcall'
+ % rather than `call' for calls to local labels, or `call_localret' for
% calls which return to local labels (i.e. most of them).
+ %
+ % We also reduce the size of the output by emitting shorthand forms of
+ % the relevant macros when possible, allowing those shorthand macros
+ % to apply mercury__ prefixes and possible MR_ENTRY() wrappers.
:- pred output_call(code_addr::in, code_addr::in, label::in, io::di, io::uo)
is det.
@@ -3351,18 +3401,10 @@
ProfileCall = no,
io__write_string("MR_set_prof_ho_caller_proc(", !IO),
output_label_as_code_addr(CallerLabel, !IO),
- io__write_string(");\n\t", !IO),
- io__write_string("MR_noprof_", !IO)
+ io__write_string(");\n\t", !IO)
;
globals__io_lookup_bool_option(profile_calls, ProfileCall,
- !IO),
- (
- ProfileCall = yes,
- io__write_string("MR_", !IO)
- ;
- ProfileCall = no,
- io__write_string("MR_noprof_", !IO)
- )
+ !IO)
),
(
Target = label(Label),
@@ -3371,22 +3413,107 @@
; Label = local(_, _)
)
->
- io__write_string("localcall(", !IO),
+ (
+ ProfileCall = yes,
+ io__write_string("MR_localcall(", !IO),
output_label(Label, !IO),
io__write_string(",\n\t\t", !IO),
output_code_addr(Continuation, !IO)
;
+ ProfileCall = no,
+ code_addr_to_string_base(Continuation, BaseStr,
+ NeedsPrefix, Wrapper),
+ (
+ NeedsPrefix = no,
+ io__write_string("MR_noprof_localcall(", !IO),
+ output_label(Label, no, !IO),
+ io__write_string(",\n\t\t", !IO),
+ io__write_string(BaseStr, !IO),
+ output_code_addr_from_pieces(BaseStr,
+ NeedsPrefix, Wrapper, !IO)
+ ;
+ NeedsPrefix = yes,
+ Wrapper = entry,
+ io__write_string("MR_np_localcall_ent(", !IO),
+ output_label(Label, no, !IO),
+ io__write_string(",\n\t\t", !IO),
+ io__write_string(BaseStr, !IO)
+ ;
+ NeedsPrefix = yes,
+ Wrapper = label,
+ io__write_string("MR_np_localcall_lab(", !IO),
+ output_label(Label, no, !IO),
+ io__write_string(",\n\t\t", !IO),
+ io__write_string(BaseStr, !IO)
+ ;
+ NeedsPrefix = yes,
+ Wrapper = none,
+ io__write_string("MR_np_localcall(", !IO),
+ output_label(Label, no, !IO),
+ io__write_string(",\n\t\t", !IO),
+ output_code_addr_from_pieces(BaseStr,
+ NeedsPrefix, Wrapper, !IO)
+ )
+ )
+ ;
Continuation = label(ContLabel),
( ContLabel = c_local(_)
; ContLabel = local(_, _)
)
->
- io__write_string("call_localret(", !IO),
+ (
+ ProfileCall = yes,
+ io__write_string("MR_call_localret(", !IO),
output_code_addr(Target, !IO),
io__write_string(",\n\t\t", !IO),
output_label(ContLabel, !IO)
;
- io__write_string("call(", !IO),
+ ProfileCall = no,
+ code_addr_to_string_base(Target, BaseStr,
+ NeedsPrefix, Wrapper),
+ (
+ NeedsPrefix = no,
+ io__write_string("MR_noprof_call_localret(",
+ !IO),
+ output_code_addr_from_pieces(BaseStr,
+ NeedsPrefix, Wrapper, !IO),
+ io__write_string(",\n\t\t", !IO),
+ output_label(ContLabel, !IO)
+ ;
+ NeedsPrefix = yes,
+ Wrapper = entry,
+ io__write_string("MR_np_call_localret_ent(",
+ !IO),
+ io__write_string(BaseStr, !IO),
+ io__write_string(",\n\t\t", !IO),
+ output_label(ContLabel, no, !IO)
+ ;
+ NeedsPrefix = yes,
+ Wrapper = label,
+ % We should never get here; the conditions
+ % that lead here in this switch should have
+ % been caught by the first if-then-else
+ % condition that tests Target.
+ error("output_call: calling label")
+ ;
+ NeedsPrefix = yes,
+ Wrapper = none,
+ io__write_string("MR_np_call_localret(",
+ !IO),
+ output_code_addr_from_pieces(BaseStr,
+ NeedsPrefix, Wrapper, !IO),
+ io__write_string(",\n\t\t", !IO),
+ output_label(ContLabel, no, !IO)
+ )
+ )
+ ;
+ (
+ ProfileCall = yes,
+ io__write_string("MR_call(", !IO)
+ ;
+ ProfileCall = no,
+ io__write_string("MR_noprof_call(", !IO)
+ ),
output_code_addr(Target, !IO),
io__write_string(",\n\t\t", !IO),
output_code_addr(Continuation, !IO)
@@ -3399,37 +3526,91 @@
),
io__write_string(");\n", !IO).
-output_code_addr(label(Label), !IO) :-
- output_label_as_code_addr(Label, !IO).
-output_code_addr(imported(ProcLabel), !IO) :-
+output_code_addr(CodeAddr, !IO) :-
+ code_addr_to_string_base(CodeAddr, BaseStr, NeedsPrefix, Wrapper),
+ output_code_addr_from_pieces(BaseStr, NeedsPrefix, Wrapper, !IO).
+
+:- type wrapper ---> entry ; label ; none.
+
+:- pred output_code_addr_from_pieces(string::in, bool::in, wrapper::in,
+ io::di, io::uo) is det.
+
+output_code_addr_from_pieces(BaseStr, NeedsPrefix, Wrapper, !IO) :-
+ (
+ Wrapper = none,
+ (
+ NeedsPrefix = yes,
+ io__write_string(mercury_label_prefix, !IO)
+ ;
+ NeedsPrefix = no
+ ),
+ io__write_string(BaseStr, !IO)
+ ;
+ Wrapper = entry,
+ (
+ NeedsPrefix = yes,
+ % The _AP version of the macro adds the prefix.
+ io__write_string("MR_ENTRY_AP(", !IO),
+ io__write_string(BaseStr, !IO),
+ io__write_string(")", !IO)
+ ;
+ NeedsPrefix = no,
io__write_string("MR_ENTRY(", !IO),
- output_proc_label(ProcLabel, !IO),
- io__write_string(")", !IO).
-output_code_addr(succip, !IO) :-
- io__write_string("MR_succip", !IO).
-output_code_addr(do_succeed(Last), !IO) :-
+ io__write_string(BaseStr, !IO),
+ io__write_string(")", !IO)
+ )
+ ;
+ Wrapper = label,
+ (
+ NeedsPrefix = yes,
+ % The _AP version of the macro adds the prefix.
+ io__write_string("MR_LABEL_AP(", !IO),
+ io__write_string(BaseStr, !IO),
+ io__write_string(")", !IO)
+ ;
+ NeedsPrefix = no,
+ io__write_string("MR_LABEL(", !IO),
+ io__write_string(BaseStr, !IO),
+ io__write_string(")", !IO)
+ )
+ ).
+
+:- pred code_addr_to_string_base(code_addr::in, string::out,
+ bool::out, wrapper::out) is det.
+
+code_addr_to_string_base(label(Label), BaseStr, yes, Wrapper) :-
+ BaseStr = label_to_c_string(Label, no),
+ IsEntry = label_is_entry(Label),
+ (
+ IsEntry = yes,
+ Wrapper = entry
+ ;
+ IsEntry = no,
+ Wrapper = label
+ ).
+code_addr_to_string_base(imported(ProcLabel), BaseStr, yes, entry) :-
+ BaseStr = proc_label_to_c_string(ProcLabel, no).
+code_addr_to_string_base(succip, "MR_succip", no, none).
+code_addr_to_string_base(do_succeed(Last), BaseStr, no, entry) :-
(
Last = no,
- io__write_string("MR_ENTRY(MR_do_succeed)", !IO)
+ BaseStr = "MR_do_succeed"
;
Last = yes,
- io__write_string("MR_ENTRY(MR_do_last_succeed)", !IO)
+ BaseStr = "MR_do_last_succeed"
).
-output_code_addr(do_redo, !IO) :-
- io__write_string("MR_ENTRY(MR_do_redo)", !IO).
-output_code_addr(do_fail, !IO) :-
- io__write_string("MR_ENTRY(MR_do_fail)", !IO).
-output_code_addr(do_trace_redo_fail_shallow, !IO) :-
- io__write_string("MR_ENTRY(MR_do_trace_redo_fail_shallow)", !IO).
-output_code_addr(do_trace_redo_fail_deep, !IO) :-
- io__write_string("MR_ENTRY(MR_do_trace_redo_fail_deep)", !IO).
-output_code_addr(do_call_closure, !IO) :-
- io__write_string("MR_ENTRY(mercury__do_call_closure_compact)", !IO).
-output_code_addr(do_call_class_method, !IO) :-
- io__write_string("MR_ENTRY(mercury__do_call_class_method_compact)",
- !IO).
-output_code_addr(do_not_reached, !IO) :-
- io__write_string("MR_ENTRY(MR_do_not_reached)", !IO).
+code_addr_to_string_base(do_redo, "MR_do_redo", no, entry).
+code_addr_to_string_base(do_fail, "MR_do_fail", no, entry).
+code_addr_to_string_base(do_trace_redo_fail_shallow, BaseStr, no, entry) :-
+ BaseStr = "MR_do_trace_redo_fail_shallow".
+code_addr_to_string_base(do_trace_redo_fail_deep, BaseStr, no, entry) :-
+ BaseStr = "MR_do_trace_redo_fail_deep".
+code_addr_to_string_base(do_call_closure, BaseStr, no, entry) :-
+ BaseStr = "mercury__do_call_closure_compact".
+code_addr_to_string_base(do_call_class_method, BaseStr, no, entry) :-
+ BaseStr = "mercury__do_call_class_method_compact".
+code_addr_to_string_base(do_not_reached, BaseStr, no, entry) :-
+ BaseStr = "MR_do_not_reached".
% Output a maybe data address, with a `no' meaning NULL.
@@ -3527,29 +3708,36 @@
:- pred output_label_as_code_addr(label::in, io::di, io::uo) is det.
-output_label_as_code_addr(exported(ProcLabel)) -->
- io__write_string("MR_ENTRY("),
- output_label(exported(ProcLabel)),
- io__write_string(")").
-output_label_as_code_addr(local(ProcLabel)) -->
- io__write_string("MR_ENTRY("),
- output_label(local(ProcLabel)),
- io__write_string(")").
-output_label_as_code_addr(c_local(ProcLabel)) -->
- io__write_string("MR_LABEL("),
- output_label(c_local(ProcLabel)),
- io__write_string(")").
-output_label_as_code_addr(local(N, ProcLabel)) -->
- io__write_string("MR_LABEL("),
- output_label(local(N, ProcLabel)),
- io__write_string(")").
+output_label_as_code_addr(Label, !IO) :-
+ label_as_code_addr_to_string(Label, Str),
+ io__write_string(Str, !IO).
+
+:- func label_is_entry(label) = bool.
+
+label_is_entry(exported(_)) = yes.
+label_is_entry(local(_)) = yes.
+label_is_entry(c_local(_)) = no.
+label_is_entry(local(_, _)) = no.
+
+:- pred label_as_code_addr_to_string(label::in, string::out) is det.
+
+label_as_code_addr_to_string(Label, Str) :-
+ LabelStr = llds_out__label_to_c_string(Label, no),
+ IsEntry = label_is_entry(Label),
+ (
+ IsEntry = yes,
+ Str = "MR_ENTRY_AP(" ++ LabelStr ++ ")"
+ ;
+ IsEntry = no,
+ Str = "MR_LABEL_AP(" ++ LabelStr ++ ")"
+ ).
:- pred output_label_list(list(label)::in, io::di, io::uo) is det.
output_label_list([], !IO).
output_label_list([Label | Labels], !IO) :-
- io__write_string("MR_LABEL(", !IO),
- output_label(Label, !IO),
+ io__write_string("MR_LABEL_AP(", !IO),
+ output_label(Label, no, !IO),
io__write_string(")", !IO),
output_label_list_2(Labels, !IO).
@@ -3558,8 +3746,8 @@
output_label_list_2([], !IO).
output_label_list_2([Label | Labels], !IO) :-
io__write_string(" MR_AND\n\t\t", !IO),
- io__write_string("MR_LABEL(", !IO),
- output_label(Label, !IO),
+ io__write_string("MR_LABEL_AP(", !IO),
+ output_label(Label, no, !IO),
io__write_string(")", !IO),
output_label_list_2(Labels, !IO).
@@ -3609,8 +3797,6 @@
LabelStr = llds_out__label_to_c_string(Label, yes),
io__write_string(LabelStr, !IO).
-:- pred output_label(label::in, bool::in, io::di, io::uo) is det.
-
output_label(Label, AddPrefix, !IO) :-
LabelStr = llds_out__label_to_c_string(Label, AddPrefix),
io__write_string(LabelStr, !IO).
@@ -3783,6 +3969,187 @@
io__write_string(")", !IO)
).
+:- pred output_test_rval(rval::in, io::di, io::uo) is det.
+
+output_test_rval(Test, !IO) :-
+ (
+ is_int_cmp(Test, Left, RightConst, OpStr, _)
+ ->
+ io__write_string(OpStr, !IO),
+ io__write_string("(", !IO),
+ output_rval(Left, !IO),
+ io__write_string(",", !IO),
+ io__write_int(RightConst, !IO),
+ io__write_string(")", !IO)
+ ;
+ Test = unop(not, InnerTest),
+ is_int_cmp(InnerTest, Left, RightConst, _, NegOpStr)
+ ->
+ io__write_string(NegOpStr, !IO),
+ io__write_string("(", !IO),
+ output_rval(Left, !IO),
+ io__write_string(",", !IO),
+ io__write_int(RightConst, !IO),
+ io__write_string(")", !IO)
+ ;
+ is_ptag_test(Test, Rval, Ptag, Negated)
+ ->
+ (
+ Negated = no,
+ io__write_string("MR_PTAG_TEST(", !IO)
+ ;
+ Negated = yes,
+ io__write_string("MR_PTAG_TESTR(", !IO)
+ ),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(")", !IO)
+ ;
+ Test = unop(not, InnerTest),
+ is_ptag_test(InnerTest, Rval, Ptag, Negated)
+ ->
+ (
+ Negated = no,
+ io__write_string("MR_PTAG_TESTR(", !IO)
+ ;
+ Negated = yes,
+ io__write_string("MR_PTAG_TEST(", !IO)
+ ),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(")", !IO)
+ ;
+ Test = binop(and, Left, Right),
+ is_ptag_test(Left, Rval, Ptag, no),
+ is_remote_stag_test(Right, Rval, Ptag, Stag)
+ ->
+ io__write_string("MR_RTAGS_TEST(", !IO),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Stag, !IO),
+ io__write_string(")", !IO)
+ ;
+ Test = unop(not, InnerTest),
+ InnerTest = binop(and, Left, Right),
+ is_ptag_test(Left, Rval, Ptag, no),
+ is_remote_stag_test(Right, Rval, Ptag, Stag)
+ ->
+ io__write_string("MR_RTAGS_TESTR(", !IO),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Stag, !IO),
+ io__write_string(")", !IO)
+ ;
+ is_local_stag_test(Test, Rval, Ptag, Stag, Negated)
+ ->
+ (
+ Negated = no,
+ io__write_string("MR_LTAGS_TEST(", !IO)
+ ;
+ Negated = yes,
+ io__write_string("MR_LTAGS_TESTR(", !IO)
+ ),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Stag, !IO),
+ io__write_string(")", !IO)
+ ;
+ Test = unop(not, InnerTest),
+ is_local_stag_test(InnerTest, Rval, Ptag, Stag, Negated)
+ ->
+ (
+ Negated = no,
+ io__write_string("MR_LTAGS_TESTR(", !IO)
+ ;
+ Negated = yes,
+ io__write_string("MR_LTAGS_TEST(", !IO)
+ ),
+ output_rval(Rval, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Ptag, !IO),
+ io__write_string(",", !IO),
+ io__write_int(Stag, !IO),
+ io__write_string(")", !IO)
+ ;
+ output_rval_as_type(Test, bool, !IO)
+ ).
+
+:- pred is_int_cmp(rval::in, rval::out, int::out, string::out, string::out)
+ is semidet.
+
+is_int_cmp(Test, Left, RightConst, OpStr, NegOpStr) :-
+ Test = binop(Op, Left, Right),
+ Right = const(int_const(RightConst)),
+ (
+ Op = eq,
+ OpStr = "MR_INT_EQ",
+ NegOpStr = "MR_INT_NE"
+ ;
+ Op = ne,
+ OpStr = "MR_INT_NE",
+ NegOpStr = "MR_INT_EQ"
+ ;
+ Op = (<),
+ OpStr = "MR_INT_LT",
+ NegOpStr = "MR_INT_GE"
+ ;
+ Op = (>),
+ OpStr = "MR_INT_GT",
+ NegOpStr = "MR_INT_LT"
+ ;
+ Op = (<=),
+ OpStr = "MR_INT_LE",
+ NegOpStr = "MR_INT_GT"
+ ;
+ Op = (>=),
+ OpStr = "MR_INT_GE",
+ NegOpStr = "MR_INT_LT"
+ ).
+
+:- pred is_ptag_test(rval::in, rval::out, int::out, bool::out) is semidet.
+
+is_ptag_test(Test, Rval, Ptag, Negated) :-
+ Test = binop(Op, Left, Right),
+ Left = unop(tag, Rval),
+ Right = unop(mktag, const(int_const(Ptag))),
+ (
+ Op = eq,
+ Negated = no
+ ;
+ Op = ne,
+ Negated = yes
+ ).
+
+:- pred is_remote_stag_test(rval::in, rval::in, int::in, int::out) is semidet.
+
+is_remote_stag_test(Test, Rval, Ptag, Stag) :-
+ Test = binop(eq, Left, Right),
+ Left = lval(field(yes(Ptag), Rval, Zero)),
+ Zero = const(int_const(0)),
+ Right = const(int_const(Stag)).
+
+:- pred is_local_stag_test(rval::in, rval::out, int::out, int::out, bool::out)
+ is semidet.
+
+is_local_stag_test(Test, Rval, Ptag, Stag, Negated) :-
+ Test = binop(Op, Rval, Right),
+ Right = mkword(Ptag, unop(mkbody, const(int_const(Stag)))),
+ (
+ Op = eq,
+ Negated = no
+ ;
+ Op = ne,
+ Negated = yes
+ ).
+
output_rval(const(Const), !IO) :-
output_rval_const(Const, !IO).
output_rval(unop(UnaryOp, Exprn), !IO) :-
@@ -3916,7 +4283,7 @@
% or its variants, to avoid warnings about discarding const.
( Lval = field(MaybeTag, Rval, FieldNumRval) ->
( MaybeTag = yes(Tag) ->
- io__write_string("MR_const_tfield(", !IO),
+ io__write_string("MR_ctfield(", !IO),
io__write_int(Tag, !IO),
io__write_string(", ", !IO)
;
@@ -3940,13 +4307,13 @@
(
MemRef = stackvar_ref(N),
output_llds_type_cast(data_ptr, !IO),
- io__write_string("&MR_stackvar(", !IO),
+ io__write_string("&MR_sv(", !IO),
io__write_int(N, !IO),
io__write_string(")", !IO)
;
MemRef = framevar_ref(N),
output_llds_type_cast(data_ptr, !IO),
- io__write_string("&MR_framevar(", !IO),
+ io__write_string("&MR_fv(", !IO),
io__write_int(N, !IO),
io__write_string(")", !IO)
;
@@ -4044,8 +4411,8 @@
io__write_string(")", !IO)
).
output_rval_const(label_entry(Label), !IO) :-
- io__write_string("MR_ENTRY(", !IO),
- output_label(Label, !IO),
+ io__write_string("MR_ENTRY_AP(", !IO),
+ output_label(Label, no, !IO),
io__write_string(")", !IO).
:- pred output_type_ctor_addr(module_name::in, string::in, int::in,
@@ -4249,11 +4616,11 @@
llds_out__lval_to_string(framevar(N), Description) :-
string__int_to_string(N, N_String),
- string__append("MR_framevar(", N_String, Tmp),
+ string__append("MR_fv(", N_String, Tmp),
string__append(Tmp, ")", Description).
llds_out__lval_to_string(stackvar(N), Description) :-
string__int_to_string(N, N_String),
- string__append("MR_stackvar(", N_String, Tmp),
+ string__append("MR_sv(", N_String, Tmp),
string__append(Tmp, ")", Description).
llds_out__lval_to_string(reg(RegType, RegNum), Description) :-
llds_out__reg_to_string(RegType, RegNum, Reg_String),
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.63
diff -u -b -r1.63 trace.m
--- compiler/trace.m 8 Apr 2004 05:35:10 -0000 1.63
+++ compiler/trace.m 3 May 2004 08:41:58 -0000
@@ -972,10 +972,10 @@
trace__stackref_to_string(Lval, LvalStr) :-
( Lval = stackvar(Slot) ->
string__int_to_string(Slot, SlotString),
- string__append_list(["MR_stackvar(", SlotString, ")"], LvalStr)
+ string__append_list(["MR_sv(", SlotString, ")"], LvalStr)
; Lval = framevar(Slot) ->
string__int_to_string(Slot, SlotString),
- string__append_list(["MR_framevar(", SlotString, ")"], LvalStr)
+ string__append_list(["MR_fv(", SlotString, ")"], LvalStr)
;
error("non-stack lval in stackref_to_string")
).
@@ -1029,7 +1029,8 @@
( CodeModel = model_non ->
RedoLayoutSlot = framevar(4)
;
- error("attempt to access redo layout slot for det or semi procedure")
+ error("attempt to access redo layout slot " ++
+ "for det or semi procedure")
).
%-----------------------------------------------------------------------------%
cvs server: Diffing compiler/notes
cvs server: Diffing debian
cvs server: Diffing deep_profiler
cvs server: Diffing deep_profiler/notes
cvs server: Diffing doc
cvs server: Diffing extras
cvs server: Diffing extras/aditi
cvs server: Diffing extras/cgi
cvs server: Diffing extras/complex_numbers
cvs server: Diffing extras/complex_numbers/samples
cvs server: Diffing extras/complex_numbers/tests
cvs server: Diffing extras/concurrency
cvs server: Diffing extras/curs
cvs server: Diffing extras/curs/samples
cvs server: Diffing extras/curses
cvs server: Diffing extras/curses/sample
cvs server: Diffing extras/dynamic_linking
cvs server: Diffing extras/error
cvs server: Diffing extras/graphics
cvs server: Diffing extras/graphics/mercury_opengl
cvs server: Diffing extras/graphics/mercury_tcltk
cvs server: Diffing extras/graphics/samples
cvs server: Diffing extras/graphics/samples/calc
cvs server: Diffing extras/graphics/samples/maze
cvs server: Diffing extras/graphics/samples/pent
cvs server: Diffing extras/lazy_evaluation
cvs server: Diffing extras/lex
cvs server: Diffing extras/lex/samples
cvs server: Diffing extras/lex/tests
cvs server: Diffing extras/logged_output
cvs server: Diffing extras/moose
cvs server: Diffing extras/moose/samples
cvs server: Diffing extras/moose/tests
cvs server: Diffing extras/morphine
cvs server: Diffing extras/morphine/non-regression-tests
cvs server: Diffing extras/morphine/scripts
cvs server: Diffing extras/morphine/source
cvs server: Diffing extras/odbc
cvs server: Diffing extras/posix
cvs server: Diffing extras/quickcheck
cvs server: Diffing extras/quickcheck/tutes
cvs server: Diffing extras/references
cvs server: Diffing extras/references/samples
cvs server: Diffing extras/references/tests
cvs server: Diffing extras/stream
cvs server: Diffing extras/trailed_update
cvs server: Diffing extras/trailed_update/samples
cvs server: Diffing extras/trailed_update/tests
cvs server: Diffing extras/xml
cvs server: Diffing extras/xml/samples
cvs server: Diffing java
cvs server: Diffing java/runtime
cvs server: Diffing library
cvs server: Diffing profiler
cvs server: Diffing robdd
cvs server: Diffing runtime
cvs server: Diffing runtime/GETOPT
cvs server: Diffing runtime/machdeps
cvs server: Diffing samples
cvs server: Diffing samples/c_interface
cvs server: Diffing samples/c_interface/c_calls_mercury
cvs server: Diffing samples/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/c_interface/mercury_calls_c
cvs server: Diffing samples/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/c_interface/mercury_calls_fortran
cvs server: Diffing samples/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/diff
cvs server: Diffing samples/muz
cvs server: Diffing samples/rot13
cvs server: Diffing samples/solutions
cvs server: Diffing samples/tests
cvs server: Diffing samples/tests/c_interface
cvs server: Diffing samples/tests/c_interface/c_calls_mercury
cvs server: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/tests/c_interface/mercury_calls_c
cvs server: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs server: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/tests/diff
cvs server: Diffing samples/tests/muz
cvs server: Diffing samples/tests/rot13
cvs server: Diffing samples/tests/solutions
cvs server: Diffing samples/tests/toplevel
cvs server: Diffing scripts
cvs server: Diffing tests
cvs server: Diffing tests/benchmarks
cvs server: Diffing tests/debugger
cvs server: Diffing tests/debugger/declarative
cvs server: Diffing tests/dppd
cvs server: Diffing tests/general
cvs server: Diffing tests/general/accumulator
cvs server: Diffing tests/general/string_format
cvs server: Diffing tests/general/structure_reuse
cvs server: Diffing tests/grade_subdirs
cvs server: Diffing tests/hard_coded
cvs server: Diffing tests/hard_coded/exceptions
cvs server: Diffing tests/hard_coded/purity
cvs server: Diffing tests/hard_coded/sub-modules
cvs server: Diffing tests/hard_coded/typeclasses
cvs server: Diffing tests/invalid
cvs server: Diffing tests/invalid/purity
cvs server: Diffing tests/misc_tests
cvs server: Diffing tests/mmc_make
cvs server: Diffing tests/mmc_make/lib
cvs server: Diffing tests/recompilation
cvs server: Diffing tests/tabling
cvs server: Diffing tests/term
cvs server: Diffing tests/valid
cvs server: Diffing tests/warnings
cvs server: Diffing tools
cvs server: Diffing trace
cvs server: Diffing util
cvs server: Diffing vim
cvs server: Diffing vim/after
cvs server: Diffing vim/ftplugin
cvs server: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list