-
Notifications
You must be signed in to change notification settings - Fork 46
/
util.h
79 lines (62 loc) · 1.68 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef UTIL_H
#define UTIL_H
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#define DEBUG 0
#define INFO 0
#define WARN 0
#define TRACE 0
//#define DEBUG 1
//#define INFO 1
//#define WARN 1
//#define TRACE 1
#define FATAL(...) { \
fprintf(stderr, "Error(%s:%d): ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); exit(1); \
}
#define ASSERT(exp, ...) { \
if (! (exp)) { \
fprintf(stderr, "Assert Failed (%s:%d): ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); exit(1); \
} \
}
#if TRACE
#define trace(...) fprintf(stderr, __VA_ARGS__);
#else
#define trace(...) ;
#endif
#if DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__);
#else
#define debug(...) ;
#endif
#if INFO
#define info(...) fprintf(stderr, __VA_ARGS__);
#else
#define info(...) ;
#endif
#if WARN
#define warn(...) fprintf(stderr, __VA_ARGS__);
#else
#define warn(...) ;
#endif
#define log(...) fprintf(stderr, __VA_ARGS__);
#define error(...) fprintf(stderr, __VA_ARGS__);
uint64_t read_LEB(uint8_t *bytes, uint32_t *pos, uint32_t maxbits);
uint64_t read_LEB_signed(uint8_t *bytes, uint32_t *pos, uint32_t maxbits);
uint32_t read_uint32(uint8_t *bytes, uint32_t *pos);
char *read_string(uint8_t *bytes, uint32_t *pos, uint32_t *result_len);
// Math
void sext_8_32(uint32_t *val);
void sext_16_32(uint32_t *val);
void sext_8_64(uint64_t *val);
void sext_16_64(uint64_t *val);
void sext_32_64(uint64_t *val);
uint32_t rotl32 (uint32_t n, unsigned int c);
uint32_t rotr32 (uint32_t n, unsigned int c);
uint64_t rotl64(uint64_t n, unsigned int c);
uint64_t rotr64(uint64_t n, unsigned int c);
double wa_fmax(double a, double b);
double wa_fmin(double a, double b);
#endif // of UTIL_H