1 /*
2 * Copyright 2001-2006 Adrian Thurston <thurston@complang.org>
3 * 2004 Erich Ocean <eric.ocean@ampede.com>
4 * 2005 Alan West <alan@alanz.com>
5 */
6
7 /* This file is part of Ragel.
8 *
9 * Ragel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * Ragel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Ragel; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "ragel.h"
25 #include "gotablish.h"
26
27 using std::endl;
28
GOTO(ostream & ret,int gotoDest,bool inFinish)29 void GoTablishCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
30 {
31 ret << vCS() << " = " << gotoDest << endl <<
32 "goto _again" << endl;
33 }
34
GOTO_EXPR(ostream & ret,GenInlineItem * ilItem,bool inFinish)35 void GoTablishCodeGen::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
36 {
37 ret << vCS() << " = (";
38 INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
39 ret << ")" << endl << "goto _again" << endl;
40 }
41
CURS(ostream & ret,bool inFinish)42 void GoTablishCodeGen::CURS( ostream &ret, bool inFinish )
43 {
44 ret << "(_ps)";
45 }
46
TARGS(ostream & ret,bool inFinish,int targState)47 void GoTablishCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
48 {
49 ret << "(" << vCS() << ")";
50 }
51
NEXT(ostream & ret,int nextDest,bool inFinish)52 void GoTablishCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
53 {
54 ret << vCS() << " = " << nextDest << endl;
55 }
56
NEXT_EXPR(ostream & ret,GenInlineItem * ilItem,bool inFinish)57 void GoTablishCodeGen::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
58 {
59 ret << vCS() << " = (";
60 INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
61 ret << ")" << endl;
62 }
63
CALL(ostream & ret,int callDest,int targState,bool inFinish)64 void GoTablishCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
65 {
66 if ( prePushExpr != 0 ) {
67 ret << "{ ";
68 INLINE_LIST( ret, prePushExpr, 0, false, false );
69 }
70
71 ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " << TOP() << "++; " <<
72 vCS() << " = " << callDest << "; " << "goto _again" << endl;
73
74 if ( prePushExpr != 0 )
75 ret << " }";
76 }
77
CALL_EXPR(ostream & ret,GenInlineItem * ilItem,int targState,bool inFinish)78 void GoTablishCodeGen::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish )
79 {
80 if ( prePushExpr != 0 ) {
81 ret << "{";
82 INLINE_LIST( ret, prePushExpr, 0, false, false );
83 }
84
85 ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " << TOP() << "++; " << vCS() << " = (";
86 INLINE_LIST( ret, ilItem->children, targState, inFinish, false );
87 ret << "); " << "goto _again" << endl;
88
89 if ( prePushExpr != 0 )
90 ret << "}";
91 }
92
RET(ostream & ret,bool inFinish)93 void GoTablishCodeGen::RET( ostream &ret, bool inFinish )
94 {
95 ret << TOP() << "--; " << vCS() << " = " << STACK() << "[" <<
96 TOP() << "]" << endl;
97
98 if ( postPopExpr != 0 ) {
99 ret << "{ ";
100 INLINE_LIST( ret, postPopExpr, 0, false, false );
101 ret << " }" << endl;
102 }
103
104 ret << "goto _again" << endl;
105 }
106
BREAK(ostream & ret,int targState,bool csForced)107 void GoTablishCodeGen::BREAK( ostream &ret, int targState, bool csForced )
108 {
109 outLabelUsed = true;
110 ret << P() << "++; " << "goto _out" << endl;
111 }
112