[m-rev.] diff: remove old C interface stuff

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jun 16 03:28:09 AEST 2011


Branches: main

Remove bits and pieces related to the old C interface.

compiler/ml_foreign_proc_gen.m:
 	Delete a dead proccedure.

compiler/term_errors.m:
 	Update and fix an error message.

compiler/mlds.m:
compiler/mlds_to_gcc.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
 	Remove reference to old C interface pragmas in comments.

Julien.

Index: compiler/ml_foreign_proc_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_foreign_proc_gen.m,v
retrieving revision 1.9
diff -u -r1.9 ml_foreign_proc_gen.m
--- compiler/ml_foreign_proc_gen.m	23 May 2011 05:08:06 -0000	1.9
+++ compiler/ml_foreign_proc_gen.m	15 Jun 2011 16:47:50 -0000
@@ -21,21 +21,11 @@
  :- import_module parse_tree.prog_data.

  :- import_module list.
-:- import_module maybe.

  :- pred ml_gen_trace_runtime_cond(trace_expr(trace_runtime)::in,
      prog_context::in, list(mlds_defn)::out, list(statement)::out,
      ml_gen_info::in, ml_gen_info::out) is det.

-:- pred ml_gen_nondet_pragma_foreign_proc(code_model::in,
-    pragma_foreign_proc_attributes::in,
-    pred_id::in, proc_id::in, list(foreign_arg)::in,
-    prog_context::in, string::in, maybe(prog_context)::in, string::in,
-    maybe(prog_context)::in, string::in, maybe(prog_context)::in,
-    string::in, maybe(prog_context)::in,
-    list(mlds_defn)::out, list(statement)::out,
-    ml_gen_info::in, ml_gen_info::out) is det.
-
  :- pred ml_gen_ordinary_pragma_foreign_proc(code_model::in,
      pragma_foreign_proc_attributes::in, pred_id::in, proc_id::in,
      list(foreign_arg)::in, list(foreign_arg)::in, string::in,
@@ -61,6 +51,7 @@

  :- import_module bool.
  :- import_module map.
+:- import_module maybe.
  :- import_module pair.
  :- import_module require.
  :- import_module string.
@@ -106,193 +97,6 @@
          CondRval = ml_binop(Op, RvalA, RvalB)
      ).

-    % For model_non pragma c_code,
-    % we generate code of the following form:
-    %
-    %   #define MR_ALLOC_ID <allocation id>
-    %   #define MR_PROC_LABEL <procedure name>
-    %   <declaration of locals needed for boxing/unboxing>
-    %   {
-    %       <declaration of one local variable for each arg>
-    %       struct {
-    %           <user's local_vars decls>
-    %       } MR_locals;
-    %       MR_bool MR_done = MR_FALSE;
-    %       MR_bool MR_succeeded = MR_FALSE;
-    %
-    %       #define FAIL            (MR_done = MR_TRUE)
-    %       #define SUCCEED         (MR_succeeded = MR_TRUE)
-    %       #define SUCCEED_LAST    (MR_succeeded = MR_TRUE, \
-    %                                   MR_done = MR_TRUE)
-    %       #define LOCALS          (&MR_locals)
-    %
-    %       <assign input args>
-    %       <obtain global lock>
-    %       <user's first_code C code>
-    %       while (true) {
-    %           <user's shared_code C code>
-    %           <release global lock>
-    %           if (MR_succeeded) {
-    %               <assign output args>
-    %               <boxing/unboxing of outputs>
-    %               CONT();
-    %           }
-    %           if (MR_done) break;
-    %           MR_succeeded = MR_FALSE;
-    %           <obtain global lock>
-    %           <user's later_code C code>
-    %       }
-    %
-    %       #undef FAIL
-    %       #undef SUCCEED
-    %       #undef SUCCEED_LAST
-    %       #undef LOCALS
-    %   }
-    %   #undef MR_ALLOC_ID
-    %   #undef MR_PROC_LABEL
-    %
-    % We insert a #define MR_ALLOC_ID so that the C code in the Mercury
-    % standard library that allocates memory manually can use MR_ALLOC_ID as an
-    % argument to incr_hp_msg(), for memory profiling.  It replaces an older
-    % macro MR_PROC_LABEL, which is retained only for backwards compatibility.
-    %
-ml_gen_nondet_pragma_foreign_proc(CodeModel, Attributes, PredId, _ProcId,
-        Args, Context, LocalVarsDecls, LocalVarsContext,
-        FirstCode, FirstContext, LaterCode, LaterContext,
-        SharedCode, SharedContext, Decls, Statements, !Info) :-
-    Lang = get_foreign_language(Attributes),
-    ( Lang = lang_csharp ->
-        sorry($module, $pred, "nondet pragma foreign_proc for C#")
-    ;
-        true
-    ),
-
-    % Generate <declaration of one local variable for each arg>
-    ml_gen_pragma_c_decls(!.Info, Lang, Args, ArgDeclsList),
-
-    % Generate definitions of the FAIL, SUCCEED, SUCCEED_LAST,
-    % and LOCALS macros.
-
-    string.append_list([
-"   #define FAIL        (MR_done = MR_TRUE)\n",
-"   #define SUCCEED     (MR_succeeded = MR_TRUE)\n",
-"   #define SUCCEED_LAST    (MR_succeeded = MR_TRUE, MR_done = MR_TRUE)\n",
-"   #define LOCALS      (&MR_locals)\n"
-        ], HashDefines),
-    string.append_list([
-            "   #undef  FAIL\n",
-            "   #undef  SUCCEED\n",
-            "   #undef  SUCCEED_LAST\n",
-            "   #undef  LOCALS\n"
-        ], HashUndefs),
-
-    % Generate code to set the values of the input variables.
-    ml_gen_pragma_ccsj_input_arg_list(Lang, Args, AssignInputsList, !Info),
-
-    % Generate code to assign the values of the output variables.
-    ml_gen_pragma_c_output_arg_list(Args, Context,
-        AssignOutputsList, ConvDecls, ConvStatements, !Info),
-
-    % Generate code fragments to obtain and release the global lock.
-    ThreadSafe = get_thread_safe(Attributes),
-    ml_gen_obtain_release_global_lock(!.Info, ThreadSafe, PredId,
-        ObtainLock, ReleaseLock),
-
-    % Generate the MR_ALLOC_ID #define.
-    ml_gen_hash_define_mr_alloc_id([FirstCode, SharedCode], Context,
-        HashDefineAllocId, HashUndefAllocId, !Info),
-
-    % Generate the MR_PROC_LABEL #define.
-    ml_gen_hash_define_mr_proc_label(!.Info, HashDefineProcLabel),
-
-    % Put it all together.
-    Starting_C_Code = list.condense([
-        [raw_target_code("{\n", [])],
-        HashDefineAllocId,
-        HashDefineProcLabel,
-        ArgDeclsList,
-        [raw_target_code("\tstruct {\n", []),
-        user_target_code(LocalVarsDecls, LocalVarsContext, []),
-        raw_target_code("\n", []),
-        raw_target_code("\t} MR_locals;\n", []),
-        raw_target_code("\tMR_bool MR_succeeded = MR_FALSE;\n", []),
-        raw_target_code("\tMR_bool MR_done = MR_FALSE;\n", []),
-        raw_target_code("\n", []),
-        raw_target_code(HashDefines, []),
-        raw_target_code("\n", [])],
-        AssignInputsList,
-        [raw_target_code(ObtainLock, []),
-        raw_target_code("\t{\n", []),
-        user_target_code(FirstCode, FirstContext, []),
-        raw_target_code("\n\t;}\n", []),
-        raw_target_code("\twhile (1) {\n", []),
-        raw_target_code("\t\t{\n", []),
-        user_target_code(SharedCode, SharedContext, []),
-        raw_target_code("\n\t\t;}\n", [])],
-        HashUndefAllocId,
-        [raw_target_code("#undef MR_PROC_LABEL\n", []),
-        raw_target_code(ReleaseLock, []),
-        raw_target_code("\t\tif (MR_succeeded) {\n", [])],
-        AssignOutputsList
-    ]),
-    ml_gen_info_get_module_info(!.Info, ModuleInfo),
-    module_info_get_globals(ModuleInfo, Globals),
-    globals.get_target(Globals, Target),
-    (
-        CodeModel = model_non,
-
-        (
-            Target = target_il,
-            % For IL code, we can't call continutations because there is no
-            % syntax for calling managed function pointers in C#. Instead,
-            % we have to call back into IL and make the continuation call
-            % in IL. This is called an "indirect" success continuation call.
-            ml_gen_call_current_success_cont_indirectly(Context, CallCont,
-                !Info)
-        ;
-            ( Target = target_c
-            ; Target = target_java
-            ; Target = target_csharp
-            ; Target = target_asm
-            ),
-            ml_gen_call_current_success_cont(Context, CallCont, !Info)
-        ;
-            Target = target_x86_64,
-            unexpected($module, $pred, "target x86_64 with --high-level-code")
-        ;
-            Target = target_erlang,
-            unexpected($module, $pred, "target erlang")
-        )
-    ;
-        ( CodeModel = model_det
-        ; CodeModel = model_semi
-        ),
-        unexpected($module, $pred, "unexpected code model")
-    ),
-    Ending_C_Code = [
-        raw_target_code("\t\t}\n", []),
-        raw_target_code("\t\tif (MR_done) break;\n", []),
-        raw_target_code("\tMR_succeeded = MR_FALSE;\n", []),
-        raw_target_code(ObtainLock, []),
-        raw_target_code("\t\t{\n", []),
-        user_target_code(LaterCode, LaterContext, []),
-        raw_target_code("\n\t\t;}\n", []),
-        raw_target_code("\t}\n", []),
-        raw_target_code("\n", []),
-        raw_target_code(HashUndefs, []),
-        raw_target_code("}\n", [])
-    ],
-    Starting_C_Code_Stmt = inline_target_code(ml_target_c, Starting_C_Code),
-    Starting_C_Code_Statement = statement(
-        ml_stmt_atomic(Starting_C_Code_Stmt), mlds_make_context(Context)),
-    Ending_C_Code_Stmt = inline_target_code(ml_target_c, Ending_C_Code),
-    Ending_C_Code_Statement = statement(
-        ml_stmt_atomic(Ending_C_Code_Stmt), mlds_make_context(Context)),
-    Statements =
-        [Starting_C_Code_Statement | ConvStatements] ++
-        [CallCont, Ending_C_Code_Statement],
-    Decls = ConvDecls.
-
  ml_gen_ordinary_pragma_foreign_proc(CodeModel, Attributes, PredId, ProcId,
          Args, ExtraArgs, Foreign_Code, Context, Decls, Statements, !Info) :-
      Lang = get_foreign_language(Attributes),
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.190
diff -u -r1.190 mlds.m
--- compiler/mlds.m	23 May 2011 05:08:07 -0000	1.190
+++ compiler/mlds.m	15 Jun 2011 16:50:56 -0000
@@ -364,7 +364,7 @@
                  mlds_name               :: mercury_module_name,

                  % Code defined in some other language, e.g.  for
-                % `pragma c_header_code', etc.
+                % `pragma foreign-decl', etc.
                  mlds_foreign_code_map   :: map(foreign_language,
                                              mlds_foreign_code),

Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.159
diff -u -r1.159 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	23 May 2011 05:08:07 -0000	1.159
+++ compiler/mlds_to_gcc.m	15 Jun 2011 16:53:18 -0000
@@ -15,18 +15,17 @@
  % without going via an external file.
  %
  % Code using the C interface, however, does get compiled to C; this module
-% invokes mlds_to_c.m to do that.  We split off all the parts of the MLDS
-% for `c_code'/`foreign_code' declarations, `c_header_code'/`foreign_decl'
-% declarations, `export' declarations, and procedures defined with
-% `c_code'/`foreign_proc', and pass them to mlds_to_c.m.  That will generate
-% a `<module>.c' file for this module; mercury_compile.m will invoke the C
-% compiler to compile that to `<module>__c_code.o'.  The remainding parts
-% of the MLDS, which don't contain any foreign code, we handle normally,
-% converting them to GCC trees and passing them to the GCC back-end
-% to generate an assembler file.  Calls to procedures defined using
-% `c_code'/`foreign_proc' will end up calling the functions defined in
-% `<module>__c_code.o'.  This works because the calling convention that
-% is used for the MLDS->C back-end is the same as (i.e. binary compatible
+% invokes mlds_to_c.m to do that.  We split off all the parts of the MLDS for
+% `foreign_code' declarations, `foreign_decl' declarations, `foreign_export'
+% declarations, and procedures defined with `foreign_proc', and pass them to
+% mlds_to_c.m.  That will generate a `<module>.c' file for this module;
+% mercury_compile.m will invoke the C compiler to compile that to
+% `<module>__c_code.o'.  The remainding parts of the MLDS, which don't contain
+% any foreign code, we handle normally, converting them to GCC trees and
+% passing them to the GCC back-end to generate an assembler file.  Calls to
+% procedures defined using `foreign_proc' will end up calling the functions
+% defined in `<module>__c_code.o'.  This works because the calling convention
+% that is used for the MLDS->C back-end is the same as (i.e. binary compatible
  % with) the calling convention that we use here in the MLDS->GCC back-end.
  %
  % Currently this back-end supports grade hlc.gc only.
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.467
diff -u -r1.467 modules.m
--- compiler/modules.m	6 May 2011 05:03:22 -0000	1.467
+++ compiler/modules.m	15 Jun 2011 16:51:57 -0000
@@ -1564,9 +1564,6 @@
      % interface, but all other pragma declarations are implementation details
      % only, and should go in the implementation.

-    % XXX we should allow c_header_code;
-    % but if we do allow it, we should put it in the generated
-    % header file, which currently we don't.
      (
          ( Pragma = pragma_foreign_code(_, _)
          ; Pragma = pragma_foreign_decl(_, _, _)
Index: compiler/prog_io_pragma.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.147
diff -u -r1.147 prog_io_pragma.m
--- compiler/prog_io_pragma.m	23 May 2011 05:08:10 -0000	1.147
+++ compiler/prog_io_pragma.m	15 Jun 2011 16:51:26 -0000
@@ -1484,7 +1484,7 @@
      Constant = "stable",
      Assertion = foreign_type_stable.

-    % This predicate parses both c_header_code and foreign_decl pragmas.
+    % This predicate parses foreign_decl pragmas.
      %
  :- pred parse_pragma_foreign_decl_pragma(module_name::in, string::in,
      list(term)::in, term::in, varset::in, prog_context::in, int::in,
Index: compiler/term_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/term_errors.m,v
retrieving revision 1.45
diff -u -r1.45 term_errors.m
--- compiler/term_errors.m	23 May 2011 05:08:13 -0000	1.45
+++ compiler/term_errors.m	15 Jun 2011 16:50:01 -0000
@@ -348,9 +348,7 @@
      Pieces = [
          words("It depends on the properties of"),
          words("foreign language code included via a"),
-        fixed("`:- pragma c_code'"),
-        words("or"),
-        fixed("`:- pragma foreign'"),
+        fixed("`:- pragma foreign_proc'"),
          words("declaration.")
      ].


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list