[m-dev.] for review: --no-const-ground-terms
Peter Ross
Peter.Ross at cs.kuleuven.ac.be
Tue Oct 10 03:30:49 AEDT 2000
Hi,
For Fergus to review, I am not sure if it is trivial to do on the MLDS
backend, so any comments appreciated.
===================================================================
Estimated hours taken: 3
Add the option --const-ground-terms, which determines whether or not
static ground terms are output as `const'. This option will be used to
avoid problem where a static ground term has one of its fields updated
by structure reuse. This causes a segfault as the memory is readonly.
compiler/llds_out.m:
Before outputing a `const' check the value of const_ground_terms.
compiler/options.m:
Add the --const-ground-terms option.
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.157
diff -u -r1.157 llds_out.m
--- compiler/llds_out.m 2000/10/03 00:34:15 1.157
+++ compiler/llds_out.m 2000/10/09 16:12:33
@@ -2090,6 +2090,8 @@
globals__io_lookup_bool_option(unboxed_float, UnboxedFloat),
globals__io_lookup_bool_option(static_ground_terms,
StaticGroundTerms),
+ globals__io_lookup_bool_option(const_ground_terms,
+ ConstGroundTerms),
( { UnboxedFloat = no, StaticGroundTerms = yes } ->
{ llds_out__float_literal_name(FloatVal, FloatName) },
{ FloatLabel = float_label(FloatName) },
@@ -2103,8 +2105,13 @@
FloatString) },
output_indent(FirstIndent, LaterIndent, N0),
{ N is N0 + 1 },
+ { ConstGroundTerms = yes ->
+ ConstStr = "const"
+ ;
+ ConstStr = ""
+ },
io__write_strings([
- "static const MR_Float ",
+ "static ", ConstStr, " MR_Float ",
"mercury_float_const_", FloatName,
" = ", FloatString, ";\n"
])
@@ -2137,6 +2144,8 @@
globals__io_lookup_bool_option(unboxed_float, UnboxFloat),
globals__io_lookup_bool_option(static_ground_terms,
StaticGroundTerms),
+ globals__io_lookup_bool_option(const_ground_terms,
+ ConstGroundTerms),
(
{ UnboxFloat = no, StaticGroundTerms = yes },
{ llds_out__float_const_binop_expr_name(Op, Rval1, Rval2,
@@ -2150,7 +2159,13 @@
{ decl_set_insert(DeclSet2, FloatLabel, DeclSet) },
output_indent(FirstIndent, LaterIndent, N2),
{ N is N2 + 1 },
- io__write_string("static const "),
+ { ConstGroundTerms = yes ->
+ Const = "const "
+ ;
+ Const= " "
+ },
+ io__write_string("static "),
+ io__write_string(Const),
output_llds_type(float),
io__write_string(" mercury_float_const_"),
io__write_string(FloatName),
@@ -2292,6 +2307,9 @@
% to initialize them dynamically, so we must omit `const'
% from the above structure.
%
+ % We also omit the `const' if --no-const-ground-terms is
+ % defined.
+ %
% Also we now conditionally output some parts. The parts that
% are conditionally output are Def, Decl and Init. It is an
% error for Init to be yes and Decl to be no.
@@ -2324,14 +2342,22 @@
),
globals__io_get_globals(Globals),
{ globals__have_static_code_addresses(Globals, StaticCode) },
+ globals__io_lookup_bool_option(const_ground_terms,
+ ConstGroundTerms),
(
% Don't make the structure `const'
% if the structure will eventually include
% code addresses but we don't have static code
- % addresses.
- { StaticCode = no },
- { DeclId = data_addr(DataAddr) },
- { data_addr_would_include_code_address(DataAddr, yes) }
+ % addresses or --no-const-ground-terms
+ % is defined.
+ (
+ { StaticCode = no },
+ { DeclId = data_addr(DataAddr) },
+ { data_addr_would_include_code_address(
+ DataAddr, yes) }
+ ;
+ { ConstGroundTerms = no }
+ )
->
[]
;
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.293
diff -u -r1.293 options.m
--- compiler/options.m 2000/10/03 00:34:22 1.293
+++ compiler/options.m 2000/10/09 16:12:33
@@ -339,6 +339,7 @@
; try_switch_size
; binary_switch_size
; static_ground_terms
+ ; const_ground_terms
; middle_rec
; simple_neg
; follow_vars
@@ -706,6 +707,7 @@
try_switch_size - int(3),
binary_switch_size - int(4),
static_ground_terms - bool(no),
+ const_ground_terms - bool(no),
middle_rec - bool(no),
simple_neg - bool(no),
follow_vars - bool(no),
@@ -1086,6 +1088,7 @@
long_option("try-switch-size", try_switch_size).
long_option("binary-switch-size", binary_switch_size).
long_option("static-ground-terms", static_ground_terms).
+long_option("const-ground-terms", const_ground_terms).
long_option("middle-rec", middle_rec).
long_option("simple-neg", simple_neg).
long_option("follow-vars", follow_vars).
@@ -1346,6 +1349,7 @@
optimize_repeat - int(1),
optimize_peep - bool(yes),
static_ground_terms - bool(yes),
+ const_ground_terms - bool(yes),
smart_indexing - bool(yes),
optimize_jumps - bool(yes),
optimize_labels - bool(yes),
@@ -2294,7 +2298,9 @@
"\tat compile time and storing them as static constants.",
"\tNote that auxiliarity data structures created by the compiler",
"\tfor purposes such as debugging will still be created as",
- "\tstatic constants.",
+ "--no-const-ground-terms",
+ "\tWhen constructing static ground terms don't store them as",
+ "\tconstants.",
"--no-middle-rec",
"\tDisable the middle recursion optimization.",
"--no-simple-neg",
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list