ack/util/int/mem.h
George Koehler 36f16b0cb8 Cut down some clang warnings
Edit C code to reduce warnings from clang.  Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().

Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c.  Such changes don't silence warnings; I make
such changes while I silence warnings in the same file.  In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.

Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning.  I wrongly added the `const` in d347207.

For warnings about implicit declarations of functions, the fix is to
declare the function before calling it.  For example, my OpenBSD
system needs <sys/wait.h> to declare wait().

In util/int, add "whatever.h" to declare more functions.  Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-30 18:36:38 -04:00

69 lines
2.1 KiB
C

/*
Memory access facilities
*/
/* $Id$ */
#include "data.h"
#include "stack.h"
/******** Memory address & location defines ********/
#define data_loc(a) (*(data + (p2i(a))))
#define stack_loc(a) (*(stackML - (a)))
#define mem_loc(a) (in_stack(a) ? stack_loc(a) : data_loc(a))
#define loc_addr(o) (((o) < 0) ? (LB + (o)) : (AB + (o)))
/******** Checks on adresses and ranges ********/
#define is_aligned(a,n) ((p2i(a)) % (n) == 0)
#define is_wordaligned(a) \
(((p2i(a)) & wsizem1) == 0)
#define ch_aligned(a,n) { if (!is_aligned(a, min(n, wsize))) \
{ trap(EBADPTR); } }
#define ch_wordaligned(a) \
{ if (!is_wordaligned(a)) \
{ trap(EBADPTR); } }
#define in_gda(p) ((p) < HB)
#define in_stack(p) (SP <= (p) && (p) <= ML)
#define is_in_data(a,n) ((a) + (n) <= HP)
#define ch_in_data(a,n) { if (!is_in_data(a, n)) { trap(EMEMFLT); } }
#define is_in_stack(a,n) (SP <= (a) && (a) + (n) - 1 <= ML)
#define ch_in_stack(a,n) { if (!is_in_stack(a, n)) { trap(EMEMFLT); } }
#define w_is_in_stack(a) (SP <= (a) && (a) + wsizem1 <= ML)
#define ch_w_in_stack(a) { if (!w_is_in_stack(a)) { trap(EMEMFLT); } }
#define is_in_FRA(a,n) ((a) + (n) <= FRASize)
/******* Address-depending memory defines *******/
#define is_in_mem(a,n) (is_in_data(a, n) || is_in_stack(a, n))
#define mem_stn(a,l,n) { if (in_stack(a)) st_stn(a, l, n); else dt_stn(a, l, n); }
#define mem_lddp(a) (in_stack(a) ? st_lddp(a) : dt_lddp(a))
#define mem_ldip(a) (in_stack(a) ? st_ldip(a) : dt_ldip(a))
#define mem_ldu(a,n) (in_stack(a) ? st_ldu(a, n) : dt_ldu(a, n))
#define mem_lduw(a) (in_stack(a) ? st_lduw(a) : dt_lduw(a))
#define mem_lds(a,n) (in_stack(a) ? st_lds(a, n) : dt_lds(a, n))
#define mem_ldsw(a) (in_stack(a) ? st_ldsw(a) : dt_ldsw(a))
#define push_m(a,n) { if (in_stack(a)) push_st(a, n); else push_dt(a, n); }
#define pushw_m(a) { if (in_stack(a)) pushw_st(a); else pushw_dt(a); }
#define pop_m(a,n) { if (in_stack(a)) pop_st(a, n); else pop_dt(a, n); }
#define popw_m(a) { if (in_stack(a)) popw_st(a); else popw_dt(a); }
/******** Simple stack manipulation ********/
#define st_inc(n) newSP(SP - (n)) /* stack grows */
#define st_dec(n) newSP(SP + (n)) /* stack shrinks */