2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @author Sebastian Hack
10 #ifndef LPP_LPP_COMM_H
11 #define LPP_LPP_COMM_H
18 #define LPP_BUFSIZE (1 << 20)
33 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
36 if((err_check_res = (expr)) op cond) { \
37 fprintf(stderr, "%s(%u): %d = %s(%d): ", \
38 __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
40 fprintf(stderr, "\n"); \
45 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
47 int _basic_errno_check_res = (expr); \
48 if(_basic_errno_check_res op cond) { \
49 fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
50 __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
55 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
56 BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
58 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
59 BASIC_ERRNO_CHECK(expr, op, cond, return retval)
61 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
62 BASIC_ERR_CHECK(expr, op, cond, fmt, return)
64 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
65 BASIC_ERRNO_CHECK(expr, op, cond, return)
67 #define ERR_CHECK(expr, op, cond, fmt) \
68 BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
70 #define ERRNO_CHECK(expr, op, cond) \
71 BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
73 typedef struct _lpp_comm_t lpp_comm_t;
75 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
77 int lpp_comm_fileno(const lpp_comm_t *comm);
79 void lpp_flush(lpp_comm_t *comm);
81 void lpp_comm_free(lpp_comm_t *comm);
83 void lpp_print_err(const char *fmt, ...);
85 void lpp_writel(lpp_comm_t *comm, uint32_t x);
87 void lpp_writed(lpp_comm_t *comm, double dbl);
89 void lpp_writes(lpp_comm_t *comm, const char *str);
91 uint32_t lpp_readl(lpp_comm_t *comm);
93 int lpp_read_cmd(lpp_comm_t *comm);
95 double lpp_readd(lpp_comm_t *comm);
97 char *lpp_reads(lpp_comm_t *comm);
99 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
101 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
103 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
105 void lpp_send_ack(lpp_comm_t *comm);
107 const char *lpp_get_cmd_name(int cmd);