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

Subversion Repositories zipcpu

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

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
^"#line"[ \t]+[0-9]+[ \t]+["][^"]*["][ \t]*$ {
55
                yylineno = atoi(&yytext[6]);
56
                char    *bg, *en;
57
                bg = strchr(yytext, '\"')+1;
58
                en = strchr(bg, '\"'); *en = '\0';
59
                if ((master_input_filename == NULL)||(strcmp(master_input_filename, bg)!=0)) {
60
                        if (!master_input_filename) delete[] master_input_filename;
61
                        master_input_filename = new char[en-bg+2];
62
                        strcpy(master_input_filename, bg);
63
                }
64
                }
65
^"#line"[ \t]+[0-9]+[ \t]+$     { yylineno = atoi(&yytext[6]); }
66
[uU][rR]1[0-5]  { yylval.u_reg=(ZPARSER::ZIPREG)(26+yytext[3]-'0');return REG; }
67
[sS][rR]1[0-5]  { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[3]-'0');return REG; }
68
[rR]1[0-5]      { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[2]-'0');return REG; }
69
[uU][rR][0-9]   { yylval.u_reg=(ZPARSER::ZIPREG)(16+yytext[2]-'0');return REG; }
70
[sS][rR][0-9]   { yylval.u_reg=(ZPARSER::ZIPREG)(   yytext[2]-'0');return REG; }
71
[rR][0-9]       { yylval.u_reg=(ZPARSER::ZIPREG)(   yytext[1]-'0');return REG; }
72
[uU][pP][cC]    { yylval.u_reg = ZPARSER::ZIP_uPC; return REG; }
73
[sS][pP][cC]    { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
74
[pP][cC]        { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
75
[uU][cC][cC]    { yylval.u_reg = ZPARSER::ZIP_uCC; return REG; }
76
[sS][cC][cC]    { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
77
[cC][cC]        { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
78
[uU][sS][pP]    { yylval.u_reg = ZPARSER::ZIP_uSP; return REG; }
79
[sS][sS][pP]    { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
80
[sS][pP]        { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
81
[bB][rR][aA]    { yylval.u_op  = OP_BRA; return BRANCHOP; }
82
[bB][rR][zZ]    { yylval.u_op  = OP_BZ;  return BRANCHOP; }
83
[bB][zZ]        { yylval.u_op  = OP_BZ;  return BRANCHOP; }
84
[bB][nN][zZ]    { yylval.u_op  = OP_BNZ; return BRANCHOP; }
85
[bB][nN][eE]    { yylval.u_op  = OP_BNZ; return BRANCHOP; }
86
[bB][gG][eE]    { yylval.u_op  = OP_BGE; return BRANCHOP; }
87
[bB][gG][tT]    { yylval.u_op  = OP_BGT; return BRANCHOP; }
88
[bB][gG]        { yylval.u_op  = OP_BGT; return BRANCHOP; }
89
[bB][lL][tT]    { yylval.u_op  = OP_BLT; return BRANCHOP; }
90
[bB][nN]        { yylval.u_op  = OP_BLT; return BRANCHOP; }
91
[bB][rR][cC]    { yylval.u_op  = OP_BRC; return BRANCHOP; }
92
[bB][cC]        { yylval.u_op  = OP_BRC; return BRANCHOP; }
93
[bB][rR][vV]    { yylval.u_op  = OP_BRV; return BRANCHOP; }
94
[bB][vV]        { yylval.u_op  = OP_BRV; return BRANCHOP; }
95
[cC][lL][rR]    { yylval.u_op  = OP_CLR; return SINGLOP; }
96
[cC][lL][rR][fF] {yylval.u_op  = OP_CLRF;return SINGLOP; }
97
[iI][nN][tT]    { yylval.u_op  = OP_TRAP;return SINGLOP; }
98
[tT][rR][aA][pP] {yylval.u_op  = OP_TRAP;return SINGLOP; }
99
[jJ][mM][pP]    { yylval.u_op  = OP_JMP; return SINGLOP; }
100
[lL][jJ][mM][pP] {yylval.u_op  = OP_LJMP;return SINGLOP; }
101
[nN][oO][tT]    { yylval.u_op  = OP_NOT; return SINGLOP; }
102
[cC][mM][pP]    { yylval.u_op  = OP_CMP; return DUALOP; }
103
[tT][sS][tT]    { yylval.u_op  = OP_TST; return DUALOP; }
104
[mM][oO][vV]    { yylval.u_op  = OP_MOV; return DUALOP; }
105
[lL][dD][iI]    { yylval.u_op  = OP_LDI; return LDIOP; }
106
[lL][dD][iI][hH][iI]    { yylval.u_op =OP_LDIHI; return LDHLOP; }
107
[lL][dD][iI][lL][oO]    { yylval.u_op =OP_LDILO; return LDHLOP; }
108
[mM][pP][yY]    { yylval.u_op  = OP_MPY; return DUALOP; }
109
[rR][oO][lL]    { yylval.u_op  = OP_ROL; return DUALOP; }
110
[sS][uU][bB]    { yylval.u_op  = OP_SUB; return DUALOP; }
111
[aA][nN][dD]    { yylval.u_op  = OP_AND; return DUALOP; }
112
[aA][dD][dD]    { yylval.u_op  = OP_ADD; return DUALOP; }
113
[oO][rR]        { yylval.u_op  = OP_OR; return DUALOP;; }
114
[xX][oO][rR]    { yylval.u_op  = OP_XOR; return DUALOP; }
115
[lL][sS][lL]    { yylval.u_op  = OP_LSL; return DUALOP; }
116
[aA][sS][rR]    { yylval.u_op  = OP_ASR; return DUALOP; }
117
[lL][sS][rR]    { yylval.u_op  = OP_LSR; return DUALOP; }
118
[lL][oO][dD]            { yylval.u_op = OP_LOD;   return LOADOP; }
119
[sS][tT][oO]            { yylval.u_op = OP_STO;   return STOROP; }
120
[hH][aA][lL][tT]        { yylval.u_op = OP_HALT;  return BAREOP;  }
121
[wW][aA][iI][tT]        { yylval.u_op = OP_HALT;  return BAREOP;  }
122
[rR][tT][uU]            { yylval.u_op = OP_RTU;   return BAREOP;  }
123
[nN][oO][pP]            { yylval.u_op = OP_NOOP;  return BAREOP; }
124
[nN][oO][oO][pP]        { yylval.u_op = OP_NOOP;  return BAREOP; }
125
[bB][rR][eE][aA][kK]    { yylval.u_op = OP_BREAK; return BAREOP; }
126
[bB][rR][kK]            { yylval.u_op = OP_BREAK; return BAREOP; }
127
[bB][uU][sS][yY]        { yylval.u_op = OP_BUSY;  return BAREOP; }
128
[eE][qQ][uU]            { return EQU; }
129
[fF][iI][lL][lL]        { return FILL; }
130
[wW][oO][rR][dD]        { return WORD; }
131
"__"[hH][eE][rR][eE]"__" { return HERE; }
132
[\.][dD][aA][tT] { return WORD; }
133
[\.][zZ]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_Z; return COND; }
134
[\.][nN][eE]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
135
[\.][nN][zZ]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
136
[\.][gG][eE]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_GE; return COND; }
137
[\.][gG][tT]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_GT; return COND; }
138
[\.][lL][tT]/[ \t\n]    { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
139
[\.][nN]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
140
[\.][cC]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_C; return COND; }
141
[\.][vV]/[ \t\n]        { yylval.u_cond = ZPARSER::ZIPC_V; return COND; }
142
[_A-Za-z][_a-zA-Z0-9]* { yylval.u_id  = strdup(yytext); return IDENTIFIER; }
143
"$"?[-]?0[xX][0-9A-Fa-f]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16);return INT;}
144
"$"?[-]?0[0-7]+           { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
145
"$"?[-]?[1-9][0-9]*       { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,10);return INT;}
146
"$"?[-]?[1-9A-Fa-f][0-9A-Fa-f]*h {yylval.u_ival=strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16); return INT;}
147
"$"?[-]?[0-7]+o           { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
148
"$"?"0"           { yylval.u_ival = 0;return INT;}
149
"$"             { return DOLLAR; }
150
","             { return COMMA; }
151
"+"             { return PLUS; }
152
"-"             { return MINUS; }
153
"*"             { return TIMES; }
154
"||"            { return BOOLEANOR; }
155
"|"             { return BITWISEOR; }
156
"&&"		{ return BOOLEANAND; }
157
"&"		{ return BITWISEAND; }
158
"^"             { return BITWISEXOR; }
159
":"             { return COLON; }
160
"."             { return DOT; }
161
[ \t]+          { }
162
[(]             { return '('; }
163
[)]             { return ')'; }
164
\n.*            { if (linecp) free(linecp); linecp = strdup(&yytext[1]); yyless(1); return '\n'; }
165
 
166
%%
167
 

powered by: WebSVN 2.1.0

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