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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.h] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    zparser.h
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU core
6
//
7
// Purpose:     The beginnings of a parser for Zip CPU assembly.
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Tecnology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
 
37
#ifndef ZPARSER_H
38
#define ZPARSER_H
39
 
40
class   ZPARSER {
41
public:
42
        typedef unsigned int    ZIPI, ZIPA;
43
        typedef int     ZIPIMM;
44
        typedef enum {
45
                ZIP_R0, ZIP_R1, ZIP_R2, ZIP_R3, ZIP_R4, ZIP_R5, ZIP_R6, ZIP_R7,
46
                ZIP_R8, ZIP_R9, ZIP_R10, ZIP_R11, ZIP_R12,
47
                        ZIP_SP, ZIP_CC, ZIP_PC,
48
                ZIP_uR0, ZIP_uR1, ZIP_uR2, ZIP_uR3, ZIP_uR4, ZIP_uR5, ZIP_uR6, ZIP_uR7,
49
                ZIP_uR8, ZIP_uR9, ZIP_uR10, ZIP_uR11, ZIP_uR12,
50
                        ZIP_uSP, ZIP_uCC, ZIP_uPC,
51
                ZIP_Rnone
52
        } ZIPREG;
53
 
54
        typedef enum {
55
                ZIPC_ALWAYS, ZIPC_Z, ZIPC_NZ, ZIPC_GE, ZIPC_GT, ZIPC_LT,
56
                ZIPC_C, ZIPC_V
57
        } ZIPCOND;
58
 
59
        bool    iscomment(const char *line) const;
60
        bool    islabel(const char *line) const;
61
        bool    parse_op(const char *line, ZIPA pc, ZIPI &instruction, const unsigned lineno) const;
62
        bool    parse(const char *line, ZIPA &pc, ZIPI &instruction, const unsigned lineno);
63
 
64
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
65
        ZIPI    op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
66
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG b, ZIPREG a) const
67
                { return op_cmp(ZIPC_ALWAYS, imm, b, a); }
68
        ZIPI    op_cmp(ZIPIMM imm, ZIPREG a) const
69
                { return op_cmp(ZIPC_ALWAYS, imm, a); }
70
 
71
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
72
        ZIPI    op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
73
        ZIPI    op_tst(ZIPIMM imm, ZIPREG a) const
74
                { return op_tst(ZIPC_ALWAYS, imm, a); }
75
        ZIPI    op_tst(ZIPCOND cnd, ZIPREG a) const
76
                { return op_tst(cnd, -1, a); }
77
 
78
        ZIPI    op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
79
        ZIPI    op_mov(ZIPIMM imm, ZIPREG b, ZIPREG a) const
80
                { return op_mov(ZIPC_ALWAYS, imm, b, a); }
81
        ZIPI    op_mov(ZIPREG b, ZIPREG a) const
82
                { return op_mov(ZIPC_ALWAYS, 0, b, a); }
83
 
84
        ZIPI    op_ldi(ZIPIMM imm, ZIPREG a) const;
85
        ZIPI    op_trap(ZIPCOND cnd, ZIPIMM imm) const;
86
        ZIPI    op_trap(ZIPIMM imm) const
87
                { return op_trap(ZIPC_ALWAYS, imm); }
88
        ZIPI    op_clr(ZIPREG a) const { return op_ldi(0, a); }
89
 
90
        ZIPI    op_noop(void) const;
91
        ZIPI    op_break(void) const;
92
 
93
        ZIPI    op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
94
        ZIPI    op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
95
        ZIPI    op_ldihi(ZIPIMM imm, ZIPREG a) const
96
                { return op_ldihi(ZIPC_ALWAYS, imm, a); }
97
        ZIPI    op_ldilo(ZIPIMM imm, ZIPREG a) const
98
                { return op_ldilo(ZIPC_ALWAYS, imm, a); }
99
 
100
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
101
        ZIPI    op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
102
        ZIPI    op_lod(ZIPIMM imm, ZIPREG b, ZIPREG a) const
103
                { return op_lod(ZIPC_ALWAYS, imm, b, a); }
104
        ZIPI    op_lod(ZIPIMM imm, ZIPREG a) const
105
                { return op_lod(ZIPC_ALWAYS, imm, a); }
106
 
107
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const;
108
        ZIPI    op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const;
109
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm, ZIPREG b) const
110
                { return op_sto(ZIPC_ALWAYS, v, imm, b); }
111
        ZIPI    op_sto(ZIPREG v, ZIPIMM imm) const
112
                { return op_sto(ZIPC_ALWAYS, v, imm); }
113
 
114
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
115
        ZIPI    op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
116
        ZIPI    op_sub(ZIPIMM imm, ZIPREG b, ZIPREG a) const
117
                { return op_sub(ZIPC_ALWAYS, imm, b, a); }
118
        ZIPI    op_sub(ZIPIMM imm, ZIPREG a) const
119
                { return op_sub(ZIPC_ALWAYS, imm, a); }
120
 
121
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
122
        ZIPI    op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
123
        ZIPI    op_and(ZIPIMM imm, ZIPREG b, ZIPREG a) const
124
                { return op_and(ZIPC_ALWAYS, imm, b, a); }
125
        ZIPI    op_and(ZIPIMM imm, ZIPREG a) const
126
                { return op_and(ZIPC_ALWAYS, imm, a); }
127
 
128
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
129
        ZIPI    op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
130
        ZIPI    op_add(ZIPIMM imm, ZIPREG b, ZIPREG a) const
131
                { return op_add(ZIPC_ALWAYS, imm, b, a); }
132
        ZIPI    op_add(ZIPIMM imm, ZIPREG a) const      // GOOD
133
                { return op_add(ZIPC_ALWAYS, imm, a); }
134
 
135
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
136
        ZIPI    op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
137
        ZIPI    op_or(ZIPIMM imm, ZIPREG b, ZIPREG a) const
138
                { return op_or(ZIPC_ALWAYS, imm, b, a); }
139
        ZIPI    op_or(ZIPIMM imm, ZIPREG a) const
140
                { return op_or(ZIPC_ALWAYS, imm, a); }
141
 
142
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
143
        ZIPI    op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
144
        ZIPI    op_xor(ZIPIMM imm, ZIPREG b, ZIPREG a) const
145
                { return op_xor(ZIPC_ALWAYS, imm, b, a); }
146
        ZIPI    op_xor(ZIPIMM imm, ZIPREG a) const
147
                { return op_xor(ZIPC_ALWAYS, imm, a); }
148
 
149
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
150
        ZIPI    op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
151
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
152
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
153
        ZIPI    op_lsl(ZIPIMM imm, ZIPREG a) const
154
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
155
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const
156
                { return op_lsl(cnd, imm, b, a); }
157
        ZIPI    op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const
158
                { return op_lsl(cnd, imm, a); }
159
        ZIPI    op_asl(ZIPIMM imm, ZIPREG b, ZIPREG a) const
160
                { return op_lsl(ZIPC_ALWAYS, imm, b, a); }
161
        ZIPI    op_asl(ZIPIMM imm, ZIPREG a) const
162
                { return op_lsl(ZIPC_ALWAYS, imm, a); }
163
 
164
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
165
        ZIPI    op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
166
        ZIPI    op_asr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
167
                { return op_asr(ZIPC_ALWAYS, imm, b, a); }
168
        ZIPI    op_asr(ZIPIMM imm, ZIPREG a) const
169
                { return op_asr(ZIPC_ALWAYS, imm, a); }
170
 
171
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const;
172
        ZIPI    op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const;
173
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG b, ZIPREG a) const
174
                { return op_lsr(ZIPC_ALWAYS, imm, b, a); }
175
        ZIPI    op_lsr(ZIPIMM imm, ZIPREG a) const
176
                { return op_lsr(ZIPC_ALWAYS, imm, a); }
177
 
178
        ZIPI    op_bra(ZIPCOND cnd, ZIPIMM imm) const
179
                { return op_mov(cnd, imm, ZIP_PC, ZIP_PC); }
180
        ZIPI    op_bra(ZIPIMM imm) const
181
                { return op_mov(ZIPC_ALWAYS, imm, ZIP_PC, ZIP_PC); }
182
        ZIPI    op_brz(ZIPIMM imm) const
183
                { return op_mov(ZIPC_Z, imm, ZIP_PC, ZIP_PC); }
184
        ZIPI    op_bnz(ZIPIMM imm) const
185
                { return op_mov(ZIPC_NZ, imm, ZIP_PC, ZIP_PC); }
186
        ZIPI    op_bge(ZIPIMM imm) const
187
                { return op_mov(ZIPC_GE, imm, ZIP_PC, ZIP_PC); }
188
        ZIPI    op_bgt(ZIPIMM imm) const
189
                { return op_mov(ZIPC_GT, imm, ZIP_PC, ZIP_PC); }
190
        ZIPI    op_blt(ZIPIMM imm) const
191
                { return op_mov(ZIPC_LT, imm, ZIP_PC, ZIP_PC); }
192
        ZIPI    op_brc(ZIPIMM imm) const
193
                { return op_mov(ZIPC_C, imm, ZIP_PC, ZIP_PC); }
194
        ZIPI    op_brv(ZIPIMM imm) const
195
                { return op_mov(ZIPC_V, imm, ZIP_PC, ZIP_PC); }
196
        ZIPI    op_bv(ZIPIMM imm) const
197
                { return op_brv(imm); }
198
 
199
        ZIPI    op_clrf(ZIPCOND cnd, ZIPREG a) const
200
                { return op_xor(cnd, 0, a, a); }
201
        ZIPI    op_clrf(ZIPREG a) const
202
                { return op_xor(ZIPC_ALWAYS, 0, a, a); }
203
        ZIPI    op_halt(ZIPCOND c) const {
204
                return op_or(c, 0x10, ZIP_CC); }
205
        ZIPI    op_wait(ZIPCOND c) const {
206
                return op_or(c, 0x10, ZIP_CC); }
207
        ZIPI    op_halt(void) const {
208
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
209
        ZIPI    op_wait(void) const {
210
                return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); }
211
        ZIPI    op_busy(ZIPCOND c) const {
212
                return op_mov(c, -1, ZIP_PC, ZIP_PC); }
213
        ZIPI    op_busy(void) const {
214
                return op_mov(ZIPC_ALWAYS, -1, ZIP_PC, ZIP_PC); }
215
 
216
        ZIPI    op_rtu(void) const {
217
                return op_or(ZIPC_ALWAYS, 0x20, ZIP_CC); }
218
        ZIPI    op_rtu(ZIPCOND cnd) const {
219
                return op_or(cnd, 0x20, ZIP_CC); }
220
 
221
        ZIPI    op_jmp(ZIPCOND c, ZIPIMM imm, ZIPREG r) const
222
                { return op_mov(ZIPC_ALWAYS, imm, r, ZIP_PC); }
223
 
224
        ZIPI    op_ljmp(ZIPCOND c, ZIPIMM imm) const {
225
                return op_add(ZIPC_ALWAYS, imm, ZIP_PC); }
226
 
227
        ZIPI    op_not(ZIPCOND c, ZIPREG r) const
228
                { return op_xor(c, -1, r); }
229
        ZIPI    op_not(ZIPREG r) const
230
                { return op_xor(ZIPC_ALWAYS, -1, r); }
231
 
232
};
233
 
234
#endif

powered by: WebSVN 2.1.0

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