[m-rev.] diff: more shorthand macros
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Apr 14 11:32:31 AEST 2004
Add macros that allow the compiler to generate smaller .c files, especially
but not exclusively with debugging enabled.
runtime/mercury_calls.h:
Add versions of the call macros that supply mercury__ prefixes, and if
relevant, MR_ENTRY and MR_LABEL wrappers as well.
runtime/mercury_misc.h:
Add shorthand macros for the declarations of common cell structures.
runtime/mercury_tags.h:
Add shorthand variants of existing macros. Add shorthand macros for
performing tag tests and other macros that, while general, are mostly
used for tag tests.
runtime/mercury_stack_layout.h:
Add macros that provide references to layout structures without
mercury_data_label_layout_ prefixes in their arguments.
Zoltan.
cvs diff: Diffing .
Index: mercury_calls.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_calls.h,v
retrieving revision 1.10
diff -u -b -r1.10 mercury_calls.h
--- mercury_calls.h 6 Apr 2004 22:29:40 -0000 1.10
+++ mercury_calls.h 10 Apr 2004 15:32:30 -0000
@@ -14,12 +14,10 @@
#include "mercury_debug.h" /* we need to debug them */
#include "mercury_prof.h" /* we need to profile them */
-#define MR_noprof_localcall(label, succ_cont) \
- do { \
- MR_debugcall(MR_LABEL(label), (succ_cont));\
- MR_succip = (succ_cont); \
- MR_GOTO_LABEL(label); \
- } while (0)
+/*
+** The noprof (no profiling) versions of call, call_localret, localcall,
+** tailcall, and localtailcall.
+*/
/*
** On some systems [basically those using PIC (Position Independent MR_Code)],
@@ -72,15 +70,62 @@
MR_noprof_call((proc), MR_LABEL(succ_cont))
#endif
-#define MR_localcall(label, succ_cont, current_label) \
+#define MR_noprof_localcall(label, succ_cont) \
do { \
- MR_debugcall(MR_LABEL(label), (succ_cont)); \
+ MR_debugcall(MR_LABEL(label), (succ_cont));\
MR_succip = (succ_cont); \
- MR_PROFILE(MR_LABEL(label), (current_label)); \
- MR_set_prof_current_proc(MR_LABEL(label)); \
MR_GOTO_LABEL(label); \
} while (0)
+#define MR_noprof_tailcall(proc) \
+ do { \
+ MR_debugtailcall(proc); \
+ MR_GOTO(proc); \
+ } while (0)
+
+#define MR_noprof_localtailcall(label) \
+ do { \
+ MR_debugtailcall(MR_LABEL(label)); \
+ MR_GOTO_LABEL(label); \
+ } while (0)
+
+/*
+** The shorthand versions of the non-profiling versions of
+** call_localret, localcall, tailcall, and localtailcall.
+** To a first approximation, just plain call doesn't occur at all,
+** so it isn't worth a shorthand form.
+*/
+
+#define MR_np_call_localret(proc, succ_cont) \
+ MR_noprof_call_localret(MR_add_prefix(proc), MR_add_prefix(succ_cont))
+
+#define MR_np_call_localret_ent(proc, succ_cont) \
+ MR_noprof_call_localret(MR_ENTRY_AP(proc), MR_add_prefix(succ_cont))
+
+#define MR_np_localcall(label, succ_cont) \
+ MR_noprof_localcall(MR_add_prefix(label), MR_add_prefix(succ_cont))
+
+#define MR_np_localcall_ent(label, succ_cont) \
+ MR_noprof_localcall(MR_add_prefix(label), MR_ENTRY_AP(succ_cont))
+
+#define MR_np_localcall_lab(label, succ_cont) \
+ MR_noprof_localcall(MR_add_prefix(label), MR_LABEL_AP(succ_cont))
+
+#define MR_np_tailcall(proc) \
+ MR_noprof_tailcall(MR_add_prefix(proc))
+
+#define MR_np_tailcall_ent(proc) \
+ MR_noprof_tailcall(MR_ENTRY_AP(proc))
+
+#define MR_np_localtailcall(label) \
+ MR_noprof_localtailcall(MR_add_prefix(label))
+
+/*
+** The plain (possibly profiling, depending on #defines) versions of
+** call, call_localret, localcall, tailcall, and localtailcall.
+** These take an extra argument, the current label.
+*/
+
#define MR_call(proc, succ_cont, current_label) \
do { \
MR_PROFILE((proc), (current_label)); \
@@ -95,33 +140,30 @@
MR_noprof_call_localret(proc, succ_cont);\
} while (0)
-#define MR_localtailcall(label, current_label) \
+#define MR_localcall(label, succ_cont, current_label) \
do { \
- MR_debugtailcall(MR_LABEL(label)); \
MR_PROFILE(MR_LABEL(label), (current_label)); \
MR_set_prof_current_proc(MR_LABEL(label)); \
- MR_GOTO_LABEL(label); \
- } while (0)
-
-#define MR_noprof_localtailcall(label) \
- do { \
- MR_debugtailcall(MR_LABEL(label)); \
- MR_GOTO_LABEL(label); \
+ MR_noprof_localcall(label, succ_cont); \
} while (0)
#define MR_tailcall(proc, current_label) \
do { \
- MR_debugtailcall(proc); \
MR_PROFILE((proc), (current_label)); \
MR_set_prof_current_proc(proc); \
- MR_GOTO(proc); \
+ MR_noprof_tailcall(proc); \
} while (0)
-#define MR_noprof_tailcall(proc) \
+#define MR_localtailcall(label, current_label) \
do { \
- MR_debugtailcall(proc); \
- MR_GOTO(proc); \
+ MR_PROFILE(MR_LABEL(label), (current_label)); \
+ MR_set_prof_current_proc(MR_LABEL(label)); \
+ MR_noprof_localtailcall(label); \
} while (0)
+
+/*
+** The macros for returning from calls from procedures.
+*/
#define MR_proceed() \
do { \
Index: mercury_goto.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.40
diff -u -b -r1.40 mercury_goto.h
--- mercury_goto.h 6 Apr 2004 22:29:40 -0000 1.40
+++ mercury_goto.h 10 Apr 2004 07:59:57 -0000
@@ -887,6 +887,14 @@
#endif /* !defined(MR_USE_GCC_NONLOCAL_GOTOS) */
+#define MR_ENTRY_AP(label) MR_ENTRY(MR_add_prefix(label))
+#define MR_LOCAL_AP(label) MR_LOCAL(MR_add_prefix(label))
+#define MR_LABEL_AP(label) MR_LABEL(MR_add_prefix(label))
+#define MR_GOTO_AP(label) MR_GOTO(MR_add_prefix(label))
+#define MR_GOTO_ENT(label) MR_GOTO_ENTRY(MR_add_prefix(label))
+#define MR_GOTO_LOC(label) MR_GOTO_LOCAL(MR_add_prefix(label))
+#define MR_GOTO_LAB(label) MR_GOTO_LABEL(MR_add_prefix(label))
+
#define MR_decl_user_entry(mod, name, arity, mode) \
MR_declare_entry(MR_proc_entry_user_name(mod, name, arity, mode))
#define MR_decl_uci_entry(mod, name, type, arity, mode) \
Index: mercury_misc.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_misc.h,v
retrieving revision 1.24
diff -u -b -r1.24 mercury_misc.h
--- mercury_misc.h 1 Apr 2004 04:51:06 -0000 1.24
+++ mercury_misc.h 11 Apr 2004 12:36:03 -0000
@@ -48,10 +48,92 @@
** generated C source files.
*/
+#define MR_COMMON_TYPE(typenum) \
+ MR_PASTE2(mercury_type_, typenum)
+
+#define MR_COMMON_NAME(cellnum) \
+ MR_PASTE2(mercury_common_, cellnum)
+
#define MR_COMMON(cellnum) \
- ((MR_Word *) &MR_PASTE2(mercury_common_, cellnum))
+ ((MR_Word *) &MR_COMMON_NAME(cellnum))
#define MR_TAG_COMMON(tag, cellnum) \
(MR_mkword(MR_mktag(tag), MR_COMMON(cellnum)))
+
+#define MR_DEF_COMMON1(typenum,c1) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1);
+#define MR_DEF_COMMON2(typenum,c1,c2) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2);
+#define MR_DEF_COMMON3(typenum,c1,c2,c3) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3);
+#define MR_DEF_COMMON4(typenum,c1,c2,c3,c4) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4);
+#define MR_DEF_COMMON5(typenum,c1,c2,c3,c4,c5) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5);
+#define MR_DEF_COMMON6(typenum,c1,c2,c3,c4,c5,c6) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5), \
+ MR_COMMON_NAME(c6);
+#define MR_DEF_COMMON7(typenum,c1,c2,c3,c4,c5,c6,c7) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5), \
+ MR_COMMON_NAME(c6), \
+ MR_COMMON_NAME(c7);
+#define MR_DEF_COMMON8(typenum,c1,c2,c3,c4,c5,c6,c7,c8) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5), \
+ MR_COMMON_NAME(c6), \
+ MR_COMMON_NAME(c7), \
+ MR_COMMON_NAME(c8);
+#define MR_DEF_COMMON9(typenum,c1,c2,c3,c4,c5,c6,c7,c8,c9) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5), \
+ MR_COMMON_NAME(c6), \
+ MR_COMMON_NAME(c7), \
+ MR_COMMON_NAME(c8), \
+ MR_COMMON_NAME(c9);
+#define MR_DEF_COMMON10(typenum,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10) \
+ static const struct MR_COMMON_TYPE(typenum) \
+ MR_COMMON_NAME(c1), \
+ MR_COMMON_NAME(c2), \
+ MR_COMMON_NAME(c3), \
+ MR_COMMON_NAME(c4), \
+ MR_COMMON_NAME(c5), \
+ MR_COMMON_NAME(c6), \
+ MR_COMMON_NAME(c7), \
+ MR_COMMON_NAME(c8), \
+ MR_COMMON_NAME(c9), \
+ MR_COMMON_NAME(c10);
#endif /* not MERCURY_MISC_H */
Index: mercury_stack_layout.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.77
diff -u -b -r1.77 mercury_stack_layout.h
--- mercury_stack_layout.h 6 Apr 2004 22:29:40 -0000 1.77
+++ mercury_stack_layout.h 10 Apr 2004 20:53:41 -0000
@@ -402,6 +402,9 @@
#define MR_LAYOUT_FROM_LABEL(label) \
MR_PASTE2(mercury_data__label_layout__, label)
+#define MR_LABEL_LAYOUT_REF(label) \
+ ((const MR_Label_Layout *) &MR_LAYOUT_FROM_LABEL(MR_add_prefix(label)))
+
#define MR_MAKE_INTERNAL_LAYOUT_WITH_ENTRY(label, entry) \
MR_Label_Layout_No_Var_Info \
MR_LAYOUT_FROM_LABEL(label) = { \
Index: mercury_tags.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_tags.h,v
retrieving revision 1.20
diff -u -b -r1.20 mercury_tags.h
--- mercury_tags.h 6 Apr 2004 22:29:41 -0000 1.20
+++ mercury_tags.h 11 Apr 2004 12:11:37 -0000
@@ -74,9 +74,11 @@
#define MR_field(t, p, i) ((MR_Word *) MR_body((p), (t)))[i]
#define MR_const_field(t, p, i) ((const MR_Word *) MR_body((p), (t)))[i]
+#define MR_cfield(t, p, i) (MR_const_field(t, p, i))
#define MR_tfield(t, p, i) (MR_field(MR_mktag(t), p, i))
#define MR_const_tfield(t, p, i) (MR_const_field(MR_mktag(t), p, i))
+#define MR_ctfield(t, p, i) (MR_const_tfield(t, p, i))
#define MR_mask_field(p, i) ((MR_Word *) MR_strip_tag(p))[i]
#define MR_const_mask_field(p, i) ((const MR_Word *) MR_strip_tag(p))[i]
@@ -338,5 +340,28 @@
x = MR_CONVERT_C_ENUM_CONSTANT(MR_PASTE2(x, _val)), \
MR_PASTE2(mercury__private_builtin__,x) = x, \
MR_PASTE2(x, _dummy) = MR_PASTE2(x, _val)
+
+#define MR_INT_EQ(rval, val) (((MR_Integer) (rval)) == ((MR_Integer) (val)))
+#define MR_INT_NE(rval, val) (((MR_Integer) (rval)) != ((MR_Integer) (val)))
+#define MR_INT_LT(rval, val) (((MR_Integer) (rval)) < ((MR_Integer) (val)))
+#define MR_INT_LE(rval, val) (((MR_Integer) (rval)) <= ((MR_Integer) (val)))
+#define MR_INT_GT(rval, val) (((MR_Integer) (rval)) > ((MR_Integer) (val)))
+#define MR_INT_GE(rval, val) (((MR_Integer) (rval)) >= ((MR_Integer) (val)))
+
+#define MR_PTAG_TEST(rval, ptag) \
+ (MR_tag(rval) == MR_mktag(ptag))
+#define MR_PTAG_TESTR(rval, ptag) \
+ (!MR_PTAG_TEST((rval), (ptag)))
+
+#define MR_RTAGS_TEST(rval, ptag, stag) \
+ ((MR_tag(rval) == MR_mktag(ptag)) && \
+ (MR_const_tfield((ptag), (rval), 0) == (stag)))
+#define MR_RTAGS_TESTR(rval, ptag, stag) \
+ (!MR_RTAGS_TEST((rval), (ptag), (stag)))
+
+#define MR_LTAGS_TEST(rval, ptag, stag) \
+ (((MR_Integer) (rval)) == ((MR_Integer) (MR_tbmkword(ptag, stag))))
+#define MR_LTAGS_TESTR(rval, ptag, stag) \
+ (!MR_LTAGS_TEST((rval), (ptag), (stag)))
#endif /* not MERCURY_TAGS_H */
cvs diff: Diffing GETOPT
cvs diff: Diffing machdeps
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list