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

Subversion Repositories diogenes

[/] [diogenes/] [trunk/] [asm/] [lex.in] - Blame information for rev 236

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 146 fellnhofer
%option noyywrap
2
 
3
%{
4
 
5
#include 
6
#include 
7
#include "tools.h"
8
 
9
#include "y.tab.h"
10
 
11
%}
12
 
13
 
14
W               [ \t\r\n]+
15
NL              [\n]+
16
COMMENT         "@"[^\n]*"\n"
17
IMM             ("0x"([0-9a-fA-F]+))|([-]?[0-9]+)
18
REG             "l"[0-7]|"h"[0-7]
19
OBRA    \[
20
CBRA    \]
21
OSBRA   \<
22
CSBRA   \>
23
C               \,
24
 
25
LABEL   ([_0-9a-zA-Z]+)":"
26
USELAB  ":"([_0-9a-zA-Z]+)
27
 
28
NOP             "nop"|"stop"
29
LDL             "LDL"
30
ARI             "add"|"sub"|"or"|"and"|"xor"|"sh"
31
LDI             "ldi"
32
LSI             "lsi"
33
SHA             "shi"|"shit"|"adi"|"adit"
34
CMP             "cmpl"|"cmpls"
35
BR              "brz"|"brnz"
36
JUMP    "jump"
37
CALL    "call"
38
MOV             "mov"
39
MEM             "ld"|"st"|"ldio"|"stio"
40
SEL             "seh"|"seb"
41
SELI    "seib"|"seih"|"seibs"|"seihs"
42
 
43
%%
44
{C}             {return C;}
45
{OBRA}  {return OBRA;}
46
{CBRA}  {return CBRA;}
47
{OSBRA} {return OSBRA;}
48
{CSBRA} {return CSBRA;}
49
{LDL}   {return LDL;}
50
{NOP}   { if (!strcmp(yytext, "stop")) yylval.num=0xffff;
51
          else yylval.num = 0xe000;
52
          return NOP;
53
        }
54
{USELAB} {yylval.str=strdup(yytext+1); return USELAB;}
55
{LABEL} {yylval.str=strdup(yytext); yylval.str[strlen(yytext)-1] = 0; return LABEL;}
56
{IMM}   {
57
                //if(yytext[0]=='\'') {
58
                //      yytext[strlen(yytext)-1]=' ';
59
                //}
60
                //yytext[0] = ' ';
61
                yylval.str = (char *) strdup(yytext);
62
                return IMM;}
63
{REG}   {
64
                //yylval.str=strdup(yytext);
65
                yylval.num=atoi(yytext+1);
66
                if(yytext[0]=='h') yylval.num+=8;
67
                return REG;}
68
 
69
{ARI}   {
70
                        if(!strcmp(str_toupper(yytext),"ADD")) yylval.num=0x00;
71
                        else if(!strcmp(str_toupper(yytext),"SUB")) yylval.num=0x01;
72
                        else if(!strcmp(str_toupper(yytext),"AND")) yylval.num=0x02;
73
                        else if(!strcmp(str_toupper(yytext),"OR")) yylval.num=0x03;
74
                        else if(!strcmp(str_toupper(yytext),"XOR")) yylval.num=0x04;
75
                        else if(!strcmp(str_toupper(yytext),"SH")) yylval.num=0x05;
76
 
77
                        return ARI;
78
                }
79
{CMP}   {
80
                  if(!strcmp(str_toupper(yytext),"CMPL")) yylval.num=0x00;
81
                  else if(!strcmp(str_toupper(yytext),"CMPLS")) yylval.num=0x01;
82
                  //else if(!strcmp(str_toupper(yytext),"CMPG")) yylval.num=0x02;
83
                  //else if(!strcmp(str_toupper(yytext),"CMPGS")) yylval.num=0x03;
84
                  return CMP;
85
                }
86
{JUMP}  { yylval.num=0; return JUMP; }
87
{CALL}  { yylval.num=8; return CALL; }
88
{MOV}   { yylval.num=1; return MOV; }
89
{MEM}   {
90
                        if(!strcmp(yytext,"ld")) yylval.num=2;
91
                        else if(!strcmp(yytext,"st")) yylval.num=3;
92
                        else if(!strcmp(yytext,"ldio")) yylval.num=10;
93
                        else if(!strcmp(yytext,"stio")) yylval.num=11;
94
                        return MEM;
95
                }
96
{SEL}   {
97
                        if(!strcmp(yytext,"seh")) yylval.num=4;
98
                        else if(!strcmp(yytext,"seb")) yylval.num=5;
99
                        return SEL;
100
                }
101
{SELI}  {
102
                        if(!strcmp(yytext,"seib")) yylval.num=0x06;
103
                        else if(!strcmp(yytext,"seih")) yylval.num=0x16;
104
                        else if(!strcmp(yytext,"seibs")) yylval.num=0x26;
105
                        else if(!strcmp(yytext,"seihs")) yylval.num=0x36;
106
                        return SELI;
107
                }
108
{LDI}   {
109
                        return LDI;
110
                }
111
{LSI}   {
112
                        return LSI;
113
                }
114
{BR}    {
115
                        if(toupper(yytext[2])=='N') yylval.num = 1;
116
                        else if(toupper(yytext[2])=='Z') yylval.num = 0;
117
                        return BR;
118
                }
119
{SHA}   {
120
                        if(toupper(yytext[0])=='A') yylval.num = 0;
121
                        else yylval.num = 1;
122
                        return SHA;
123
                }
124
{COMMENT}       /* remove comment */
125
{W}             /* remove ws */
126
 
127
%%
128
 
129
void PROC_FLUSH_BUF ( FILE * xFile )
130
{
131
        yy_delete_buffer ( YY_CURRENT_BUFFER );
132
                yy_init_globals();
133
        yy_switch_to_buffer ( yy_create_buffer ( xFile, YY_BUF_SIZE ) );
134
}
135
 
136
 
137
//void main() { while(yylex()); }
138
 

powered by: WebSVN 2.1.0

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