2 * $Id: astnode.h,v 1.14 2007/08/12 18:59:10 khansen Exp $
4 * Revision 1.14 2007/08/12 18:59:10 khansen
5 * ability to generate pure 6502 binary
7 * Revision 1.13 2007/08/09 22:06:00 khansen
8 * general-purpose flags
10 * Revision 1.12 2007/08/07 21:12:16 khansen
13 * Revision 1.11 2007/07/22 13:35:20 khansen
14 * convert tabs to whitespaces
16 * Revision 1.10 2004/12/29 21:44:23 kenth
18 * added create_index()
20 * Revision 1.9 2004/12/19 20:46:49 kenth
23 * Revision 1.8 2004/12/19 09:53:56 kenth
24 * added create_align()
26 * Revision 1.7 2004/12/18 16:56:55 kenth
27 * create_extrn() takes unit id
29 * Revision 1.6 2004/12/16 13:19:28 kenth
30 * changed astnode_create_label() signature
32 * Revision 1.5 2004/12/14 01:51:22 kenth
35 * Revision 1.4 2004/12/11 02:01:44 kenth
36 * added forward/backward branching
38 * Revision 1.3 2004/12/09 11:17:41 kenth
39 * added: warning, error nodes
41 * Revision 1.2 2004/12/06 04:54:00 kenth
44 * Revision 1.1 2004/06/30 07:56:09 kenth
50 * (C) 2004 Kent Hansen
52 * The XORcyst is free software; you can redistribute it and/or modify
53 * it under the terms of the GNU General Public License as published by
54 * the Free Software Foundation; either version 2 of the License, or
55 * (at your option) any later version.
57 * The XORcyst is distributed in the hope that it will be useful,
58 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60 * GNU General Public License for more details.
62 * You should have received a copy of the GNU General Public License
63 * along with The XORcyst; if not, write to the Free Software
64 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
68 * Header file with definitions for Abstract Syntax Tree (AST) nodes.
75 #define LHS(e) astnode_get_child(e, 0)
76 #define RHS(e) astnode_get_child(e, 1)
79 * The possible addressing modes for a parsed instruction.
80 * Note that there is not a 1:1 correspondence between these and
81 * the "real" 6502 addressing modes. Specifically, the parser doesn't
82 * distinguish between absolute and relative mode, or between
83 * 8-bit (zeropage) absolute addressing and 16-bit addressing.
84 * That's for the code generator to figure out.
86 enum tag_addressing_mode
{
96 PREINDEXED_INDIRECT_MODE
,
97 POSTINDEXED_INDIRECT_MODE
,
103 typedef enum tag_addressing_mode addressing_mode
;
106 * The possible instruction mnemonics.
108 enum tag_instr_mnemonic
{
167 typedef enum tag_instr_mnemonic instr_mnemonic
;
170 * The possible types of a node in the abstract syntax tree.
172 enum tag_astnode_type
{
222 FORWARD_BRANCH_DECL_NODE
,
223 BACKWARD_BRANCH_DECL_NODE
,
225 BACKWARD_BRANCH_NODE
,
232 typedef enum tag_astnode_type astnode_type
;
235 * The possible data types.
242 USER_DATATYPE
/* i.e. structure, union, enumeration, ... */
245 typedef enum tag_datatype datatype
;
248 * The possible types of operators for an ARITHMETIC_NODE.
250 enum tag_arithmetic_operator
{
275 typedef enum tag_arithmetic_operator arithmetic_operator
;
278 * Instruction attributes.
280 struct tag_instruction_attribs
{
282 addressing_mode mode
;
283 unsigned char opcode
;
286 typedef struct tag_instruction_attribs instruction_attribs
;
289 * Binary (byte buffer) attributes.
291 struct tag_binary_attribs
{
296 typedef struct tag_binary_attribs binary_attribs
;
299 * Structure that defines content of a node in the abstract syntax tree.
304 int integer
; /* type == INTEGER_NODE */
305 char *string
; /* type == STRING_NODE */
306 char *ident
; /* type == IDENTIFIER_NODE */
307 char *label
; /* type == LABEL_NODE */
308 char *file_path
; /* type == FILE_PATH_NODE */
309 binary_attribs binary
; /* type == BINARY_NODE */
310 instruction_attribs instr
; /* type == INSTRUCTION_NODE */
311 arithmetic_operator oper
; /* type == ARITHMETIC_NODE */
312 datatype datatype
; /* type == DATATYPE_NODE */
313 int modifiers
; /* type == DATASEG_NODE, VAR_DECL_NODE */
314 /* The other node types have attributes stored as children,
315 or can use this general-purpose field: */
319 location loc
; /* File location where node was parsed */
320 struct tag_astnode
*prev_sibling
;
321 struct tag_astnode
*next_sibling
;
322 struct tag_astnode
*first_child
;
323 struct tag_astnode
*parent
;
326 typedef struct tag_astnode astnode
;
329 * Function prototypes.
331 astnode
*astnode_create(astnode_type
, location
);
332 void astnode_finalize(astnode
*);
333 void astnode_replace(astnode
*, astnode
*);
334 void astnode_remove(astnode
*);
335 void astnode_insert_child(astnode
*, astnode
*, int);
336 int astnode_remove_child(astnode
*, astnode
*);
337 astnode
*astnode_remove_child_at(astnode
*, int);
338 astnode
*astnode_remove_children(astnode
*);
339 void astnode_add_sibling(astnode
*, astnode
*);
340 void astnode_add_child(astnode
*, astnode
*);
341 void astnode_add_children(astnode
*, int, ...);
342 astnode
*astnode_get_child(const astnode
*, int);
343 astnode
*astnode_get_first_child(const astnode
*);
344 int astnode_get_child_count(const astnode
*);
345 astnode
*astnode_get_parent(const astnode
*);
346 astnode
*astnode_get_ancestor(const astnode
*, int);
347 int astnode_has_ancestor_of_type(const astnode
*, astnode_type
);
348 int astnode_get_child_index(const astnode
*, const astnode
*);
349 astnode
*astnode_get_last_sibling(const astnode
*);
350 astnode_type
astnode_get_type(const astnode
*);
351 astnode
*astnode_get_next_sibling(const astnode
*);
352 astnode
*astnode_get_prev_sibling(const astnode
*);
353 void astnode_print(const astnode
*, int);
354 astnode
*astnode_clone(const astnode
*, location
);
355 //void astnode_serialize(astnode *, FILE *);
356 //astnode *astnode_deserialize(FILE *);
357 int astnode_equal(const astnode
*, const astnode
*);
358 int astnode_is_literal(const astnode
*);
359 const char *astnode_type_to_string(astnode_type
);
360 #define astnode_is_type(n, t) (astnode_get_type(n) == (t))
362 astnode
*astnode_create_null(location
);
363 astnode
*astnode_create_instruction(int, addressing_mode
, astnode
*, location
);
364 astnode
*astnode_create_identifier(const char *, location
);
365 astnode
*astnode_create_integer(int, location
);
366 astnode
*astnode_create_string(const char *, location
);
367 astnode
*astnode_create_file_path(const char *, location
);
368 astnode
*astnode_create_arithmetic(arithmetic_operator
, astnode
*, astnode
*, location
);
369 astnode
*astnode_create_if(astnode
*, astnode
*, astnode
*, astnode
*, location
);
370 astnode
*astnode_create_case(astnode
*, astnode
*, location
);
371 astnode
*astnode_create_default(astnode
*, location
);
372 astnode
*astnode_create_ifdef(astnode
*, astnode
*, astnode
*, location
);
373 astnode
*astnode_create_ifndef(astnode
*, astnode
*, astnode
*, location
);
374 astnode
*astnode_create_macro_decl(astnode
*, astnode
*, astnode
*, location
);
375 astnode
*astnode_create_macro(astnode
*, astnode
*, location
);
376 astnode
*astnode_create_equ(astnode
*, astnode
*, location
);
377 astnode
*astnode_create_assign(astnode
*, astnode
*, location
);
378 astnode
*astnode_create_incsrc(astnode
*, location
);
379 astnode
*astnode_create_incbin(astnode
*, location
);
380 astnode
*astnode_create_public(astnode
*, location
);
381 astnode
*astnode_create_extrn(astnode
*, astnode
*, astnode
*, location
);
382 astnode
*astnode_create_charmap(astnode
*, location
);
383 astnode
*astnode_create_struc(astnode
*, location
);
384 astnode
*astnode_create_struc_decl(astnode
*, astnode
*, location
);
385 astnode
*astnode_create_union_decl(astnode
*, astnode
*, location
);
386 astnode
*astnode_create_enum_decl(astnode
*, astnode
*, location
);
387 astnode
*astnode_create_record_decl(astnode
*, astnode
*, location
);
388 astnode
*astnode_create_bitfield_decl(astnode
*, astnode
*, location
);
389 astnode
*astnode_create_dot(astnode
*, astnode
*, location
);
390 astnode
*astnode_create_data(astnode
*, astnode
*, location
);
391 astnode
*astnode_create_storage(astnode
*, astnode
*, location
);
392 astnode
*astnode_create_dataseg(int, location
);
393 astnode
*astnode_create_codeseg(location
);
394 astnode
*astnode_create_pc(location
);
395 astnode
*astnode_create_label(const char *, astnode
*, astnode
*, location
);
396 astnode
*astnode_create_local_label(const char *, location
);
397 astnode
*astnode_create_local_id(const char *, location
);
398 astnode
*astnode_create_binary(unsigned char *, int, location
);
399 astnode
*astnode_create_list(astnode
*);
400 astnode
*astnode_create_sizeof(astnode
*, location
);
401 astnode
*astnode_create_datatype(datatype
, astnode
*, location
);
402 astnode
*astnode_create_var_decl(int, astnode
*, astnode
*, location
);
403 astnode
*astnode_create_scope(astnode
*, astnode
*, location
);
404 astnode
*astnode_create_proc(astnode
*, astnode
*, location
);
405 astnode
*astnode_create_rept(astnode
*, astnode
*, location
);
406 astnode
*astnode_create_while(astnode
*, astnode
*, location
);
407 astnode
*astnode_create_message(astnode
*, location
);
408 astnode
*astnode_create_warning(astnode
*, location
);
409 astnode
*astnode_create_error(astnode
*, location
);
410 astnode
*astnode_create_forward_branch_decl(const char *, location
);
411 astnode
*astnode_create_backward_branch_decl(const char *, location
);
412 astnode
*astnode_create_forward_branch(const char *, location
);
413 astnode
*astnode_create_backward_branch(const char *, location
);
414 astnode
*astnode_create_mask(astnode
*, location
);
415 astnode
*astnode_create_align(astnode
*, astnode
*, location
);
416 astnode
*astnode_create_index(astnode
*, astnode
*, location
);
417 astnode
*astnode_create_org(astnode
*, location
);
418 astnode
*astnode_create_tombstone(astnode_type type
, location
);
420 #endif /* !ASTNODE_H */