[m-dev.] Diff: Dump entry point labels into bytecode
Bert THOMPSON
aet at cs.mu.oz.au
Thu Jun 5 23:49:58 AEST 1997
Zoltan,
Please review the following diff.
Bert
==================================================
Estimated hours taken: 1
In order to avoid adding code for name mangling into the bytecode interpreter,
we now dump entry point labels in the `call' and `enter_proc' bytecodes.
We need to know the entry point labels to allow calls from bytecode
to compiled code and vice versa:
- When bytecode calls compiled code, dlsym(3) (or a similar
function for accessing shared objects) needs to know
the entry point label.
- When compiled code calls bytecode, a compiled stub,
which corresponds to a bytecode procedure, passes the entry
point label through to the bytecode interpreter, which
then interprets the bytecode procedure.
(This of course glosses over details such as parameter-passing and
re-entrancy, but this is a log message not a spec. 8^)
compiler/bytecode.m:
compiler/bytecode_gen.m:
The call bytecode now has as an argument the entry point label
of the procedure to call.
The enter_proc bytecode now has its own entry point label
as an argument.
The predicate bytecode_gen.proc now has an argument of type
pred_id since code_util.make_proc_label, which creates the
entry point label, requires the pred_id.
CVS: ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS: ' are removed automatically
CVS:
CVS: Modified Files:
CVS: bytecode.m bytecode_gen.m
CVS: ----------------------------------------------------------------------
Index: bytecode.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode.m,v
retrieving revision 1.27
diff -u -r1.27 bytecode.m
--- 1.27 1997/06/05 06:53:58
+++ bytecode.m 1997/06/05 13:02:41
@@ -22,7 +22,7 @@
:- type byte_code ---> enter_pred(byte_pred_id, int,
byte_pred_or_func, int)
; endof_pred
- ; enter_proc(byte_proc_id, determinism,
+ ; enter_proc(string, byte_proc_id, determinism,
int, int, list(byte_var_info))
; endof_proc
; label(byte_label_id)
@@ -55,7 +55,7 @@
list(pair(byte_var, byte_dir)))
; place_arg(reg_type, int, byte_var)
; pickup_arg(reg_type, int, byte_var)
- ; call(byte_module_id, byte_pred_id,
+ ; call(string, byte_module_id, byte_pred_id,
arity, byte_proc_id)
; higher_order_call(byte_var, arity, arity,
determinism)
@@ -199,7 +199,9 @@
output_byte(IsFunc),
output_length(ProcCount).
output_args(endof_pred) --> [].
-output_args(enter_proc(ProcId, Detism, LabelCount, TempCount, Vars)) -->
+output_args(enter_proc(EntryPointLabel, ProcId, Detism, LabelCount,
+ TempCount, Vars)) -->
+ output_string(EntryPointLabel),
output_proc_id(ProcId),
output_determinism(Detism),
output_length(LabelCount),
@@ -278,7 +280,8 @@
output_args(pickup_arg(RegType, RegNum, Var)) -->
output_reg(RegType, RegNum),
output_var(Var).
-output_args(call(ModuleId, PredId, Arity, ProcId)) -->
+output_args(call(EntryPointLabel, ModuleId, PredId, Arity, ProcId)) -->
+ output_string(EntryPointLabel),
output_module_id(ModuleId),
output_pred_id(PredId),
output_length(Arity),
@@ -317,15 +320,16 @@
debug_args(enter_pred(PredId, PredArity, IsFunc, ProcsCount)) -->
debug_pred_id(PredId),
debug_length(PredArity),
- (
- { IsFunc = 0 } ->
+ ( { IsFunc = 0 } ->
debug_string("pred")
- ;
+ ;
debug_string("func")
),
debug_length(ProcsCount).
debug_args(endof_pred) --> [].
-debug_args(enter_proc(ProcId, Detism, LabelCount, TempCount, Vars)) -->
+debug_args(enter_proc(EntryPointLabel, ProcId, Detism, LabelCount,
+ TempCount, Vars)) -->
+ debug_string(EntryPointLabel),
debug_proc_id(ProcId),
debug_determinism(Detism),
debug_length(LabelCount),
@@ -404,7 +408,8 @@
debug_args(pickup_arg(RegType, RegNum, Var)) -->
debug_reg(RegType, RegNum),
debug_var(Var).
-debug_args(call(ModuleId, PredId, Arity, ProcId)) -->
+debug_args(call(EntryPointLabel, ModuleId, PredId, Arity, ProcId)) -->
+ debug_string(EntryPointLabel),
debug_module_id(ModuleId),
debug_pred_id(PredId),
debug_length(Arity),
@@ -848,7 +853,7 @@
byte_code(enter_pred(_, _, _, _), 0).
byte_code(endof_pred, 1).
-byte_code(enter_proc(_, _, _, _, _), 2).
+byte_code(enter_proc(_, _, _, _, _, _), 2).
byte_code(endof_proc, 3).
byte_code(label(_), 4).
byte_code(enter_disjunction(_), 5).
@@ -875,7 +880,7 @@
byte_code(complex_deconstruct(_, _, _), 26).
byte_code(place_arg(_, _, _), 27).
byte_code(pickup_arg(_, _, _), 28).
-byte_code(call(_, _, _, _), 29).
+byte_code(call(_, _, _, _, _), 29).
byte_code(higher_order_call(_, _, _, _), 30).
byte_code(builtin_binop(_, _, _, _), 31).
byte_code(builtin_unop(_, _, _), 32).
@@ -892,7 +897,7 @@
byte_debug(enter_pred(_, _, _, _), "enter_pred").
byte_debug(endof_pred, "endof_pred").
-byte_debug(enter_proc(_, _, _, _, _), "enter_proc").
+byte_debug(enter_proc(_, _, _, _, _, _), "enter_proc").
byte_debug(endof_proc, "endof_proc").
byte_debug(label(_), "label").
byte_debug(enter_disjunction(_), "enter_disjunction").
@@ -919,7 +924,7 @@
byte_debug(complex_deconstruct(_, _, _), "complex_deconstruct").
byte_debug(place_arg(_, _, _), "place_arg").
byte_debug(pickup_arg(_, _, _), "pickup_arg").
-byte_debug(call(_, _, _, _), "call").
+byte_debug(call(_, _, _, _, _), "call").
byte_debug(higher_order_call(_, _, _, _), "higher_order_call").
byte_debug(builtin_binop(_, _, _, _), "builtin_binop").
byte_debug(builtin_unop(_, _, _), "builtin_unop").
Index: bytecode_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.28
diff -u -r1.28 bytecode_gen.m
--- 1.28 1997/06/05 06:54:00
+++ bytecode_gen.m 1997/06/05 13:02:42
@@ -26,7 +26,7 @@
:- import_module hlds_pred, hlds_goal, hlds_data, prog_data, llds, arg_info.
:- import_module passes_aux, call_gen, mode_util, code_util, goal_util.
-:- import_module globals, tree.
+:- import_module globals, tree, llds_out.
:- import_module bool, int, string, list, assoc_list, set, map, varset.
:- import_module std_util, require, term.
@@ -54,13 +54,11 @@
{ list__length(ProcIds, ProcsCount) },
{ pred_info_arity(PredInfo, Arity) },
{ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
- {
- (PredOrFunc = predicate ->
+ { (PredOrFunc = predicate ->
IsFunc = 0
- ;
+ ;
IsFunc = 1
- )
- },
+ ) },
{ EnterCode = node([enter_pred(PredName, Arity, IsFunc,
ProcsCount)]) },
{ EndofCode = node([endof_pred]) },
@@ -76,14 +74,14 @@
bytecode_gen__pred(PredId, [ProcId | ProcIds], PredInfo, ModuleInfo, Code) -->
write_proc_progress_message("% Generating bytecode for ",
PredId, ProcId, ModuleInfo),
- { bytecode_gen__proc(ProcId, PredInfo, ModuleInfo, ProcCode) },
+ { bytecode_gen__proc(ProcId, PredId, PredInfo, ModuleInfo, ProcCode) },
bytecode_gen__pred(PredId, ProcIds, PredInfo, ModuleInfo, ProcsCode),
{ Code = tree(ProcCode, ProcsCode) }.
-:- pred bytecode_gen__proc(proc_id::in, pred_info::in,
+:- pred bytecode_gen__proc(proc_id::in, pred_id::in, pred_info::in,
module_info::in, byte_tree::out) is det.
-bytecode_gen__proc(ProcId, PredInfo, ModuleInfo, Code) :-
+bytecode_gen__proc(ProcId, PredId, PredInfo, ModuleInfo, Code) :-
pred_info_procedures(PredInfo, ProcTable),
map__lookup(ProcTable, ProcId, ProcInfo),
@@ -130,8 +128,10 @@
BodyCode = node(BodyCode0)
),
proc_id_to_int(ProcId, ProcInt),
- EnterCode = node([enter_proc(ProcInt, Detism, LabelCount, TempCount,
- VarInfos)]),
+ code_util__make_proc_label(ModuleInfo, PredId, ProcId, ProcLabel),
+ llds_out__get_proc_label(ProcLabel, EntryPointLabel),
+ EnterCode = node([enter_proc(EntryPointLabel, ProcInt, Detism,
+ LabelCount, TempCount, VarInfos)]),
( CodeModel = model_semi ->
EndofCode = node([semidet_succeed, endof_proc])
;
@@ -317,7 +317,10 @@
predicate_id(ModuleInfo, PredId, ModuleName, PredName, Arity),
proc_id_to_int(ProcId, ProcInt),
- Call = node([call(ModuleName, PredName, Arity, ProcInt)]),
+ code_util__make_proc_label(ModuleInfo, PredId, ProcId, ProcLabel),
+ llds_out__get_proc_label(ProcLabel, EntryPointLabel),
+ Call = node([call(EntryPointLabel, ModuleName, PredName, Arity,
+ ProcInt)]),
determinism_to_code_model(Detism, CodeModel),
( CodeModel = model_semi ->
Check = node([semidet_success_check])
More information about the developers
mailing list