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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zasm.l] - Blame information for rev 34

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

Line No. Rev Author Line
1 13 dgisselq
/*******************************************************************************
2
**
3
** Filename:    zasm.l
4
**
5
** Project:     Zip CPU -- a small, lightweight, RISC CPU core
6
**
7
** Purpose:     The lexical analyzer for the assembler.  This converts assembler
8
**              input into tokens, to feed the parser.
9
**
10
**
11
** Creator:     Dan Gisselquist, Ph.D.
12
**              Gisselquist Tecnology, LLC
13
**
14
********************************************************************************
15
**
16
** Copyright (C) 2015, Gisselquist Technology, LLC
17
**
18
** This program is free software (firmware): you can redistribute it and/or
19
** modify it under the terms of  the GNU General Public License as published
20
** by the Free Software Foundation, either version 3 of the License, or (at
21
** your option) any later version.
22
**
23
** This program is distributed in the hope that it will be useful, but WITHOUT
24
** ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
** FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
** for more details.
27
**
28
** You should have received a copy of the GNU General Public License along
29
** with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
** target there if the PDF file isn't present.)  If not, see
31
**  for a copy.
32
**
33
** License:     GPL, v3, as defined and found on www.gnu.org,
34
**              http://www.gnu.org/licenses/gpl.html
35
**
36
**
37
*******************************************************************************/
38
 
39
%{
40
#include 
41
#include "asmdata.h"
42
#include "zasm.tab.h"
43
 
44
extern "C" int yylex();
45
extern "C" int  yywrap() { return 1;}
46
extern  char *master_input_filename;
47
%}
48
 
49
%option yylineno
50
%option warn
51
 
52
%%
53
 
54 26 dgisselq
"#line"[ \t]+[0-9]+[ \t]+[\"][^"]*[\"][ \t]*$ {
55
        /* This should really be true *only* at the beginning of a line,
56
        * however such line beginnings aren't matching.  My guess is that
57
        * the reason is my line copying code at the bottom that sucks up the
58
        * newline for LEX.  Hence, this is what we have.
59
        */
60 13 dgisselq
                yylineno = atoi(&yytext[6]);
61
                char    *bg, *en;
62
                bg = strchr(yytext, '\"')+1;
63
                en = strchr(bg, '\"'); *en = '\0';
64
                if ((master_input_filename == NULL)||(strcmp(master_input_filename, bg)!=0)) {
65
                        if (!master_input_filename) delete[] master_input_filename;
66
                        master_input_filename = new char[en-bg+2];
67
                        strcpy(master_input_filename, bg);
68
                }
69 26 dgisselq
                return '\n';
70 13 dgisselq
                }
71 26 dgisselq
"#line"[ \t]+[0-9]+[ \t]*$      { yylineno = atoi(&yytext[6]); return '\n';}
72
^"#line".*$             { printf("WARNING: Unmatched #line: %s\n", yytext); return '\n'; }
73
"#line".*$              { printf("WARNING: Unmatched #line, not at beginnning: %s\n", yytext); return '\n'; }
74 13 dgisselq
[uU][rR]1[0-5]  { yylval.u_reg=(ZPARSER::ZIPREG)(26+yytext[3]-'0');return REG; }
75
[sS][rR]1[0-5]  { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[3]-'0');return REG; }
76
[rR]1[0-5]      { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[2]-'0');return REG; }
77
[uU][rR][0-9]   { yylval.u_reg=(ZPARSER::ZIPREG)(16+yytext[2]-'0');return REG; }
78
[sS][rR][0-9]   { yylval.u_reg=(ZPARSER::ZIPREG)(   yytext[2]-'0');return REG; }
79
[rR][0-9]       { yylval.u_reg=(ZPARSER::ZIPREG)(   yytext[1]-'0');return REG; }
80 26 dgisselq
(?i:upc)        { yylval.u_reg = ZPARSER::ZIP_uPC; return REG; }
81
(?i:spc)        { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
82
(?i:pc)         { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
83
(?i:ucc)        { yylval.u_reg = ZPARSER::ZIP_uCC; return REG; }
84
(?i:scc)        { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
85
(?i:cc)         { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
86
(?i:usp)        { yylval.u_reg = ZPARSER::ZIP_uSP; return REG; }
87
(?i:ssp)        { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
88
(?i:sp)         { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
89 13 dgisselq
[bB][rR][aA]    { yylval.u_op  = OP_BRA; return BRANCHOP; }
90
[bB][rR][zZ]    { yylval.u_op  = OP_BZ;  return BRANCHOP; }
91
[bB][zZ]        { yylval.u_op  = OP_BZ;  return BRANCHOP; }
92
[bB][nN][zZ]    { yylval.u_op  = OP_BNZ; return BRANCHOP; }
93
[bB][nN][eE]    { yylval.u_op  = OP_BNZ; return BRANCHOP; }
94
[bB][gG][eE]    { yylval.u_op  = OP_BGE; return BRANCHOP; }
95
[bB][gG][tT]    { yylval.u_op  = OP_BGT; return BRANCHOP; }
96
[bB][gG]        { yylval.u_op  = OP_BGT; return BRANCHOP; }
97
[bB][lL][tT]    { yylval.u_op  = OP_BLT; return BRANCHOP; }
98
[bB][nN]        { yylval.u_op  = OP_BLT; return BRANCHOP; }
99
[bB][rR][cC]    { yylval.u_op  = OP_BRC; return BRANCHOP; }
100
[bB][cC]        { yylval.u_op  = OP_BRC; return BRANCHOP; }
101
[bB][rR][vV]    { yylval.u_op  = OP_BRV; return BRANCHOP; }
102
[bB][vV]        { yylval.u_op  = OP_BRV; return BRANCHOP; }
103 26 dgisselq
(?i:clr)        { yylval.u_op  = OP_CLR; return SINGLOP; }
104
(?i:clrf)       {yylval.u_op  = OP_CLRF;return SINGLOP; }
105
(?i:int)        { yylval.u_op  = OP_TRAP;return SINGLOP; }
106
(?i:trap)       {yylval.u_op  = OP_TRAP;return SINGLOP; }
107
(?i:jmp)        { yylval.u_op  = OP_JMP; return SINGLOP; }
108 13 dgisselq
[lL][jJ][mM][pP] {yylval.u_op  = OP_LJMP;return SINGLOP; }
109 26 dgisselq
(?i:neg)        { yylval.u_op  = OP_NEG; return SINGLOP; }
110
(?i:not)        { yylval.u_op  = OP_NOT; return SINGLOP; }
111
(?i:cmp)        { yylval.u_op  = OP_CMP; return DUALOP; }
112
(?i:tst)        { yylval.u_op  = OP_TST; return DUALOP; }
113
(?i:mov)        { yylval.u_op  = OP_MOV; return DUALOP; }
114
(?i:ldi)        { yylval.u_op  = OP_LDI; return LDIOP; }
115 13 dgisselq
[lL][dD][iI][hH][iI]    { yylval.u_op =OP_LDIHI; return LDHLOP; }
116
[lL][dD][iI][lL][oO]    { yylval.u_op =OP_LDILO; return LDHLOP; }
117 26 dgisselq
(?i:mpyu)       { yylval.u_op = OP_MPYU; return DUALOP; }
118
(?i:mpys)       { yylval.u_op = OP_MPYS; return DUALOP; }
119
(?i:rol)        { yylval.u_op  = OP_ROL; return DUALOP; }
120
(?i:sub)        { yylval.u_op  = OP_SUB; return DUALOP; }
121
(?i:and)        { yylval.u_op  = OP_AND; return DUALOP; }
122
(?i:add)        { yylval.u_op  = OP_ADD; return DUALOP; }
123
(?i:or)         { yylval.u_op  = OP_OR; return DUALOP;; }
124
(?i:xor)        { yylval.u_op  = OP_XOR; return DUALOP; }
125
(?i:lsl)        { yylval.u_op  = OP_LSL; return DUALOP; }
126
(?i:asr)        { yylval.u_op  = OP_ASR; return DUALOP; }
127
(?i:lsr)        { yylval.u_op  = OP_LSR; return DUALOP; }
128
(?i:lod)        { yylval.u_op = OP_LOD;   return LOADOP; }
129
(?i:sto)        { yylval.u_op = OP_STO;   return STOROP; }
130
(?i:halt)       { yylval.u_op = OP_HALT;  return BAREOP;  }
131
(?i:wait)       { yylval.u_op = OP_HALT;  return BAREOP;  }
132
(?i:rtu)        { yylval.u_op = OP_RTU;   return BAREOP;  }
133
(?i:nop)        { yylval.u_op = OP_NOOP;  return BAREOP; }
134
(?i:noop)       { yylval.u_op = OP_NOOP;  return BAREOP; }
135
(?i:break)      { yylval.u_op = OP_BREAK; return BAREOP; }
136
(?i:brk)        { yylval.u_op = OP_BREAK; return BAREOP; }
137
(?i:busy)       { yylval.u_op = OP_BUSY;  return BAREOP; }
138
(?i:equ)        { return EQU; }
139
(?i:fill)       { return FILL; }
140
(?i:word)       { return WORD; }
141 13 dgisselq
"__"[hH][eE][rR][eE]"__" { return HERE; }
142
[\.][dD][aA][tT] { return WORD; }
143
[\.][zZ]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_Z; return COND; }
144
[\.][nN][eE]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
145
[\.][nN][zZ]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
146
[\.][gG][eE]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_GE; return COND; }
147
[\.][gG][tT]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_GT; return COND; }
148
[\.][lL][tT]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
149
[\.][nN]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
150
[\.][cC]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_C; return COND; }
151
[\.][vV]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_V; return COND; }
152
[_A-Za-z][_a-zA-Z0-9]* { yylval.u_id  = strdup(yytext); return IDENTIFIER; }
153
"$"?[-]?0[xX][0-9A-Fa-f]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16);return INT;}
154
"$"?[-]?0[0-7]+           { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
155
"$"?[-]?[1-9][0-9]*       { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,10);return INT;}
156
"$"?[-]?[1-9A-Fa-f][0-9A-Fa-f]*h {yylval.u_ival=strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16); return INT;}
157
"$"?[-]?[0-7]+o           { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
158 26 dgisselq
"\'"[^\\\']"\'"         { printf("Match char, %s\n", yytext); yylval.u_ival = yytext[1]&0x0ff; return INT; }
159
"\'\\"[abnr\\]"\'"              {
160
                yylval.u_ival = yytext[2];
161
                if (yytext[2] == 'a') yylval.u_ival = '\a';
162
                else if (yytext[2] == 'b') yylval.u_ival = '\b';
163
                else if (yytext[2] == 'f') yylval.u_ival = '\f';
164
                else if (yytext[2] == 'n') yylval.u_ival = '\n';
165
                else if (yytext[2] == 'r') yylval.u_ival = '\r';
166
                else if (yytext[2] == 't') yylval.u_ival = '\t';
167
                else if (yytext[2] == 'v') yylval.u_ival = '\v';
168
                else if (yytext[2] == '0') yylval.u_ival = '\0';
169
                else if (yytext[2] == '\\') yylval.u_ival = '\\';
170
                return INT; }
171
"\'"[^\\\'][^\\\']"\'"          { yylval.u_ival = ((yytext[1]&0x0ff)<<8)+(yytext[2]&0x0ff); return INT; }
172
"\'"[^\\\'][^\\\'][^\\\']"\'"           { yylval.u_ival = ((yytext[1]&0x0ff)<<16)
173
                                        +((yytext[2]&0x0ff)<<8)
174
                                        +(yytext[3]&0x0ff); return INT; }
175
"\'"[^\\\'][^\\\'][^\\\'][^\\\']"\'"    { yylval.u_ival = ((yytext[1]&0x0ff)<<24)
176
                                        +((yytext[2]&0x0ff)<<16)
177
                                        +((yytext[3]&0x0ff)<<8)
178
                                        +(yytext[4]&0x0ff); return INT; }
179 13 dgisselq
"$"?"0"           { yylval.u_ival = 0;return INT;}
180
"$"             { return DOLLAR; }
181
","             { return COMMA; }
182
"+"             { return PLUS; }
183
"-"             { return MINUS; }
184
"*"             { return TIMES; }
185
"||"            { return BOOLEANOR; }
186
"|"             { return BITWISEOR; }
187
"&&"		{ return BOOLEANAND; }
188
"&"		{ return BITWISEAND; }
189
"^"             { return BITWISEXOR; }
190
":"             { return COLON; }
191
"."             { return DOT; }
192 34 dgisselq
"%"             { return '%'; }
193 13 dgisselq
[ \t]+          { }
194
[(]             { return '('; }
195
[)]             { return ')'; }
196
\n.*            { if (linecp) free(linecp); linecp = strdup(&yytext[1]); yyless(1); return '\n'; }
197
 
198
%%
199
 

powered by: WebSVN 2.1.0

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