spot/iface/nips/nips_vm/tools.h
Guillaume Sadegh bc5f13bb4e NIPS VM added to the SPOT distribution.
2008-05-29  Guillaume SADEGH  <sadegh@lrde.epita.fr>

	* iface/nips/nips.cc, iface/nips/nips.hh, iface/nips/common.cc,
	iface/nips/common.hh, iface/nips/Makefile.am: TGBA implementation
	with the NIPS library.
	* iface/nips/emptiness_check.cc: Emptiness check on a Promela
	interface.
	* iface/nips/dottynips.cc: Dot printer on the NIPS interface.
	* iface/nips/compile.sh: Add. Wrapper around nips compiler to
	compile Promela to NIPS bytecode.
	* iface/nips/nips_vm,iface/nips/nips_vm/bytecode.h,
	iface/nips/nips_vm/ChangeLog, iface/nips/nips_vm/COPYING,
	iface/nips/nips_vm/hashtab.c, iface/nips/nips_vm/hashtab.h,
	iface/nips/nips_vm/INSTALL, iface/nips/nips_vm/instr.c,
	iface/nips/nips_vm/instr.h, iface/nips/nips_vm/instr_step.c,
	iface/nips/nips_vm/instr_step.h,
	iface/nips/nips_vm/instr_tools.c,
	iface/nips/nips_vm/instr_tools.h,
	iface/nips/nips_vm/instr_wrap.c,
	iface/nips/nips_vm/instr_wrap.h,
	iface/nips/nips_vm/interactive.c,
	iface/nips/nips_vm/interactive.h, iface/nips/nips_vm/main.c,
	iface/nips/nips_vm/Makefile, iface/nips/nips_vm/Makefile.am,
	iface/nips/nips_vm/nips_asm_help.pl,
	iface/nips/nips_vm/nips_asm_instr.pl,
	iface/nips/nips_vm/nips_asm.pl,
	iface/nips/nips_vm/nips_disasm.pl, iface/nips/nips_vm/nipsvm.c,
	iface/nips/nips_vm/nipsvm.h, iface/nips/nips_vm/README,
	iface/nips/nips_vm/rt_err.c, iface/nips/nips_vm/rt_err.h,
	iface/nips/nips_vm/search.c, iface/nips/nips_vm/search.h,
	iface/nips/nips_vm/split.c, iface/nips/nips_vm/split.h,
	iface/nips/nips_vm/state.c, iface/nips/nips_vm/state.h,
	iface/nips/nips_vm/state_inline.h,
	iface/nips/nips_vm/state_parts.c,
	iface/nips/nips_vm/state_parts.h, iface/nips/nips_vm/timeval.h,
	iface/nips/nips_vm/tools.h: NIPS VM added to the SPOT
	distribution.
	* configure.ac, iface/Makefile.am: Build system updated for the
	NIPS front-end.
2008-05-30 13:22:00 +02:00

60 lines
2.1 KiB
C

/* NIPS VM - New Implementation of Promela Semantics Virtual Machine
* Copyright (C) 2005: Stefan Schuermans <stefan@schuermans.info>
* Michael Weber <michaelw@i2.informatik.rwth-aachen.de>
* Lehrstuhl fuer Informatik II, RWTH Aachen
* Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
*/
#ifndef INC_tools
#define INC_tools
#include <sys/types.h>
#ifdef WIN32
# include <winsock2.h>
#else
# include <sys/socket.h>
# include <netinet/in.h>
#endif
// minimum and maximum
#ifndef min
# define min( a, b ) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
# define max( a, b ) ((a) > (b) ? (a) : (b))
#endif
// number of entries in an array
#define count( array ) (sizeof( (array) ) / sizeof( (array)[0] ))
// packed (and unaligned) structures
#define PACKED __attribute__((packed))
// types to define macros for unaligned reads and writes
typedef struct { uint16_t u16; } PACKED ua_16;
typedef struct { uint32_t u32; } PACKED ua_32;
// unaligned reads
#define ua_rd_16( ptr ) (((ua_16 *)(ptr))->u16)
#define ua_rd_32( ptr ) (((ua_32 *)(ptr))->u32)
// unaligned writes
#define ua_wr_16( ptr, val ) (((ua_16 *)(ptr))->u16 = (uint16_t)(val))
#define ua_wr_32( ptr, val ) (((ua_32 *)(ptr))->u32 = (uint32_t)(val))
// byte order (big endian)
// we steal this code from netinet/in.h
#define h2be_16( x ) ((uint16_t)htons( (uint16_t)(x) ))
#define h2be_32( x ) ((uint32_t)htonl( (uint32_t)(x) ))
#define be2h_16( x ) ((uint16_t)ntohs( (uint16_t)(x) ))
#define be2h_32( x ) ((uint32_t)ntohl( (uint32_t)(x) ))
// byte oder (little endian)
// use big endian macros and swap bytes
// FIXME: there must be a better way
#define byteswap_16( x ) ((uint16_t)x << 8 | (uint16_t)x >> 8)
#define byteswap_32( x ) ((uint32_t)x << 24 | ((uint32_t)x << 8 & 0x00FF0000) | ((uint32_t)x >> 8 & 0x0000FF00) | (uint32_t)x >> 24)
#define h2le_16( x ) (byteswap_16( h2be_16( x ) ))
#define h2le_32( x ) (byteswap_32( h2be_32( x ) ))
#define le2h_16( x ) (be2h_16( byteswap_16( x ) ))
#define le2h_32( x ) (be2h_32( byteswap_32( x ) ))
#endif // #ifndef INC_tools