nppcset.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl and Carl Eric Codere
  4. Generate PowerPC assembler for in set/case nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nppcset;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,nset,ncgset,cpubase,cgbase,cgobj,aasmbase,aasmtai;
  23. type
  24. tppccasenode = class(tcgcasenode)
  25. protected
  26. procedure genlinearlist(hp : pcaselabel); override;
  27. end;
  28. implementation
  29. uses
  30. globtype,systems,
  31. verbose,globals,
  32. symconst,symdef,defutil,
  33. paramgr,
  34. cpuinfo,
  35. pass_2,cgcpu,
  36. ncon,
  37. tgobj,ncgutil,regvars,rgobj,aasmcpu;
  38. {*****************************************************************************
  39. TCGCASENODE
  40. *****************************************************************************}
  41. procedure tppccasenode.genlinearlist(hp : pcaselabel);
  42. var
  43. first, lastrange : boolean;
  44. last : TConstExprInt;
  45. procedure genitem(t : pcaselabel);
  46. procedure gensub(value:longint);
  47. var
  48. tmpreg: tregister;
  49. begin
  50. value := -value;
  51. if (value >= low(smallint)) and
  52. (value <= high(smallint)) then
  53. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDIC_,hregister,
  54. hregister,value))
  55. else
  56. begin
  57. tmpreg := cg.getintregister(exprasmlist,OS_INT);
  58. cg.a_load_const_reg(exprasmlist,OS_INT,value,tmpreg);
  59. exprasmlist.concat(taicpu.op_reg_reg_reg(A_ADD_,hregister,
  60. hregister,tmpreg));
  61. end;
  62. end;
  63. begin
  64. if assigned(t^.less) then
  65. genitem(t^.less);
  66. { need we to test the first value }
  67. if first and (t^._low>get_min_value(left.resulttype.def)) then
  68. begin
  69. cg.a_cmp_const_reg_label(exprasmlist,OS_INT,jmp_lt,aword(t^._low),hregister,elselabel);
  70. end;
  71. if t^._low=t^._high then
  72. begin
  73. if t^._low-last=0 then
  74. cg.a_cmp_const_reg_label(exprasmlist, opsize, OC_EQ,0,hregister,blocklabel(t^.blockid))
  75. else
  76. gensub(longint(t^._low-last));
  77. tcgppc(cg).a_jmp_cond(exprasmlist,OC_EQ,blocklabel(t^.blockid));
  78. last:=t^._low;
  79. lastrange := false;
  80. end
  81. else
  82. begin
  83. { it begins with the smallest label, if the value }
  84. { is even smaller then jump immediately to the }
  85. { ELSE-label }
  86. if first then
  87. begin
  88. { have we to ajust the first value ? }
  89. if (t^._low>get_min_value(left.resulttype.def)) then
  90. gensub(longint(t^._low));
  91. end
  92. else
  93. begin
  94. { if there is no unused label between the last and the }
  95. { present label then the lower limit can be checked }
  96. { immediately. else check the range in between: }
  97. gensub(longint(t^._low-last));
  98. if ((t^._low-last) <> 1) or
  99. (not lastrange) then
  100. tcgppc(cg).a_jmp_cond(exprasmlist,jmp_lt,elselabel);
  101. end;
  102. gensub(longint(t^._high-t^._low));
  103. tcgppc(cg).a_jmp_cond(exprasmlist,jmp_le,blocklabel(t^.blockid));
  104. last:=t^._high;
  105. lastrange := true;
  106. end;
  107. first:=false;
  108. if assigned(t^.greater) then
  109. genitem(t^.greater);
  110. end;
  111. begin
  112. { do we need to generate cmps? }
  113. if (with_sign and (min_label<0)) or
  114. (opsize = OS_32) then
  115. genlinearcmplist(hp)
  116. else
  117. begin
  118. last:=0;
  119. lastrange:=false;
  120. first:=true;
  121. genitem(hp);
  122. cg.a_jmp_always(exprasmlist,elselabel);
  123. end;
  124. end;
  125. begin
  126. ccasenode:=tppccasenode;
  127. end.
  128. {
  129. $Log$
  130. Revision 1.19 2005-03-25 21:55:43 jonas
  131. * removed some unused variables
  132. Revision 1.18 2005/02/14 17:13:10 peter
  133. * truncate log
  134. }