From 50967cba95f5b729c66f81fc75293571adaa7475 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Wed, 5 Mar 2008 16:54:29 +0000 Subject: [PATCH] Split the common C99/C++ support code out into a separate header. Or, rather, add a new CIF-specific header, so tock_support.h is now the common code and each of the backends has its own. This means some of the conditional stuff can go away. --- Makefile.am | 1 + backends/GenerateC.hs | 2 +- support/tock_support.h | 23 +----------------- support/tock_support_cif.h | 45 +++++++++++++++++++++++++++++++++++ support/tock_support_cppcsp.h | 7 ++---- 5 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 support/tock_support_cif.h diff --git a/Makefile.am b/Makefile.am index aeb9387..a934a9d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -169,6 +169,7 @@ bin_PROGRAMS = tock noinst_PROGRAMS = tocktest GenTagAST GenOrdAST pkginclude_HEADERS = support/tock_support.h +pkginclude_HEADERS += support/tock_support_cif.h pkginclude_HEADERS += support/tock_support_cppcsp.h clean-local: diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 63f7c7a..4eb68f2 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -155,7 +155,7 @@ cgenTLPChannel TLPError = tell ["err"] cgenTopLevel :: A.AST -> CGen () cgenTopLevel s - = do tell ["#include \n"] + = do tell ["#include \n"] cs <- get (tlpName, chans) <- tlpInterface diff --git a/support/tock_support.h b/support/tock_support.h index 506a34f..0843a46 100644 --- a/support/tock_support.h +++ b/support/tock_support.h @@ -1,5 +1,5 @@ /* - * C99 support code for Tock programs + * C99/C++ common support code for Tock programs * Copyright (C) 2007, 2008 University of Kent * * This library is free software; you can redistribute it and/or modify it @@ -27,10 +27,6 @@ #include #include -#ifndef BACKEND_CPPCSP -#include -#endif - //{{{ mostneg/mostpos #define occam_mostneg_bool false #define occam_mostpos_bool true @@ -61,24 +57,7 @@ #endif //}}} -//{{{ channel array initialisation -static inline void tock_init_chan_array (Channel *, Channel **, int) occam_unused; -static inline void tock_init_chan_array (Channel *pointTo, Channel **pointFrom, int count) { - for (int i = 0; i < count; i++) { - pointFrom[i] = &(pointTo[i]); - } -} -//}}} - //{{{ runtime check functions -#ifndef BACKEND_CPPCSP -#define occam_stop(pos, nargs, format, args...) \ - do { \ - ExternalCallN (fprintf, 3 + nargs, stderr, "Program stopped at %s: " format "\n", pos, ##args); \ - SetErr (); \ - } while (0) -#endif - static inline int occam_check_slice (int, int, int, const char *) occam_unused; static inline int occam_check_slice (int start, int count, int limit, const char *pos) { int end = start + count; diff --git a/support/tock_support_cif.h b/support/tock_support_cif.h new file mode 100644 index 0000000..168859a --- /dev/null +++ b/support/tock_support_cif.h @@ -0,0 +1,45 @@ +/* + * CIF support code for Tock programs + * Copyright (C) 2008 University of Kent + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#ifndef TOCK_SUPPORT_CIF_H +#define TOCK_SUPPORT_CIF_H + +#include + +//{{{ occam_stop +#define occam_stop(pos, nargs, format, args...) \ + do { \ + ExternalCallN (fprintf, 3 + nargs, stderr, \ + "Program stopped at %s: " format "\n", \ + pos, ##args); \ + SetErr (); \ + } while (0) +//}}} + +#include + +//{{{ channel array initialisation +static inline void tock_init_chan_array (Channel *, Channel **, int) occam_unused; +static inline void tock_init_chan_array (Channel *pointTo, Channel **pointFrom, int count) { + for (int i = 0; i < count; i++) { + pointFrom[i] = &(pointTo[i]); + } +} +//}}} + +#endif diff --git a/support/tock_support_cppcsp.h b/support/tock_support_cppcsp.h index f408b69..65e2844 100644 --- a/support/tock_support_cppcsp.h +++ b/support/tock_support_cppcsp.h @@ -1,5 +1,5 @@ /* - * C++ support code for Tock programs + * C++CSP support code for Tock programs * Copyright (C) 2007, 2008 University of Kent * * This library is free software; you can redistribute it and/or modify it @@ -37,10 +37,7 @@ public: throw StopException(""); \ } while (0) -#define BACKEND_CPPCSP -#define Channel int - -#include "tock_support.h" +#include #include #include