1 /* eval.h   header file for eval.c
2  *
3  * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4  * Julian Hall. All rights reserved. The software is
5  * redistributable under the licence given in the file "Licence"
6  * distributed in the NASM archive.
7  */
8 
9 #ifndef YASM_EVAL_H
10 #define YASM_EVAL_H
11 
12 /*
13  * -------------------------
14  * Error reporting functions
15  * -------------------------
16  */
17 
18 /*
19  * An error reporting function should look like this.
20  */
21 typedef void (*efunc) (void *private_data, int severity, const char *fmt, ...);
22 
23 /*
24  * These are the error severity codes which get passed as the first
25  * argument to an efunc.
26  */
27 
28 #define ERR_DEBUG       0x00000008      /* put out debugging message */
29 #define ERR_WARNING     0x00000000      /* warn only: no further action */
30 #define ERR_NONFATAL    0x00000001      /* terminate assembly after phase */
31 #define ERR_FATAL       0x00000002      /* instantly fatal: exit with error */
32 #define ERR_PANIC       0x00000003      /* internal error: panic instantly
33                                         * and dump core for reference */
34 #define ERR_MASK        0x0000000F      /* mask off the above codes */
35 #define ERR_NOFILE      0x00000010      /* don't give source file name/line */
36 #define ERR_USAGE       0x00000020      /* print a usage message */
37 #define ERR_PASS1       0x00000040      /* only print this error on pass one */
38 
39 /*
40  * These codes define specific types of suppressible warning.
41  */
42 
43 #define ERR_WARN_MASK   0x0000FF00      /* the mask for this feature */
44 #define ERR_WARN_SHR    8               /* how far to shift right */
45 
46 #define ERR_WARN_MNP    0x00000100      /* macro-num-parameters warning */
47 #define ERR_WARN_MSR    0x00000200      /* macro self-reference */
48 #define ERR_WARN_OL     0x00000300      /* orphan label (no colon, and
49                                         * alone on line) */
50 #define ERR_WARN_NOV    0x00000400      /* numeric overflow */
51 #define ERR_WARN_GNUELF 0x00000500      /* using GNU ELF extensions */
52 #define ERR_WARN_MAX    5               /* the highest numbered one */
53 
54 /*
55  * The expression evaluator must be passed a scanner function; a
56  * standard scanner is provided as part of nasmlib.c. The
57  * preprocessor will use a different one. Scanners, and the
58  * token-value structures they return, look like this.
59  *
60  * The return value from the scanner is always a copy of the
61  * `t_type' field in the structure.
62  */
63 struct tokenval {
64     int t_type;
65     yasm_intnum *t_integer, *t_inttwo;
66     char *t_charptr;
67 };
68 typedef int (*scanner) (void *private_data, struct tokenval *tv);
69 
70 /*
71  * Token types returned by the scanner, in addition to ordinary
72  * ASCII character values, and zero for end-of-string.
73  */
74 enum {                                 /* token types, other than chars */
75     TOKEN_INVALID = -1,                /* a placeholder value */
76     TOKEN_EOS = 0,                     /* end of string */
77     TOKEN_EQ = '=', TOKEN_GT = '>', TOKEN_LT = '<',   /* aliases */
78     TOKEN_ID = 256, TOKEN_NUM, TOKEN_REG, TOKEN_INSN,  /* major token types */
79     TOKEN_ERRNUM,                      /* numeric constant with error in */
80     TOKEN_HERE, TOKEN_BASE,            /* $ and $$ */
81     TOKEN_SPECIAL,                     /* BYTE, WORD, DWORD, FAR, NEAR, etc */
82     TOKEN_PREFIX,                      /* A32, O16, LOCK, REPNZ, TIMES, etc */
83     TOKEN_SHL, TOKEN_SHR,              /* << and >> */
84     TOKEN_SDIV, TOKEN_SMOD,            /* // and %% */
85     TOKEN_GE, TOKEN_LE, TOKEN_NE,      /* >=, <= and <> (!= is same as <>) */
86     TOKEN_DBL_AND, TOKEN_DBL_OR, TOKEN_DBL_XOR,   /* &&, || and ^^ */
87     TOKEN_SEG, TOKEN_WRT,              /* SEG and WRT */
88     TOKEN_FLOAT                        /* floating-point constant */
89 };
90 
91 /*
92  * The actual expression evaluator function looks like this. When
93  * called, it expects the first token of its expression to already
94  * be in `*tv'; if it is not, set tv->t_type to TOKEN_INVALID and
95  * it will start by calling the scanner.
96  *
97  * `critical' is non-zero if the expression may not contain forward
98  * references. The evaluator will report its own error if this
99  * occurs; if `critical' is 1, the error will be "symbol not
100  * defined before use", whereas if `critical' is 2, the error will
101  * be "symbol undefined".
102  *
103  * If `critical' has bit 8 set (in addition to its main value: 0x101
104  * and 0x102 correspond to 1 and 2) then an extended expression
105  * syntax is recognised, in which relational operators such as =, <
106  * and >= are accepted, as well as low-precedence logical operators
107  * &&, ^^ and ||.
108  */
109 #define CRITICAL 0x100
110 typedef yasm_expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
111                                 int critical, efunc error, yasm_symtab *symtab);
112 
113 /*
114  * The evaluator itself.
115  */
116 yasm_expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
117                      void *eprivate, int critical, efunc report_error,
118                      yasm_symtab *symtab);
119 
120 #endif
121