[m-rev.] for review: fix MSVC LLDS code compilation
Peter Ross
pro at missioncriticalit.com
Mon May 28 14:23:24 AEST 2007
On Mon, May 28, 2007 at 09:32:07AM +1000, Peter Ross wrote:
> Estimated hours taken: 2
> Branches: main
>
> Fixes to make the compiler compile using MSVC in the LLDSgrades.
>
> compiler/llds_out.m:
> MSVC treats declarations such as
> "static const struct s a[];"
> as definitions. As a definition it doesn't know the size
> of the definition, so aborts.
> Thus we now output
> "extern const struct s a[];"
> which both gcc and msvc seem to handle.
>
I changed the code so that we only use extern if the C compiler
is MSVC.
Index: llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.306
diff -u -r1.306 llds_out.m
--- llds_out.m 7 May 2007 05:21:31 -0000 1.306
+++ llds_out.m 28 May 2007 04:00:51 -0000
@@ -303,6 +303,7 @@
gather_c_file_labels(Modules, Labels),
order_layout_datas(LayoutDatas0, LayoutDatas),
+ output_static_linkage_define(!IO),
list.foldl2(output_scalar_common_data_decl, ScalarCommonDatas,
!DeclSet, !IO),
list.foldl2(output_vector_common_data_decl, VectorCommonDatas,
@@ -1137,6 +1138,15 @@
%-----------------------------------------------------------------------------%
+:- pred output_static_linkage_define(io::di, io::uo) is det.
+
+output_static_linkage_define(!IO) :-
+ io.write_string("#ifdef _MSC_VER\n", !IO),
+ io.write_string("#define MR_STATIC_LINKAGE extern\n", !IO),
+ io.write_string("#else", !IO),
+ io.write_string("#define MR_STATIC_LINKAGE static\n", !IO),
+ io.write_string("#endif\n", !IO).
+
:- pred output_common_type_defn(type_num::in, common_cell_type::in,
decl_set::in, decl_set::out, io::di, io::uo) is det.
@@ -1168,7 +1178,7 @@
io.write_string("\n", !IO),
output_common_type_defn(TypeNum, CellType, !DeclSet, !IO),
VarDeclId = decl_scalar_common_array(TypeNum),
- io.write_string("static const struct ", !IO),
+ io.write_string("MR_STATIC_LINKAGE const struct ", !IO),
output_common_cell_type_name(TypeNum, !IO),
io.write_string(" ", !IO),
output_common_scalar_cell_array_name(TypeNum, !IO),
@@ -1185,7 +1195,7 @@
output_common_type_defn(TypeNum, CellType, !DeclSet, !IO),
VarDeclId = decl_data_addr(data_addr(ModuleName,
vector_common_ref(TypeNum, CellNum))),
- io.write_string("static const struct ", !IO),
+ io.write_string("MR_STATIC_LINKAGE const struct ", !IO),
output_common_cell_type_name(TypeNum, !IO),
io.write_string(" ", !IO),
output_common_vector_cell_array_name(TypeNum, CellNum, !IO),
--------------------------------------------------------------------------
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