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

Subversion Repositories tinyvliw8

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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