/* */
This source file includes following definitions.
- assembly
- yyerror
1 %{
2 /*
3 * Copyright (c) 2004, 2010 Tama Communications Corporation
4 *
5 * This file is part of GNU GLOBAL.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 #include <assert.h>
25 #include <ctype.h>
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #else
29 #include <strings.h>
30 #endif
31
32 #include "internal.h"
33 #include "die.h"
34 #include "linetable.h"
35 #include "strbuf.h"
36
37 #define YYLTYPE int
38 #define YYLLOC_DEFAULT(Current, Rhs, N) ((Current) = (Rhs)[1])
39
40 #undef PUT
41 #define PUT(type, tag, lno) do { \
42 const char *line_image = linetable_get(lno, NULL); \
43 char *nl = strchr(line_image, '\n'); \
44 if (nl != NULL) \
45 *nl = '\0'; \
46 param->put(type, tag, lno, param->file, line_image, param->arg);\
47 if (nl != NULL) \
48 *nl = '\n'; \
49 } while (0)
50
51 #define GET_SYM(offset) (assert((offset) < strbuf_getlen(asm_symtable)),\
52 &strbuf_value(asm_symtable)[offset])
53
54 STRBUF *asm_symtable;
55
56 static void yyerror(const struct parser_param *, const char *);
57
58 %}
59
60 %token ASM_CONST /* number, string, character */
61
62 %token ASM_CALL /* call, jsr */
63 %token ASM_ENTRY /* ENTRY, ALTENTRY, ... */
64 %token ASM_EXT /* EXT, SYMBOL_NAME, ... */
65 %token ASM_SYMBOL
66 %token ASM_LABEL /* ^sym */
67
68 %token ASM_DEFINE "#define"
69 %token ASM_UNDEF "#undef"
70 %token ASM_DIRECTIVE /* #xxx */
71
72 %token ASM_MACRO /* .macro */
73 %token ASM_EQU /* .equ */
74
75 %start input
76 %name-prefix="asm_"
77
78 %parse-param { const struct parser_param *param }
79 %lex-param { const struct parser_param *param }
80
81 %%
82
83 input: /* empty */
84 | input line
85 ;
86
87 line: ASM_ENTRY '(' ASM_SYMBOL ')' error '\n'
88 {
89 PUT(PARSER_REF_SYM, GET_SYM($1), @1);
90 PUT(PARSER_DEF, GET_SYM($3), @3);
91 strbuf_reset(asm_symtable);
92 }
93 | ASM_CALL ASM_SYMBOL error '\n'
94 {
95 const char *sym = GET_SYM($2);
96
97 if (sym[0] == '_') {
98 int c = (unsigned char)sym[1];
99
100 if (isalpha(c) || c == '_' || c >= 0x80)
101 PUT(PARSER_REF_SYM, &sym[1], @2);
102 }
103 strbuf_reset(asm_symtable);
104 }
105 | ASM_CALL ASM_EXT '(' ASM_SYMBOL ')' error '\n'
106 {
107 PUT(PARSER_REF_SYM, GET_SYM($2), @2);
108 PUT(PARSER_REF_SYM, GET_SYM($4), @4);
109 strbuf_reset(asm_symtable);
110 }
111 | "#define" ASM_SYMBOL error '\n'
112 {
113 PUT(PARSER_DEF, GET_SYM($2), @2);
114 strbuf_reset(asm_symtable);
115 }
116 | "#undef" ASM_SYMBOL error '\n'
117 {
118 PUT(PARSER_DEF, GET_SYM($2), @2);
119 strbuf_reset(asm_symtable);
120 }
121 | ASM_MACRO ASM_SYMBOL error '\n'
122 {
123 PUT(PARSER_DEF, GET_SYM($2), @2);
124 strbuf_reset(asm_symtable);
125 }
126 | ASM_LABEL ASM_MACRO error '\n'
127 {
128 PUT(PARSER_DEF, GET_SYM($1), @1);
129 strbuf_reset(asm_symtable);
130 }
131 | ASM_EQU ASM_SYMBOL ',' error '\n'
132 {
133 PUT(PARSER_DEF, GET_SYM($2), @2);
134 strbuf_reset(asm_symtable);
135 }
136 | ASM_LABEL ASM_EQU error '\n'
137 {
138 PUT(PARSER_DEF, GET_SYM($1), @1);
139 strbuf_reset(asm_symtable);
140 }
141 | error '\n'
142 { strbuf_reset(asm_symtable); }
143 ;
144
145 %%
146
147 void
148 assembly(const struct parser_param *param)
149 {
150 if (linetable_open(param->file) == -1)
151 die("'%s' cannot open.", param->file);
152
153 asm_symtable = strbuf_open(0);
154 asm_initscan();
155
156 asm_parse(param);
157
158 strbuf_close(asm_symtable);
159 linetable_close();
160 }
161
162 static void
163 yyerror(const struct parser_param *param, const char *s)
164 {
165
166 }
/* */