verify: Clarify assertion message.
[libfirm] / ir / lpp / lpp_comm.h
1 /*
2  * Copyright (C) 2005-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @author  Sebastian Hack
23  */
24 #ifndef LPP_LPP_COMM_H
25 #define LPP_LPP_COMM_H
26
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <stdint.h>
30
31 #define LPP_PORT    2175
32 #define LPP_BUFSIZE (1 << 20)
33
34 enum {
35         LPP_CMD_BAD,
36         LPP_CMD_OK,
37         LPP_CMD_PROBLEM,
38         LPP_CMD_SOLUTION,
39         LPP_CMD_SOLVER,
40         LPP_CMD_BYE,
41         LPP_CMD_SOLVERS,
42         LPP_CMD_SET_DEBUG,
43         LPP_CMD_INFO,
44         LPP_CMD_LAST
45 };
46
47 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
48 do { \
49   int err_check_res; \
50   if((err_check_res = (expr)) op cond) { \
51     fprintf(stderr, "%s(%u): %d = %s(%d): ", \
52         __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
53     lpp_print_err fmt; \
54     fprintf(stderr, "\n"); \
55     last; \
56   } \
57 } while(0)
58
59 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
60 do { \
61   int _basic_errno_check_res = (expr); \
62   if(_basic_errno_check_res op cond) { \
63     fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
64         __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
65     last; \
66   } \
67 } while(0)
68
69 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
70   BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
71
72 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
73   BASIC_ERRNO_CHECK(expr, op, cond, return retval)
74
75 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
76   BASIC_ERR_CHECK(expr, op, cond, fmt, return)
77
78 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
79   BASIC_ERRNO_CHECK(expr, op, cond, return)
80
81 #define ERR_CHECK(expr, op, cond, fmt) \
82   BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
83
84 #define ERRNO_CHECK(expr, op, cond) \
85   BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
86
87 typedef struct _lpp_comm_t lpp_comm_t;
88
89 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
90
91 int lpp_comm_fileno(const lpp_comm_t *comm);
92
93 void lpp_flush(lpp_comm_t *comm);
94
95 void lpp_comm_free(lpp_comm_t *comm);
96
97 void lpp_print_err(const char *fmt, ...);
98
99 void lpp_writel(lpp_comm_t *comm, uint32_t x);
100
101 void lpp_writed(lpp_comm_t *comm, double dbl);
102
103 void lpp_writes(lpp_comm_t *comm, const char *str);
104
105 uint32_t lpp_readl(lpp_comm_t *comm);
106
107 int lpp_read_cmd(lpp_comm_t *comm);
108
109 double lpp_readd(lpp_comm_t *comm);
110
111 char *lpp_reads(lpp_comm_t *comm);
112
113 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
114
115 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
116
117 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
118
119 void lpp_send_ack(lpp_comm_t *comm);
120
121 const char *lpp_get_cmd_name(int cmd);
122
123 #endif