summaryrefslogtreecommitdiff
path: root/nios2sim-ng.h
blob: 40cb2ddc700b86343de84e3d0ff1a832f15cea34 (plain)
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
/*
 *
 */

#ifndef _NIOS2SIM_NG_H_
#define _NIOS2SIM_NG_H_

#include <stdint.h>
#include <stdbool.h>

#include "bits.h"
#include "compiler.h"
#include "util.h"

extern bool verbose;

#define __round_mask(x, y)	((__typeof__(x))((y) - 1))
#define round_up(x, y)		((((x) - 1) | __round_mask(x, y)) + 1)

#define ARRAY_SIZE(arr)		(sizeof(arr) / sizeof((arr)[0]))

#define err(fmt, args...)	fprintf(stderr, "Error: " fmt, ##args)
#define warn(fmt, args...)	fprintf(stderr, "Warning: " fmt, ##args)
#define info(fmt, args...)	fprintf(stdout, fmt, ##args)
#define vinfo(fmt, args...)	\
	do { if (verbose) fprintf(stdout, fmt, ##args); } while (0)
#ifdef DEBUG
# define dbg(fmt, args...)	fprintf(stdout, fmt, ##args)
# define trace(fmt, args...)	dbg("%s: " fmt, __func__, ##args)
#else
# define dbg(fmt, args...)
# define trace(fmt, args...)
#endif

static inline size_t size_scale(size_t size)
{
	if (size >= 1024 * 1024)
		size /= 1024 * 1024;
	else if (size >= 1024)
		size /= 1024;

	return size;
}

static inline char *size_postfix(size_t size)
{
	char *ret = "";

	if (size >= 1024 * 1024)
		ret = "M";
	else if (size >= 1024)
		ret = "K";

	return ret;
}

#endif /* _NIOS2SIM_NG_H_ */