lpp: only read solution in gurobi solver if one was found
[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 #ifdef _WIN32
32 #include <BaseTsd.h>
33 typedef SSIZE_T ssize_t;
34 #endif
35
36 #define LPP_PORT    2175
37 #define LPP_BUFSIZE (1 << 20)
38
39 enum {
40         LPP_CMD_BAD,
41         LPP_CMD_OK,
42         LPP_CMD_PROBLEM,
43         LPP_CMD_SOLUTION,
44         LPP_CMD_SOLVER,
45         LPP_CMD_BYE,
46         LPP_CMD_SOLVERS,
47         LPP_CMD_SET_DEBUG,
48         LPP_CMD_INFO,
49         LPP_CMD_LAST
50 };
51
52 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
53 do { \
54   int err_check_res; \
55   if((err_check_res = (expr)) op cond) { \
56     fprintf(stderr, "%s(%u): %d = %s(%d): ", \
57         __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
58     lpp_print_err fmt; \
59     fprintf(stderr, "\n"); \
60     last; \
61   } \
62 } while(0)
63
64 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
65 do { \
66   int _basic_errno_check_res = (expr); \
67   if(_basic_errno_check_res op cond) { \
68     fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
69         __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
70     last; \
71   } \
72 } while(0)
73
74 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
75   BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
76
77 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
78   BASIC_ERRNO_CHECK(expr, op, cond, return retval)
79
80 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
81   BASIC_ERR_CHECK(expr, op, cond, fmt, return)
82
83 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
84   BASIC_ERRNO_CHECK(expr, op, cond, return)
85
86 #define ERR_CHECK(expr, op, cond, fmt) \
87   BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
88
89 #define ERRNO_CHECK(expr, op, cond) \
90   BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
91
92 typedef struct _lpp_comm_t lpp_comm_t;
93
94 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
95
96 int lpp_comm_fileno(const lpp_comm_t *comm);
97
98 ssize_t lpp_flush(lpp_comm_t *comm);
99
100 void lpp_comm_free(lpp_comm_t *comm);
101
102 void lpp_print_err(const char *fmt, ...);
103
104 void lpp_writel(lpp_comm_t *comm, uint32_t x);
105
106 void lpp_writed(lpp_comm_t *comm, double dbl);
107
108 void lpp_writes(lpp_comm_t *comm, const char *str);
109
110 uint32_t lpp_readl(lpp_comm_t *comm);
111
112 int lpp_read_cmd(lpp_comm_t *comm);
113
114 double lpp_readd(lpp_comm_t *comm);
115
116 char *lpp_reads(lpp_comm_t *comm);
117
118 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
119
120 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
121
122 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
123
124 void lpp_send_ack(lpp_comm_t *comm);
125
126 const char *lpp_get_cmd_name(int cmd);
127
128 #endif