1 /* libgputils typedefs
2    Copyright (C) 2001, 2002, 2003, 2004, 2005
3    Craig Franklin
4 
5     Copyright (C) 2016 Molnar Karoly
6 
7 This file is part of gputils.
8 
9 gputils is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13 
14 gputils is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with gputils; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.  */
23 
24 #ifndef __GPTYPES_H__
25 #define __GPTYPES_H__
26 
27 #include "stdhdr.h"
28 
29 typedef enum {
30   false = (0 == 1),
31   true  = (0 == 0)
32 } gp_boolean;
33 
34 typedef long    gp_symvalue_t;
35 
36 typedef int     gpasmVal;               /* The type that internal arithmetic uses. */
37 
38 typedef struct __attribute__ ((packed))
39 {
40   union __attribute__ ((packed))
41   {
42     uint32_t u32[2];
43     uint64_t u64;
44   } low;
45 
46   union __attribute__ ((packed))
47   {
48     uint32_t u32[2];
49     uint64_t u64;
50   } high;
51 } hash128_t;
52 
53 #define BYTE_SIZE               (sizeof(uint8_t))
54 #define WORD_SIZE               (sizeof(uint16_t))
55 #define DWORD_SIZE              (sizeof(uint32_t))
56 #define QWORD_SIZE              (sizeof(uint64_t))
57 
58 /*------------------------------------------------------------------------------------------------*/
59 
60 /* Parse node: created by the parser, interpreted by the 'backend' */
61 
62 typedef struct pnode {
63   enum pnode_tag {
64     PTAG_CONSTANT = 0,
65     PTAG_SYMBOL,
66     PTAG_STRING,
67     PTAG_OFFSET,
68     PTAG_LIST,
69     PTAG_BINOP,
70     PTAG_UNOP
71   } tag;
72 
73   union {
74     int             constant;
75     const char     *symbol;
76     char           *string;
77 
78     struct pnode   *offset;
79 
80     struct {
81       struct pnode *head;
82       struct pnode *tail;
83     } list;
84 
85     struct {
86       int           op;
87       struct pnode *p0;
88       struct pnode *p1;
89     } binop;
90 
91     struct {
92       int           op;
93       struct pnode *p0;
94     } unop;
95   } value;
96 } pnode_t;
97 
98 #define PnIsConstant(Node)              (Node)->tag == PTAG_CONSTANT
99 #define PnIsSymbol(Node)                (Node)->tag == PTAG_SYMBOL
100 #define PnIsString(Node)                (Node)->tag == PTAG_STRING
101 #define PnIsOffset(Node)                (Node)->tag == PTAG_OFFSET
102 #define PnIsList(Node)                  (Node)->tag == PTAG_LIST
103 #define PnIsBinOp(Node)                 (Node)->tag == PTAG_BINOP
104 #define PnIsUnOp(Node)                  (Node)->tag == PTAG_UNOP
105 
106 #define PnConstant(Node)                (Node)->value.constant
107 #define PnSymbol(Node)                  (Node)->value.symbol
108 #define PnString(Node)                  (Node)->value.string
109 #define PnOffset(Node)                  (Node)->value.offset
110 #define PnListHead(Node)                (Node)->value.list.head
111 #define PnListTail(Node)                (Node)->value.list.tail
112 #define PnBinOpOp(Node)                 (Node)->value.binop.op
113 #define PnBinOpP0(Node)                 (Node)->value.binop.p0
114 #define PnBinOpP1(Node)                 (Node)->value.binop.p1
115 #define PnUnOpOp(Node)                  (Node)->value.unop.op
116 #define PnUnOpP0(Node)                  (Node)->value.unop.p0
117 
118 #endif
119