1 /*
2     $Id: addressobj.h 2576 2021-04-14 20:29:14Z soci $
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 #ifndef ADDRESSOBJ_H
20 #define ADDRESSOBJ_H
21 #include "obj.h"
22 #include "values.h"
23 #include "stdbool.h"
24 
25 #define MAX_ADDRESS_MASK 0xffff
26 
27 extern struct Type *const ADDRESS_OBJ;
28 
29 typedef enum Address_types {
30     A_NONE,             /*       */
31     A_IMMEDIATE,        /* #     */
32     A_IMMEDIATE_SIGNED, /* #+    */
33     A_XR,               /* ,x    */
34     A_YR,               /* ,y    */
35     A_ZR,               /* ,z    */
36     A_RR,               /* ,r    */
37     A_SR,               /* ,s    */
38     A_DR,               /* ,d    */
39     A_BR,               /* ,b    */
40     A_KR,               /* ,k    */
41     A_I,                /* )     */
42     A_LI                /* ]     */
43 } Address_types;
44 
45 typedef uint32_t atype_t;
46 typedef struct Address {
47     Obj v;
48     atype_t type;
49     Obj *val;
50 } Address;
51 
52 #define Address(a) ((Address *)(1 ? (a) : (Obj *)(Address *)(a)))
53 
54 extern void addressobj_init(void);
55 extern void addressobj_names(void);
56 
new_address(Obj * val,atype_t type)57 static inline MUST_CHECK Obj *new_address(Obj *val, atype_t type) {
58     Address *v = Address(val_alloc(ADDRESS_OBJ));
59     v->val = val;
60     v->type = type;
61     return Obj(v);
62 }
63 
64 extern MUST_CHECK Obj *int_from_address(Address *, linepos_t);
65 extern MUST_CHECK Obj *float_from_address(Address *, linepos_t);
66 extern MUST_CHECK Obj *bits_from_address(Address *, linepos_t);
67 extern MUST_CHECK Obj *bytes_from_address(Address *, linepos_t);
68 extern bool check_addr(atype_t);
69 extern Address_types register_to_indexing(unsigned int);
70 #endif
71