9 date 2007.08.12.18.59.10; author khansen; state Exp;
14 date 2007.08.09.22.06.00; author khansen; state Exp;
19 date 2007.08.07.21.12.16; author khansen; state Exp;
24 date 2007.07.22.13.35.20; author khansen; state Exp;
29 date 2004.12.29.21.44.23; author kenth; state Exp;
34 date 2004.12.19.20.46.49; author kenth; state Exp;
39 date 2004.12.19.09.53.56; author kenth; state Exp;
44 date 2004.12.18.16.56.55; author kenth; state Exp;
49 date 2004.12.16.13.19.28; author kenth; state Exp;
54 date 2004.12.14.01.51.22; author kenth; state Exp;
59 date 2004.12.11.02.01.44; author kenth; state Exp;
64 date 2004.12.09.11.17.41; author kenth; state Exp;
69 date 2004.12.06.04.54.00; author kenth; state Exp;
74 date 2004.06.30.07.56.09; author kenth; state Exp;
85 @ability to generate pure 6502 binary
89 * $Id: astnode.h,v 1.13 2007/08/09 22:06:00 khansen Exp khansen $
91 * Revision 1.13 2007/08/09 22:06:00 khansen
92 * general-purpose flags
94 * Revision 1.12 2007/08/07 21:12:16 khansen
97 * Revision 1.11 2007/07/22 13:35:20 khansen
98 * convert tabs to whitespaces
100 * Revision 1.10 2004/12/29 21:44:23 kenth
102 * added create_index()
104 * Revision 1.9 2004/12/19 20:46:49 kenth
107 * Revision 1.8 2004/12/19 09:53:56 kenth
108 * added create_align()
110 * Revision 1.7 2004/12/18 16:56:55 kenth
111 * create_extrn() takes unit id
113 * Revision 1.6 2004/12/16 13:19:28 kenth
114 * changed astnode_create_label() signature
116 * Revision 1.5 2004/12/14 01:51:22 kenth
119 * Revision 1.4 2004/12/11 02:01:44 kenth
120 * added forward/backward branching
122 * Revision 1.3 2004/12/09 11:17:41 kenth
123 * added: warning, error nodes
125 * Revision 1.2 2004/12/06 04:54:00 kenth
128 * Revision 1.1 2004/06/30 07:56:09 kenth
134 * (C) 2004 Kent Hansen
136 * The XORcyst is free software; you can redistribute it and/or modify
137 * it under the terms of the GNU General Public License as published by
138 * the Free Software Foundation; either version 2 of the License, or
139 * (at your option) any later version.
141 * The XORcyst is distributed in the hope that it will be useful,
142 * but WITHOUT ANY WARRANTY; without even the implied warranty of
143 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144 * GNU General Public License for more details.
146 * You should have received a copy of the GNU General Public License
147 * along with The XORcyst; if not, write to the Free Software
148 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
152 * Header file with definitions for Abstract Syntax Tree (AST) nodes.
159 #define LHS(e) astnode_get_child(e, 0)
160 #define RHS(e) astnode_get_child(e, 1)
163 * The possible addressing modes for a parsed instruction.
164 * Note that there is not a 1:1 correspondence between these and
165 * the "real" 6502 addressing modes. Specifically, the parser doesn't
166 * distinguish between absolute and relative mode, or between
167 * 8-bit (zeropage) absolute addressing and 16-bit addressing.
168 * That's for the code generator to figure out.
170 enum tag_addressing_mode {
180 PREINDEXED_INDIRECT_MODE,
181 POSTINDEXED_INDIRECT_MODE,
186 typedef enum tag_addressing_mode addressing_mode;
189 * The possible instruction mnemonics.
191 enum tag_instr_mnemonic {
250 typedef enum tag_instr_mnemonic instr_mnemonic;
253 * The possible types of a node in the abstract syntax tree.
255 enum tag_astnode_type {
305 FORWARD_BRANCH_DECL_NODE,
306 BACKWARD_BRANCH_DECL_NODE,
308 BACKWARD_BRANCH_NODE,
315 typedef enum tag_astnode_type astnode_type;
318 * The possible data types.
325 USER_DATATYPE /* i.e. structure, union, enumeration, ... */
328 typedef enum tag_datatype datatype;
331 * The possible types of operators for an ARITHMETIC_NODE.
333 enum tag_arithmetic_operator {
358 typedef enum tag_arithmetic_operator arithmetic_operator;
361 * Instruction attributes.
363 struct tag_instruction_attribs {
365 addressing_mode mode;
366 unsigned char opcode;
369 typedef struct tag_instruction_attribs instruction_attribs;
372 * Binary (byte buffer) attributes.
374 struct tag_binary_attribs {
379 typedef struct tag_binary_attribs binary_attribs;
382 * Structure that defines content of a node in the abstract syntax tree.
387 int integer; /* type == INTEGER_NODE */
388 char *string; /* type == STRING_NODE */
389 char *ident; /* type == IDENTIFIER_NODE */
390 char *label; /* type == LABEL_NODE */
391 char *file_path; /* type == FILE_PATH_NODE */
392 binary_attribs binary; /* type == BINARY_NODE */
393 instruction_attribs instr; /* type == INSTRUCTION_NODE */
394 arithmetic_operator oper; /* type == ARITHMETIC_NODE */
395 datatype datatype; /* type == DATATYPE_NODE */
396 int modifiers; /* type == DATASEG_NODE, VAR_DECL_NODE */
397 /* The other node types have attributes stored as children,
398 or can use this general-purpose field: */
402 location loc; /* File location where node was parsed */
403 struct tag_astnode *prev_sibling;
404 struct tag_astnode *next_sibling;
405 struct tag_astnode *first_child;
406 struct tag_astnode *parent;
409 typedef struct tag_astnode astnode;
412 * Function prototypes.
414 astnode *astnode_create(astnode_type, location);
415 void astnode_finalize(astnode *);
416 void astnode_replace(astnode *, astnode *);
417 void astnode_remove(astnode *);
418 void astnode_insert_child(astnode *, astnode *, int);
419 int astnode_remove_child(astnode *, astnode *);
420 astnode *astnode_remove_child_at(astnode *, int);
421 astnode *astnode_remove_children(astnode *);
422 void astnode_add_sibling(astnode *, astnode *);
423 void astnode_add_child(astnode *, astnode *);
424 void astnode_add_children(astnode *, int, ...);
425 astnode *astnode_get_child(const astnode *, int);
426 astnode *astnode_get_first_child(const astnode *);
427 int astnode_get_child_count(const astnode *);
428 astnode *astnode_get_parent(const astnode *);
429 astnode *astnode_get_ancestor(const astnode *, int);
430 int astnode_has_ancestor_of_type(const astnode *, astnode_type);
431 int astnode_get_child_index(const astnode *, const astnode *);
432 astnode *astnode_get_last_sibling(const astnode *);
433 astnode_type astnode_get_type(const astnode *);
434 astnode *astnode_get_next_sibling(const astnode *);
435 astnode *astnode_get_prev_sibling(const astnode *);
436 void astnode_print(const astnode *, int);
437 astnode *astnode_clone(const astnode *, location);
438 //void astnode_serialize(astnode *, FILE *);
439 //astnode *astnode_deserialize(FILE *);
440 int astnode_equal(const astnode *, const astnode *);
441 int astnode_is_literal(const astnode *);
442 const char *astnode_type_to_string(astnode_type);
443 #define astnode_is_type(n, t) (astnode_get_type(n) == (t))
445 astnode *astnode_create_null(location);
446 astnode *astnode_create_instruction(int, addressing_mode, astnode *, location);
447 astnode *astnode_create_identifier(const char *, location);
448 astnode *astnode_create_integer(int, location);
449 astnode *astnode_create_string(const char *, location);
450 astnode *astnode_create_file_path(const char *, location);
451 astnode *astnode_create_arithmetic(arithmetic_operator, astnode *, astnode *, location);
452 astnode *astnode_create_if(astnode *, astnode *, astnode *, astnode *, location);
453 astnode *astnode_create_case(astnode *, astnode *, location);
454 astnode *astnode_create_default(astnode *, location);
455 astnode *astnode_create_ifdef(astnode *, astnode *, astnode *, location);
456 astnode *astnode_create_ifndef(astnode *, astnode *, astnode *, location);
457 astnode *astnode_create_macro_decl(astnode *, astnode *, astnode *, location);
458 astnode *astnode_create_macro(astnode *, astnode *, location);
459 astnode *astnode_create_equ(astnode *, astnode *, location);
460 astnode *astnode_create_assign(astnode *, astnode *, location);
461 astnode *astnode_create_incsrc(astnode *, location);
462 astnode *astnode_create_incbin(astnode *, location);
463 astnode *astnode_create_public(astnode *, location);
464 astnode *astnode_create_extrn(astnode *, astnode *, astnode *, location);
465 astnode *astnode_create_charmap(astnode *, location);
466 astnode *astnode_create_struc(astnode *, location);
467 astnode *astnode_create_struc_decl(astnode *, astnode *, location);
468 astnode *astnode_create_union_decl(astnode *, astnode *, location);
469 astnode *astnode_create_enum_decl(astnode *, astnode *, location);
470 astnode *astnode_create_record_decl(astnode *, astnode *, location);
471 astnode *astnode_create_bitfield_decl(astnode *, astnode *, location);
472 astnode *astnode_create_dot(astnode *, astnode *, location);
473 astnode *astnode_create_data(astnode *, astnode *, location);
474 astnode *astnode_create_storage(astnode *, astnode *, location);
475 astnode *astnode_create_dataseg(int, location);
476 astnode *astnode_create_codeseg(location);
477 astnode *astnode_create_pc(location);
478 astnode *astnode_create_label(const char *, astnode *, astnode *, location);
479 astnode *astnode_create_local_label(const char *, location);
480 astnode *astnode_create_local_id(const char *, location);
481 astnode *astnode_create_binary(unsigned char *, int, location);
482 astnode *astnode_create_list(astnode *);
483 astnode *astnode_create_sizeof(astnode *, location);
484 astnode *astnode_create_datatype(datatype, astnode *, location);
485 astnode *astnode_create_var_decl(int, astnode *, astnode *, location);
486 astnode *astnode_create_scope(astnode *, astnode *, location);
487 astnode *astnode_create_proc(astnode *, astnode *, location);
488 astnode *astnode_create_rept(astnode *, astnode *, location);
489 astnode *astnode_create_while(astnode *, astnode *, location);
490 astnode *astnode_create_message(astnode *, location);
491 astnode *astnode_create_warning(astnode *, location);
492 astnode *astnode_create_error(astnode *, location);
493 astnode *astnode_create_forward_branch_decl(const char *, location);
494 astnode *astnode_create_backward_branch_decl(const char *, location);
495 astnode *astnode_create_forward_branch(const char *, location);
496 astnode *astnode_create_backward_branch(const char *, location);
497 astnode *astnode_create_mask(astnode *, location);
498 astnode *astnode_create_align(astnode *, astnode *, location);
499 astnode *astnode_create_index(astnode *, astnode *, location);
500 astnode *astnode_create_org(astnode *, location);
501 astnode *astnode_create_tombstone(astnode_type type, location);
503 #endif /* !ASTNODE_H */
509 @general-purpose flags
514 * $Id: astnode.h,v 1.12 2007/08/07 21:12:16 khansen Exp khansen $
528 * $Id: astnode.h,v 1.11 2007/07/22 13:35:20 khansen Exp khansen $
536 @convert tabs to whitespaces
541 * $Id: astnode.h,v 1.10 2004/12/29 21:44:23 kenth Exp khansen $
545 astnode *astnode_get_child(astnode *, int);
546 astnode *astnode_get_first_child(astnode *);
547 int astnode_get_child_count(astnode *);
548 astnode *astnode_get_parent(astnode *);
549 astnode *astnode_get_ancestor(astnode *, int);
550 int astnode_has_ancestor_of_type(astnode *, astnode_type);
551 int astnode_get_child_index(astnode *, astnode *);
552 astnode *astnode_get_last_sibling(astnode *);
553 astnode_type astnode_get_type(astnode *);
554 astnode *astnode_get_next_sibling(astnode *);
555 astnode *astnode_get_prev_sibling(astnode *);
556 void astnode_print(astnode *, int);
557 astnode *astnode_clone(astnode *, location);
560 int astnode_equal(astnode *, astnode *);
561 int astnode_is_literal(astnode *);
564 astnode *astnode_create_identifier(char *, location);
567 astnode *astnode_create_string(char *, location);
568 astnode *astnode_create_file_path(char *, location);
571 astnode *astnode_create_label(char *, astnode *, astnode *, location);
572 astnode *astnode_create_local_label(char *, location);
573 astnode *astnode_create_local_id(char *, location);
576 astnode *astnode_create_forward_branch_decl(char *, location);
577 astnode *astnode_create_backward_branch_decl(char *, location);
578 astnode *astnode_create_forward_branch(char *, location);
579 astnode *astnode_create_backward_branch(char *, location);
591 * $Id: astnode.h,v 1.9 2004/12/19 20:46:49 kenth Exp kenth $
604 PREINDEXED_INDIRECT_MODE,
605 POSTINDEXED_INDIRECT_MODE,
717 FORWARD_BRANCH_DECL_NODE,
718 BACKWARD_BRANCH_DECL_NODE,
720 BACKWARD_BRANCH_NODE,
730 USER_DATATYPE /* i.e. structure, union, enumeration, ... */
758 addressing_mode mode;
759 unsigned char opcode;
768 int integer; /* type == INTEGER_NODE */
769 char *string; /* type == STRING_NODE */
770 char *ident; /* type == IDENTIFIER_NODE */
771 char *label; /* type == LABEL_NODE */
772 char *file_path; /* type == FILE_PATH_NODE */
773 binary_attribs binary; /* type == BINARY_NODE */
774 instruction_attribs instr; /* type == INSTRUCTION_NODE */
775 arithmetic_operator oper; /* type == ARITHMETIC_NODE */
776 datatype datatype; /* type == DATATYPE_NODE */
777 int modifiers; /* type == DATASEG_NODE, VAR_DECL_NODE */
778 /* The other node types have attributes stored as children,
779 or can use this general-purpose field: */
782 location loc; /* File location where node was parsed */
783 struct tag_astnode *prev_sibling;
784 struct tag_astnode *next_sibling;
785 struct tag_astnode *first_child;
786 struct tag_astnode *parent;
789 #endif /* !ASTNODE_H */
800 * $Id: astnode.h,v 1.8 2004/12/19 09:53:56 kenth Exp kenth $
809 @added create_align()
814 * $Id: astnode.h,v 1.7 2004/12/18 16:56:55 kenth Exp kenth $
819 astnode *astnode_create_dataseg(location);
822 astnode *astnode_create_label(char *, astnode *, location);
825 astnode *astnode_create_var_decl(astnode *, astnode *, location);
828 astnode *astnode_create_align(astnode *, location);
834 @create_extrn() takes unit id
839 * $Id: astnode.h,v 1.6 2004/12/16 13:19:28 kenth Exp kenth $
847 @changed astnode_create_label() signature
852 * $Id: astnode.h,v 1.5 2004/12/14 01:51:22 kenth Exp kenth $
856 astnode *astnode_create_extrn(astnode *, astnode *, location);
867 * $Id: astnode.h,v 1.4 2004/12/11 02:01:44 kenth Exp kenth $
871 astnode *astnode_create_label(char *, location);
877 @added forward/backward branching
882 * $Id: astnode.h,v 1.3 2004/12/09 11:17:41 kenth Exp kenth $
892 astnode *astnode_create_elif(astnode *, astnode *, location);
901 @added: warning, error nodes
906 * $Id: astnode.h,v 1.2 2004/12/06 04:54:00 kenth Exp kenth $
920 * $Id: astnode.h,v 1.1 2004/06/30 07:56:09 kenth Exp kenth $
942 * The possible types for a data node.
948 int datatype; /* type == DATA_NODE */
955 void astnode_serialize(astnode *, FILE *);
956 astnode *astnode_deserialize(FILE *);
961 astnode *astnode_create_extrn(astnode *, location);
964 astnode *astnode_create_data(int, astnode *, location);
965 astnode *astnode_create_storage(int, astnode *, location);