1 /* atom.h - atomic objects from source */
2 /* (c) in 2010-2016 by Volker Barthelmann and Frank Wille */
3 
4 #ifndef ATOM_H
5 #define ATOM_H
6 
7 /* types of atoms */
8 #define LABEL 1
9 #define DATA  2
10 #define INSTRUCTION 3
11 #define SPACE 4
12 #define DATADEF 5
13 #define LINE 6
14 #define OPTS 7
15 #define PRINTTEXT 8
16 #define PRINTEXPR 9
17 #define ROFFS 10
18 #define RORG 11
19 #define RORGEND 12
20 #define ASSERT 13
21 #define NLIST 14
22 
23 /* a machine instruction */
24 typedef struct instruction {
25   int code;
26 #if MAX_QUALIFIERS!=0
27   char *qualifiers[MAX_QUALIFIERS];
28 #endif
29 #if MAX_OPERANDS!=0
30   operand *op[MAX_OPERANDS];
31 #endif
32 #if HAVE_INSTRUCTION_EXTENSION
33   instruction_ext ext;
34 #endif
35 } instruction;
36 
37 typedef struct defblock {
38   size_t bitsize;
39   operand *op;
40 } defblock;
41 
42 struct dblock {
43   size_t size;
44   unsigned char *data;
45   rlist *relocs;
46 };
47 
48 struct sblock {
49   size_t space;
50   expr *space_exp;  /* copied to space, when evaluated as constant */
51   size_t size;
52   uint8_t fill[MAXPADBYTES];
53   expr *fill_exp;   /* copied to fill, when evaluated - may be NULL */
54   rlist *relocs;
55   taddr maxalignbytes;
56 };
57 
58 typedef struct printexpr {
59   expr *print_exp;
60   short type;  /* hex, signed, unsigned */
61   short size;  /* precision in bits */
62 } printexpr;
63 #define PEXP_HEX 0
64 #define PEXP_SDEC 1
65 #define PEXP_UDEC 2
66 #define PEXP_BIN 3
67 #define PEXP_ASC 4
68 
69 typedef struct assertion {
70   expr *assert_exp;
71   char *expstr;
72   char *msgstr;
73 } assertion;
74 
75 typedef struct aoutnlist {
76   char *name;
77   int type;
78   int other;
79   int desc;
80   expr *value;
81 } aoutnlist;
82 
83 /* an atomic element of data */
84 typedef struct atom {
85   struct atom *next;
86   int type;
87   taddr align;
88   size_t lastsize;
89   unsigned changes;
90   source *src;
91   int line;
92   listing *list;
93   union {
94     instruction *inst;
95     dblock *db;
96     symbol *label;
97     sblock *sb;
98     defblock *defb;
99     void *opts;
100     int srcline;
101     char *ptext;
102     printexpr *pexpr;
103     expr *roffs;
104     taddr *rorg;
105     assertion *assert;
106     aoutnlist *nlist;
107   } content;
108 } atom;
109 
110 #define MAXSIZECHANGES 5  /* warning, when atom changed size so many times */
111 
112 instruction *new_inst(char *inst,int len,int op_cnt,char **op,int *op_len);
113 dblock *new_dblock();
114 sblock *new_sblock(expr *,size_t,expr *);
115 
116 void add_atom(section *,atom *);
117 size_t atom_size(atom *,section *,taddr);
118 void print_atom(FILE *,atom *);
119 void atom_printexpr(printexpr *,section *,taddr);
120 atom *clone_atom(atom *);
121 
122 atom *new_inst_atom(instruction *);
123 atom *new_data_atom(dblock *,taddr);
124 atom *new_label_atom(symbol *);
125 atom *new_space_atom(expr *,size_t,expr *);
126 atom *new_datadef_atom(size_t,operand *);
127 atom *new_srcline_atom(int);
128 atom *new_opts_atom(void *);
129 atom *new_text_atom(char *);
130 atom *new_expr_atom(expr *,int,int);
131 atom *new_roffs_atom(expr *);
132 atom *new_rorg_atom(taddr);
133 atom *new_rorgend_atom(void);
134 atom *new_assert_atom(expr *,char *,char *);
135 atom *new_nlist_atom(char *,int,int,int,expr *);
136 
137 #endif
138