gotablish.cpp 3.2 KB

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