for review: bug fix for c_code & intermod opt
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Jan 24 18:14:19 AEDT 1998
Zoltan, when you get back, can you please take a look at this one?
Estimated hours taken: 2
compiler/intermod.m:
Fix a bug introduced in Zoltan's changes to add support
for nondet pragma c_code: when writing out `pragma c_code'
declarations in `.opt' or `.trans_opt' files, take into
account the possibility that the variables may have been
renamed. Use the original names in the pragma c_code
declaration, not the new names, so that the names match
with the names used in the C code fragment.
Index: intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.42
diff -u -u -r1.42 intermod.m
--- intermod.m 1998/01/24 05:44:16 1.42
+++ intermod.m 1998/01/24 06:46:10
@@ -923,7 +923,7 @@
intermod__write_pragmas(SymName, Arity, MarkerList, PredOrFunc),
{ pred_info_clauses_info(PredInfo, ClausesInfo) },
{ ClausesInfo = clauses_info(Varset, _, _VarTypes, HeadVars, Clauses) },
- % handle pragma(c_code, ...) separately
+ % handle pragma c_code(...) separately
( { pred_info_get_goal_type(PredInfo, pragmas) } ->
{ pred_info_procedures(PredInfo, Procs) },
intermod__write_c_code(SymName, PredOrFunc, HeadVars, Varset,
@@ -977,14 +977,15 @@
)),
Goals, [CCodeGoal]) },
{ CCodeGoal = pragma_c_code(MayCallMercury,
- _, _, Vars, _, _, PragmaCode) - _ }
+ _, _, Vars, Names, _, PragmaCode) - _ }
;
{ Goal = pragma_c_code(MayCallMercury,
- _, _, Vars, _, _, PragmaCode) - _ }
+ _, _, Vars, Names, _, PragmaCode) - _ }
)
->
intermod__write_c_clauses(Procs, ProcIds, PredOrFunc,
- PragmaCode, MayCallMercury, Vars, Varset, SymName)
+ PragmaCode, MayCallMercury, Vars, VarSet, Names,
+ SymName)
;
{ error("intermod__write_c_code called with non c_code goal") }
),
@@ -993,42 +994,55 @@
:- pred intermod__write_c_clauses(proc_table::in, list(proc_id)::in,
pred_or_func::in, pragma_c_code_impl::in, may_call_mercury::in,
- list(var)::in, varset::in, sym_name::in,
- io__state::di, io__state::uo) is det.
+ list(var)::in, varset::in, list(maybe(pair(string, mode)))::in,
+ sym_name::in, io__state::di, io__state::uo) is det.
-intermod__write_c_clauses(_, [], _, _, _, _, _, _) --> [].
+intermod__write_c_clauses(_, [], _, _, _, _, _, _, _) --> [].
intermod__write_c_clauses(Procs, [ProcId | ProcIds], PredOrFunc,
- PragmaImpl, MayCallMercury, Vars, Varset, SymName) -->
+ PragmaImpl, MayCallMercury, Vars, Names, Varset0, SymName) -->
{ map__lookup(Procs, ProcId, ProcInfo) },
{ proc_info_maybe_declared_argmodes(ProcInfo, MaybeArgModes) },
( { MaybeArgModes = yes(ArgModes) } ->
- { get_pragma_c_code_vars(Vars, Varset, ArgModes, PragmaVars) },
+ { get_pragma_c_code_vars(Vars, Names, Varset0, ArgModes,
+ Varset, PragmaVars) },
mercury_output_pragma_c_code(MayCallMercury, SymName,
PredOrFunc, PragmaVars, Varset, PragmaImpl),
intermod__write_c_clauses(Procs, ProcIds, PredOrFunc,
- PragmaImpl, MayCallMercury, Vars, Varset, SymName)
+ PragmaImpl, MayCallMercury, Vars, Names, Varset,
+ SymName)
;
{ error("intermod__write_c_clauses: no mode declaration") }
).
-:- pred get_pragma_c_code_vars(list(var)::in, varset::in,
- list(mode)::in, list(pragma_var)::out) is det.
+:- pred get_pragma_c_code_vars(list(var)::in,
+ list(maybe(pair(string, mode)))::in, varset::in, list(mode)::in,
+ varset::out, list(pragma_var)::out) is det.
-get_pragma_c_code_vars(HeadVars, VarNames,
- ArgModes, PragmaVars) :-
+get_pragma_c_code_vars(HeadVars, VarNames, VarSet0, ArgModes,
+ VarSet, PragmaVars) :-
(
HeadVars = [Var | Vars],
+ VarNames = [Maybe_NameAndMode | Names],
ArgModes = [Mode | Modes]
->
- varset__lookup_name(VarNames, Var, Name),
+ (
+ Maybe_NameAndMode = no,
+ Name = "_"
+ ;
+ Maybe_Name = yes(Name - _Mode2)
+ ),
PragmaVar = pragma_var(Var, Name, Mode),
- get_pragma_c_code_vars(Vars, VarNames, Modes, PragmaVars1),
+ varset__name_var(VarSet0, Var, Name, VarSet1),
+ get_pragma_c_code_vars(Vars, Names, VarSet1, Modes,
+ VarSet, PragmaVars1),
PragmaVars = [PragmaVar | PragmaVars1]
;
HeadVars = [],
+ VarNames = [],
ArgModes = []
->
- PragmaVars = []
+ PragmaVars = [],
+ VarSet = VarSet0
;
error("intermod:get_pragma_c_code_vars")
).
cvs diff: Diffing notes
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list