OpenCores
URL https://opencores.org/ocsvn/tinyvliw8/tinyvliw8/trunk

Subversion Repositories tinyvliw8

[/] [tinyvliw8/] [trunk/] [tools/] [asm/] [src/] [parser.y] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 steckol
/**
2
 * \file   parser.y
3
 * \author Oliver Stecklina 
4
 * \date   12.12.2015
5
 *
6
 * \brief  Yacc parser file
7
 *
8
 * 

9
 *    Copyright (C) 2015 IHP GmbH, Frankfurt (Oder), Germany
10
 *
11
 * This code is free software. It is licensed under the EUPL, Version 1.1
12
 * or - as soon they will be approved by the European Commission - subsequent
13
 * versions of the EUPL (the "License").
14
 * You may redistribute this code and/or modify it under the terms of this
15
 * License.
16
 * You may not use this work except in compliance with the License.
17
 * You may obtain a copy of the License at:
18
 *
19
 * http://joinup.ec.europa.eu/software/page/eupl/licence-eupl
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" basis,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 * 

27
 */
28
 
29 5 steckol
%{
30
        #include 
31
        #include 
32
 
33
        #include "instr.h"
34
 
35
        static instr_t _instr[2];
36
        static unsigned char _instr_num = 0;
37
 
38
    extern int yylex();
39
        extern int get_linenum();
40
 
41
        unsigned char _sign;
42
 
43
    void yyerror(const char *s) {
44
                printf("ERROR: %s near line %d\n", s, get_linenum());
45
        }
46
 
47
        void _instr_clean(void)
48
        {
49
                memset((char *) &_instr[0], 0x00, 2 * sizeof(instr_t));
50
 
51
                _instr[0].source.next = &_instr[0].source;
52
                _instr[0].source.prev = &_instr[0].source;
53
                _instr[1].source.next = &_instr[1].source;
54
                _instr[1].source.prev = &_instr[1].source;
55
 
56
                _instr_num = 0;
57
        }
58
%}
59
 
60
%union {
61
        char* str;
62
        int   num;
63
}
64
 
65
%start PROGRAM
66
 
67
%token CONSTSEC
68
%token RESSEC
69
%token CODESEC
70
%token  IRQSEC
71
%token LOADI
72
%token LOAD
73
%token STOREI
74
%token STORE
75
%token RLA
76
%token RLC
77
%token RRA
78
%token RRC
79
%token MOVE
80
%token ADDI
81
%token ADD
82
%token OR
83
%token XOR
84
%token XNOR
85
%token NOR
86
%token AND
87
%token NAND
88
%token JMP
89
%token JNZ
90
%token JZ
91
%token JC
92
%token COLON
93
%token PLUS
94
%token MINUS
95
%token TILDE
96
%token PIPE
97
%token DOLLAR
98
%token HASH
99
%token AT
100
%token  REG
101
%token  HEXNUM
102
%token  HEXADDR
103
%token  NAME
104
%token  UNAME
105
%token NEWLINE
106
%token SEMICOLON
107
%token COMMA
108
 
109
   %%
110
 
111
PROGRAM:
112
        constseq resseq codeseq irqseq
113
 
114
empty:
115
 
116
constseq:
117
          CONSTSEC linebreak consts
118
        | empty
119
 
120
resseq:
121
        RESSEC linebreak ress
122
        | empty
123
 
124
codeseq:
125
          CODESEC { _instr_clean(); } linebreak code
126
        | empty
127
 
128
irqseq:
129
          irq irq irq irq
130
        | irq irq irq
131
        | irq irq
132
        | irq
133
        | empty
134
 
135
irq:
136
          IRQSEC linebreak instr { instr_irq($1); instr_add(&_instr[0], _instr_num); _instr_clean(); }
137
 
138
ress:
139
          res ress
140
        | res
141
 
142
res:
143
        NAME HEXNUM SEMICOLON linebreak
144
 
145
consts:
146
          cvar consts
147
        | cvar
148
 
149
cvar:
150
        UNAME HEXNUM SEMICOLON linebreak
151
 
152
linebreak:
153
          linebreak NEWLINE
154
        | NEWLINE
155
 
156
code:
157
          cinstr code
158
        | cinstr
159
 
160
cinstr:
161
          NAME COLON linebreak instr { instr_label($1); instr_add(&_instr[0], _instr_num); _instr_clean(); }
162
        | instr                      { instr_add(&_instr[0], _instr_num); _instr_clean(); }
163
 
164
instr:
165
          cmd SEMICOLON linebreak
166
        | cmd PIPE cmd SEMICOLON linebreak
167
 
168
cmd:
169
          ldsti REG COMMA src     { instr_add_dest(&_instr[_instr_num].dest, $2); _instr_num++; }
170
        | logici REG COMMA alusrc { instr_add_dest(&_instr[_instr_num].dest, $2); _instr_num++; }
171
        | alui REG COMMA alusrc   { instr_add_dest(&_instr[_instr_num].dest, $2); _instr_num++; }
172
        | sh                      { _instr_num++; }
173
        | jmpi jmpdst             { _instr_num++; }
174
 
175
sh:
176
          shi REG COMMA srcreg  { instr_add_dest(&_instr[_instr_num].dest, $2); }
177
        | MOVE REG COMMA movsrc { instr_add_dest(&_instr[_instr_num].dest, $2); _instr[_instr_num].opcode = instr_opcode_mov; }
178
 
179
shi:
180
          RLA { _instr[_instr_num].opcode = instr_opcode_rla; }
181
        | RLC { _instr[_instr_num].opcode = instr_opcode_rlc; }
182
        | RRA { _instr[_instr_num].opcode = instr_opcode_rra; }
183
        | RRC { _instr[_instr_num].opcode = instr_opcode_rrc; }
184
 
185
movsrc:
186
          srcreg
187
        | HASH HEXNUM { instr_add_source(&_instr[_instr_num].source, instr_operand_type_const, &($2)); }
188
 
189
jmpi:
190
          JMP { _instr[_instr_num].opcode = instr_opcode_jmp; }
191
        | JZ  { _instr[_instr_num].opcode = instr_opcode_jz; }
192
        | JC  { _instr[_instr_num].opcode = instr_opcode_jc; }
193
        | JNZ { _instr[_instr_num].opcode = instr_opcode_jnz; }
194
 
195
alui:
196
          ADD  { _instr[_instr_num].opcode = instr_opcode_add; }
197
        | ADDI { _instr[_instr_num].opcode = instr_opcode_addi; }
198
 
199
jmpdst:
200
          DOLLAR NAME { instr_add_source(&_instr[_instr_num].source, instr_operand_type_label, $2); }
201
        | sign HEXADDR { instr_add_source(&_instr[_instr_num].source, instr_operand_type_const, &($2)); instr_source_flag(&_instr[_instr_num].source, _sign);}
202
 
203
ldsti:
204
          LOAD   { _instr[_instr_num].opcode = instr_opcode_ld; }
205
        | LOADI  { _instr[_instr_num].opcode = instr_opcode_ldi; }
206
        | STORE  { _instr[_instr_num].opcode = instr_opcode_st; }
207
        | STOREI { _instr[_instr_num].opcode = instr_opcode_sti; }
208
 
209
sign:
210
          PLUS  { _sign = 0x00; }
211
        | MINUS { _sign = INSTR_FLAG_MINUS; }
212
 
213
src:
214
          AT REG { instr_add_source(&_instr[_instr_num].source, instr_operand_type_reg, &($2)); }
215
        | HASH HEXNUM { instr_add_source(&_instr[_instr_num].source, instr_operand_type_const, &($2)); }
216
        | DOLLAR UNAME { instr_add_source(&_instr[_instr_num].source, instr_operand_type_label, $2); }
217
        | DOLLAR NAME { instr_add_source(&_instr[_instr_num].source, instr_operand_type_label, $2); }
218
 
219
logici:
220
          OR   { _instr[_instr_num].opcode = instr_opcode_or; }
221
        | NOR  { _instr[_instr_num].opcode = instr_opcode_nor; }
222
        | AND  { _instr[_instr_num].opcode = instr_opcode_and; }
223
        | NAND { _instr[_instr_num].opcode = instr_opcode_nand; }
224
        | XOR  { _instr[_instr_num].opcode = instr_opcode_xor; }
225
        | XNOR { _instr[_instr_num].opcode = instr_opcode_xnor; }
226
 
227
alusrc:
228
          HASH HEXNUM { instr_add_source(&_instr[_instr_num].source, instr_operand_type_const, &($2)); }
229
        | srcreg
230
        | srcreg COMMA srcreg
231
 
232
srcreg:
233
          REG { instr_add_source(&_instr[_instr_num].source, instr_operand_type_reg, &($1)); }
234
        | TILDE REG { instr_add_source(&_instr[_instr_num].source, instr_operand_type_reg, &($2)); instr_source_flag(&_instr[_instr_num].source, INSTR_FLAG_TILDE);}
235
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.