libv8-sgonyea 3.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (500) hide show
  1. data/.gitignore +8 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +4 -0
  4. data/README.md +76 -0
  5. data/Rakefile +113 -0
  6. data/ext/libv8/extconf.rb +28 -0
  7. data/lib/libv8.rb +15 -0
  8. data/lib/libv8/Makefile +30 -0
  9. data/lib/libv8/detect_cpu.rb +27 -0
  10. data/lib/libv8/fpic-on-linux-amd64.patch +13 -0
  11. data/lib/libv8/v8/.gitignore +35 -0
  12. data/lib/libv8/v8/AUTHORS +44 -0
  13. data/lib/libv8/v8/ChangeLog +2839 -0
  14. data/lib/libv8/v8/LICENSE +52 -0
  15. data/lib/libv8/v8/LICENSE.strongtalk +29 -0
  16. data/lib/libv8/v8/LICENSE.v8 +26 -0
  17. data/lib/libv8/v8/LICENSE.valgrind +45 -0
  18. data/lib/libv8/v8/SConstruct +1478 -0
  19. data/lib/libv8/v8/build/README.txt +49 -0
  20. data/lib/libv8/v8/build/all.gyp +18 -0
  21. data/lib/libv8/v8/build/armu.gypi +32 -0
  22. data/lib/libv8/v8/build/common.gypi +144 -0
  23. data/lib/libv8/v8/build/gyp_v8 +145 -0
  24. data/lib/libv8/v8/include/v8-debug.h +395 -0
  25. data/lib/libv8/v8/include/v8-preparser.h +117 -0
  26. data/lib/libv8/v8/include/v8-profiler.h +505 -0
  27. data/lib/libv8/v8/include/v8-testing.h +104 -0
  28. data/lib/libv8/v8/include/v8.h +4124 -0
  29. data/lib/libv8/v8/include/v8stdint.h +53 -0
  30. data/lib/libv8/v8/preparser/SConscript +38 -0
  31. data/lib/libv8/v8/preparser/preparser-process.cc +379 -0
  32. data/lib/libv8/v8/src/SConscript +368 -0
  33. data/lib/libv8/v8/src/accessors.cc +767 -0
  34. data/lib/libv8/v8/src/accessors.h +123 -0
  35. data/lib/libv8/v8/src/allocation-inl.h +49 -0
  36. data/lib/libv8/v8/src/allocation.cc +122 -0
  37. data/lib/libv8/v8/src/allocation.h +143 -0
  38. data/lib/libv8/v8/src/api.cc +5845 -0
  39. data/lib/libv8/v8/src/api.h +574 -0
  40. data/lib/libv8/v8/src/apinatives.js +110 -0
  41. data/lib/libv8/v8/src/apiutils.h +73 -0
  42. data/lib/libv8/v8/src/arguments.h +118 -0
  43. data/lib/libv8/v8/src/arm/assembler-arm-inl.h +353 -0
  44. data/lib/libv8/v8/src/arm/assembler-arm.cc +2661 -0
  45. data/lib/libv8/v8/src/arm/assembler-arm.h +1375 -0
  46. data/lib/libv8/v8/src/arm/builtins-arm.cc +1658 -0
  47. data/lib/libv8/v8/src/arm/code-stubs-arm.cc +6398 -0
  48. data/lib/libv8/v8/src/arm/code-stubs-arm.h +673 -0
  49. data/lib/libv8/v8/src/arm/codegen-arm.cc +52 -0
  50. data/lib/libv8/v8/src/arm/codegen-arm.h +91 -0
  51. data/lib/libv8/v8/src/arm/constants-arm.cc +152 -0
  52. data/lib/libv8/v8/src/arm/constants-arm.h +775 -0
  53. data/lib/libv8/v8/src/arm/cpu-arm.cc +120 -0
  54. data/lib/libv8/v8/src/arm/debug-arm.cc +317 -0
  55. data/lib/libv8/v8/src/arm/deoptimizer-arm.cc +754 -0
  56. data/lib/libv8/v8/src/arm/disasm-arm.cc +1506 -0
  57. data/lib/libv8/v8/src/arm/frames-arm.cc +45 -0
  58. data/lib/libv8/v8/src/arm/frames-arm.h +168 -0
  59. data/lib/libv8/v8/src/arm/full-codegen-arm.cc +4375 -0
  60. data/lib/libv8/v8/src/arm/ic-arm.cc +1562 -0
  61. data/lib/libv8/v8/src/arm/lithium-arm.cc +2206 -0
  62. data/lib/libv8/v8/src/arm/lithium-arm.h +2348 -0
  63. data/lib/libv8/v8/src/arm/lithium-codegen-arm.cc +4526 -0
  64. data/lib/libv8/v8/src/arm/lithium-codegen-arm.h +403 -0
  65. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.cc +305 -0
  66. data/lib/libv8/v8/src/arm/lithium-gap-resolver-arm.h +84 -0
  67. data/lib/libv8/v8/src/arm/macro-assembler-arm.cc +3163 -0
  68. data/lib/libv8/v8/src/arm/macro-assembler-arm.h +1126 -0
  69. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.cc +1287 -0
  70. data/lib/libv8/v8/src/arm/regexp-macro-assembler-arm.h +253 -0
  71. data/lib/libv8/v8/src/arm/simulator-arm.cc +3424 -0
  72. data/lib/libv8/v8/src/arm/simulator-arm.h +431 -0
  73. data/lib/libv8/v8/src/arm/stub-cache-arm.cc +4243 -0
  74. data/lib/libv8/v8/src/array.js +1366 -0
  75. data/lib/libv8/v8/src/assembler.cc +1207 -0
  76. data/lib/libv8/v8/src/assembler.h +858 -0
  77. data/lib/libv8/v8/src/ast-inl.h +112 -0
  78. data/lib/libv8/v8/src/ast.cc +1146 -0
  79. data/lib/libv8/v8/src/ast.h +2188 -0
  80. data/lib/libv8/v8/src/atomicops.h +167 -0
  81. data/lib/libv8/v8/src/atomicops_internals_arm_gcc.h +145 -0
  82. data/lib/libv8/v8/src/atomicops_internals_mips_gcc.h +169 -0
  83. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.cc +133 -0
  84. data/lib/libv8/v8/src/atomicops_internals_x86_gcc.h +287 -0
  85. data/lib/libv8/v8/src/atomicops_internals_x86_macosx.h +301 -0
  86. data/lib/libv8/v8/src/atomicops_internals_x86_msvc.h +203 -0
  87. data/lib/libv8/v8/src/bignum-dtoa.cc +655 -0
  88. data/lib/libv8/v8/src/bignum-dtoa.h +81 -0
  89. data/lib/libv8/v8/src/bignum.cc +768 -0
  90. data/lib/libv8/v8/src/bignum.h +140 -0
  91. data/lib/libv8/v8/src/bootstrapper.cc +2184 -0
  92. data/lib/libv8/v8/src/bootstrapper.h +188 -0
  93. data/lib/libv8/v8/src/builtins.cc +1707 -0
  94. data/lib/libv8/v8/src/builtins.h +371 -0
  95. data/lib/libv8/v8/src/bytecodes-irregexp.h +105 -0
  96. data/lib/libv8/v8/src/cached-powers.cc +177 -0
  97. data/lib/libv8/v8/src/cached-powers.h +65 -0
  98. data/lib/libv8/v8/src/char-predicates-inl.h +94 -0
  99. data/lib/libv8/v8/src/char-predicates.h +67 -0
  100. data/lib/libv8/v8/src/checks.cc +110 -0
  101. data/lib/libv8/v8/src/checks.h +296 -0
  102. data/lib/libv8/v8/src/circular-queue-inl.h +53 -0
  103. data/lib/libv8/v8/src/circular-queue.cc +122 -0
  104. data/lib/libv8/v8/src/circular-queue.h +103 -0
  105. data/lib/libv8/v8/src/code-stubs.cc +267 -0
  106. data/lib/libv8/v8/src/code-stubs.h +1011 -0
  107. data/lib/libv8/v8/src/code.h +70 -0
  108. data/lib/libv8/v8/src/codegen.cc +231 -0
  109. data/lib/libv8/v8/src/codegen.h +84 -0
  110. data/lib/libv8/v8/src/compilation-cache.cc +540 -0
  111. data/lib/libv8/v8/src/compilation-cache.h +287 -0
  112. data/lib/libv8/v8/src/compiler.cc +786 -0
  113. data/lib/libv8/v8/src/compiler.h +312 -0
  114. data/lib/libv8/v8/src/contexts.cc +347 -0
  115. data/lib/libv8/v8/src/contexts.h +391 -0
  116. data/lib/libv8/v8/src/conversions-inl.h +106 -0
  117. data/lib/libv8/v8/src/conversions.cc +1131 -0
  118. data/lib/libv8/v8/src/conversions.h +135 -0
  119. data/lib/libv8/v8/src/counters.cc +93 -0
  120. data/lib/libv8/v8/src/counters.h +254 -0
  121. data/lib/libv8/v8/src/cpu-profiler-inl.h +101 -0
  122. data/lib/libv8/v8/src/cpu-profiler.cc +609 -0
  123. data/lib/libv8/v8/src/cpu-profiler.h +302 -0
  124. data/lib/libv8/v8/src/cpu.h +69 -0
  125. data/lib/libv8/v8/src/d8-debug.cc +367 -0
  126. data/lib/libv8/v8/src/d8-debug.h +158 -0
  127. data/lib/libv8/v8/src/d8-posix.cc +695 -0
  128. data/lib/libv8/v8/src/d8-readline.cc +130 -0
  129. data/lib/libv8/v8/src/d8-windows.cc +42 -0
  130. data/lib/libv8/v8/src/d8.cc +803 -0
  131. data/lib/libv8/v8/src/d8.gyp +91 -0
  132. data/lib/libv8/v8/src/d8.h +235 -0
  133. data/lib/libv8/v8/src/d8.js +2798 -0
  134. data/lib/libv8/v8/src/data-flow.cc +66 -0
  135. data/lib/libv8/v8/src/data-flow.h +205 -0
  136. data/lib/libv8/v8/src/date.js +1103 -0
  137. data/lib/libv8/v8/src/dateparser-inl.h +127 -0
  138. data/lib/libv8/v8/src/dateparser.cc +178 -0
  139. data/lib/libv8/v8/src/dateparser.h +266 -0
  140. data/lib/libv8/v8/src/debug-agent.cc +447 -0
  141. data/lib/libv8/v8/src/debug-agent.h +129 -0
  142. data/lib/libv8/v8/src/debug-debugger.js +2569 -0
  143. data/lib/libv8/v8/src/debug.cc +3165 -0
  144. data/lib/libv8/v8/src/debug.h +1057 -0
  145. data/lib/libv8/v8/src/deoptimizer.cc +1256 -0
  146. data/lib/libv8/v8/src/deoptimizer.h +602 -0
  147. data/lib/libv8/v8/src/disasm.h +80 -0
  148. data/lib/libv8/v8/src/disassembler.cc +343 -0
  149. data/lib/libv8/v8/src/disassembler.h +58 -0
  150. data/lib/libv8/v8/src/diy-fp.cc +58 -0
  151. data/lib/libv8/v8/src/diy-fp.h +117 -0
  152. data/lib/libv8/v8/src/double.h +238 -0
  153. data/lib/libv8/v8/src/dtoa.cc +103 -0
  154. data/lib/libv8/v8/src/dtoa.h +85 -0
  155. data/lib/libv8/v8/src/execution.cc +849 -0
  156. data/lib/libv8/v8/src/execution.h +297 -0
  157. data/lib/libv8/v8/src/extensions/experimental/break-iterator.cc +250 -0
  158. data/lib/libv8/v8/src/extensions/experimental/break-iterator.h +89 -0
  159. data/lib/libv8/v8/src/extensions/experimental/collator.cc +218 -0
  160. data/lib/libv8/v8/src/extensions/experimental/collator.h +69 -0
  161. data/lib/libv8/v8/src/extensions/experimental/experimental.gyp +94 -0
  162. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.cc +78 -0
  163. data/lib/libv8/v8/src/extensions/experimental/i18n-extension.h +54 -0
  164. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.cc +112 -0
  165. data/lib/libv8/v8/src/extensions/experimental/i18n-locale.h +60 -0
  166. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.cc +43 -0
  167. data/lib/libv8/v8/src/extensions/experimental/i18n-utils.h +49 -0
  168. data/lib/libv8/v8/src/extensions/experimental/i18n.js +180 -0
  169. data/lib/libv8/v8/src/extensions/experimental/language-matcher.cc +251 -0
  170. data/lib/libv8/v8/src/extensions/experimental/language-matcher.h +95 -0
  171. data/lib/libv8/v8/src/extensions/externalize-string-extension.cc +141 -0
  172. data/lib/libv8/v8/src/extensions/externalize-string-extension.h +50 -0
  173. data/lib/libv8/v8/src/extensions/gc-extension.cc +58 -0
  174. data/lib/libv8/v8/src/extensions/gc-extension.h +49 -0
  175. data/lib/libv8/v8/src/factory.cc +1222 -0
  176. data/lib/libv8/v8/src/factory.h +442 -0
  177. data/lib/libv8/v8/src/fast-dtoa.cc +736 -0
  178. data/lib/libv8/v8/src/fast-dtoa.h +83 -0
  179. data/lib/libv8/v8/src/fixed-dtoa.cc +405 -0
  180. data/lib/libv8/v8/src/fixed-dtoa.h +55 -0
  181. data/lib/libv8/v8/src/flag-definitions.h +560 -0
  182. data/lib/libv8/v8/src/flags.cc +551 -0
  183. data/lib/libv8/v8/src/flags.h +79 -0
  184. data/lib/libv8/v8/src/frames-inl.h +247 -0
  185. data/lib/libv8/v8/src/frames.cc +1243 -0
  186. data/lib/libv8/v8/src/frames.h +870 -0
  187. data/lib/libv8/v8/src/full-codegen.cc +1374 -0
  188. data/lib/libv8/v8/src/full-codegen.h +771 -0
  189. data/lib/libv8/v8/src/func-name-inferrer.cc +92 -0
  190. data/lib/libv8/v8/src/func-name-inferrer.h +111 -0
  191. data/lib/libv8/v8/src/gdb-jit.cc +1555 -0
  192. data/lib/libv8/v8/src/gdb-jit.h +143 -0
  193. data/lib/libv8/v8/src/global-handles.cc +665 -0
  194. data/lib/libv8/v8/src/global-handles.h +284 -0
  195. data/lib/libv8/v8/src/globals.h +325 -0
  196. data/lib/libv8/v8/src/handles-inl.h +177 -0
  197. data/lib/libv8/v8/src/handles.cc +987 -0
  198. data/lib/libv8/v8/src/handles.h +382 -0
  199. data/lib/libv8/v8/src/hashmap.cc +230 -0
  200. data/lib/libv8/v8/src/hashmap.h +123 -0
  201. data/lib/libv8/v8/src/heap-inl.h +704 -0
  202. data/lib/libv8/v8/src/heap-profiler.cc +1173 -0
  203. data/lib/libv8/v8/src/heap-profiler.h +397 -0
  204. data/lib/libv8/v8/src/heap.cc +5930 -0
  205. data/lib/libv8/v8/src/heap.h +2268 -0
  206. data/lib/libv8/v8/src/hydrogen-instructions.cc +1769 -0
  207. data/lib/libv8/v8/src/hydrogen-instructions.h +3971 -0
  208. data/lib/libv8/v8/src/hydrogen.cc +6239 -0
  209. data/lib/libv8/v8/src/hydrogen.h +1202 -0
  210. data/lib/libv8/v8/src/ia32/assembler-ia32-inl.h +446 -0
  211. data/lib/libv8/v8/src/ia32/assembler-ia32.cc +2487 -0
  212. data/lib/libv8/v8/src/ia32/assembler-ia32.h +1144 -0
  213. data/lib/libv8/v8/src/ia32/builtins-ia32.cc +1621 -0
  214. data/lib/libv8/v8/src/ia32/code-stubs-ia32.cc +6198 -0
  215. data/lib/libv8/v8/src/ia32/code-stubs-ia32.h +517 -0
  216. data/lib/libv8/v8/src/ia32/codegen-ia32.cc +265 -0
  217. data/lib/libv8/v8/src/ia32/codegen-ia32.h +79 -0
  218. data/lib/libv8/v8/src/ia32/cpu-ia32.cc +88 -0
  219. data/lib/libv8/v8/src/ia32/debug-ia32.cc +312 -0
  220. data/lib/libv8/v8/src/ia32/deoptimizer-ia32.cc +774 -0
  221. data/lib/libv8/v8/src/ia32/disasm-ia32.cc +1628 -0
  222. data/lib/libv8/v8/src/ia32/frames-ia32.cc +45 -0
  223. data/lib/libv8/v8/src/ia32/frames-ia32.h +142 -0
  224. data/lib/libv8/v8/src/ia32/full-codegen-ia32.cc +4338 -0
  225. data/lib/libv8/v8/src/ia32/ic-ia32.cc +1597 -0
  226. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.cc +4461 -0
  227. data/lib/libv8/v8/src/ia32/lithium-codegen-ia32.h +375 -0
  228. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.cc +475 -0
  229. data/lib/libv8/v8/src/ia32/lithium-gap-resolver-ia32.h +110 -0
  230. data/lib/libv8/v8/src/ia32/lithium-ia32.cc +2261 -0
  231. data/lib/libv8/v8/src/ia32/lithium-ia32.h +2396 -0
  232. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.cc +2136 -0
  233. data/lib/libv8/v8/src/ia32/macro-assembler-ia32.h +775 -0
  234. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.cc +1263 -0
  235. data/lib/libv8/v8/src/ia32/regexp-macro-assembler-ia32.h +216 -0
  236. data/lib/libv8/v8/src/ia32/simulator-ia32.cc +30 -0
  237. data/lib/libv8/v8/src/ia32/simulator-ia32.h +74 -0
  238. data/lib/libv8/v8/src/ia32/stub-cache-ia32.cc +3847 -0
  239. data/lib/libv8/v8/src/ic-inl.h +130 -0
  240. data/lib/libv8/v8/src/ic.cc +2577 -0
  241. data/lib/libv8/v8/src/ic.h +736 -0
  242. data/lib/libv8/v8/src/inspector.cc +63 -0
  243. data/lib/libv8/v8/src/inspector.h +62 -0
  244. data/lib/libv8/v8/src/interpreter-irregexp.cc +659 -0
  245. data/lib/libv8/v8/src/interpreter-irregexp.h +49 -0
  246. data/lib/libv8/v8/src/isolate-inl.h +50 -0
  247. data/lib/libv8/v8/src/isolate.cc +1869 -0
  248. data/lib/libv8/v8/src/isolate.h +1382 -0
  249. data/lib/libv8/v8/src/json-parser.cc +504 -0
  250. data/lib/libv8/v8/src/json-parser.h +161 -0
  251. data/lib/libv8/v8/src/json.js +342 -0
  252. data/lib/libv8/v8/src/jsregexp.cc +5385 -0
  253. data/lib/libv8/v8/src/jsregexp.h +1492 -0
  254. data/lib/libv8/v8/src/list-inl.h +212 -0
  255. data/lib/libv8/v8/src/list.h +174 -0
  256. data/lib/libv8/v8/src/lithium-allocator-inl.h +142 -0
  257. data/lib/libv8/v8/src/lithium-allocator.cc +2123 -0
  258. data/lib/libv8/v8/src/lithium-allocator.h +630 -0
  259. data/lib/libv8/v8/src/lithium.cc +190 -0
  260. data/lib/libv8/v8/src/lithium.h +597 -0
  261. data/lib/libv8/v8/src/liveedit-debugger.js +1082 -0
  262. data/lib/libv8/v8/src/liveedit.cc +1691 -0
  263. data/lib/libv8/v8/src/liveedit.h +180 -0
  264. data/lib/libv8/v8/src/liveobjectlist-inl.h +126 -0
  265. data/lib/libv8/v8/src/liveobjectlist.cc +2589 -0
  266. data/lib/libv8/v8/src/liveobjectlist.h +322 -0
  267. data/lib/libv8/v8/src/log-inl.h +59 -0
  268. data/lib/libv8/v8/src/log-utils.cc +428 -0
  269. data/lib/libv8/v8/src/log-utils.h +231 -0
  270. data/lib/libv8/v8/src/log.cc +1993 -0
  271. data/lib/libv8/v8/src/log.h +476 -0
  272. data/lib/libv8/v8/src/macro-assembler.h +120 -0
  273. data/lib/libv8/v8/src/macros.py +178 -0
  274. data/lib/libv8/v8/src/mark-compact.cc +3143 -0
  275. data/lib/libv8/v8/src/mark-compact.h +506 -0
  276. data/lib/libv8/v8/src/math.js +264 -0
  277. data/lib/libv8/v8/src/messages.cc +179 -0
  278. data/lib/libv8/v8/src/messages.h +113 -0
  279. data/lib/libv8/v8/src/messages.js +1096 -0
  280. data/lib/libv8/v8/src/mips/assembler-mips-inl.h +312 -0
  281. data/lib/libv8/v8/src/mips/assembler-mips.cc +1960 -0
  282. data/lib/libv8/v8/src/mips/assembler-mips.h +1138 -0
  283. data/lib/libv8/v8/src/mips/builtins-mips.cc +1628 -0
  284. data/lib/libv8/v8/src/mips/code-stubs-mips.cc +6656 -0
  285. data/lib/libv8/v8/src/mips/code-stubs-mips.h +682 -0
  286. data/lib/libv8/v8/src/mips/codegen-mips.cc +52 -0
  287. data/lib/libv8/v8/src/mips/codegen-mips.h +98 -0
  288. data/lib/libv8/v8/src/mips/constants-mips.cc +352 -0
  289. data/lib/libv8/v8/src/mips/constants-mips.h +739 -0
  290. data/lib/libv8/v8/src/mips/cpu-mips.cc +96 -0
  291. data/lib/libv8/v8/src/mips/debug-mips.cc +308 -0
  292. data/lib/libv8/v8/src/mips/deoptimizer-mips.cc +91 -0
  293. data/lib/libv8/v8/src/mips/disasm-mips.cc +1050 -0
  294. data/lib/libv8/v8/src/mips/frames-mips.cc +47 -0
  295. data/lib/libv8/v8/src/mips/frames-mips.h +219 -0
  296. data/lib/libv8/v8/src/mips/full-codegen-mips.cc +4388 -0
  297. data/lib/libv8/v8/src/mips/ic-mips.cc +1580 -0
  298. data/lib/libv8/v8/src/mips/lithium-codegen-mips.h +65 -0
  299. data/lib/libv8/v8/src/mips/lithium-mips.h +307 -0
  300. data/lib/libv8/v8/src/mips/macro-assembler-mips.cc +4056 -0
  301. data/lib/libv8/v8/src/mips/macro-assembler-mips.h +1214 -0
  302. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.cc +1251 -0
  303. data/lib/libv8/v8/src/mips/regexp-macro-assembler-mips.h +252 -0
  304. data/lib/libv8/v8/src/mips/simulator-mips.cc +2621 -0
  305. data/lib/libv8/v8/src/mips/simulator-mips.h +401 -0
  306. data/lib/libv8/v8/src/mips/stub-cache-mips.cc +4285 -0
  307. data/lib/libv8/v8/src/mirror-debugger.js +2382 -0
  308. data/lib/libv8/v8/src/mksnapshot.cc +328 -0
  309. data/lib/libv8/v8/src/natives.h +64 -0
  310. data/lib/libv8/v8/src/objects-debug.cc +738 -0
  311. data/lib/libv8/v8/src/objects-inl.h +4323 -0
  312. data/lib/libv8/v8/src/objects-printer.cc +829 -0
  313. data/lib/libv8/v8/src/objects-visiting.cc +148 -0
  314. data/lib/libv8/v8/src/objects-visiting.h +424 -0
  315. data/lib/libv8/v8/src/objects.cc +10585 -0
  316. data/lib/libv8/v8/src/objects.h +6838 -0
  317. data/lib/libv8/v8/src/parser.cc +4997 -0
  318. data/lib/libv8/v8/src/parser.h +765 -0
  319. data/lib/libv8/v8/src/platform-cygwin.cc +779 -0
  320. data/lib/libv8/v8/src/platform-freebsd.cc +826 -0
  321. data/lib/libv8/v8/src/platform-linux.cc +1149 -0
  322. data/lib/libv8/v8/src/platform-macos.cc +830 -0
  323. data/lib/libv8/v8/src/platform-nullos.cc +479 -0
  324. data/lib/libv8/v8/src/platform-openbsd.cc +640 -0
  325. data/lib/libv8/v8/src/platform-posix.cc +424 -0
  326. data/lib/libv8/v8/src/platform-solaris.cc +762 -0
  327. data/lib/libv8/v8/src/platform-tls-mac.h +62 -0
  328. data/lib/libv8/v8/src/platform-tls-win32.h +62 -0
  329. data/lib/libv8/v8/src/platform-tls.h +50 -0
  330. data/lib/libv8/v8/src/platform-win32.cc +2021 -0
  331. data/lib/libv8/v8/src/platform.h +667 -0
  332. data/lib/libv8/v8/src/preparse-data-format.h +62 -0
  333. data/lib/libv8/v8/src/preparse-data.cc +183 -0
  334. data/lib/libv8/v8/src/preparse-data.h +225 -0
  335. data/lib/libv8/v8/src/preparser-api.cc +220 -0
  336. data/lib/libv8/v8/src/preparser.cc +1450 -0
  337. data/lib/libv8/v8/src/preparser.h +493 -0
  338. data/lib/libv8/v8/src/prettyprinter.cc +1493 -0
  339. data/lib/libv8/v8/src/prettyprinter.h +223 -0
  340. data/lib/libv8/v8/src/profile-generator-inl.h +128 -0
  341. data/lib/libv8/v8/src/profile-generator.cc +3098 -0
  342. data/lib/libv8/v8/src/profile-generator.h +1126 -0
  343. data/lib/libv8/v8/src/property.cc +105 -0
  344. data/lib/libv8/v8/src/property.h +365 -0
  345. data/lib/libv8/v8/src/proxy.js +83 -0
  346. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp-inl.h +78 -0
  347. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.cc +471 -0
  348. data/lib/libv8/v8/src/regexp-macro-assembler-irregexp.h +142 -0
  349. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.cc +373 -0
  350. data/lib/libv8/v8/src/regexp-macro-assembler-tracer.h +104 -0
  351. data/lib/libv8/v8/src/regexp-macro-assembler.cc +267 -0
  352. data/lib/libv8/v8/src/regexp-macro-assembler.h +243 -0
  353. data/lib/libv8/v8/src/regexp-stack.cc +111 -0
  354. data/lib/libv8/v8/src/regexp-stack.h +147 -0
  355. data/lib/libv8/v8/src/regexp.js +483 -0
  356. data/lib/libv8/v8/src/rewriter.cc +360 -0
  357. data/lib/libv8/v8/src/rewriter.h +50 -0
  358. data/lib/libv8/v8/src/runtime-profiler.cc +489 -0
  359. data/lib/libv8/v8/src/runtime-profiler.h +201 -0
  360. data/lib/libv8/v8/src/runtime.cc +12227 -0
  361. data/lib/libv8/v8/src/runtime.h +652 -0
  362. data/lib/libv8/v8/src/runtime.js +649 -0
  363. data/lib/libv8/v8/src/safepoint-table.cc +256 -0
  364. data/lib/libv8/v8/src/safepoint-table.h +270 -0
  365. data/lib/libv8/v8/src/scanner-base.cc +952 -0
  366. data/lib/libv8/v8/src/scanner-base.h +670 -0
  367. data/lib/libv8/v8/src/scanner.cc +345 -0
  368. data/lib/libv8/v8/src/scanner.h +146 -0
  369. data/lib/libv8/v8/src/scopeinfo.cc +646 -0
  370. data/lib/libv8/v8/src/scopeinfo.h +254 -0
  371. data/lib/libv8/v8/src/scopes.cc +1150 -0
  372. data/lib/libv8/v8/src/scopes.h +507 -0
  373. data/lib/libv8/v8/src/serialize.cc +1574 -0
  374. data/lib/libv8/v8/src/serialize.h +589 -0
  375. data/lib/libv8/v8/src/shell.h +55 -0
  376. data/lib/libv8/v8/src/simulator.h +43 -0
  377. data/lib/libv8/v8/src/small-pointer-list.h +163 -0
  378. data/lib/libv8/v8/src/smart-pointer.h +109 -0
  379. data/lib/libv8/v8/src/snapshot-common.cc +83 -0
  380. data/lib/libv8/v8/src/snapshot-empty.cc +54 -0
  381. data/lib/libv8/v8/src/snapshot.h +91 -0
  382. data/lib/libv8/v8/src/spaces-inl.h +529 -0
  383. data/lib/libv8/v8/src/spaces.cc +3145 -0
  384. data/lib/libv8/v8/src/spaces.h +2369 -0
  385. data/lib/libv8/v8/src/splay-tree-inl.h +310 -0
  386. data/lib/libv8/v8/src/splay-tree.h +205 -0
  387. data/lib/libv8/v8/src/string-search.cc +41 -0
  388. data/lib/libv8/v8/src/string-search.h +568 -0
  389. data/lib/libv8/v8/src/string-stream.cc +592 -0
  390. data/lib/libv8/v8/src/string-stream.h +191 -0
  391. data/lib/libv8/v8/src/string.js +994 -0
  392. data/lib/libv8/v8/src/strtod.cc +440 -0
  393. data/lib/libv8/v8/src/strtod.h +40 -0
  394. data/lib/libv8/v8/src/stub-cache.cc +1965 -0
  395. data/lib/libv8/v8/src/stub-cache.h +924 -0
  396. data/lib/libv8/v8/src/third_party/valgrind/valgrind.h +3925 -0
  397. data/lib/libv8/v8/src/token.cc +63 -0
  398. data/lib/libv8/v8/src/token.h +288 -0
  399. data/lib/libv8/v8/src/type-info.cc +507 -0
  400. data/lib/libv8/v8/src/type-info.h +272 -0
  401. data/lib/libv8/v8/src/unbound-queue-inl.h +95 -0
  402. data/lib/libv8/v8/src/unbound-queue.h +69 -0
  403. data/lib/libv8/v8/src/unicode-inl.h +238 -0
  404. data/lib/libv8/v8/src/unicode.cc +1624 -0
  405. data/lib/libv8/v8/src/unicode.h +280 -0
  406. data/lib/libv8/v8/src/uri.js +408 -0
  407. data/lib/libv8/v8/src/utils-inl.h +48 -0
  408. data/lib/libv8/v8/src/utils.cc +371 -0
  409. data/lib/libv8/v8/src/utils.h +800 -0
  410. data/lib/libv8/v8/src/v8-counters.cc +62 -0
  411. data/lib/libv8/v8/src/v8-counters.h +314 -0
  412. data/lib/libv8/v8/src/v8.cc +213 -0
  413. data/lib/libv8/v8/src/v8.h +131 -0
  414. data/lib/libv8/v8/src/v8checks.h +64 -0
  415. data/lib/libv8/v8/src/v8dll-main.cc +44 -0
  416. data/lib/libv8/v8/src/v8globals.h +512 -0
  417. data/lib/libv8/v8/src/v8memory.h +82 -0
  418. data/lib/libv8/v8/src/v8natives.js +1310 -0
  419. data/lib/libv8/v8/src/v8preparserdll-main.cc +39 -0
  420. data/lib/libv8/v8/src/v8threads.cc +464 -0
  421. data/lib/libv8/v8/src/v8threads.h +165 -0
  422. data/lib/libv8/v8/src/v8utils.h +319 -0
  423. data/lib/libv8/v8/src/variables.cc +114 -0
  424. data/lib/libv8/v8/src/variables.h +167 -0
  425. data/lib/libv8/v8/src/version.cc +116 -0
  426. data/lib/libv8/v8/src/version.h +68 -0
  427. data/lib/libv8/v8/src/vm-state-inl.h +138 -0
  428. data/lib/libv8/v8/src/vm-state.h +71 -0
  429. data/lib/libv8/v8/src/win32-headers.h +96 -0
  430. data/lib/libv8/v8/src/x64/assembler-x64-inl.h +462 -0
  431. data/lib/libv8/v8/src/x64/assembler-x64.cc +3027 -0
  432. data/lib/libv8/v8/src/x64/assembler-x64.h +1633 -0
  433. data/lib/libv8/v8/src/x64/builtins-x64.cc +1520 -0
  434. data/lib/libv8/v8/src/x64/code-stubs-x64.cc +5132 -0
  435. data/lib/libv8/v8/src/x64/code-stubs-x64.h +514 -0
  436. data/lib/libv8/v8/src/x64/codegen-x64.cc +146 -0
  437. data/lib/libv8/v8/src/x64/codegen-x64.h +76 -0
  438. data/lib/libv8/v8/src/x64/cpu-x64.cc +88 -0
  439. data/lib/libv8/v8/src/x64/debug-x64.cc +319 -0
  440. data/lib/libv8/v8/src/x64/deoptimizer-x64.cc +815 -0
  441. data/lib/libv8/v8/src/x64/disasm-x64.cc +1832 -0
  442. data/lib/libv8/v8/src/x64/frames-x64.cc +45 -0
  443. data/lib/libv8/v8/src/x64/frames-x64.h +130 -0
  444. data/lib/libv8/v8/src/x64/full-codegen-x64.cc +4318 -0
  445. data/lib/libv8/v8/src/x64/ic-x64.cc +1608 -0
  446. data/lib/libv8/v8/src/x64/lithium-codegen-x64.cc +4267 -0
  447. data/lib/libv8/v8/src/x64/lithium-codegen-x64.h +367 -0
  448. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.cc +320 -0
  449. data/lib/libv8/v8/src/x64/lithium-gap-resolver-x64.h +74 -0
  450. data/lib/libv8/v8/src/x64/lithium-x64.cc +2202 -0
  451. data/lib/libv8/v8/src/x64/lithium-x64.h +2333 -0
  452. data/lib/libv8/v8/src/x64/macro-assembler-x64.cc +3745 -0
  453. data/lib/libv8/v8/src/x64/macro-assembler-x64.h +1290 -0
  454. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.cc +1398 -0
  455. data/lib/libv8/v8/src/x64/regexp-macro-assembler-x64.h +282 -0
  456. data/lib/libv8/v8/src/x64/simulator-x64.cc +27 -0
  457. data/lib/libv8/v8/src/x64/simulator-x64.h +72 -0
  458. data/lib/libv8/v8/src/x64/stub-cache-x64.cc +3610 -0
  459. data/lib/libv8/v8/src/zone-inl.h +140 -0
  460. data/lib/libv8/v8/src/zone.cc +196 -0
  461. data/lib/libv8/v8/src/zone.h +240 -0
  462. data/lib/libv8/v8/tools/codemap.js +265 -0
  463. data/lib/libv8/v8/tools/consarray.js +93 -0
  464. data/lib/libv8/v8/tools/csvparser.js +78 -0
  465. data/lib/libv8/v8/tools/disasm.py +92 -0
  466. data/lib/libv8/v8/tools/freebsd-tick-processor +10 -0
  467. data/lib/libv8/v8/tools/gc-nvp-trace-processor.py +342 -0
  468. data/lib/libv8/v8/tools/gcmole/README +62 -0
  469. data/lib/libv8/v8/tools/gcmole/gccause.lua +60 -0
  470. data/lib/libv8/v8/tools/gcmole/gcmole.cc +1261 -0
  471. data/lib/libv8/v8/tools/gcmole/gcmole.lua +378 -0
  472. data/lib/libv8/v8/tools/generate-ten-powers.scm +286 -0
  473. data/lib/libv8/v8/tools/grokdump.py +841 -0
  474. data/lib/libv8/v8/tools/gyp/v8.gyp +995 -0
  475. data/lib/libv8/v8/tools/js2c.py +364 -0
  476. data/lib/libv8/v8/tools/jsmin.py +280 -0
  477. data/lib/libv8/v8/tools/linux-tick-processor +35 -0
  478. data/lib/libv8/v8/tools/ll_prof.py +942 -0
  479. data/lib/libv8/v8/tools/logreader.js +185 -0
  480. data/lib/libv8/v8/tools/mac-nm +18 -0
  481. data/lib/libv8/v8/tools/mac-tick-processor +6 -0
  482. data/lib/libv8/v8/tools/oom_dump/README +31 -0
  483. data/lib/libv8/v8/tools/oom_dump/SConstruct +42 -0
  484. data/lib/libv8/v8/tools/oom_dump/oom_dump.cc +288 -0
  485. data/lib/libv8/v8/tools/presubmit.py +305 -0
  486. data/lib/libv8/v8/tools/process-heap-prof.py +120 -0
  487. data/lib/libv8/v8/tools/profile.js +751 -0
  488. data/lib/libv8/v8/tools/profile_view.js +219 -0
  489. data/lib/libv8/v8/tools/run-valgrind.py +77 -0
  490. data/lib/libv8/v8/tools/splaytree.js +316 -0
  491. data/lib/libv8/v8/tools/stats-viewer.py +468 -0
  492. data/lib/libv8/v8/tools/test.py +1510 -0
  493. data/lib/libv8/v8/tools/tickprocessor-driver.js +59 -0
  494. data/lib/libv8/v8/tools/tickprocessor.js +877 -0
  495. data/lib/libv8/v8/tools/utils.py +96 -0
  496. data/lib/libv8/v8/tools/visual_studio/README.txt +12 -0
  497. data/lib/libv8/v8/tools/windows-tick-processor.bat +30 -0
  498. data/lib/libv8/version.rb +5 -0
  499. data/libv8.gemspec +36 -0
  500. metadata +578 -0
@@ -0,0 +1,47 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+
29
+ #include "v8.h"
30
+
31
+ #if defined(V8_TARGET_ARCH_MIPS)
32
+
33
+ #include "frames-inl.h"
34
+ #include "mips/assembler-mips-inl.h"
35
+
36
+ namespace v8 {
37
+ namespace internal {
38
+
39
+
40
+ Address ExitFrame::ComputeStackPointer(Address fp) {
41
+ return Memory::Address_at(fp + ExitFrameConstants::kSPOffset);
42
+ }
43
+
44
+
45
+ } } // namespace v8::internal
46
+
47
+ #endif // V8_TARGET_ARCH_MIPS
@@ -0,0 +1,219 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+
29
+
30
+ #ifndef V8_MIPS_FRAMES_MIPS_H_
31
+ #define V8_MIPS_FRAMES_MIPS_H_
32
+
33
+
34
+ namespace v8 {
35
+ namespace internal {
36
+
37
+ // Register lists.
38
+ // Note that the bit values must match those used in actual instruction
39
+ // encoding.
40
+ static const int kNumRegs = 32;
41
+
42
+ static const RegList kJSCallerSaved =
43
+ 1 << 2 | // v0
44
+ 1 << 4 | // a0
45
+ 1 << 5 | // a1
46
+ 1 << 6 | // a2
47
+ 1 << 7; // a3
48
+
49
+ static const int kNumJSCallerSaved = 5;
50
+
51
+
52
+ // Return the code of the n-th caller-saved register available to JavaScript
53
+ // e.g. JSCallerSavedReg(0) returns a0.code() == 4.
54
+ int JSCallerSavedCode(int n);
55
+
56
+
57
+ // Callee-saved registers preserved when switching from C to JavaScript.
58
+ static const RegList kCalleeSaved =
59
+ // Saved temporaries.
60
+ 1 << 16 | 1 << 17 | 1 << 18 | 1 << 19 |
61
+ 1 << 20 | 1 << 21 | 1 << 22 | 1 << 23 |
62
+ // gp, sp, fp.
63
+ 1 << 28 | 1 << 29 | 1 << 30;
64
+
65
+ static const int kNumCalleeSaved = 11;
66
+
67
+
68
+ // Number of registers for which space is reserved in safepoints. Must be a
69
+ // multiple of 8.
70
+ // TODO(mips): Only 8 registers may actually be sufficient. Revisit.
71
+ static const int kNumSafepointRegisters = 16;
72
+
73
+ // Define the list of registers actually saved at safepoints.
74
+ // Note that the number of saved registers may be smaller than the reserved
75
+ // space, i.e. kNumSafepointSavedRegisters <= kNumSafepointRegisters.
76
+ static const RegList kSafepointSavedRegisters = kJSCallerSaved | kCalleeSaved;
77
+ static const int kNumSafepointSavedRegisters =
78
+ kNumJSCallerSaved + kNumCalleeSaved;
79
+
80
+ typedef Object* JSCallerSavedBuffer[kNumJSCallerSaved];
81
+
82
+ static const int kUndefIndex = -1;
83
+ // Map with indexes on stack that corresponds to codes of saved registers.
84
+ static const int kSafepointRegisterStackIndexMap[kNumRegs] = {
85
+ kUndefIndex,
86
+ kUndefIndex,
87
+ 0, // v0
88
+ kUndefIndex,
89
+ 1, // a0
90
+ 2, // a1
91
+ 3, // a2
92
+ 4, // a3
93
+ kUndefIndex,
94
+ kUndefIndex,
95
+ kUndefIndex,
96
+ kUndefIndex,
97
+ kUndefIndex,
98
+ kUndefIndex,
99
+ kUndefIndex,
100
+ kUndefIndex,
101
+ 5, // Saved temporaries.
102
+ 6,
103
+ 7,
104
+ 8,
105
+ 9,
106
+ 10,
107
+ 11,
108
+ 12,
109
+ kUndefIndex,
110
+ kUndefIndex,
111
+ kUndefIndex,
112
+ kUndefIndex,
113
+ 13, // gp
114
+ 14, // sp
115
+ 15, // fp
116
+ kUndefIndex
117
+ };
118
+
119
+
120
+ // ----------------------------------------------------
121
+
122
+ class StackHandlerConstants : public AllStatic {
123
+ public:
124
+ static const int kNextOffset = 0 * kPointerSize;
125
+ static const int kStateOffset = 1 * kPointerSize;
126
+ static const int kFPOffset = 2 * kPointerSize;
127
+ static const int kPCOffset = 3 * kPointerSize;
128
+
129
+ static const int kSize = kPCOffset + kPointerSize;
130
+ };
131
+
132
+
133
+ class EntryFrameConstants : public AllStatic {
134
+ public:
135
+ static const int kCallerFPOffset = -3 * kPointerSize;
136
+ };
137
+
138
+
139
+ class ExitFrameConstants : public AllStatic {
140
+ public:
141
+ // See some explanation in MacroAssembler::EnterExitFrame.
142
+ // This marks the top of the extra allocated stack space.
143
+ static const int kStackSpaceOffset = -3 * kPointerSize;
144
+
145
+ static const int kCodeOffset = -2 * kPointerSize;
146
+
147
+ static const int kSPOffset = -1 * kPointerSize;
148
+
149
+ // The caller fields are below the frame pointer on the stack.
150
+ static const int kCallerFPOffset = +0 * kPointerSize;
151
+ // The calling JS function is between FP and PC.
152
+ static const int kCallerPCOffset = +1 * kPointerSize;
153
+
154
+ // MIPS-specific: a pointer to the old sp to avoid unnecessary calculations.
155
+ static const int kCallerSPOffset = +2 * kPointerSize;
156
+
157
+ // FP-relative displacement of the caller's SP.
158
+ static const int kCallerSPDisplacement = +2 * kPointerSize;
159
+ };
160
+
161
+
162
+ class StandardFrameConstants : public AllStatic {
163
+ public:
164
+ static const int kExpressionsOffset = -3 * kPointerSize;
165
+ static const int kMarkerOffset = -2 * kPointerSize;
166
+ static const int kContextOffset = -1 * kPointerSize;
167
+ static const int kCallerFPOffset = 0 * kPointerSize;
168
+ static const int kCallerPCOffset = +1 * kPointerSize;
169
+ static const int kCallerSPOffset = +2 * kPointerSize;
170
+
171
+ // Size of the MIPS 4 32-bit argument slots.
172
+ // This is just an alias with a shorter name. Use it from now on.
173
+ static const int kRArgsSlotsSize = 4 * kPointerSize;
174
+ static const int kRegularArgsSlotsSize = kRArgsSlotsSize;
175
+
176
+ // C/C++ argument slots size.
177
+ static const int kCArgSlotCount = 4;
178
+ static const int kCArgsSlotsSize = kCArgSlotCount * kPointerSize;
179
+ // JS argument slots size.
180
+ static const int kJSArgsSlotsSize = 0 * kPointerSize;
181
+ // Assembly builtins argument slots size.
182
+ static const int kBArgsSlotsSize = 0 * kPointerSize;
183
+ };
184
+
185
+
186
+ class JavaScriptFrameConstants : public AllStatic {
187
+ public:
188
+ // FP-relative.
189
+ static const int kLocal0Offset = StandardFrameConstants::kExpressionsOffset;
190
+ static const int kLastParameterOffset = +2 * kPointerSize;
191
+ static const int kFunctionOffset = StandardFrameConstants::kMarkerOffset;
192
+
193
+ // Caller SP-relative.
194
+ static const int kParam0Offset = -2 * kPointerSize;
195
+ static const int kReceiverOffset = -1 * kPointerSize;
196
+ };
197
+
198
+
199
+ class ArgumentsAdaptorFrameConstants : public AllStatic {
200
+ public:
201
+ static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset;
202
+ };
203
+
204
+
205
+ class InternalFrameConstants : public AllStatic {
206
+ public:
207
+ static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset;
208
+ };
209
+
210
+
211
+ inline Object* JavaScriptFrame::function_slot_object() const {
212
+ const int offset = JavaScriptFrameConstants::kFunctionOffset;
213
+ return Memory::Object_at(fp() + offset);
214
+ }
215
+
216
+
217
+ } } // namespace v8::internal
218
+
219
+ #endif
@@ -0,0 +1,4388 @@
1
+ // Copyright 2011 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #include "v8.h"
29
+
30
+ #if defined(V8_TARGET_ARCH_MIPS)
31
+
32
+ // Note on Mips implementation:
33
+ //
34
+ // The result_register() for mips is the 'v0' register, which is defined
35
+ // by the ABI to contain function return values. However, the first
36
+ // parameter to a function is defined to be 'a0'. So there are many
37
+ // places where we have to move a previous result in v0 to a0 for the
38
+ // next call: mov(a0, v0). This is not needed on the other architectures.
39
+
40
+ #include "code-stubs.h"
41
+ #include "codegen.h"
42
+ #include "compiler.h"
43
+ #include "debug.h"
44
+ #include "full-codegen.h"
45
+ #include "parser.h"
46
+ #include "scopes.h"
47
+ #include "stub-cache.h"
48
+
49
+ #include "mips/code-stubs-mips.h"
50
+
51
+ namespace v8 {
52
+ namespace internal {
53
+
54
+ #define __ ACCESS_MASM(masm_)
55
+
56
+
57
+ static unsigned GetPropertyId(Property* property) {
58
+ if (property->is_synthetic()) return AstNode::kNoNumber;
59
+ return property->id();
60
+ }
61
+
62
+
63
+ // A patch site is a location in the code which it is possible to patch. This
64
+ // class has a number of methods to emit the code which is patchable and the
65
+ // method EmitPatchInfo to record a marker back to the patchable code. This
66
+ // marker is a andi at, rx, #yyy instruction, and x * 0x0000ffff + yyy (raw 16
67
+ // bit immediate value is used) is the delta from the pc to the first
68
+ // instruction of the patchable code.
69
+ class JumpPatchSite BASE_EMBEDDED {
70
+ public:
71
+ explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) {
72
+ #ifdef DEBUG
73
+ info_emitted_ = false;
74
+ #endif
75
+ }
76
+
77
+ ~JumpPatchSite() {
78
+ ASSERT(patch_site_.is_bound() == info_emitted_);
79
+ }
80
+
81
+ // When initially emitting this ensure that a jump is always generated to skip
82
+ // the inlined smi code.
83
+ void EmitJumpIfNotSmi(Register reg, Label* target) {
84
+ ASSERT(!patch_site_.is_bound() && !info_emitted_);
85
+ Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
86
+ __ bind(&patch_site_);
87
+ __ andi(at, reg, 0);
88
+ // Always taken before patched.
89
+ __ Branch(target, eq, at, Operand(zero_reg));
90
+ }
91
+
92
+ // When initially emitting this ensure that a jump is never generated to skip
93
+ // the inlined smi code.
94
+ void EmitJumpIfSmi(Register reg, Label* target) {
95
+ Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
96
+ ASSERT(!patch_site_.is_bound() && !info_emitted_);
97
+ __ bind(&patch_site_);
98
+ __ andi(at, reg, 0);
99
+ // Never taken before patched.
100
+ __ Branch(target, ne, at, Operand(zero_reg));
101
+ }
102
+
103
+ void EmitPatchInfo() {
104
+ int delta_to_patch_site = masm_->InstructionsGeneratedSince(&patch_site_);
105
+ Register reg = Register::from_code(delta_to_patch_site / kImm16Mask);
106
+ __ andi(at, reg, delta_to_patch_site % kImm16Mask);
107
+ #ifdef DEBUG
108
+ info_emitted_ = true;
109
+ #endif
110
+ }
111
+
112
+ bool is_bound() const { return patch_site_.is_bound(); }
113
+
114
+ private:
115
+ MacroAssembler* masm_;
116
+ Label patch_site_;
117
+ #ifdef DEBUG
118
+ bool info_emitted_;
119
+ #endif
120
+ };
121
+
122
+
123
+ // Generate code for a JS function. On entry to the function the receiver
124
+ // and arguments have been pushed on the stack left to right. The actual
125
+ // argument count matches the formal parameter count expected by the
126
+ // function.
127
+ //
128
+ // The live registers are:
129
+ // o a1: the JS function object being called (ie, ourselves)
130
+ // o cp: our context
131
+ // o fp: our caller's frame pointer
132
+ // o sp: stack pointer
133
+ // o ra: return address
134
+ //
135
+ // The function builds a JS frame. Please see JavaScriptFrameConstants in
136
+ // frames-mips.h for its layout.
137
+ void FullCodeGenerator::Generate(CompilationInfo* info) {
138
+ ASSERT(info_ == NULL);
139
+ info_ = info;
140
+ SetFunctionPosition(function());
141
+ Comment cmnt(masm_, "[ function compiled by full code generator");
142
+
143
+ #ifdef DEBUG
144
+ if (strlen(FLAG_stop_at) > 0 &&
145
+ info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
146
+ __ stop("stop-at");
147
+ }
148
+ #endif
149
+
150
+ // Strict mode functions need to replace the receiver with undefined
151
+ // when called as functions (without an explicit receiver
152
+ // object). t1 is zero for method calls and non-zero for function
153
+ // calls.
154
+ if (info->is_strict_mode()) {
155
+ Label ok;
156
+ __ Branch(&ok, eq, t1, Operand(zero_reg));
157
+ int receiver_offset = scope()->num_parameters() * kPointerSize;
158
+ __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
159
+ __ sw(a2, MemOperand(sp, receiver_offset));
160
+ __ bind(&ok);
161
+ }
162
+
163
+ int locals_count = scope()->num_stack_slots();
164
+
165
+ __ Push(ra, fp, cp, a1);
166
+ if (locals_count > 0) {
167
+ // Load undefined value here, so the value is ready for the loop
168
+ // below.
169
+ __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
170
+ }
171
+ // Adjust fp to point to caller's fp.
172
+ __ Addu(fp, sp, Operand(2 * kPointerSize));
173
+
174
+ { Comment cmnt(masm_, "[ Allocate locals");
175
+ for (int i = 0; i < locals_count; i++) {
176
+ __ push(at);
177
+ }
178
+ }
179
+
180
+ bool function_in_register = true;
181
+
182
+ // Possibly allocate a local context.
183
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
184
+ if (heap_slots > 0) {
185
+ Comment cmnt(masm_, "[ Allocate local context");
186
+ // Argument to NewContext is the function, which is in a1.
187
+ __ push(a1);
188
+ if (heap_slots <= FastNewContextStub::kMaximumSlots) {
189
+ FastNewContextStub stub(heap_slots);
190
+ __ CallStub(&stub);
191
+ } else {
192
+ __ CallRuntime(Runtime::kNewContext, 1);
193
+ }
194
+ function_in_register = false;
195
+ // Context is returned in both v0 and cp. It replaces the context
196
+ // passed to us. It's saved in the stack and kept live in cp.
197
+ __ sw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
198
+ // Copy any necessary parameters into the context.
199
+ int num_parameters = scope()->num_parameters();
200
+ for (int i = 0; i < num_parameters; i++) {
201
+ Slot* slot = scope()->parameter(i)->AsSlot();
202
+ if (slot != NULL && slot->type() == Slot::CONTEXT) {
203
+ int parameter_offset = StandardFrameConstants::kCallerSPOffset +
204
+ (num_parameters - 1 - i) * kPointerSize;
205
+ // Load parameter from stack.
206
+ __ lw(a0, MemOperand(fp, parameter_offset));
207
+ // Store it in the context.
208
+ __ li(a1, Operand(Context::SlotOffset(slot->index())));
209
+ __ addu(a2, cp, a1);
210
+ __ sw(a0, MemOperand(a2, 0));
211
+ // Update the write barrier. This clobbers all involved
212
+ // registers, so we have to use two more registers to avoid
213
+ // clobbering cp.
214
+ __ mov(a2, cp);
215
+ __ RecordWrite(a2, a1, a3);
216
+ }
217
+ }
218
+ }
219
+
220
+ Variable* arguments = scope()->arguments();
221
+ if (arguments != NULL) {
222
+ // Function uses arguments object.
223
+ Comment cmnt(masm_, "[ Allocate arguments object");
224
+ if (!function_in_register) {
225
+ // Load this again, if it's used by the local context below.
226
+ __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
227
+ } else {
228
+ __ mov(a3, a1);
229
+ }
230
+ // Receiver is just before the parameters on the caller's stack.
231
+ int offset = scope()->num_parameters() * kPointerSize;
232
+ __ Addu(a2, fp,
233
+ Operand(StandardFrameConstants::kCallerSPOffset + offset));
234
+ __ li(a1, Operand(Smi::FromInt(scope()->num_parameters())));
235
+ __ Push(a3, a2, a1);
236
+
237
+ // Arguments to ArgumentsAccessStub:
238
+ // function, receiver address, parameter count.
239
+ // The stub will rewrite receiever and parameter count if the previous
240
+ // stack frame was an arguments adapter frame.
241
+ ArgumentsAccessStub stub(
242
+ is_strict_mode() ? ArgumentsAccessStub::NEW_STRICT
243
+ : ArgumentsAccessStub::NEW_NON_STRICT);
244
+ __ CallStub(&stub);
245
+
246
+ Variable* arguments_shadow = scope()->arguments_shadow();
247
+ if (arguments_shadow != NULL) {
248
+ // Duplicate the value; move-to-slot operation might clobber registers.
249
+ __ mov(a3, v0);
250
+ Move(arguments_shadow->AsSlot(), a3, a1, a2);
251
+ }
252
+ Move(arguments->AsSlot(), v0, a1, a2);
253
+ }
254
+
255
+ if (FLAG_trace) {
256
+ __ CallRuntime(Runtime::kTraceEnter, 0);
257
+ }
258
+
259
+ // Visit the declarations and body unless there is an illegal
260
+ // redeclaration.
261
+ if (scope()->HasIllegalRedeclaration()) {
262
+ Comment cmnt(masm_, "[ Declarations");
263
+ scope()->VisitIllegalRedeclaration(this);
264
+
265
+ } else {
266
+ { Comment cmnt(masm_, "[ Declarations");
267
+ // For named function expressions, declare the function name as a
268
+ // constant.
269
+ if (scope()->is_function_scope() && scope()->function() != NULL) {
270
+ EmitDeclaration(scope()->function(), Variable::CONST, NULL);
271
+ }
272
+ VisitDeclarations(scope()->declarations());
273
+ }
274
+
275
+ { Comment cmnt(masm_, "[ Stack check");
276
+ PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
277
+ Label ok;
278
+ __ LoadRoot(t0, Heap::kStackLimitRootIndex);
279
+ __ Branch(&ok, hs, sp, Operand(t0));
280
+ StackCheckStub stub;
281
+ __ CallStub(&stub);
282
+ __ bind(&ok);
283
+ }
284
+
285
+ { Comment cmnt(masm_, "[ Body");
286
+ ASSERT(loop_depth() == 0);
287
+ VisitStatements(function()->body());
288
+ ASSERT(loop_depth() == 0);
289
+ }
290
+ }
291
+
292
+ // Always emit a 'return undefined' in case control fell off the end of
293
+ // the body.
294
+ { Comment cmnt(masm_, "[ return <undefined>;");
295
+ __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
296
+ }
297
+ EmitReturnSequence();
298
+ }
299
+
300
+
301
+ void FullCodeGenerator::ClearAccumulator() {
302
+ ASSERT(Smi::FromInt(0) == 0);
303
+ __ mov(v0, zero_reg);
304
+ }
305
+
306
+
307
+ void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) {
308
+ Comment cmnt(masm_, "[ Stack check");
309
+ Label ok;
310
+ __ LoadRoot(t0, Heap::kStackLimitRootIndex);
311
+ __ Branch(&ok, hs, sp, Operand(t0));
312
+ StackCheckStub stub;
313
+ // Record a mapping of this PC offset to the OSR id. This is used to find
314
+ // the AST id from the unoptimized code in order to use it as a key into
315
+ // the deoptimization input data found in the optimized code.
316
+ RecordStackCheck(stmt->OsrEntryId());
317
+
318
+ __ CallStub(&stub);
319
+ __ bind(&ok);
320
+ PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
321
+ // Record a mapping of the OSR id to this PC. This is used if the OSR
322
+ // entry becomes the target of a bailout. We don't expect it to be, but
323
+ // we want it to work if it is.
324
+ PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
325
+ }
326
+
327
+
328
+ void FullCodeGenerator::EmitReturnSequence() {
329
+ Comment cmnt(masm_, "[ Return sequence");
330
+ if (return_label_.is_bound()) {
331
+ __ Branch(&return_label_);
332
+ } else {
333
+ __ bind(&return_label_);
334
+ if (FLAG_trace) {
335
+ // Push the return value on the stack as the parameter.
336
+ // Runtime::TraceExit returns its parameter in v0.
337
+ __ push(v0);
338
+ __ CallRuntime(Runtime::kTraceExit, 1);
339
+ }
340
+
341
+ #ifdef DEBUG
342
+ // Add a label for checking the size of the code used for returning.
343
+ Label check_exit_codesize;
344
+ masm_->bind(&check_exit_codesize);
345
+ #endif
346
+ // Make sure that the constant pool is not emitted inside of the return
347
+ // sequence.
348
+ { Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
349
+ // Here we use masm_-> instead of the __ macro to avoid the code coverage
350
+ // tool from instrumenting as we rely on the code size here.
351
+ int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize;
352
+ CodeGenerator::RecordPositions(masm_, function()->end_position() - 1);
353
+ __ RecordJSReturn();
354
+ masm_->mov(sp, fp);
355
+ masm_->MultiPop(static_cast<RegList>(fp.bit() | ra.bit()));
356
+ masm_->Addu(sp, sp, Operand(sp_delta));
357
+ masm_->Jump(ra);
358
+ }
359
+
360
+ #ifdef DEBUG
361
+ // Check that the size of the code used for returning is large enough
362
+ // for the debugger's requirements.
363
+ ASSERT(Assembler::kJSReturnSequenceInstructions <=
364
+ masm_->InstructionsGeneratedSince(&check_exit_codesize));
365
+ #endif
366
+ }
367
+ }
368
+
369
+
370
+ void FullCodeGenerator::EffectContext::Plug(Slot* slot) const {
371
+ }
372
+
373
+
374
+ void FullCodeGenerator::AccumulatorValueContext::Plug(Slot* slot) const {
375
+ codegen()->Move(result_register(), slot);
376
+ }
377
+
378
+
379
+ void FullCodeGenerator::StackValueContext::Plug(Slot* slot) const {
380
+ codegen()->Move(result_register(), slot);
381
+ __ push(result_register());
382
+ }
383
+
384
+
385
+ void FullCodeGenerator::TestContext::Plug(Slot* slot) const {
386
+ // For simplicity we always test the accumulator register.
387
+ codegen()->Move(result_register(), slot);
388
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
389
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
390
+ }
391
+
392
+
393
+ void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const {
394
+ }
395
+
396
+
397
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
398
+ Heap::RootListIndex index) const {
399
+ __ LoadRoot(result_register(), index);
400
+ }
401
+
402
+
403
+ void FullCodeGenerator::StackValueContext::Plug(
404
+ Heap::RootListIndex index) const {
405
+ __ LoadRoot(result_register(), index);
406
+ __ push(result_register());
407
+ }
408
+
409
+
410
+ void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const {
411
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG,
412
+ true,
413
+ true_label_,
414
+ false_label_);
415
+ if (index == Heap::kUndefinedValueRootIndex ||
416
+ index == Heap::kNullValueRootIndex ||
417
+ index == Heap::kFalseValueRootIndex) {
418
+ if (false_label_ != fall_through_) __ Branch(false_label_);
419
+ } else if (index == Heap::kTrueValueRootIndex) {
420
+ if (true_label_ != fall_through_) __ Branch(true_label_);
421
+ } else {
422
+ __ LoadRoot(result_register(), index);
423
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
424
+ }
425
+ }
426
+
427
+
428
+ void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const {
429
+ }
430
+
431
+
432
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
433
+ Handle<Object> lit) const {
434
+ __ li(result_register(), Operand(lit));
435
+ }
436
+
437
+
438
+ void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
439
+ // Immediates cannot be pushed directly.
440
+ __ li(result_register(), Operand(lit));
441
+ __ push(result_register());
442
+ }
443
+
444
+
445
+ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
446
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG,
447
+ true,
448
+ true_label_,
449
+ false_label_);
450
+ ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals.
451
+ if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) {
452
+ if (false_label_ != fall_through_) __ Branch(false_label_);
453
+ } else if (lit->IsTrue() || lit->IsJSObject()) {
454
+ if (true_label_ != fall_through_) __ Branch(true_label_);
455
+ } else if (lit->IsString()) {
456
+ if (String::cast(*lit)->length() == 0) {
457
+ if (false_label_ != fall_through_) __ Branch(false_label_);
458
+ } else {
459
+ if (true_label_ != fall_through_) __ Branch(true_label_);
460
+ }
461
+ } else if (lit->IsSmi()) {
462
+ if (Smi::cast(*lit)->value() == 0) {
463
+ if (false_label_ != fall_through_) __ Branch(false_label_);
464
+ } else {
465
+ if (true_label_ != fall_through_) __ Branch(true_label_);
466
+ }
467
+ } else {
468
+ // For simplicity we always test the accumulator register.
469
+ __ li(result_register(), Operand(lit));
470
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
471
+ }
472
+ }
473
+
474
+
475
+ void FullCodeGenerator::EffectContext::DropAndPlug(int count,
476
+ Register reg) const {
477
+ ASSERT(count > 0);
478
+ __ Drop(count);
479
+ }
480
+
481
+
482
+ void FullCodeGenerator::AccumulatorValueContext::DropAndPlug(
483
+ int count,
484
+ Register reg) const {
485
+ ASSERT(count > 0);
486
+ __ Drop(count);
487
+ __ Move(result_register(), reg);
488
+ }
489
+
490
+
491
+ void FullCodeGenerator::StackValueContext::DropAndPlug(int count,
492
+ Register reg) const {
493
+ ASSERT(count > 0);
494
+ if (count > 1) __ Drop(count - 1);
495
+ __ sw(reg, MemOperand(sp, 0));
496
+ }
497
+
498
+
499
+ void FullCodeGenerator::TestContext::DropAndPlug(int count,
500
+ Register reg) const {
501
+ ASSERT(count > 0);
502
+ // For simplicity we always test the accumulator register.
503
+ __ Drop(count);
504
+ __ Move(result_register(), reg);
505
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
506
+ codegen()->DoTest(true_label_, false_label_, fall_through_);
507
+ }
508
+
509
+
510
+ void FullCodeGenerator::EffectContext::Plug(Label* materialize_true,
511
+ Label* materialize_false) const {
512
+ ASSERT(materialize_true == materialize_false);
513
+ __ bind(materialize_true);
514
+ }
515
+
516
+
517
+ void FullCodeGenerator::AccumulatorValueContext::Plug(
518
+ Label* materialize_true,
519
+ Label* materialize_false) const {
520
+ Label done;
521
+ __ bind(materialize_true);
522
+ __ LoadRoot(result_register(), Heap::kTrueValueRootIndex);
523
+ __ Branch(&done);
524
+ __ bind(materialize_false);
525
+ __ LoadRoot(result_register(), Heap::kFalseValueRootIndex);
526
+ __ bind(&done);
527
+ }
528
+
529
+
530
+ void FullCodeGenerator::StackValueContext::Plug(
531
+ Label* materialize_true,
532
+ Label* materialize_false) const {
533
+ Label done;
534
+ __ bind(materialize_true);
535
+ __ LoadRoot(at, Heap::kTrueValueRootIndex);
536
+ __ push(at);
537
+ __ Branch(&done);
538
+ __ bind(materialize_false);
539
+ __ LoadRoot(at, Heap::kFalseValueRootIndex);
540
+ __ push(at);
541
+ __ bind(&done);
542
+ }
543
+
544
+
545
+ void FullCodeGenerator::TestContext::Plug(Label* materialize_true,
546
+ Label* materialize_false) const {
547
+ ASSERT(materialize_true == true_label_);
548
+ ASSERT(materialize_false == false_label_);
549
+ }
550
+
551
+
552
+ void FullCodeGenerator::EffectContext::Plug(bool flag) const {
553
+ }
554
+
555
+
556
+ void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const {
557
+ Heap::RootListIndex value_root_index =
558
+ flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
559
+ __ LoadRoot(result_register(), value_root_index);
560
+ }
561
+
562
+
563
+ void FullCodeGenerator::StackValueContext::Plug(bool flag) const {
564
+ Heap::RootListIndex value_root_index =
565
+ flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex;
566
+ __ LoadRoot(at, value_root_index);
567
+ __ push(at);
568
+ }
569
+
570
+
571
+ void FullCodeGenerator::TestContext::Plug(bool flag) const {
572
+ codegen()->PrepareForBailoutBeforeSplit(TOS_REG,
573
+ true,
574
+ true_label_,
575
+ false_label_);
576
+ if (flag) {
577
+ if (true_label_ != fall_through_) __ Branch(true_label_);
578
+ } else {
579
+ if (false_label_ != fall_through_) __ Branch(false_label_);
580
+ }
581
+ }
582
+
583
+
584
+ void FullCodeGenerator::DoTest(Label* if_true,
585
+ Label* if_false,
586
+ Label* fall_through) {
587
+ if (CpuFeatures::IsSupported(FPU)) {
588
+ ToBooleanStub stub(result_register());
589
+ __ CallStub(&stub);
590
+ __ mov(at, zero_reg);
591
+ } else {
592
+ // Call the runtime to find the boolean value of the source and then
593
+ // translate it into control flow to the pair of labels.
594
+ __ push(result_register());
595
+ __ CallRuntime(Runtime::kToBool, 1);
596
+ __ LoadRoot(at, Heap::kFalseValueRootIndex);
597
+ }
598
+ Split(ne, v0, Operand(at), if_true, if_false, fall_through);
599
+ }
600
+
601
+
602
+ void FullCodeGenerator::Split(Condition cc,
603
+ Register lhs,
604
+ const Operand& rhs,
605
+ Label* if_true,
606
+ Label* if_false,
607
+ Label* fall_through) {
608
+ if (if_false == fall_through) {
609
+ __ Branch(if_true, cc, lhs, rhs);
610
+ } else if (if_true == fall_through) {
611
+ __ Branch(if_false, NegateCondition(cc), lhs, rhs);
612
+ } else {
613
+ __ Branch(if_true, cc, lhs, rhs);
614
+ __ Branch(if_false);
615
+ }
616
+ }
617
+
618
+
619
+ MemOperand FullCodeGenerator::EmitSlotSearch(Slot* slot, Register scratch) {
620
+ switch (slot->type()) {
621
+ case Slot::PARAMETER:
622
+ case Slot::LOCAL:
623
+ return MemOperand(fp, SlotOffset(slot));
624
+ case Slot::CONTEXT: {
625
+ int context_chain_length =
626
+ scope()->ContextChainLength(slot->var()->scope());
627
+ __ LoadContext(scratch, context_chain_length);
628
+ return ContextOperand(scratch, slot->index());
629
+ }
630
+ case Slot::LOOKUP:
631
+ UNREACHABLE();
632
+ }
633
+ UNREACHABLE();
634
+ return MemOperand(v0, 0);
635
+ }
636
+
637
+
638
+ void FullCodeGenerator::Move(Register destination, Slot* source) {
639
+ // Use destination as scratch.
640
+ MemOperand slot_operand = EmitSlotSearch(source, destination);
641
+ __ lw(destination, slot_operand);
642
+ }
643
+
644
+
645
+ void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state,
646
+ bool should_normalize,
647
+ Label* if_true,
648
+ Label* if_false) {
649
+ // Only prepare for bailouts before splits if we're in a test
650
+ // context. Otherwise, we let the Visit function deal with the
651
+ // preparation to avoid preparing with the same AST id twice.
652
+ if (!context()->IsTest() || !info_->IsOptimizable()) return;
653
+
654
+ Label skip;
655
+ if (should_normalize) __ Branch(&skip);
656
+
657
+ ForwardBailoutStack* current = forward_bailout_stack_;
658
+ while (current != NULL) {
659
+ PrepareForBailout(current->expr(), state);
660
+ current = current->parent();
661
+ }
662
+
663
+ if (should_normalize) {
664
+ __ LoadRoot(t0, Heap::kTrueValueRootIndex);
665
+ Split(eq, a0, Operand(t0), if_true, if_false, NULL);
666
+ __ bind(&skip);
667
+ }
668
+ }
669
+
670
+
671
+ void FullCodeGenerator::Move(Slot* dst,
672
+ Register src,
673
+ Register scratch1,
674
+ Register scratch2) {
675
+ ASSERT(dst->type() != Slot::LOOKUP); // Not yet implemented.
676
+ ASSERT(!scratch1.is(src) && !scratch2.is(src));
677
+ MemOperand location = EmitSlotSearch(dst, scratch1);
678
+ __ sw(src, location);
679
+ // Emit the write barrier code if the location is in the heap.
680
+ if (dst->type() == Slot::CONTEXT) {
681
+ __ RecordWrite(scratch1,
682
+ Operand(Context::SlotOffset(dst->index())),
683
+ scratch2,
684
+ src);
685
+ }
686
+ }
687
+
688
+
689
+ void FullCodeGenerator::EmitDeclaration(Variable* variable,
690
+ Variable::Mode mode,
691
+ FunctionLiteral* function) {
692
+ Comment cmnt(masm_, "[ Declaration");
693
+ ASSERT(variable != NULL); // Must have been resolved.
694
+ Slot* slot = variable->AsSlot();
695
+ Property* prop = variable->AsProperty();
696
+
697
+ if (slot != NULL) {
698
+ switch (slot->type()) {
699
+ case Slot::PARAMETER:
700
+ case Slot::LOCAL:
701
+ if (mode == Variable::CONST) {
702
+ __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
703
+ __ sw(t0, MemOperand(fp, SlotOffset(slot)));
704
+ } else if (function != NULL) {
705
+ VisitForAccumulatorValue(function);
706
+ __ sw(result_register(), MemOperand(fp, SlotOffset(slot)));
707
+ }
708
+ break;
709
+
710
+ case Slot::CONTEXT:
711
+ // We bypass the general EmitSlotSearch because we know more about
712
+ // this specific context.
713
+
714
+ // The variable in the decl always resides in the current function
715
+ // context.
716
+ ASSERT_EQ(0, scope()->ContextChainLength(variable->scope()));
717
+ if (FLAG_debug_code) {
718
+ // Check that we're not inside a 'with'.
719
+ __ lw(a1, ContextOperand(cp, Context::FCONTEXT_INDEX));
720
+ __ Check(eq, "Unexpected declaration in current context.",
721
+ a1, Operand(cp));
722
+ }
723
+ if (mode == Variable::CONST) {
724
+ __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
725
+ __ sw(at, ContextOperand(cp, slot->index()));
726
+ // No write barrier since the_hole_value is in old space.
727
+ } else if (function != NULL) {
728
+ VisitForAccumulatorValue(function);
729
+ __ sw(result_register(), ContextOperand(cp, slot->index()));
730
+ int offset = Context::SlotOffset(slot->index());
731
+ // We know that we have written a function, which is not a smi.
732
+ __ mov(a1, cp);
733
+ __ RecordWrite(a1, Operand(offset), a2, result_register());
734
+ }
735
+ break;
736
+
737
+ case Slot::LOOKUP: {
738
+ __ li(a2, Operand(variable->name()));
739
+ // Declaration nodes are always introduced in one of two modes.
740
+ ASSERT(mode == Variable::VAR ||
741
+ mode == Variable::CONST);
742
+ PropertyAttributes attr =
743
+ (mode == Variable::VAR) ? NONE : READ_ONLY;
744
+ __ li(a1, Operand(Smi::FromInt(attr)));
745
+ // Push initial value, if any.
746
+ // Note: For variables we must not push an initial value (such as
747
+ // 'undefined') because we may have a (legal) redeclaration and we
748
+ // must not destroy the current value.
749
+ if (mode == Variable::CONST) {
750
+ __ LoadRoot(a0, Heap::kTheHoleValueRootIndex);
751
+ __ Push(cp, a2, a1, a0);
752
+ } else if (function != NULL) {
753
+ __ Push(cp, a2, a1);
754
+ // Push initial value for function declaration.
755
+ VisitForStackValue(function);
756
+ } else {
757
+ ASSERT(Smi::FromInt(0) == 0);
758
+ // No initial value!
759
+ __ mov(a0, zero_reg); // Operand(Smi::FromInt(0)));
760
+ __ Push(cp, a2, a1, a0);
761
+ }
762
+ __ CallRuntime(Runtime::kDeclareContextSlot, 4);
763
+ break;
764
+ }
765
+ }
766
+
767
+ } else if (prop != NULL) {
768
+ // A const declaration aliasing a parameter is an illegal redeclaration.
769
+ ASSERT(mode != Variable::CONST);
770
+ if (function != NULL) {
771
+ // We are declaring a function that rewrites to a property.
772
+ // Use (keyed) IC to set the initial value. We cannot visit the
773
+ // rewrite because it's shared and we risk recording duplicate AST
774
+ // IDs for bailouts from optimized code.
775
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
776
+ { AccumulatorValueContext for_object(this);
777
+ EmitVariableLoad(prop->obj()->AsVariableProxy()->var());
778
+ }
779
+
780
+ __ push(result_register());
781
+ VisitForAccumulatorValue(function);
782
+ __ mov(a0, result_register());
783
+ __ pop(a2);
784
+
785
+ ASSERT(prop->key()->AsLiteral() != NULL &&
786
+ prop->key()->AsLiteral()->handle()->IsSmi());
787
+ __ li(a1, Operand(prop->key()->AsLiteral()->handle()));
788
+
789
+ Handle<Code> ic = is_strict_mode()
790
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
791
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
792
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
793
+ // Value in v0 is ignored (declarations are statements).
794
+ }
795
+ }
796
+ }
797
+
798
+
799
+ void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
800
+ EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
801
+ }
802
+
803
+
804
+ void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
805
+ // Call the runtime to declare the globals.
806
+ // The context is the first argument.
807
+ __ li(a2, Operand(pairs));
808
+ __ li(a1, Operand(Smi::FromInt(is_eval() ? 1 : 0)));
809
+ __ li(a0, Operand(Smi::FromInt(strict_mode_flag())));
810
+ __ Push(cp, a2, a1, a0);
811
+ __ CallRuntime(Runtime::kDeclareGlobals, 4);
812
+ // Return value is ignored.
813
+ }
814
+
815
+
816
+ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) {
817
+ Comment cmnt(masm_, "[ SwitchStatement");
818
+ Breakable nested_statement(this, stmt);
819
+ SetStatementPosition(stmt);
820
+
821
+ // Keep the switch value on the stack until a case matches.
822
+ VisitForStackValue(stmt->tag());
823
+ PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
824
+
825
+ ZoneList<CaseClause*>* clauses = stmt->cases();
826
+ CaseClause* default_clause = NULL; // Can occur anywhere in the list.
827
+
828
+ Label next_test; // Recycled for each test.
829
+ // Compile all the tests with branches to their bodies.
830
+ for (int i = 0; i < clauses->length(); i++) {
831
+ CaseClause* clause = clauses->at(i);
832
+ clause->body_target()->Unuse();
833
+
834
+ // The default is not a test, but remember it as final fall through.
835
+ if (clause->is_default()) {
836
+ default_clause = clause;
837
+ continue;
838
+ }
839
+
840
+ Comment cmnt(masm_, "[ Case comparison");
841
+ __ bind(&next_test);
842
+ next_test.Unuse();
843
+
844
+ // Compile the label expression.
845
+ VisitForAccumulatorValue(clause->label());
846
+ __ mov(a0, result_register()); // CompareStub requires args in a0, a1.
847
+
848
+ // Perform the comparison as if via '==='.
849
+ __ lw(a1, MemOperand(sp, 0)); // Switch value.
850
+ bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT);
851
+ JumpPatchSite patch_site(masm_);
852
+ if (inline_smi_code) {
853
+ Label slow_case;
854
+ __ or_(a2, a1, a0);
855
+ patch_site.EmitJumpIfNotSmi(a2, &slow_case);
856
+
857
+ __ Branch(&next_test, ne, a1, Operand(a0));
858
+ __ Drop(1); // Switch value is no longer needed.
859
+ __ Branch(clause->body_target());
860
+
861
+ __ bind(&slow_case);
862
+ }
863
+
864
+ // Record position before stub call for type feedback.
865
+ SetSourcePosition(clause->position());
866
+ Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT);
867
+ EmitCallIC(ic, &patch_site, clause->CompareId());
868
+
869
+ __ Branch(&next_test, ne, v0, Operand(zero_reg));
870
+ __ Drop(1); // Switch value is no longer needed.
871
+ __ Branch(clause->body_target());
872
+ }
873
+
874
+ // Discard the test value and jump to the default if present, otherwise to
875
+ // the end of the statement.
876
+ __ bind(&next_test);
877
+ __ Drop(1); // Switch value is no longer needed.
878
+ if (default_clause == NULL) {
879
+ __ Branch(nested_statement.break_target());
880
+ } else {
881
+ __ Branch(default_clause->body_target());
882
+ }
883
+
884
+ // Compile all the case bodies.
885
+ for (int i = 0; i < clauses->length(); i++) {
886
+ Comment cmnt(masm_, "[ Case body");
887
+ CaseClause* clause = clauses->at(i);
888
+ __ bind(clause->body_target());
889
+ PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS);
890
+ VisitStatements(clause->statements());
891
+ }
892
+
893
+ __ bind(nested_statement.break_target());
894
+ PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
895
+ }
896
+
897
+
898
+ void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) {
899
+ Comment cmnt(masm_, "[ ForInStatement");
900
+ SetStatementPosition(stmt);
901
+
902
+ Label loop, exit;
903
+ ForIn loop_statement(this, stmt);
904
+ increment_loop_depth();
905
+
906
+ // Get the object to enumerate over. Both SpiderMonkey and JSC
907
+ // ignore null and undefined in contrast to the specification; see
908
+ // ECMA-262 section 12.6.4.
909
+ VisitForAccumulatorValue(stmt->enumerable());
910
+ __ mov(a0, result_register()); // Result as param to InvokeBuiltin below.
911
+ __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
912
+ __ Branch(&exit, eq, a0, Operand(at));
913
+ Register null_value = t1;
914
+ __ LoadRoot(null_value, Heap::kNullValueRootIndex);
915
+ __ Branch(&exit, eq, a0, Operand(null_value));
916
+
917
+ // Convert the object to a JS object.
918
+ Label convert, done_convert;
919
+ __ JumpIfSmi(a0, &convert);
920
+ __ GetObjectType(a0, a1, a1);
921
+ __ Branch(&done_convert, hs, a1, Operand(FIRST_JS_OBJECT_TYPE));
922
+ __ bind(&convert);
923
+ __ push(a0);
924
+ __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
925
+ __ mov(a0, v0);
926
+ __ bind(&done_convert);
927
+ __ push(a0);
928
+
929
+ // Check cache validity in generated code. This is a fast case for
930
+ // the JSObject::IsSimpleEnum cache validity checks. If we cannot
931
+ // guarantee cache validity, call the runtime system to check cache
932
+ // validity or get the property names in a fixed array.
933
+ Label next, call_runtime;
934
+ // Preload a couple of values used in the loop.
935
+ Register empty_fixed_array_value = t2;
936
+ __ LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex);
937
+ Register empty_descriptor_array_value = t3;
938
+ __ LoadRoot(empty_descriptor_array_value,
939
+ Heap::kEmptyDescriptorArrayRootIndex);
940
+ __ mov(a1, a0);
941
+ __ bind(&next);
942
+
943
+ // Check that there are no elements. Register a1 contains the
944
+ // current JS object we've reached through the prototype chain.
945
+ __ lw(a2, FieldMemOperand(a1, JSObject::kElementsOffset));
946
+ __ Branch(&call_runtime, ne, a2, Operand(empty_fixed_array_value));
947
+
948
+ // Check that instance descriptors are not empty so that we can
949
+ // check for an enum cache. Leave the map in a2 for the subsequent
950
+ // prototype load.
951
+ __ lw(a2, FieldMemOperand(a1, HeapObject::kMapOffset));
952
+ __ lw(a3, FieldMemOperand(a2, Map::kInstanceDescriptorsOrBitField3Offset));
953
+ __ JumpIfSmi(a3, &call_runtime);
954
+
955
+ // Check that there is an enum cache in the non-empty instance
956
+ // descriptors (a3). This is the case if the next enumeration
957
+ // index field does not contain a smi.
958
+ __ lw(a3, FieldMemOperand(a3, DescriptorArray::kEnumerationIndexOffset));
959
+ __ JumpIfSmi(a3, &call_runtime);
960
+
961
+ // For all objects but the receiver, check that the cache is empty.
962
+ Label check_prototype;
963
+ __ Branch(&check_prototype, eq, a1, Operand(a0));
964
+ __ lw(a3, FieldMemOperand(a3, DescriptorArray::kEnumCacheBridgeCacheOffset));
965
+ __ Branch(&call_runtime, ne, a3, Operand(empty_fixed_array_value));
966
+
967
+ // Load the prototype from the map and loop if non-null.
968
+ __ bind(&check_prototype);
969
+ __ lw(a1, FieldMemOperand(a2, Map::kPrototypeOffset));
970
+ __ Branch(&next, ne, a1, Operand(null_value));
971
+
972
+ // The enum cache is valid. Load the map of the object being
973
+ // iterated over and use the cache for the iteration.
974
+ Label use_cache;
975
+ __ lw(v0, FieldMemOperand(a0, HeapObject::kMapOffset));
976
+ __ Branch(&use_cache);
977
+
978
+ // Get the set of properties to enumerate.
979
+ __ bind(&call_runtime);
980
+ __ push(a0); // Duplicate the enumerable object on the stack.
981
+ __ CallRuntime(Runtime::kGetPropertyNamesFast, 1);
982
+
983
+ // If we got a map from the runtime call, we can do a fast
984
+ // modification check. Otherwise, we got a fixed array, and we have
985
+ // to do a slow check.
986
+ Label fixed_array;
987
+ __ mov(a2, v0);
988
+ __ lw(a1, FieldMemOperand(a2, HeapObject::kMapOffset));
989
+ __ LoadRoot(at, Heap::kMetaMapRootIndex);
990
+ __ Branch(&fixed_array, ne, a1, Operand(at));
991
+
992
+ // We got a map in register v0. Get the enumeration cache from it.
993
+ __ bind(&use_cache);
994
+ __ LoadInstanceDescriptors(v0, a1);
995
+ __ lw(a1, FieldMemOperand(a1, DescriptorArray::kEnumerationIndexOffset));
996
+ __ lw(a2, FieldMemOperand(a1, DescriptorArray::kEnumCacheBridgeCacheOffset));
997
+
998
+ // Setup the four remaining stack slots.
999
+ __ push(v0); // Map.
1000
+ __ lw(a1, FieldMemOperand(a2, FixedArray::kLengthOffset));
1001
+ __ li(a0, Operand(Smi::FromInt(0)));
1002
+ // Push enumeration cache, enumeration cache length (as smi) and zero.
1003
+ __ Push(a2, a1, a0);
1004
+ __ jmp(&loop);
1005
+
1006
+ // We got a fixed array in register v0. Iterate through that.
1007
+ __ bind(&fixed_array);
1008
+ __ li(a1, Operand(Smi::FromInt(0))); // Map (0) - force slow check.
1009
+ __ Push(a1, v0);
1010
+ __ lw(a1, FieldMemOperand(v0, FixedArray::kLengthOffset));
1011
+ __ li(a0, Operand(Smi::FromInt(0)));
1012
+ __ Push(a1, a0); // Fixed array length (as smi) and initial index.
1013
+
1014
+ // Generate code for doing the condition check.
1015
+ __ bind(&loop);
1016
+ // Load the current count to a0, load the length to a1.
1017
+ __ lw(a0, MemOperand(sp, 0 * kPointerSize));
1018
+ __ lw(a1, MemOperand(sp, 1 * kPointerSize));
1019
+ __ Branch(loop_statement.break_target(), hs, a0, Operand(a1));
1020
+
1021
+ // Get the current entry of the array into register a3.
1022
+ __ lw(a2, MemOperand(sp, 2 * kPointerSize));
1023
+ __ Addu(a2, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
1024
+ __ sll(t0, a0, kPointerSizeLog2 - kSmiTagSize);
1025
+ __ addu(t0, a2, t0); // Array base + scaled (smi) index.
1026
+ __ lw(a3, MemOperand(t0)); // Current entry.
1027
+
1028
+ // Get the expected map from the stack or a zero map in the
1029
+ // permanent slow case into register a2.
1030
+ __ lw(a2, MemOperand(sp, 3 * kPointerSize));
1031
+
1032
+ // Check if the expected map still matches that of the enumerable.
1033
+ // If not, we have to filter the key.
1034
+ Label update_each;
1035
+ __ lw(a1, MemOperand(sp, 4 * kPointerSize));
1036
+ __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1037
+ __ Branch(&update_each, eq, t0, Operand(a2));
1038
+
1039
+ // Convert the entry to a string or (smi) 0 if it isn't a property
1040
+ // any more. If the property has been removed while iterating, we
1041
+ // just skip it.
1042
+ __ push(a1); // Enumerable.
1043
+ __ push(a3); // Current entry.
1044
+ __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION);
1045
+ __ mov(a3, result_register());
1046
+ __ Branch(loop_statement.continue_target(), eq, a3, Operand(zero_reg));
1047
+
1048
+ // Update the 'each' property or variable from the possibly filtered
1049
+ // entry in register a3.
1050
+ __ bind(&update_each);
1051
+ __ mov(result_register(), a3);
1052
+ // Perform the assignment as if via '='.
1053
+ { EffectContext context(this);
1054
+ EmitAssignment(stmt->each(), stmt->AssignmentId());
1055
+ }
1056
+
1057
+ // Generate code for the body of the loop.
1058
+ Visit(stmt->body());
1059
+
1060
+ // Generate code for the going to the next element by incrementing
1061
+ // the index (smi) stored on top of the stack.
1062
+ __ bind(loop_statement.continue_target());
1063
+ __ pop(a0);
1064
+ __ Addu(a0, a0, Operand(Smi::FromInt(1)));
1065
+ __ push(a0);
1066
+
1067
+ EmitStackCheck(stmt);
1068
+ __ Branch(&loop);
1069
+
1070
+ // Remove the pointers stored on the stack.
1071
+ __ bind(loop_statement.break_target());
1072
+ __ Drop(5);
1073
+
1074
+ // Exit and decrement the loop depth.
1075
+ __ bind(&exit);
1076
+ decrement_loop_depth();
1077
+ }
1078
+
1079
+
1080
+ void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info,
1081
+ bool pretenure) {
1082
+ // Use the fast case closure allocation code that allocates in new
1083
+ // space for nested functions that don't need literals cloning. If
1084
+ // we're running with the --always-opt or the --prepare-always-opt
1085
+ // flag, we need to use the runtime function so that the new function
1086
+ // we are creating here gets a chance to have its code optimized and
1087
+ // doesn't just get a copy of the existing unoptimized code.
1088
+ if (!FLAG_always_opt &&
1089
+ !FLAG_prepare_always_opt &&
1090
+ !pretenure &&
1091
+ scope()->is_function_scope() &&
1092
+ info->num_literals() == 0) {
1093
+ FastNewClosureStub stub(info->strict_mode() ? kStrictMode : kNonStrictMode);
1094
+ __ li(a0, Operand(info));
1095
+ __ push(a0);
1096
+ __ CallStub(&stub);
1097
+ } else {
1098
+ __ li(a0, Operand(info));
1099
+ __ LoadRoot(a1, pretenure ? Heap::kTrueValueRootIndex
1100
+ : Heap::kFalseValueRootIndex);
1101
+ __ Push(cp, a0, a1);
1102
+ __ CallRuntime(Runtime::kNewClosure, 3);
1103
+ }
1104
+ context()->Plug(v0);
1105
+ }
1106
+
1107
+
1108
+ void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
1109
+ Comment cmnt(masm_, "[ VariableProxy");
1110
+ EmitVariableLoad(expr->var());
1111
+ }
1112
+
1113
+
1114
+ void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions(
1115
+ Slot* slot,
1116
+ TypeofState typeof_state,
1117
+ Label* slow) {
1118
+ Register current = cp;
1119
+ Register next = a1;
1120
+ Register temp = a2;
1121
+
1122
+ Scope* s = scope();
1123
+ while (s != NULL) {
1124
+ if (s->num_heap_slots() > 0) {
1125
+ if (s->calls_eval()) {
1126
+ // Check that extension is NULL.
1127
+ __ lw(temp, ContextOperand(current, Context::EXTENSION_INDEX));
1128
+ __ Branch(slow, ne, temp, Operand(zero_reg));
1129
+ }
1130
+ // Load next context in chain.
1131
+ __ lw(next, ContextOperand(current, Context::CLOSURE_INDEX));
1132
+ __ lw(next, FieldMemOperand(next, JSFunction::kContextOffset));
1133
+ // Walk the rest of the chain without clobbering cp.
1134
+ current = next;
1135
+ }
1136
+ // If no outer scope calls eval, we do not need to check more
1137
+ // context extensions.
1138
+ if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break;
1139
+ s = s->outer_scope();
1140
+ }
1141
+
1142
+ if (s->is_eval_scope()) {
1143
+ Label loop, fast;
1144
+ if (!current.is(next)) {
1145
+ __ Move(next, current);
1146
+ }
1147
+ __ bind(&loop);
1148
+ // Terminate at global context.
1149
+ __ lw(temp, FieldMemOperand(next, HeapObject::kMapOffset));
1150
+ __ LoadRoot(t0, Heap::kGlobalContextMapRootIndex);
1151
+ __ Branch(&fast, eq, temp, Operand(t0));
1152
+ // Check that extension is NULL.
1153
+ __ lw(temp, ContextOperand(next, Context::EXTENSION_INDEX));
1154
+ __ Branch(slow, ne, temp, Operand(zero_reg));
1155
+ // Load next context in chain.
1156
+ __ lw(next, ContextOperand(next, Context::CLOSURE_INDEX));
1157
+ __ lw(next, FieldMemOperand(next, JSFunction::kContextOffset));
1158
+ __ Branch(&loop);
1159
+ __ bind(&fast);
1160
+ }
1161
+
1162
+ __ lw(a0, GlobalObjectOperand());
1163
+ __ li(a2, Operand(slot->var()->name()));
1164
+ RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF)
1165
+ ? RelocInfo::CODE_TARGET
1166
+ : RelocInfo::CODE_TARGET_CONTEXT;
1167
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1168
+ EmitCallIC(ic, mode, AstNode::kNoNumber);
1169
+ }
1170
+
1171
+
1172
+ MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(
1173
+ Slot* slot,
1174
+ Label* slow) {
1175
+ ASSERT(slot->type() == Slot::CONTEXT);
1176
+ Register context = cp;
1177
+ Register next = a3;
1178
+ Register temp = t0;
1179
+
1180
+ for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) {
1181
+ if (s->num_heap_slots() > 0) {
1182
+ if (s->calls_eval()) {
1183
+ // Check that extension is NULL.
1184
+ __ lw(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1185
+ __ Branch(slow, ne, temp, Operand(zero_reg));
1186
+ }
1187
+ __ lw(next, ContextOperand(context, Context::CLOSURE_INDEX));
1188
+ __ lw(next, FieldMemOperand(next, JSFunction::kContextOffset));
1189
+ // Walk the rest of the chain without clobbering cp.
1190
+ context = next;
1191
+ }
1192
+ }
1193
+ // Check that last extension is NULL.
1194
+ __ lw(temp, ContextOperand(context, Context::EXTENSION_INDEX));
1195
+ __ Branch(slow, ne, temp, Operand(zero_reg));
1196
+
1197
+ // This function is used only for loads, not stores, so it's safe to
1198
+ // return an cp-based operand (the write barrier cannot be allowed to
1199
+ // destroy the cp register).
1200
+ return ContextOperand(context, slot->index());
1201
+ }
1202
+
1203
+
1204
+ void FullCodeGenerator::EmitDynamicLoadFromSlotFastCase(
1205
+ Slot* slot,
1206
+ TypeofState typeof_state,
1207
+ Label* slow,
1208
+ Label* done) {
1209
+ // Generate fast-case code for variables that might be shadowed by
1210
+ // eval-introduced variables. Eval is used a lot without
1211
+ // introducing variables. In those cases, we do not want to
1212
+ // perform a runtime call for all variables in the scope
1213
+ // containing the eval.
1214
+ if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) {
1215
+ EmitLoadGlobalSlotCheckExtensions(slot, typeof_state, slow);
1216
+ __ Branch(done);
1217
+ } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) {
1218
+ Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot();
1219
+ Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite();
1220
+ if (potential_slot != NULL) {
1221
+ // Generate fast case for locals that rewrite to slots.
1222
+ __ lw(v0, ContextSlotOperandCheckExtensions(potential_slot, slow));
1223
+ if (potential_slot->var()->mode() == Variable::CONST) {
1224
+ __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
1225
+ __ subu(at, v0, at); // Sub as compare: at == 0 on eq.
1226
+ __ LoadRoot(a0, Heap::kUndefinedValueRootIndex);
1227
+ __ movz(v0, a0, at); // Conditional move.
1228
+ }
1229
+ __ Branch(done);
1230
+ } else if (rewrite != NULL) {
1231
+ // Generate fast case for calls of an argument function.
1232
+ Property* property = rewrite->AsProperty();
1233
+ if (property != NULL) {
1234
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1235
+ Literal* key_literal = property->key()->AsLiteral();
1236
+ if (obj_proxy != NULL &&
1237
+ key_literal != NULL &&
1238
+ obj_proxy->IsArguments() &&
1239
+ key_literal->handle()->IsSmi()) {
1240
+ // Load arguments object if there are no eval-introduced
1241
+ // variables. Then load the argument from the arguments
1242
+ // object using keyed load.
1243
+ __ lw(a1,
1244
+ ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(),
1245
+ slow));
1246
+ __ li(a0, Operand(key_literal->handle()));
1247
+ Handle<Code> ic =
1248
+ isolate()->builtins()->KeyedLoadIC_Initialize();
1249
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property));
1250
+ __ Branch(done);
1251
+ }
1252
+ }
1253
+ }
1254
+ }
1255
+ }
1256
+
1257
+
1258
+ void FullCodeGenerator::EmitVariableLoad(Variable* var) {
1259
+ // Four cases: non-this global variables, lookup slots, all other
1260
+ // types of slots, and parameters that rewrite to explicit property
1261
+ // accesses on the arguments object.
1262
+ Slot* slot = var->AsSlot();
1263
+ Property* property = var->AsProperty();
1264
+
1265
+ if (var->is_global() && !var->is_this()) {
1266
+ Comment cmnt(masm_, "Global variable");
1267
+ // Use inline caching. Variable name is passed in a2 and the global
1268
+ // object (receiver) in a0.
1269
+ __ lw(a0, GlobalObjectOperand());
1270
+ __ li(a2, Operand(var->name()));
1271
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1272
+ EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber);
1273
+ context()->Plug(v0);
1274
+
1275
+ } else if (slot != NULL && slot->type() == Slot::LOOKUP) {
1276
+ Label done, slow;
1277
+
1278
+ // Generate code for loading from variables potentially shadowed
1279
+ // by eval-introduced variables.
1280
+ EmitDynamicLoadFromSlotFastCase(slot, NOT_INSIDE_TYPEOF, &slow, &done);
1281
+
1282
+ __ bind(&slow);
1283
+ Comment cmnt(masm_, "Lookup slot");
1284
+ __ li(a1, Operand(var->name()));
1285
+ __ Push(cp, a1); // Context and name.
1286
+ __ CallRuntime(Runtime::kLoadContextSlot, 2);
1287
+ __ bind(&done);
1288
+
1289
+ context()->Plug(v0);
1290
+
1291
+ } else if (slot != NULL) {
1292
+ Comment cmnt(masm_, (slot->type() == Slot::CONTEXT)
1293
+ ? "Context slot"
1294
+ : "Stack slot");
1295
+ if (var->mode() == Variable::CONST) {
1296
+ // Constants may be the hole value if they have not been initialized.
1297
+ // Unhole them.
1298
+ MemOperand slot_operand = EmitSlotSearch(slot, a0);
1299
+ __ lw(v0, slot_operand);
1300
+ __ LoadRoot(at, Heap::kTheHoleValueRootIndex);
1301
+ __ subu(at, v0, at); // Sub as compare: at == 0 on eq.
1302
+ __ LoadRoot(a0, Heap::kUndefinedValueRootIndex);
1303
+ __ movz(v0, a0, at); // Conditional move.
1304
+ context()->Plug(v0);
1305
+ } else {
1306
+ context()->Plug(slot);
1307
+ }
1308
+ } else {
1309
+ Comment cmnt(masm_, "Rewritten parameter");
1310
+ ASSERT_NOT_NULL(property);
1311
+ // Rewritten parameter accesses are of the form "slot[literal]".
1312
+ // Assert that the object is in a slot.
1313
+ Variable* object_var = property->obj()->AsVariableProxy()->AsVariable();
1314
+ ASSERT_NOT_NULL(object_var);
1315
+ Slot* object_slot = object_var->AsSlot();
1316
+ ASSERT_NOT_NULL(object_slot);
1317
+
1318
+ // Load the object.
1319
+ Move(a1, object_slot);
1320
+
1321
+ // Assert that the key is a smi.
1322
+ Literal* key_literal = property->key()->AsLiteral();
1323
+ ASSERT_NOT_NULL(key_literal);
1324
+ ASSERT(key_literal->handle()->IsSmi());
1325
+
1326
+ // Load the key.
1327
+ __ li(a0, Operand(key_literal->handle()));
1328
+
1329
+ // Call keyed load IC. It has arguments key and receiver in a0 and a1.
1330
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
1331
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(property));
1332
+ context()->Plug(v0);
1333
+ }
1334
+ }
1335
+
1336
+
1337
+ void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) {
1338
+ Comment cmnt(masm_, "[ RegExpLiteral");
1339
+ Label materialized;
1340
+ // Registers will be used as follows:
1341
+ // t1 = materialized value (RegExp literal)
1342
+ // t0 = JS function, literals array
1343
+ // a3 = literal index
1344
+ // a2 = RegExp pattern
1345
+ // a1 = RegExp flags
1346
+ // a0 = RegExp literal clone
1347
+ __ lw(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1348
+ __ lw(t0, FieldMemOperand(a0, JSFunction::kLiteralsOffset));
1349
+ int literal_offset =
1350
+ FixedArray::kHeaderSize + expr->literal_index() * kPointerSize;
1351
+ __ lw(t1, FieldMemOperand(t0, literal_offset));
1352
+ __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
1353
+ __ Branch(&materialized, ne, t1, Operand(at));
1354
+
1355
+ // Create regexp literal using runtime function.
1356
+ // Result will be in v0.
1357
+ __ li(a3, Operand(Smi::FromInt(expr->literal_index())));
1358
+ __ li(a2, Operand(expr->pattern()));
1359
+ __ li(a1, Operand(expr->flags()));
1360
+ __ Push(t0, a3, a2, a1);
1361
+ __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
1362
+ __ mov(t1, v0);
1363
+
1364
+ __ bind(&materialized);
1365
+ int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
1366
+ Label allocated, runtime_allocate;
1367
+ __ AllocateInNewSpace(size, v0, a2, a3, &runtime_allocate, TAG_OBJECT);
1368
+ __ jmp(&allocated);
1369
+
1370
+ __ bind(&runtime_allocate);
1371
+ __ push(t1);
1372
+ __ li(a0, Operand(Smi::FromInt(size)));
1373
+ __ push(a0);
1374
+ __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
1375
+ __ pop(t1);
1376
+
1377
+ __ bind(&allocated);
1378
+
1379
+ // After this, registers are used as follows:
1380
+ // v0: Newly allocated regexp.
1381
+ // t1: Materialized regexp.
1382
+ // a2: temp.
1383
+ __ CopyFields(v0, t1, a2.bit(), size / kPointerSize);
1384
+ context()->Plug(v0);
1385
+ }
1386
+
1387
+
1388
+ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
1389
+ Comment cmnt(masm_, "[ ObjectLiteral");
1390
+ __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1391
+ __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset));
1392
+ __ li(a2, Operand(Smi::FromInt(expr->literal_index())));
1393
+ __ li(a1, Operand(expr->constant_properties()));
1394
+ int flags = expr->fast_elements()
1395
+ ? ObjectLiteral::kFastElements
1396
+ : ObjectLiteral::kNoFlags;
1397
+ flags |= expr->has_function()
1398
+ ? ObjectLiteral::kHasFunction
1399
+ : ObjectLiteral::kNoFlags;
1400
+ __ li(a0, Operand(Smi::FromInt(flags)));
1401
+ __ Push(a3, a2, a1, a0);
1402
+ if (expr->depth() > 1) {
1403
+ __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
1404
+ } else {
1405
+ __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4);
1406
+ }
1407
+
1408
+ // If result_saved is true the result is on top of the stack. If
1409
+ // result_saved is false the result is in v0.
1410
+ bool result_saved = false;
1411
+
1412
+ // Mark all computed expressions that are bound to a key that
1413
+ // is shadowed by a later occurrence of the same key. For the
1414
+ // marked expressions, no store code is emitted.
1415
+ expr->CalculateEmitStore();
1416
+
1417
+ for (int i = 0; i < expr->properties()->length(); i++) {
1418
+ ObjectLiteral::Property* property = expr->properties()->at(i);
1419
+ if (property->IsCompileTimeValue()) continue;
1420
+
1421
+ Literal* key = property->key();
1422
+ Expression* value = property->value();
1423
+ if (!result_saved) {
1424
+ __ push(v0); // Save result on stack.
1425
+ result_saved = true;
1426
+ }
1427
+ switch (property->kind()) {
1428
+ case ObjectLiteral::Property::CONSTANT:
1429
+ UNREACHABLE();
1430
+ case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1431
+ ASSERT(!CompileTimeValue::IsCompileTimeValue(property->value()));
1432
+ // Fall through.
1433
+ case ObjectLiteral::Property::COMPUTED:
1434
+ if (key->handle()->IsSymbol()) {
1435
+ if (property->emit_store()) {
1436
+ VisitForAccumulatorValue(value);
1437
+ __ mov(a0, result_register());
1438
+ __ li(a2, Operand(key->handle()));
1439
+ __ lw(a1, MemOperand(sp));
1440
+ Handle<Code> ic = is_strict_mode()
1441
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1442
+ : isolate()->builtins()->StoreIC_Initialize();
1443
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, key->id());
1444
+ PrepareForBailoutForId(key->id(), NO_REGISTERS);
1445
+ } else {
1446
+ VisitForEffect(value);
1447
+ }
1448
+ break;
1449
+ }
1450
+ // Fall through.
1451
+ case ObjectLiteral::Property::PROTOTYPE:
1452
+ // Duplicate receiver on stack.
1453
+ __ lw(a0, MemOperand(sp));
1454
+ __ push(a0);
1455
+ VisitForStackValue(key);
1456
+ VisitForStackValue(value);
1457
+ if (property->emit_store()) {
1458
+ __ li(a0, Operand(Smi::FromInt(NONE))); // PropertyAttributes.
1459
+ __ push(a0);
1460
+ __ CallRuntime(Runtime::kSetProperty, 4);
1461
+ } else {
1462
+ __ Drop(3);
1463
+ }
1464
+ break;
1465
+ case ObjectLiteral::Property::GETTER:
1466
+ case ObjectLiteral::Property::SETTER:
1467
+ // Duplicate receiver on stack.
1468
+ __ lw(a0, MemOperand(sp));
1469
+ __ push(a0);
1470
+ VisitForStackValue(key);
1471
+ __ li(a1, Operand(property->kind() == ObjectLiteral::Property::SETTER ?
1472
+ Smi::FromInt(1) :
1473
+ Smi::FromInt(0)));
1474
+ __ push(a1);
1475
+ VisitForStackValue(value);
1476
+ __ CallRuntime(Runtime::kDefineAccessor, 4);
1477
+ break;
1478
+ }
1479
+ }
1480
+
1481
+ if (expr->has_function()) {
1482
+ ASSERT(result_saved);
1483
+ __ lw(a0, MemOperand(sp));
1484
+ __ push(a0);
1485
+ __ CallRuntime(Runtime::kToFastProperties, 1);
1486
+ }
1487
+
1488
+ if (result_saved) {
1489
+ context()->PlugTOS();
1490
+ } else {
1491
+ context()->Plug(v0);
1492
+ }
1493
+ }
1494
+
1495
+
1496
+ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
1497
+ Comment cmnt(masm_, "[ ArrayLiteral");
1498
+
1499
+ ZoneList<Expression*>* subexprs = expr->values();
1500
+ int length = subexprs->length();
1501
+ __ mov(a0, result_register());
1502
+ __ lw(a3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1503
+ __ lw(a3, FieldMemOperand(a3, JSFunction::kLiteralsOffset));
1504
+ __ li(a2, Operand(Smi::FromInt(expr->literal_index())));
1505
+ __ li(a1, Operand(expr->constant_elements()));
1506
+ __ Push(a3, a2, a1);
1507
+ if (expr->constant_elements()->map() ==
1508
+ isolate()->heap()->fixed_cow_array_map()) {
1509
+ FastCloneShallowArrayStub stub(
1510
+ FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length);
1511
+ __ CallStub(&stub);
1512
+ __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(),
1513
+ 1, a1, a2);
1514
+ } else if (expr->depth() > 1) {
1515
+ __ CallRuntime(Runtime::kCreateArrayLiteral, 3);
1516
+ } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) {
1517
+ __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3);
1518
+ } else {
1519
+ FastCloneShallowArrayStub stub(
1520
+ FastCloneShallowArrayStub::CLONE_ELEMENTS, length);
1521
+ __ CallStub(&stub);
1522
+ }
1523
+
1524
+ bool result_saved = false; // Is the result saved to the stack?
1525
+
1526
+ // Emit code to evaluate all the non-constant subexpressions and to store
1527
+ // them into the newly cloned array.
1528
+ for (int i = 0; i < length; i++) {
1529
+ Expression* subexpr = subexprs->at(i);
1530
+ // If the subexpression is a literal or a simple materialized literal it
1531
+ // is already set in the cloned array.
1532
+ if (subexpr->AsLiteral() != NULL ||
1533
+ CompileTimeValue::IsCompileTimeValue(subexpr)) {
1534
+ continue;
1535
+ }
1536
+
1537
+ if (!result_saved) {
1538
+ __ push(v0);
1539
+ result_saved = true;
1540
+ }
1541
+ VisitForAccumulatorValue(subexpr);
1542
+
1543
+ // Store the subexpression value in the array's elements.
1544
+ __ lw(a1, MemOperand(sp)); // Copy of array literal.
1545
+ __ lw(a1, FieldMemOperand(a1, JSObject::kElementsOffset));
1546
+ int offset = FixedArray::kHeaderSize + (i * kPointerSize);
1547
+ __ sw(result_register(), FieldMemOperand(a1, offset));
1548
+
1549
+ // Update the write barrier for the array store with v0 as the scratch
1550
+ // register.
1551
+ __ li(a2, Operand(offset));
1552
+ // TODO(PJ): double check this RecordWrite call.
1553
+ __ RecordWrite(a1, a2, result_register());
1554
+
1555
+ PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
1556
+ }
1557
+
1558
+ if (result_saved) {
1559
+ context()->PlugTOS();
1560
+ } else {
1561
+ context()->Plug(v0);
1562
+ }
1563
+ }
1564
+
1565
+
1566
+ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
1567
+ Comment cmnt(masm_, "[ Assignment");
1568
+ // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
1569
+ // on the left-hand side.
1570
+ if (!expr->target()->IsValidLeftHandSide()) {
1571
+ VisitForEffect(expr->target());
1572
+ return;
1573
+ }
1574
+
1575
+ // Left-hand side can only be a property, a global or a (parameter or local)
1576
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
1577
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
1578
+ LhsKind assign_type = VARIABLE;
1579
+ Property* property = expr->target()->AsProperty();
1580
+ if (property != NULL) {
1581
+ assign_type = (property->key()->IsPropertyName())
1582
+ ? NAMED_PROPERTY
1583
+ : KEYED_PROPERTY;
1584
+ }
1585
+
1586
+ // Evaluate LHS expression.
1587
+ switch (assign_type) {
1588
+ case VARIABLE:
1589
+ // Nothing to do here.
1590
+ break;
1591
+ case NAMED_PROPERTY:
1592
+ if (expr->is_compound()) {
1593
+ // We need the receiver both on the stack and in the accumulator.
1594
+ VisitForAccumulatorValue(property->obj());
1595
+ __ push(result_register());
1596
+ } else {
1597
+ VisitForStackValue(property->obj());
1598
+ }
1599
+ break;
1600
+ case KEYED_PROPERTY:
1601
+ // We need the key and receiver on both the stack and in v0 and a1.
1602
+ if (expr->is_compound()) {
1603
+ if (property->is_arguments_access()) {
1604
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1605
+ __ lw(v0, EmitSlotSearch(obj_proxy->var()->AsSlot(), v0));
1606
+ __ push(v0);
1607
+ __ li(v0, Operand(property->key()->AsLiteral()->handle()));
1608
+ } else {
1609
+ VisitForStackValue(property->obj());
1610
+ VisitForAccumulatorValue(property->key());
1611
+ }
1612
+ __ lw(a1, MemOperand(sp, 0));
1613
+ __ push(v0);
1614
+ } else {
1615
+ if (property->is_arguments_access()) {
1616
+ VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
1617
+ __ lw(a1, EmitSlotSearch(obj_proxy->var()->AsSlot(), v0));
1618
+ __ li(v0, Operand(property->key()->AsLiteral()->handle()));
1619
+ __ Push(a1, v0);
1620
+ } else {
1621
+ VisitForStackValue(property->obj());
1622
+ VisitForStackValue(property->key());
1623
+ }
1624
+ }
1625
+ break;
1626
+ }
1627
+
1628
+ // For compound assignments we need another deoptimization point after the
1629
+ // variable/property load.
1630
+ if (expr->is_compound()) {
1631
+ { AccumulatorValueContext context(this);
1632
+ switch (assign_type) {
1633
+ case VARIABLE:
1634
+ EmitVariableLoad(expr->target()->AsVariableProxy()->var());
1635
+ PrepareForBailout(expr->target(), TOS_REG);
1636
+ break;
1637
+ case NAMED_PROPERTY:
1638
+ EmitNamedPropertyLoad(property);
1639
+ PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG);
1640
+ break;
1641
+ case KEYED_PROPERTY:
1642
+ EmitKeyedPropertyLoad(property);
1643
+ PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG);
1644
+ break;
1645
+ }
1646
+ }
1647
+
1648
+ Token::Value op = expr->binary_op();
1649
+ __ push(v0); // Left operand goes on the stack.
1650
+ VisitForAccumulatorValue(expr->value());
1651
+
1652
+ OverwriteMode mode = expr->value()->ResultOverwriteAllowed()
1653
+ ? OVERWRITE_RIGHT
1654
+ : NO_OVERWRITE;
1655
+ SetSourcePosition(expr->position() + 1);
1656
+ AccumulatorValueContext context(this);
1657
+ if (ShouldInlineSmiCase(op)) {
1658
+ EmitInlineSmiBinaryOp(expr->binary_operation(),
1659
+ op,
1660
+ mode,
1661
+ expr->target(),
1662
+ expr->value());
1663
+ } else {
1664
+ EmitBinaryOp(expr->binary_operation(), op, mode);
1665
+ }
1666
+
1667
+ // Deoptimization point in case the binary operation may have side effects.
1668
+ PrepareForBailout(expr->binary_operation(), TOS_REG);
1669
+ } else {
1670
+ VisitForAccumulatorValue(expr->value());
1671
+ }
1672
+
1673
+ // Record source position before possible IC call.
1674
+ SetSourcePosition(expr->position());
1675
+
1676
+ // Store the value.
1677
+ switch (assign_type) {
1678
+ case VARIABLE:
1679
+ EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
1680
+ expr->op());
1681
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
1682
+ context()->Plug(v0);
1683
+ break;
1684
+ case NAMED_PROPERTY:
1685
+ EmitNamedPropertyAssignment(expr);
1686
+ break;
1687
+ case KEYED_PROPERTY:
1688
+ EmitKeyedPropertyAssignment(expr);
1689
+ break;
1690
+ }
1691
+ }
1692
+
1693
+
1694
+ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
1695
+ SetSourcePosition(prop->position());
1696
+ Literal* key = prop->key()->AsLiteral();
1697
+ __ mov(a0, result_register());
1698
+ __ li(a2, Operand(key->handle()));
1699
+ // Call load IC. It has arguments receiver and property name a0 and a2.
1700
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1701
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
1702
+ }
1703
+
1704
+
1705
+ void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
1706
+ SetSourcePosition(prop->position());
1707
+ __ mov(a0, result_register());
1708
+ // Call keyed load IC. It has arguments key and receiver in a0 and a1.
1709
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
1710
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
1711
+ }
1712
+
1713
+
1714
+ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr,
1715
+ Token::Value op,
1716
+ OverwriteMode mode,
1717
+ Expression* left_expr,
1718
+ Expression* right_expr) {
1719
+ Label done, smi_case, stub_call;
1720
+
1721
+ Register scratch1 = a2;
1722
+ Register scratch2 = a3;
1723
+
1724
+ // Get the arguments.
1725
+ Register left = a1;
1726
+ Register right = a0;
1727
+ __ pop(left);
1728
+ __ mov(a0, result_register());
1729
+
1730
+ // Perform combined smi check on both operands.
1731
+ __ Or(scratch1, left, Operand(right));
1732
+ STATIC_ASSERT(kSmiTag == 0);
1733
+ JumpPatchSite patch_site(masm_);
1734
+ patch_site.EmitJumpIfSmi(scratch1, &smi_case);
1735
+
1736
+ __ bind(&stub_call);
1737
+ BinaryOpStub stub(op, mode);
1738
+ EmitCallIC(stub.GetCode(), &patch_site, expr->id());
1739
+ __ jmp(&done);
1740
+
1741
+ __ bind(&smi_case);
1742
+ // Smi case. This code works the same way as the smi-smi case in the type
1743
+ // recording binary operation stub, see
1744
+ // BinaryOpStub::GenerateSmiSmiOperation for comments.
1745
+ switch (op) {
1746
+ case Token::SAR:
1747
+ __ Branch(&stub_call);
1748
+ __ GetLeastBitsFromSmi(scratch1, right, 5);
1749
+ __ srav(right, left, scratch1);
1750
+ __ And(v0, right, Operand(~kSmiTagMask));
1751
+ break;
1752
+ case Token::SHL: {
1753
+ __ Branch(&stub_call);
1754
+ __ SmiUntag(scratch1, left);
1755
+ __ GetLeastBitsFromSmi(scratch2, right, 5);
1756
+ __ sllv(scratch1, scratch1, scratch2);
1757
+ __ Addu(scratch2, scratch1, Operand(0x40000000));
1758
+ __ Branch(&stub_call, lt, scratch2, Operand(zero_reg));
1759
+ __ SmiTag(v0, scratch1);
1760
+ break;
1761
+ }
1762
+ case Token::SHR: {
1763
+ __ Branch(&stub_call);
1764
+ __ SmiUntag(scratch1, left);
1765
+ __ GetLeastBitsFromSmi(scratch2, right, 5);
1766
+ __ srlv(scratch1, scratch1, scratch2);
1767
+ __ And(scratch2, scratch1, 0xc0000000);
1768
+ __ Branch(&stub_call, ne, scratch2, Operand(zero_reg));
1769
+ __ SmiTag(v0, scratch1);
1770
+ break;
1771
+ }
1772
+ case Token::ADD:
1773
+ __ AdduAndCheckForOverflow(v0, left, right, scratch1);
1774
+ __ BranchOnOverflow(&stub_call, scratch1);
1775
+ break;
1776
+ case Token::SUB:
1777
+ __ SubuAndCheckForOverflow(v0, left, right, scratch1);
1778
+ __ BranchOnOverflow(&stub_call, scratch1);
1779
+ break;
1780
+ case Token::MUL: {
1781
+ __ SmiUntag(scratch1, right);
1782
+ __ Mult(left, scratch1);
1783
+ __ mflo(scratch1);
1784
+ __ mfhi(scratch2);
1785
+ __ sra(scratch1, scratch1, 31);
1786
+ __ Branch(&stub_call, ne, scratch1, Operand(scratch2));
1787
+ __ mflo(v0);
1788
+ __ Branch(&done, ne, v0, Operand(zero_reg));
1789
+ __ Addu(scratch2, right, left);
1790
+ __ Branch(&stub_call, lt, scratch2, Operand(zero_reg));
1791
+ ASSERT(Smi::FromInt(0) == 0);
1792
+ __ mov(v0, zero_reg);
1793
+ break;
1794
+ }
1795
+ case Token::BIT_OR:
1796
+ __ Or(v0, left, Operand(right));
1797
+ break;
1798
+ case Token::BIT_AND:
1799
+ __ And(v0, left, Operand(right));
1800
+ break;
1801
+ case Token::BIT_XOR:
1802
+ __ Xor(v0, left, Operand(right));
1803
+ break;
1804
+ default:
1805
+ UNREACHABLE();
1806
+ }
1807
+
1808
+ __ bind(&done);
1809
+ context()->Plug(v0);
1810
+ }
1811
+
1812
+
1813
+ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr,
1814
+ Token::Value op,
1815
+ OverwriteMode mode) {
1816
+ __ mov(a0, result_register());
1817
+ __ pop(a1);
1818
+ BinaryOpStub stub(op, mode);
1819
+ EmitCallIC(stub.GetCode(), NULL, expr->id());
1820
+ context()->Plug(v0);
1821
+ }
1822
+
1823
+
1824
+ void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) {
1825
+ // Invalid left-hand sides are rewritten to have a 'throw
1826
+ // ReferenceError' on the left-hand side.
1827
+ if (!expr->IsValidLeftHandSide()) {
1828
+ VisitForEffect(expr);
1829
+ return;
1830
+ }
1831
+
1832
+ // Left-hand side can only be a property, a global or a (parameter or local)
1833
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
1834
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
1835
+ LhsKind assign_type = VARIABLE;
1836
+ Property* prop = expr->AsProperty();
1837
+ if (prop != NULL) {
1838
+ assign_type = (prop->key()->IsPropertyName())
1839
+ ? NAMED_PROPERTY
1840
+ : KEYED_PROPERTY;
1841
+ }
1842
+
1843
+ switch (assign_type) {
1844
+ case VARIABLE: {
1845
+ Variable* var = expr->AsVariableProxy()->var();
1846
+ EffectContext context(this);
1847
+ EmitVariableAssignment(var, Token::ASSIGN);
1848
+ break;
1849
+ }
1850
+ case NAMED_PROPERTY: {
1851
+ __ push(result_register()); // Preserve value.
1852
+ VisitForAccumulatorValue(prop->obj());
1853
+ __ mov(a1, result_register());
1854
+ __ pop(a0); // Restore value.
1855
+ __ li(a2, Operand(prop->key()->AsLiteral()->handle()));
1856
+ Handle<Code> ic = is_strict_mode()
1857
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1858
+ : isolate()->builtins()->StoreIC_Initialize();
1859
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
1860
+ break;
1861
+ }
1862
+ case KEYED_PROPERTY: {
1863
+ __ push(result_register()); // Preserve value.
1864
+ if (prop->is_synthetic()) {
1865
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
1866
+ ASSERT(prop->key()->AsLiteral() != NULL);
1867
+ { AccumulatorValueContext for_object(this);
1868
+ EmitVariableLoad(prop->obj()->AsVariableProxy()->var());
1869
+ }
1870
+ __ mov(a2, result_register());
1871
+ __ li(a1, Operand(prop->key()->AsLiteral()->handle()));
1872
+ } else {
1873
+ VisitForStackValue(prop->obj());
1874
+ VisitForAccumulatorValue(prop->key());
1875
+ __ mov(a1, result_register());
1876
+ __ pop(a2);
1877
+ }
1878
+ __ pop(a0); // Restore value.
1879
+ Handle<Code> ic = is_strict_mode()
1880
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
1881
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
1882
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
1883
+ break;
1884
+ }
1885
+ }
1886
+ PrepareForBailoutForId(bailout_ast_id, TOS_REG);
1887
+ context()->Plug(v0);
1888
+ }
1889
+
1890
+
1891
+ void FullCodeGenerator::EmitVariableAssignment(Variable* var,
1892
+ Token::Value op) {
1893
+ // Left-hand sides that rewrite to explicit property accesses do not reach
1894
+ // here.
1895
+ ASSERT(var != NULL);
1896
+ ASSERT(var->is_global() || var->AsSlot() != NULL);
1897
+
1898
+ if (var->is_global()) {
1899
+ ASSERT(!var->is_this());
1900
+ // Assignment to a global variable. Use inline caching for the
1901
+ // assignment. Right-hand-side value is passed in a0, variable name in
1902
+ // a2, and the global object in a1.
1903
+ __ mov(a0, result_register());
1904
+ __ li(a2, Operand(var->name()));
1905
+ __ lw(a1, GlobalObjectOperand());
1906
+ Handle<Code> ic = is_strict_mode()
1907
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
1908
+ : isolate()->builtins()->StoreIC_Initialize();
1909
+ EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT, AstNode::kNoNumber);
1910
+
1911
+ } else if (op == Token::INIT_CONST) {
1912
+ // Like var declarations, const declarations are hoisted to function
1913
+ // scope. However, unlike var initializers, const initializers are able
1914
+ // to drill a hole to that function context, even from inside a 'with'
1915
+ // context. We thus bypass the normal static scope lookup.
1916
+ Slot* slot = var->AsSlot();
1917
+ Label skip;
1918
+ switch (slot->type()) {
1919
+ case Slot::PARAMETER:
1920
+ // No const parameters.
1921
+ UNREACHABLE();
1922
+ break;
1923
+ case Slot::LOCAL:
1924
+ // Detect const reinitialization by checking for the hole value.
1925
+ __ lw(a1, MemOperand(fp, SlotOffset(slot)));
1926
+ __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1927
+ __ Branch(&skip, ne, a1, Operand(t0));
1928
+ __ sw(result_register(), MemOperand(fp, SlotOffset(slot)));
1929
+ break;
1930
+ case Slot::CONTEXT: {
1931
+ __ lw(a1, ContextOperand(cp, Context::FCONTEXT_INDEX));
1932
+ __ lw(a2, ContextOperand(a1, slot->index()));
1933
+ __ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
1934
+ __ Branch(&skip, ne, a2, Operand(t0));
1935
+ __ sw(result_register(), ContextOperand(a1, slot->index()));
1936
+ int offset = Context::SlotOffset(slot->index());
1937
+ __ mov(a3, result_register()); // Preserve the stored value in v0.
1938
+ __ RecordWrite(a1, Operand(offset), a3, a2);
1939
+ break;
1940
+ }
1941
+ case Slot::LOOKUP:
1942
+ __ push(result_register());
1943
+ __ li(a0, Operand(slot->var()->name()));
1944
+ __ Push(cp, a0); // Context and name.
1945
+ __ CallRuntime(Runtime::kInitializeConstContextSlot, 3);
1946
+ break;
1947
+ }
1948
+ __ bind(&skip);
1949
+
1950
+ } else if (var->mode() != Variable::CONST) {
1951
+ // Perform the assignment for non-const variables. Const assignments
1952
+ // are simply skipped.
1953
+ Slot* slot = var->AsSlot();
1954
+ switch (slot->type()) {
1955
+ case Slot::PARAMETER:
1956
+ case Slot::LOCAL:
1957
+ // Perform the assignment.
1958
+ __ sw(result_register(), MemOperand(fp, SlotOffset(slot)));
1959
+ break;
1960
+
1961
+ case Slot::CONTEXT: {
1962
+ MemOperand target = EmitSlotSearch(slot, a1);
1963
+ // Perform the assignment and issue the write barrier.
1964
+ __ sw(result_register(), target);
1965
+ // RecordWrite may destroy all its register arguments.
1966
+ __ mov(a3, result_register());
1967
+ int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize;
1968
+ __ RecordWrite(a1, Operand(offset), a2, a3);
1969
+ break;
1970
+ }
1971
+
1972
+ case Slot::LOOKUP:
1973
+ // Call the runtime for the assignment.
1974
+ __ push(v0); // Value.
1975
+ __ li(a1, Operand(slot->var()->name()));
1976
+ __ li(a0, Operand(Smi::FromInt(strict_mode_flag())));
1977
+ __ Push(cp, a1, a0); // Context, name, strict mode.
1978
+ __ CallRuntime(Runtime::kStoreContextSlot, 4);
1979
+ break;
1980
+ }
1981
+ }
1982
+ }
1983
+
1984
+
1985
+ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
1986
+ // Assignment to a property, using a named store IC.
1987
+ Property* prop = expr->target()->AsProperty();
1988
+ ASSERT(prop != NULL);
1989
+ ASSERT(prop->key()->AsLiteral() != NULL);
1990
+
1991
+ // If the assignment starts a block of assignments to the same object,
1992
+ // change to slow case to avoid the quadratic behavior of repeatedly
1993
+ // adding fast properties.
1994
+ if (expr->starts_initialization_block()) {
1995
+ __ push(result_register());
1996
+ __ lw(t0, MemOperand(sp, kPointerSize)); // Receiver is now under value.
1997
+ __ push(t0);
1998
+ __ CallRuntime(Runtime::kToSlowProperties, 1);
1999
+ __ pop(result_register());
2000
+ }
2001
+
2002
+ // Record source code position before IC call.
2003
+ SetSourcePosition(expr->position());
2004
+ __ mov(a0, result_register()); // Load the value.
2005
+ __ li(a2, Operand(prop->key()->AsLiteral()->handle()));
2006
+ // Load receiver to a1. Leave a copy in the stack if needed for turning the
2007
+ // receiver into fast case.
2008
+ if (expr->ends_initialization_block()) {
2009
+ __ lw(a1, MemOperand(sp));
2010
+ } else {
2011
+ __ pop(a1);
2012
+ }
2013
+
2014
+ Handle<Code> ic = is_strict_mode()
2015
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
2016
+ : isolate()->builtins()->StoreIC_Initialize();
2017
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2018
+
2019
+ // If the assignment ends an initialization block, revert to fast case.
2020
+ if (expr->ends_initialization_block()) {
2021
+ __ push(v0); // Result of assignment, saved even if not needed.
2022
+ // Receiver is under the result value.
2023
+ __ lw(t0, MemOperand(sp, kPointerSize));
2024
+ __ push(t0);
2025
+ __ CallRuntime(Runtime::kToFastProperties, 1);
2026
+ __ pop(v0);
2027
+ __ Drop(1);
2028
+ }
2029
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2030
+ context()->Plug(v0);
2031
+ }
2032
+
2033
+
2034
+ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) {
2035
+ // Assignment to a property, using a keyed store IC.
2036
+
2037
+ // If the assignment starts a block of assignments to the same object,
2038
+ // change to slow case to avoid the quadratic behavior of repeatedly
2039
+ // adding fast properties.
2040
+ if (expr->starts_initialization_block()) {
2041
+ __ push(result_register());
2042
+ // Receiver is now under the key and value.
2043
+ __ lw(t0, MemOperand(sp, 2 * kPointerSize));
2044
+ __ push(t0);
2045
+ __ CallRuntime(Runtime::kToSlowProperties, 1);
2046
+ __ pop(result_register());
2047
+ }
2048
+
2049
+ // Record source code position before IC call.
2050
+ SetSourcePosition(expr->position());
2051
+ // Call keyed store IC.
2052
+ // The arguments are:
2053
+ // - a0 is the value,
2054
+ // - a1 is the key,
2055
+ // - a2 is the receiver.
2056
+ __ mov(a0, result_register());
2057
+ __ pop(a1); // Key.
2058
+ // Load receiver to a2. Leave a copy in the stack if needed for turning the
2059
+ // receiver into fast case.
2060
+ if (expr->ends_initialization_block()) {
2061
+ __ lw(a2, MemOperand(sp));
2062
+ } else {
2063
+ __ pop(a2);
2064
+ }
2065
+
2066
+ Handle<Code> ic = is_strict_mode()
2067
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
2068
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
2069
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2070
+
2071
+ // If the assignment ends an initialization block, revert to fast case.
2072
+ if (expr->ends_initialization_block()) {
2073
+ __ push(v0); // Result of assignment, saved even if not needed.
2074
+ // Receiver is under the result value.
2075
+ __ lw(t0, MemOperand(sp, kPointerSize));
2076
+ __ push(t0);
2077
+ __ CallRuntime(Runtime::kToFastProperties, 1);
2078
+ __ pop(v0);
2079
+ __ Drop(1);
2080
+ }
2081
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
2082
+ context()->Plug(v0);
2083
+ }
2084
+
2085
+
2086
+ void FullCodeGenerator::VisitProperty(Property* expr) {
2087
+ Comment cmnt(masm_, "[ Property");
2088
+ Expression* key = expr->key();
2089
+
2090
+ if (key->IsPropertyName()) {
2091
+ VisitForAccumulatorValue(expr->obj());
2092
+ EmitNamedPropertyLoad(expr);
2093
+ context()->Plug(v0);
2094
+ } else {
2095
+ VisitForStackValue(expr->obj());
2096
+ VisitForAccumulatorValue(expr->key());
2097
+ __ pop(a1);
2098
+ EmitKeyedPropertyLoad(expr);
2099
+ context()->Plug(v0);
2100
+ }
2101
+ }
2102
+
2103
+
2104
+ void FullCodeGenerator::EmitCallWithIC(Call* expr,
2105
+ Handle<Object> name,
2106
+ RelocInfo::Mode mode) {
2107
+ // Code common for calls using the IC.
2108
+ ZoneList<Expression*>* args = expr->arguments();
2109
+ int arg_count = args->length();
2110
+ { PreservePositionScope scope(masm()->positions_recorder());
2111
+ for (int i = 0; i < arg_count; i++) {
2112
+ VisitForStackValue(args->at(i));
2113
+ }
2114
+ __ li(a2, Operand(name));
2115
+ }
2116
+ // Record source position for debugger.
2117
+ SetSourcePosition(expr->position());
2118
+ // Call the IC initialization code.
2119
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2120
+ Handle<Code> ic =
2121
+ isolate()->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode);
2122
+ EmitCallIC(ic, mode, expr->id());
2123
+ RecordJSReturnSite(expr);
2124
+ // Restore context register.
2125
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2126
+ context()->Plug(v0);
2127
+ }
2128
+
2129
+
2130
+ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
2131
+ Expression* key) {
2132
+ // Load the key.
2133
+ VisitForAccumulatorValue(key);
2134
+
2135
+ // Swap the name of the function and the receiver on the stack to follow
2136
+ // the calling convention for call ICs.
2137
+ __ pop(a1);
2138
+ __ push(v0);
2139
+ __ push(a1);
2140
+
2141
+ // Code common for calls using the IC.
2142
+ ZoneList<Expression*>* args = expr->arguments();
2143
+ int arg_count = args->length();
2144
+ { PreservePositionScope scope(masm()->positions_recorder());
2145
+ for (int i = 0; i < arg_count; i++) {
2146
+ VisitForStackValue(args->at(i));
2147
+ }
2148
+ }
2149
+ // Record source position for debugger.
2150
+ SetSourcePosition(expr->position());
2151
+ // Call the IC initialization code.
2152
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2153
+ Handle<Code> ic =
2154
+ isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count, in_loop);
2155
+ __ lw(a2, MemOperand(sp, (arg_count + 1) * kPointerSize)); // Key.
2156
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2157
+ RecordJSReturnSite(expr);
2158
+ // Restore context register.
2159
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2160
+ context()->DropAndPlug(1, v0); // Drop the key still on the stack.
2161
+ }
2162
+
2163
+
2164
+ void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) {
2165
+ // Code common for calls using the call stub.
2166
+ ZoneList<Expression*>* args = expr->arguments();
2167
+ int arg_count = args->length();
2168
+ { PreservePositionScope scope(masm()->positions_recorder());
2169
+ for (int i = 0; i < arg_count; i++) {
2170
+ VisitForStackValue(args->at(i));
2171
+ }
2172
+ }
2173
+ // Record source position for debugger.
2174
+ SetSourcePosition(expr->position());
2175
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2176
+ CallFunctionStub stub(arg_count, in_loop, flags);
2177
+ __ CallStub(&stub);
2178
+ RecordJSReturnSite(expr);
2179
+ // Restore context register.
2180
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2181
+ context()->DropAndPlug(1, v0);
2182
+ }
2183
+
2184
+
2185
+ void FullCodeGenerator::EmitResolvePossiblyDirectEval(ResolveEvalFlag flag,
2186
+ int arg_count) {
2187
+ // Push copy of the first argument or undefined if it doesn't exist.
2188
+ if (arg_count > 0) {
2189
+ __ lw(a1, MemOperand(sp, arg_count * kPointerSize));
2190
+ } else {
2191
+ __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
2192
+ }
2193
+ __ push(a1);
2194
+
2195
+ // Push the receiver of the enclosing function and do runtime call.
2196
+ __ lw(a1, MemOperand(fp, (2 + scope()->num_parameters()) * kPointerSize));
2197
+ __ push(a1);
2198
+ // Push the strict mode flag.
2199
+ __ li(a1, Operand(Smi::FromInt(strict_mode_flag())));
2200
+ __ push(a1);
2201
+
2202
+ __ CallRuntime(flag == SKIP_CONTEXT_LOOKUP
2203
+ ? Runtime::kResolvePossiblyDirectEvalNoLookup
2204
+ : Runtime::kResolvePossiblyDirectEval, 4);
2205
+ }
2206
+
2207
+
2208
+ void FullCodeGenerator::VisitCall(Call* expr) {
2209
+ #ifdef DEBUG
2210
+ // We want to verify that RecordJSReturnSite gets called on all paths
2211
+ // through this function. Avoid early returns.
2212
+ expr->return_is_recorded_ = false;
2213
+ #endif
2214
+
2215
+ Comment cmnt(masm_, "[ Call");
2216
+ Expression* fun = expr->expression();
2217
+ Variable* var = fun->AsVariableProxy()->AsVariable();
2218
+
2219
+ if (var != NULL && var->is_possibly_eval()) {
2220
+ // In a call to eval, we first call %ResolvePossiblyDirectEval to
2221
+ // resolve the function we need to call and the receiver of the
2222
+ // call. Then we call the resolved function using the given
2223
+ // arguments.
2224
+ ZoneList<Expression*>* args = expr->arguments();
2225
+ int arg_count = args->length();
2226
+
2227
+ { PreservePositionScope pos_scope(masm()->positions_recorder());
2228
+ VisitForStackValue(fun);
2229
+ __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2230
+ __ push(a2); // Reserved receiver slot.
2231
+
2232
+ // Push the arguments.
2233
+ for (int i = 0; i < arg_count; i++) {
2234
+ VisitForStackValue(args->at(i));
2235
+ }
2236
+ // If we know that eval can only be shadowed by eval-introduced
2237
+ // variables we attempt to load the global eval function directly
2238
+ // in generated code. If we succeed, there is no need to perform a
2239
+ // context lookup in the runtime system.
2240
+ Label done;
2241
+ if (var->AsSlot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) {
2242
+ Label slow;
2243
+ EmitLoadGlobalSlotCheckExtensions(var->AsSlot(),
2244
+ NOT_INSIDE_TYPEOF,
2245
+ &slow);
2246
+ // Push the function and resolve eval.
2247
+ __ push(v0);
2248
+ EmitResolvePossiblyDirectEval(SKIP_CONTEXT_LOOKUP, arg_count);
2249
+ __ jmp(&done);
2250
+ __ bind(&slow);
2251
+ }
2252
+
2253
+ // Push copy of the function (found below the arguments) and
2254
+ // resolve eval.
2255
+ __ lw(a1, MemOperand(sp, (arg_count + 1) * kPointerSize));
2256
+ __ push(a1);
2257
+ EmitResolvePossiblyDirectEval(PERFORM_CONTEXT_LOOKUP, arg_count);
2258
+ if (done.is_linked()) {
2259
+ __ bind(&done);
2260
+ }
2261
+
2262
+ // The runtime call returns a pair of values in v0 (function) and
2263
+ // v1 (receiver). Touch up the stack with the right values.
2264
+ __ sw(v0, MemOperand(sp, (arg_count + 1) * kPointerSize));
2265
+ __ sw(v1, MemOperand(sp, arg_count * kPointerSize));
2266
+ }
2267
+ // Record source position for debugger.
2268
+ SetSourcePosition(expr->position());
2269
+ InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2270
+ CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_IMPLICIT);
2271
+ __ CallStub(&stub);
2272
+ RecordJSReturnSite(expr);
2273
+ // Restore context register.
2274
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2275
+ context()->DropAndPlug(1, v0);
2276
+ } else if (var != NULL && !var->is_this() && var->is_global()) {
2277
+ // Push global object as receiver for the call IC.
2278
+ __ lw(a0, GlobalObjectOperand());
2279
+ __ push(a0);
2280
+ EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
2281
+ } else if (var != NULL && var->AsSlot() != NULL &&
2282
+ var->AsSlot()->type() == Slot::LOOKUP) {
2283
+ // Call to a lookup slot (dynamically introduced variable).
2284
+ Label slow, done;
2285
+
2286
+ { PreservePositionScope scope(masm()->positions_recorder());
2287
+ // Generate code for loading from variables potentially shadowed
2288
+ // by eval-introduced variables.
2289
+ EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
2290
+ NOT_INSIDE_TYPEOF,
2291
+ &slow,
2292
+ &done);
2293
+ }
2294
+
2295
+ __ bind(&slow);
2296
+ // Call the runtime to find the function to call (returned in v0)
2297
+ // and the object holding it (returned in v1).
2298
+ __ push(context_register());
2299
+ __ li(a2, Operand(var->name()));
2300
+ __ push(a2);
2301
+ __ CallRuntime(Runtime::kLoadContextSlot, 2);
2302
+ __ Push(v0, v1); // Function, receiver.
2303
+
2304
+ // If fast case code has been generated, emit code to push the
2305
+ // function and receiver and have the slow path jump around this
2306
+ // code.
2307
+ if (done.is_linked()) {
2308
+ Label call;
2309
+ __ Branch(&call);
2310
+ __ bind(&done);
2311
+ // Push function.
2312
+ __ push(v0);
2313
+ // Push global receiver.
2314
+ __ lw(a1, GlobalObjectOperand());
2315
+ __ lw(a1, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2316
+ __ push(a1);
2317
+ __ bind(&call);
2318
+ }
2319
+
2320
+ // The receiver is either the global receiver or an object found
2321
+ // by LoadContextSlot. That object could be the hole if the
2322
+ // receiver is implicitly the global object.
2323
+ EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT);
2324
+ } else if (fun->AsProperty() != NULL) {
2325
+ // Call to an object property.
2326
+ Property* prop = fun->AsProperty();
2327
+ Literal* key = prop->key()->AsLiteral();
2328
+ if (key != NULL && key->handle()->IsSymbol()) {
2329
+ // Call to a named property, use call IC.
2330
+ { PreservePositionScope scope(masm()->positions_recorder());
2331
+ VisitForStackValue(prop->obj());
2332
+ }
2333
+ EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
2334
+ } else {
2335
+ // Call to a keyed property.
2336
+ // For a synthetic property use keyed load IC followed by function call,
2337
+ // for a regular property use keyed EmitCallIC.
2338
+ if (prop->is_synthetic()) {
2339
+ // Do not visit the object and key subexpressions (they are shared
2340
+ // by all occurrences of the same rewritten parameter).
2341
+ ASSERT(prop->obj()->AsVariableProxy() != NULL);
2342
+ ASSERT(prop->obj()->AsVariableProxy()->var()->AsSlot() != NULL);
2343
+ Slot* slot = prop->obj()->AsVariableProxy()->var()->AsSlot();
2344
+ MemOperand operand = EmitSlotSearch(slot, a1);
2345
+ __ lw(a1, operand);
2346
+
2347
+ ASSERT(prop->key()->AsLiteral() != NULL);
2348
+ ASSERT(prop->key()->AsLiteral()->handle()->IsSmi());
2349
+ __ li(a0, Operand(prop->key()->AsLiteral()->handle()));
2350
+
2351
+ // Record source code position for IC call.
2352
+ SetSourcePosition(prop->position());
2353
+
2354
+ Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize();
2355
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, GetPropertyId(prop));
2356
+ __ lw(a1, GlobalObjectOperand());
2357
+ __ lw(a1, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2358
+ __ Push(v0, a1); // Function, receiver.
2359
+ EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2360
+ } else {
2361
+ { PreservePositionScope scope(masm()->positions_recorder());
2362
+ VisitForStackValue(prop->obj());
2363
+ }
2364
+ EmitKeyedCallWithIC(expr, prop->key());
2365
+ }
2366
+ }
2367
+ } else {
2368
+ { PreservePositionScope scope(masm()->positions_recorder());
2369
+ VisitForStackValue(fun);
2370
+ }
2371
+ // Load global receiver object.
2372
+ __ lw(a1, GlobalObjectOperand());
2373
+ __ lw(a1, FieldMemOperand(a1, GlobalObject::kGlobalReceiverOffset));
2374
+ __ push(a1);
2375
+ // Emit function call.
2376
+ EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2377
+ }
2378
+
2379
+ #ifdef DEBUG
2380
+ // RecordJSReturnSite should have been called.
2381
+ ASSERT(expr->return_is_recorded_);
2382
+ #endif
2383
+ }
2384
+
2385
+
2386
+ void FullCodeGenerator::VisitCallNew(CallNew* expr) {
2387
+ Comment cmnt(masm_, "[ CallNew");
2388
+ // According to ECMA-262, section 11.2.2, page 44, the function
2389
+ // expression in new calls must be evaluated before the
2390
+ // arguments.
2391
+
2392
+ // Push constructor on the stack. If it's not a function it's used as
2393
+ // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
2394
+ // ignored.
2395
+ VisitForStackValue(expr->expression());
2396
+
2397
+ // Push the arguments ("left-to-right") on the stack.
2398
+ ZoneList<Expression*>* args = expr->arguments();
2399
+ int arg_count = args->length();
2400
+ for (int i = 0; i < arg_count; i++) {
2401
+ VisitForStackValue(args->at(i));
2402
+ }
2403
+
2404
+ // Call the construct call builtin that handles allocation and
2405
+ // constructor invocation.
2406
+ SetSourcePosition(expr->position());
2407
+
2408
+ // Load function and argument count into a1 and a0.
2409
+ __ li(a0, Operand(arg_count));
2410
+ __ lw(a1, MemOperand(sp, arg_count * kPointerSize));
2411
+
2412
+ Handle<Code> construct_builtin =
2413
+ isolate()->builtins()->JSConstructCall();
2414
+ __ Call(construct_builtin, RelocInfo::CONSTRUCT_CALL);
2415
+ context()->Plug(v0);
2416
+ }
2417
+
2418
+
2419
+ void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) {
2420
+ ASSERT(args->length() == 1);
2421
+
2422
+ VisitForAccumulatorValue(args->at(0));
2423
+
2424
+ Label materialize_true, materialize_false;
2425
+ Label* if_true = NULL;
2426
+ Label* if_false = NULL;
2427
+ Label* fall_through = NULL;
2428
+ context()->PrepareTest(&materialize_true, &materialize_false,
2429
+ &if_true, &if_false, &fall_through);
2430
+
2431
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2432
+ __ And(t0, v0, Operand(kSmiTagMask));
2433
+ Split(eq, t0, Operand(zero_reg), if_true, if_false, fall_through);
2434
+
2435
+ context()->Plug(if_true, if_false);
2436
+ }
2437
+
2438
+
2439
+ void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) {
2440
+ ASSERT(args->length() == 1);
2441
+
2442
+ VisitForAccumulatorValue(args->at(0));
2443
+
2444
+ Label materialize_true, materialize_false;
2445
+ Label* if_true = NULL;
2446
+ Label* if_false = NULL;
2447
+ Label* fall_through = NULL;
2448
+ context()->PrepareTest(&materialize_true, &materialize_false,
2449
+ &if_true, &if_false, &fall_through);
2450
+
2451
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2452
+ __ And(at, v0, Operand(kSmiTagMask | 0x80000000));
2453
+ Split(eq, at, Operand(zero_reg), if_true, if_false, fall_through);
2454
+
2455
+ context()->Plug(if_true, if_false);
2456
+ }
2457
+
2458
+
2459
+ void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) {
2460
+ ASSERT(args->length() == 1);
2461
+
2462
+ VisitForAccumulatorValue(args->at(0));
2463
+
2464
+ Label materialize_true, materialize_false;
2465
+ Label* if_true = NULL;
2466
+ Label* if_false = NULL;
2467
+ Label* fall_through = NULL;
2468
+ context()->PrepareTest(&materialize_true, &materialize_false,
2469
+ &if_true, &if_false, &fall_through);
2470
+
2471
+ __ JumpIfSmi(v0, if_false);
2472
+ __ LoadRoot(at, Heap::kNullValueRootIndex);
2473
+ __ Branch(if_true, eq, v0, Operand(at));
2474
+ __ lw(a2, FieldMemOperand(v0, HeapObject::kMapOffset));
2475
+ // Undetectable objects behave like undefined when tested with typeof.
2476
+ __ lbu(a1, FieldMemOperand(a2, Map::kBitFieldOffset));
2477
+ __ And(at, a1, Operand(1 << Map::kIsUndetectable));
2478
+ __ Branch(if_false, ne, at, Operand(zero_reg));
2479
+ __ lbu(a1, FieldMemOperand(a2, Map::kInstanceTypeOffset));
2480
+ __ Branch(if_false, lt, a1, Operand(FIRST_JS_OBJECT_TYPE));
2481
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2482
+ Split(le, a1, Operand(LAST_JS_OBJECT_TYPE), if_true, if_false, fall_through);
2483
+
2484
+ context()->Plug(if_true, if_false);
2485
+ }
2486
+
2487
+
2488
+ void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) {
2489
+ ASSERT(args->length() == 1);
2490
+
2491
+ VisitForAccumulatorValue(args->at(0));
2492
+
2493
+ Label materialize_true, materialize_false;
2494
+ Label* if_true = NULL;
2495
+ Label* if_false = NULL;
2496
+ Label* fall_through = NULL;
2497
+ context()->PrepareTest(&materialize_true, &materialize_false,
2498
+ &if_true, &if_false, &fall_through);
2499
+
2500
+ __ JumpIfSmi(v0, if_false);
2501
+ __ GetObjectType(v0, a1, a1);
2502
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2503
+ Split(ge, a1, Operand(FIRST_JS_OBJECT_TYPE),
2504
+ if_true, if_false, fall_through);
2505
+
2506
+ context()->Plug(if_true, if_false);
2507
+ }
2508
+
2509
+
2510
+ void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) {
2511
+ ASSERT(args->length() == 1);
2512
+
2513
+ VisitForAccumulatorValue(args->at(0));
2514
+
2515
+ Label materialize_true, materialize_false;
2516
+ Label* if_true = NULL;
2517
+ Label* if_false = NULL;
2518
+ Label* fall_through = NULL;
2519
+ context()->PrepareTest(&materialize_true, &materialize_false,
2520
+ &if_true, &if_false, &fall_through);
2521
+
2522
+ __ JumpIfSmi(v0, if_false);
2523
+ __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
2524
+ __ lbu(a1, FieldMemOperand(a1, Map::kBitFieldOffset));
2525
+ __ And(at, a1, Operand(1 << Map::kIsUndetectable));
2526
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2527
+ Split(ne, at, Operand(zero_reg), if_true, if_false, fall_through);
2528
+
2529
+ context()->Plug(if_true, if_false);
2530
+ }
2531
+
2532
+
2533
+ void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf(
2534
+ ZoneList<Expression*>* args) {
2535
+
2536
+ ASSERT(args->length() == 1);
2537
+
2538
+ VisitForAccumulatorValue(args->at(0));
2539
+
2540
+ Label materialize_true, materialize_false;
2541
+ Label* if_true = NULL;
2542
+ Label* if_false = NULL;
2543
+ Label* fall_through = NULL;
2544
+ context()->PrepareTest(&materialize_true, &materialize_false,
2545
+ &if_true, &if_false, &fall_through);
2546
+
2547
+ if (FLAG_debug_code) __ AbortIfSmi(v0);
2548
+
2549
+ __ lw(a1, FieldMemOperand(v0, HeapObject::kMapOffset));
2550
+ __ lbu(t0, FieldMemOperand(a1, Map::kBitField2Offset));
2551
+ __ And(t0, t0, 1 << Map::kStringWrapperSafeForDefaultValueOf);
2552
+ __ Branch(if_true, ne, t0, Operand(zero_reg));
2553
+
2554
+ // Check for fast case object. Generate false result for slow case object.
2555
+ __ lw(a2, FieldMemOperand(v0, JSObject::kPropertiesOffset));
2556
+ __ lw(a2, FieldMemOperand(a2, HeapObject::kMapOffset));
2557
+ __ LoadRoot(t0, Heap::kHashTableMapRootIndex);
2558
+ __ Branch(if_false, eq, a2, Operand(t0));
2559
+
2560
+ // Look for valueOf symbol in the descriptor array, and indicate false if
2561
+ // found. The type is not checked, so if it is a transition it is a false
2562
+ // negative.
2563
+ __ LoadInstanceDescriptors(a1, t0);
2564
+ __ lw(a3, FieldMemOperand(t0, FixedArray::kLengthOffset));
2565
+ // t0: descriptor array
2566
+ // a3: length of descriptor array
2567
+ // Calculate the end of the descriptor array.
2568
+ STATIC_ASSERT(kSmiTag == 0);
2569
+ STATIC_ASSERT(kSmiTagSize == 1);
2570
+ STATIC_ASSERT(kPointerSize == 4);
2571
+ __ Addu(a2, t0, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2572
+ __ sll(t1, a3, kPointerSizeLog2 - kSmiTagSize);
2573
+ __ Addu(a2, a2, t1);
2574
+
2575
+ // Calculate location of the first key name.
2576
+ __ Addu(t0,
2577
+ t0,
2578
+ Operand(FixedArray::kHeaderSize - kHeapObjectTag +
2579
+ DescriptorArray::kFirstIndex * kPointerSize));
2580
+ // Loop through all the keys in the descriptor array. If one of these is the
2581
+ // symbol valueOf the result is false.
2582
+ Label entry, loop;
2583
+ // The use of t2 to store the valueOf symbol asumes that it is not otherwise
2584
+ // used in the loop below.
2585
+ __ li(t2, Operand(FACTORY->value_of_symbol()));
2586
+ __ jmp(&entry);
2587
+ __ bind(&loop);
2588
+ __ lw(a3, MemOperand(t0, 0));
2589
+ __ Branch(if_false, eq, a3, Operand(t2));
2590
+ __ Addu(t0, t0, Operand(kPointerSize));
2591
+ __ bind(&entry);
2592
+ __ Branch(&loop, ne, t0, Operand(a2));
2593
+
2594
+ // If a valueOf property is not found on the object check that it's
2595
+ // prototype is the un-modified String prototype. If not result is false.
2596
+ __ lw(a2, FieldMemOperand(a1, Map::kPrototypeOffset));
2597
+ __ JumpIfSmi(a2, if_false);
2598
+ __ lw(a2, FieldMemOperand(a2, HeapObject::kMapOffset));
2599
+ __ lw(a3, ContextOperand(cp, Context::GLOBAL_INDEX));
2600
+ __ lw(a3, FieldMemOperand(a3, GlobalObject::kGlobalContextOffset));
2601
+ __ lw(a3, ContextOperand(a3, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
2602
+ __ Branch(if_false, ne, a2, Operand(a3));
2603
+
2604
+ // Set the bit in the map to indicate that it has been checked safe for
2605
+ // default valueOf and set true result.
2606
+ __ lbu(a2, FieldMemOperand(a1, Map::kBitField2Offset));
2607
+ __ Or(a2, a2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
2608
+ __ sb(a2, FieldMemOperand(a1, Map::kBitField2Offset));
2609
+ __ jmp(if_true);
2610
+
2611
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2612
+ context()->Plug(if_true, if_false);
2613
+ }
2614
+
2615
+
2616
+ void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) {
2617
+ ASSERT(args->length() == 1);
2618
+
2619
+ VisitForAccumulatorValue(args->at(0));
2620
+
2621
+ Label materialize_true, materialize_false;
2622
+ Label* if_true = NULL;
2623
+ Label* if_false = NULL;
2624
+ Label* fall_through = NULL;
2625
+ context()->PrepareTest(&materialize_true, &materialize_false,
2626
+ &if_true, &if_false, &fall_through);
2627
+
2628
+ __ JumpIfSmi(v0, if_false);
2629
+ __ GetObjectType(v0, a1, a2);
2630
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2631
+ __ Branch(if_true, eq, a2, Operand(JS_FUNCTION_TYPE));
2632
+ __ Branch(if_false);
2633
+
2634
+ context()->Plug(if_true, if_false);
2635
+ }
2636
+
2637
+
2638
+ void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) {
2639
+ ASSERT(args->length() == 1);
2640
+
2641
+ VisitForAccumulatorValue(args->at(0));
2642
+
2643
+ Label materialize_true, materialize_false;
2644
+ Label* if_true = NULL;
2645
+ Label* if_false = NULL;
2646
+ Label* fall_through = NULL;
2647
+ context()->PrepareTest(&materialize_true, &materialize_false,
2648
+ &if_true, &if_false, &fall_through);
2649
+
2650
+ __ JumpIfSmi(v0, if_false);
2651
+ __ GetObjectType(v0, a1, a1);
2652
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2653
+ Split(eq, a1, Operand(JS_ARRAY_TYPE),
2654
+ if_true, if_false, fall_through);
2655
+
2656
+ context()->Plug(if_true, if_false);
2657
+ }
2658
+
2659
+
2660
+ void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) {
2661
+ ASSERT(args->length() == 1);
2662
+
2663
+ VisitForAccumulatorValue(args->at(0));
2664
+
2665
+ Label materialize_true, materialize_false;
2666
+ Label* if_true = NULL;
2667
+ Label* if_false = NULL;
2668
+ Label* fall_through = NULL;
2669
+ context()->PrepareTest(&materialize_true, &materialize_false,
2670
+ &if_true, &if_false, &fall_through);
2671
+
2672
+ __ JumpIfSmi(v0, if_false);
2673
+ __ GetObjectType(v0, a1, a1);
2674
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2675
+ Split(eq, a1, Operand(JS_REGEXP_TYPE), if_true, if_false, fall_through);
2676
+
2677
+ context()->Plug(if_true, if_false);
2678
+ }
2679
+
2680
+
2681
+ void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) {
2682
+ ASSERT(args->length() == 0);
2683
+
2684
+ Label materialize_true, materialize_false;
2685
+ Label* if_true = NULL;
2686
+ Label* if_false = NULL;
2687
+ Label* fall_through = NULL;
2688
+ context()->PrepareTest(&materialize_true, &materialize_false,
2689
+ &if_true, &if_false, &fall_through);
2690
+
2691
+ // Get the frame pointer for the calling frame.
2692
+ __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2693
+
2694
+ // Skip the arguments adaptor frame if it exists.
2695
+ Label check_frame_marker;
2696
+ __ lw(a1, MemOperand(a2, StandardFrameConstants::kContextOffset));
2697
+ __ Branch(&check_frame_marker, ne,
2698
+ a1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2699
+ __ lw(a2, MemOperand(a2, StandardFrameConstants::kCallerFPOffset));
2700
+
2701
+ // Check the marker in the calling frame.
2702
+ __ bind(&check_frame_marker);
2703
+ __ lw(a1, MemOperand(a2, StandardFrameConstants::kMarkerOffset));
2704
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2705
+ Split(eq, a1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)),
2706
+ if_true, if_false, fall_through);
2707
+
2708
+ context()->Plug(if_true, if_false);
2709
+ }
2710
+
2711
+
2712
+ void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) {
2713
+ ASSERT(args->length() == 2);
2714
+
2715
+ // Load the two objects into registers and perform the comparison.
2716
+ VisitForStackValue(args->at(0));
2717
+ VisitForAccumulatorValue(args->at(1));
2718
+
2719
+ Label materialize_true, materialize_false;
2720
+ Label* if_true = NULL;
2721
+ Label* if_false = NULL;
2722
+ Label* fall_through = NULL;
2723
+ context()->PrepareTest(&materialize_true, &materialize_false,
2724
+ &if_true, &if_false, &fall_through);
2725
+
2726
+ __ pop(a1);
2727
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
2728
+ Split(eq, v0, Operand(a1), if_true, if_false, fall_through);
2729
+
2730
+ context()->Plug(if_true, if_false);
2731
+ }
2732
+
2733
+
2734
+ void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) {
2735
+ ASSERT(args->length() == 1);
2736
+
2737
+ // ArgumentsAccessStub expects the key in a1 and the formal
2738
+ // parameter count in a0.
2739
+ VisitForAccumulatorValue(args->at(0));
2740
+ __ mov(a1, v0);
2741
+ __ li(a0, Operand(Smi::FromInt(scope()->num_parameters())));
2742
+ ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT);
2743
+ __ CallStub(&stub);
2744
+ context()->Plug(v0);
2745
+ }
2746
+
2747
+
2748
+ void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) {
2749
+ ASSERT(args->length() == 0);
2750
+
2751
+ Label exit;
2752
+ // Get the number of formal parameters.
2753
+ __ li(v0, Operand(Smi::FromInt(scope()->num_parameters())));
2754
+
2755
+ // Check if the calling frame is an arguments adaptor frame.
2756
+ __ lw(a2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2757
+ __ lw(a3, MemOperand(a2, StandardFrameConstants::kContextOffset));
2758
+ __ Branch(&exit, ne, a3,
2759
+ Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
2760
+
2761
+ // Arguments adaptor case: Read the arguments length from the
2762
+ // adaptor frame.
2763
+ __ lw(v0, MemOperand(a2, ArgumentsAdaptorFrameConstants::kLengthOffset));
2764
+
2765
+ __ bind(&exit);
2766
+ context()->Plug(v0);
2767
+ }
2768
+
2769
+
2770
+ void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) {
2771
+ ASSERT(args->length() == 1);
2772
+ Label done, null, function, non_function_constructor;
2773
+
2774
+ VisitForAccumulatorValue(args->at(0));
2775
+
2776
+ // If the object is a smi, we return null.
2777
+ __ JumpIfSmi(v0, &null);
2778
+
2779
+ // Check that the object is a JS object but take special care of JS
2780
+ // functions to make sure they have 'Function' as their class.
2781
+ __ GetObjectType(v0, v0, a1); // Map is now in v0.
2782
+ __ Branch(&null, lt, a1, Operand(FIRST_JS_OBJECT_TYPE));
2783
+
2784
+ // As long as JS_FUNCTION_TYPE is the last instance type and it is
2785
+ // right after LAST_JS_OBJECT_TYPE, we can avoid checking for
2786
+ // LAST_JS_OBJECT_TYPE.
2787
+ ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
2788
+ ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1);
2789
+ __ Branch(&function, eq, a1, Operand(JS_FUNCTION_TYPE));
2790
+
2791
+ // Check if the constructor in the map is a function.
2792
+ __ lw(v0, FieldMemOperand(v0, Map::kConstructorOffset));
2793
+ __ GetObjectType(v0, a1, a1);
2794
+ __ Branch(&non_function_constructor, ne, a1, Operand(JS_FUNCTION_TYPE));
2795
+
2796
+ // v0 now contains the constructor function. Grab the
2797
+ // instance class name from there.
2798
+ __ lw(v0, FieldMemOperand(v0, JSFunction::kSharedFunctionInfoOffset));
2799
+ __ lw(v0, FieldMemOperand(v0, SharedFunctionInfo::kInstanceClassNameOffset));
2800
+ __ Branch(&done);
2801
+
2802
+ // Functions have class 'Function'.
2803
+ __ bind(&function);
2804
+ __ LoadRoot(v0, Heap::kfunction_class_symbolRootIndex);
2805
+ __ jmp(&done);
2806
+
2807
+ // Objects with a non-function constructor have class 'Object'.
2808
+ __ bind(&non_function_constructor);
2809
+ __ LoadRoot(v0, Heap::kfunction_class_symbolRootIndex);
2810
+ __ jmp(&done);
2811
+
2812
+ // Non-JS objects have class null.
2813
+ __ bind(&null);
2814
+ __ LoadRoot(v0, Heap::kNullValueRootIndex);
2815
+
2816
+ // All done.
2817
+ __ bind(&done);
2818
+
2819
+ context()->Plug(v0);
2820
+ }
2821
+
2822
+
2823
+ void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) {
2824
+ // Conditionally generate a log call.
2825
+ // Args:
2826
+ // 0 (literal string): The type of logging (corresponds to the flags).
2827
+ // This is used to determine whether or not to generate the log call.
2828
+ // 1 (string): Format string. Access the string at argument index 2
2829
+ // with '%2s' (see Logger::LogRuntime for all the formats).
2830
+ // 2 (array): Arguments to the format string.
2831
+ ASSERT_EQ(args->length(), 3);
2832
+ #ifdef ENABLE_LOGGING_AND_PROFILING
2833
+ if (CodeGenerator::ShouldGenerateLog(args->at(0))) {
2834
+ VisitForStackValue(args->at(1));
2835
+ VisitForStackValue(args->at(2));
2836
+ __ CallRuntime(Runtime::kLog, 2);
2837
+ }
2838
+ #endif
2839
+ // Finally, we're expected to leave a value on the top of the stack.
2840
+ __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
2841
+ context()->Plug(v0);
2842
+ }
2843
+
2844
+
2845
+ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
2846
+ ASSERT(args->length() == 0);
2847
+
2848
+ Label slow_allocate_heapnumber;
2849
+ Label heapnumber_allocated;
2850
+
2851
+ // Save the new heap number in callee-saved register s0, since
2852
+ // we call out to external C code below.
2853
+ __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
2854
+ __ AllocateHeapNumber(s0, a1, a2, t6, &slow_allocate_heapnumber);
2855
+ __ jmp(&heapnumber_allocated);
2856
+
2857
+ __ bind(&slow_allocate_heapnumber);
2858
+
2859
+ // Allocate a heap number.
2860
+ __ CallRuntime(Runtime::kNumberAlloc, 0);
2861
+ __ mov(s0, v0); // Save result in s0, so it is saved thru CFunc call.
2862
+
2863
+ __ bind(&heapnumber_allocated);
2864
+
2865
+ // Convert 32 random bits in v0 to 0.(32 random bits) in a double
2866
+ // by computing:
2867
+ // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
2868
+ if (CpuFeatures::IsSupported(FPU)) {
2869
+ __ PrepareCallCFunction(1, a0);
2870
+ __ li(a0, Operand(ExternalReference::isolate_address()));
2871
+ __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
2872
+
2873
+
2874
+ CpuFeatures::Scope scope(FPU);
2875
+ // 0x41300000 is the top half of 1.0 x 2^20 as a double.
2876
+ __ li(a1, Operand(0x41300000));
2877
+ // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU.
2878
+ __ Move(f12, v0, a1);
2879
+ // Move 0x4130000000000000 to FPU.
2880
+ __ Move(f14, zero_reg, a1);
2881
+ // Subtract and store the result in the heap number.
2882
+ __ sub_d(f0, f12, f14);
2883
+ __ sdc1(f0, MemOperand(s0, HeapNumber::kValueOffset - kHeapObjectTag));
2884
+ __ mov(v0, s0);
2885
+ } else {
2886
+ __ PrepareCallCFunction(2, a0);
2887
+ __ mov(a0, s0);
2888
+ __ li(a1, Operand(ExternalReference::isolate_address()));
2889
+ __ CallCFunction(
2890
+ ExternalReference::fill_heap_number_with_random_function(isolate()), 2);
2891
+ }
2892
+
2893
+ context()->Plug(v0);
2894
+ }
2895
+
2896
+
2897
+ void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) {
2898
+ // Load the arguments on the stack and call the stub.
2899
+ SubStringStub stub;
2900
+ ASSERT(args->length() == 3);
2901
+ VisitForStackValue(args->at(0));
2902
+ VisitForStackValue(args->at(1));
2903
+ VisitForStackValue(args->at(2));
2904
+ __ CallStub(&stub);
2905
+ context()->Plug(v0);
2906
+ }
2907
+
2908
+
2909
+ void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) {
2910
+ // Load the arguments on the stack and call the stub.
2911
+ RegExpExecStub stub;
2912
+ ASSERT(args->length() == 4);
2913
+ VisitForStackValue(args->at(0));
2914
+ VisitForStackValue(args->at(1));
2915
+ VisitForStackValue(args->at(2));
2916
+ VisitForStackValue(args->at(3));
2917
+ __ CallStub(&stub);
2918
+ context()->Plug(v0);
2919
+ }
2920
+
2921
+
2922
+ void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) {
2923
+ ASSERT(args->length() == 1);
2924
+
2925
+ VisitForAccumulatorValue(args->at(0)); // Load the object.
2926
+
2927
+ Label done;
2928
+ // If the object is a smi return the object.
2929
+ __ JumpIfSmi(v0, &done);
2930
+ // If the object is not a value type, return the object.
2931
+ __ GetObjectType(v0, a1, a1);
2932
+ __ Branch(&done, ne, a1, Operand(JS_VALUE_TYPE));
2933
+
2934
+ __ lw(v0, FieldMemOperand(v0, JSValue::kValueOffset));
2935
+
2936
+ __ bind(&done);
2937
+ context()->Plug(v0);
2938
+ }
2939
+
2940
+
2941
+ void FullCodeGenerator::EmitMathPow(ZoneList<Expression*>* args) {
2942
+ // Load the arguments on the stack and call the runtime function.
2943
+ ASSERT(args->length() == 2);
2944
+ VisitForStackValue(args->at(0));
2945
+ VisitForStackValue(args->at(1));
2946
+ MathPowStub stub;
2947
+ __ CallStub(&stub);
2948
+ context()->Plug(v0);
2949
+ }
2950
+
2951
+
2952
+ void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) {
2953
+ ASSERT(args->length() == 2);
2954
+
2955
+ VisitForStackValue(args->at(0)); // Load the object.
2956
+ VisitForAccumulatorValue(args->at(1)); // Load the value.
2957
+ __ pop(a1); // v0 = value. a1 = object.
2958
+
2959
+ Label done;
2960
+ // If the object is a smi, return the value.
2961
+ __ JumpIfSmi(a1, &done);
2962
+
2963
+ // If the object is not a value type, return the value.
2964
+ __ GetObjectType(a1, a2, a2);
2965
+ __ Branch(&done, ne, a2, Operand(JS_VALUE_TYPE));
2966
+
2967
+ // Store the value.
2968
+ __ sw(v0, FieldMemOperand(a1, JSValue::kValueOffset));
2969
+ // Update the write barrier. Save the value as it will be
2970
+ // overwritten by the write barrier code and is needed afterward.
2971
+ __ RecordWrite(a1, Operand(JSValue::kValueOffset - kHeapObjectTag), a2, a3);
2972
+
2973
+ __ bind(&done);
2974
+ context()->Plug(v0);
2975
+ }
2976
+
2977
+
2978
+ void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) {
2979
+ ASSERT_EQ(args->length(), 1);
2980
+
2981
+ // Load the argument on the stack and call the stub.
2982
+ VisitForStackValue(args->at(0));
2983
+
2984
+ NumberToStringStub stub;
2985
+ __ CallStub(&stub);
2986
+ context()->Plug(v0);
2987
+ }
2988
+
2989
+
2990
+ void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) {
2991
+ ASSERT(args->length() == 1);
2992
+
2993
+ VisitForAccumulatorValue(args->at(0));
2994
+
2995
+ Label done;
2996
+ StringCharFromCodeGenerator generator(v0, a1);
2997
+ generator.GenerateFast(masm_);
2998
+ __ jmp(&done);
2999
+
3000
+ NopRuntimeCallHelper call_helper;
3001
+ generator.GenerateSlow(masm_, call_helper);
3002
+
3003
+ __ bind(&done);
3004
+ context()->Plug(a1);
3005
+ }
3006
+
3007
+
3008
+ void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) {
3009
+ ASSERT(args->length() == 2);
3010
+
3011
+ VisitForStackValue(args->at(0));
3012
+ VisitForAccumulatorValue(args->at(1));
3013
+ __ mov(a0, result_register());
3014
+
3015
+ Register object = a1;
3016
+ Register index = a0;
3017
+ Register scratch = a2;
3018
+ Register result = v0;
3019
+
3020
+ __ pop(object);
3021
+
3022
+ Label need_conversion;
3023
+ Label index_out_of_range;
3024
+ Label done;
3025
+ StringCharCodeAtGenerator generator(object,
3026
+ index,
3027
+ scratch,
3028
+ result,
3029
+ &need_conversion,
3030
+ &need_conversion,
3031
+ &index_out_of_range,
3032
+ STRING_INDEX_IS_NUMBER);
3033
+ generator.GenerateFast(masm_);
3034
+ __ jmp(&done);
3035
+
3036
+ __ bind(&index_out_of_range);
3037
+ // When the index is out of range, the spec requires us to return
3038
+ // NaN.
3039
+ __ LoadRoot(result, Heap::kNanValueRootIndex);
3040
+ __ jmp(&done);
3041
+
3042
+ __ bind(&need_conversion);
3043
+ // Load the undefined value into the result register, which will
3044
+ // trigger conversion.
3045
+ __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
3046
+ __ jmp(&done);
3047
+
3048
+ NopRuntimeCallHelper call_helper;
3049
+ generator.GenerateSlow(masm_, call_helper);
3050
+
3051
+ __ bind(&done);
3052
+ context()->Plug(result);
3053
+ }
3054
+
3055
+
3056
+ void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) {
3057
+ ASSERT(args->length() == 2);
3058
+
3059
+ VisitForStackValue(args->at(0));
3060
+ VisitForAccumulatorValue(args->at(1));
3061
+ __ mov(a0, result_register());
3062
+
3063
+ Register object = a1;
3064
+ Register index = a0;
3065
+ Register scratch1 = a2;
3066
+ Register scratch2 = a3;
3067
+ Register result = v0;
3068
+
3069
+ __ pop(object);
3070
+
3071
+ Label need_conversion;
3072
+ Label index_out_of_range;
3073
+ Label done;
3074
+ StringCharAtGenerator generator(object,
3075
+ index,
3076
+ scratch1,
3077
+ scratch2,
3078
+ result,
3079
+ &need_conversion,
3080
+ &need_conversion,
3081
+ &index_out_of_range,
3082
+ STRING_INDEX_IS_NUMBER);
3083
+ generator.GenerateFast(masm_);
3084
+ __ jmp(&done);
3085
+
3086
+ __ bind(&index_out_of_range);
3087
+ // When the index is out of range, the spec requires us to return
3088
+ // the empty string.
3089
+ __ LoadRoot(result, Heap::kEmptyStringRootIndex);
3090
+ __ jmp(&done);
3091
+
3092
+ __ bind(&need_conversion);
3093
+ // Move smi zero into the result register, which will trigger
3094
+ // conversion.
3095
+ __ li(result, Operand(Smi::FromInt(0)));
3096
+ __ jmp(&done);
3097
+
3098
+ NopRuntimeCallHelper call_helper;
3099
+ generator.GenerateSlow(masm_, call_helper);
3100
+
3101
+ __ bind(&done);
3102
+ context()->Plug(result);
3103
+ }
3104
+
3105
+
3106
+ void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) {
3107
+ ASSERT_EQ(2, args->length());
3108
+
3109
+ VisitForStackValue(args->at(0));
3110
+ VisitForStackValue(args->at(1));
3111
+
3112
+ StringAddStub stub(NO_STRING_ADD_FLAGS);
3113
+ __ CallStub(&stub);
3114
+ context()->Plug(v0);
3115
+ }
3116
+
3117
+
3118
+ void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) {
3119
+ ASSERT_EQ(2, args->length());
3120
+
3121
+ VisitForStackValue(args->at(0));
3122
+ VisitForStackValue(args->at(1));
3123
+
3124
+ StringCompareStub stub;
3125
+ __ CallStub(&stub);
3126
+ context()->Plug(v0);
3127
+ }
3128
+
3129
+
3130
+ void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) {
3131
+ // Load the argument on the stack and call the stub.
3132
+ TranscendentalCacheStub stub(TranscendentalCache::SIN,
3133
+ TranscendentalCacheStub::TAGGED);
3134
+ ASSERT(args->length() == 1);
3135
+ VisitForStackValue(args->at(0));
3136
+ __ mov(a0, result_register()); // Stub requires parameter in a0 and on tos.
3137
+ __ CallStub(&stub);
3138
+ context()->Plug(v0);
3139
+ }
3140
+
3141
+
3142
+ void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) {
3143
+ // Load the argument on the stack and call the stub.
3144
+ TranscendentalCacheStub stub(TranscendentalCache::COS,
3145
+ TranscendentalCacheStub::TAGGED);
3146
+ ASSERT(args->length() == 1);
3147
+ VisitForStackValue(args->at(0));
3148
+ __ mov(a0, result_register()); // Stub requires parameter in a0 and on tos.
3149
+ __ CallStub(&stub);
3150
+ context()->Plug(v0);
3151
+ }
3152
+
3153
+
3154
+ void FullCodeGenerator::EmitMathLog(ZoneList<Expression*>* args) {
3155
+ // Load the argument on the stack and call the stub.
3156
+ TranscendentalCacheStub stub(TranscendentalCache::LOG,
3157
+ TranscendentalCacheStub::TAGGED);
3158
+ ASSERT(args->length() == 1);
3159
+ VisitForStackValue(args->at(0));
3160
+ __ mov(a0, result_register()); // Stub requires parameter in a0 and on tos.
3161
+ __ CallStub(&stub);
3162
+ context()->Plug(v0);
3163
+ }
3164
+
3165
+
3166
+ void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) {
3167
+ // Load the argument on the stack and call the runtime function.
3168
+ ASSERT(args->length() == 1);
3169
+ VisitForStackValue(args->at(0));
3170
+ __ CallRuntime(Runtime::kMath_sqrt, 1);
3171
+ context()->Plug(v0);
3172
+ }
3173
+
3174
+
3175
+ void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) {
3176
+ ASSERT(args->length() >= 2);
3177
+
3178
+ int arg_count = args->length() - 2; // 2 ~ receiver and function.
3179
+ for (int i = 0; i < arg_count + 1; i++) {
3180
+ VisitForStackValue(args->at(i));
3181
+ }
3182
+ VisitForAccumulatorValue(args->last()); // Function.
3183
+
3184
+ // InvokeFunction requires the function in a1. Move it in there.
3185
+ __ mov(a1, result_register());
3186
+ ParameterCount count(arg_count);
3187
+ __ InvokeFunction(a1, count, CALL_FUNCTION);
3188
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3189
+ context()->Plug(v0);
3190
+ }
3191
+
3192
+
3193
+ void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) {
3194
+ RegExpConstructResultStub stub;
3195
+ ASSERT(args->length() == 3);
3196
+ VisitForStackValue(args->at(0));
3197
+ VisitForStackValue(args->at(1));
3198
+ VisitForStackValue(args->at(2));
3199
+ __ CallStub(&stub);
3200
+ context()->Plug(v0);
3201
+ }
3202
+
3203
+
3204
+ void FullCodeGenerator::EmitSwapElements(ZoneList<Expression*>* args) {
3205
+ ASSERT(args->length() == 3);
3206
+ VisitForStackValue(args->at(0));
3207
+ VisitForStackValue(args->at(1));
3208
+ VisitForStackValue(args->at(2));
3209
+ Label done;
3210
+ Label slow_case;
3211
+ Register object = a0;
3212
+ Register index1 = a1;
3213
+ Register index2 = a2;
3214
+ Register elements = a3;
3215
+ Register scratch1 = t0;
3216
+ Register scratch2 = t1;
3217
+
3218
+ __ lw(object, MemOperand(sp, 2 * kPointerSize));
3219
+ // Fetch the map and check if array is in fast case.
3220
+ // Check that object doesn't require security checks and
3221
+ // has no indexed interceptor.
3222
+ __ GetObjectType(object, scratch1, scratch2);
3223
+ __ Branch(&slow_case, ne, scratch2, Operand(JS_ARRAY_TYPE));
3224
+ // Map is now in scratch1.
3225
+
3226
+ __ lbu(scratch2, FieldMemOperand(scratch1, Map::kBitFieldOffset));
3227
+ __ And(scratch2, scratch2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask));
3228
+ __ Branch(&slow_case, ne, scratch2, Operand(zero_reg));
3229
+
3230
+ // Check the object's elements are in fast case and writable.
3231
+ __ lw(elements, FieldMemOperand(object, JSObject::kElementsOffset));
3232
+ __ lw(scratch1, FieldMemOperand(elements, HeapObject::kMapOffset));
3233
+ __ LoadRoot(scratch2, Heap::kFixedArrayMapRootIndex);
3234
+ __ Branch(&slow_case, ne, scratch1, Operand(scratch2));
3235
+
3236
+ // Check that both indices are smis.
3237
+ __ lw(index1, MemOperand(sp, 1 * kPointerSize));
3238
+ __ lw(index2, MemOperand(sp, 0));
3239
+ __ JumpIfNotBothSmi(index1, index2, &slow_case);
3240
+
3241
+ // Check that both indices are valid.
3242
+ Label not_hi;
3243
+ __ lw(scratch1, FieldMemOperand(object, JSArray::kLengthOffset));
3244
+ __ Branch(&slow_case, ls, scratch1, Operand(index1));
3245
+ __ Branch(&not_hi, NegateCondition(hi), scratch1, Operand(index1));
3246
+ __ Branch(&slow_case, ls, scratch1, Operand(index2));
3247
+ __ bind(&not_hi);
3248
+
3249
+ // Bring the address of the elements into index1 and index2.
3250
+ __ Addu(scratch1, elements,
3251
+ Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3252
+ __ sll(index1, index1, kPointerSizeLog2 - kSmiTagSize);
3253
+ __ Addu(index1, scratch1, index1);
3254
+ __ sll(index2, index2, kPointerSizeLog2 - kSmiTagSize);
3255
+ __ Addu(index2, scratch1, index2);
3256
+
3257
+ // Swap elements.
3258
+ __ lw(scratch1, MemOperand(index1, 0));
3259
+ __ lw(scratch2, MemOperand(index2, 0));
3260
+ __ sw(scratch1, MemOperand(index2, 0));
3261
+ __ sw(scratch2, MemOperand(index1, 0));
3262
+
3263
+ Label new_space;
3264
+ __ InNewSpace(elements, scratch1, eq, &new_space);
3265
+ // Possible optimization: do a check that both values are Smis
3266
+ // (or them and test against Smi mask).
3267
+
3268
+ __ mov(scratch1, elements);
3269
+ __ RecordWriteHelper(elements, index1, scratch2);
3270
+ __ RecordWriteHelper(scratch1, index2, scratch2); // scratch1 holds elements.
3271
+
3272
+ __ bind(&new_space);
3273
+ // We are done. Drop elements from the stack, and return undefined.
3274
+ __ Drop(3);
3275
+ __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
3276
+ __ jmp(&done);
3277
+
3278
+ __ bind(&slow_case);
3279
+ __ CallRuntime(Runtime::kSwapElements, 3);
3280
+
3281
+ __ bind(&done);
3282
+ context()->Plug(v0);
3283
+ }
3284
+
3285
+
3286
+ void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) {
3287
+ ASSERT_EQ(2, args->length());
3288
+
3289
+ ASSERT_NE(NULL, args->at(0)->AsLiteral());
3290
+ int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value();
3291
+
3292
+ Handle<FixedArray> jsfunction_result_caches(
3293
+ isolate()->global_context()->jsfunction_result_caches());
3294
+ if (jsfunction_result_caches->length() <= cache_id) {
3295
+ __ Abort("Attempt to use undefined cache.");
3296
+ __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
3297
+ context()->Plug(v0);
3298
+ return;
3299
+ }
3300
+
3301
+ VisitForAccumulatorValue(args->at(1));
3302
+
3303
+ Register key = v0;
3304
+ Register cache = a1;
3305
+ __ lw(cache, ContextOperand(cp, Context::GLOBAL_INDEX));
3306
+ __ lw(cache, FieldMemOperand(cache, GlobalObject::kGlobalContextOffset));
3307
+ __ lw(cache,
3308
+ ContextOperand(
3309
+ cache, Context::JSFUNCTION_RESULT_CACHES_INDEX));
3310
+ __ lw(cache,
3311
+ FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id)));
3312
+
3313
+
3314
+ Label done, not_found;
3315
+ ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
3316
+ __ lw(a2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset));
3317
+ // a2 now holds finger offset as a smi.
3318
+ __ Addu(a3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3319
+ // a3 now points to the start of fixed array elements.
3320
+ __ sll(at, a2, kPointerSizeLog2 - kSmiTagSize);
3321
+ __ addu(a3, a3, at);
3322
+ // a3 now points to key of indexed element of cache.
3323
+ __ lw(a2, MemOperand(a3));
3324
+ __ Branch(&not_found, ne, key, Operand(a2));
3325
+
3326
+ __ lw(v0, MemOperand(a3, kPointerSize));
3327
+ __ Branch(&done);
3328
+
3329
+ __ bind(&not_found);
3330
+ // Call runtime to perform the lookup.
3331
+ __ Push(cache, key);
3332
+ __ CallRuntime(Runtime::kGetFromCache, 2);
3333
+
3334
+ __ bind(&done);
3335
+ context()->Plug(v0);
3336
+ }
3337
+
3338
+
3339
+ void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) {
3340
+ ASSERT_EQ(2, args->length());
3341
+
3342
+ Register right = v0;
3343
+ Register left = a1;
3344
+ Register tmp = a2;
3345
+ Register tmp2 = a3;
3346
+
3347
+ VisitForStackValue(args->at(0));
3348
+ VisitForAccumulatorValue(args->at(1)); // Result (right) in v0.
3349
+ __ pop(left);
3350
+
3351
+ Label done, fail, ok;
3352
+ __ Branch(&ok, eq, left, Operand(right));
3353
+ // Fail if either is a non-HeapObject.
3354
+ __ And(tmp, left, Operand(right));
3355
+ __ And(at, tmp, Operand(kSmiTagMask));
3356
+ __ Branch(&fail, eq, at, Operand(zero_reg));
3357
+ __ lw(tmp, FieldMemOperand(left, HeapObject::kMapOffset));
3358
+ __ lbu(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset));
3359
+ __ Branch(&fail, ne, tmp2, Operand(JS_REGEXP_TYPE));
3360
+ __ lw(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
3361
+ __ Branch(&fail, ne, tmp, Operand(tmp2));
3362
+ __ lw(tmp, FieldMemOperand(left, JSRegExp::kDataOffset));
3363
+ __ lw(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset));
3364
+ __ Branch(&ok, eq, tmp, Operand(tmp2));
3365
+ __ bind(&fail);
3366
+ __ LoadRoot(v0, Heap::kFalseValueRootIndex);
3367
+ __ jmp(&done);
3368
+ __ bind(&ok);
3369
+ __ LoadRoot(v0, Heap::kTrueValueRootIndex);
3370
+ __ bind(&done);
3371
+
3372
+ context()->Plug(v0);
3373
+ }
3374
+
3375
+
3376
+ void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) {
3377
+ VisitForAccumulatorValue(args->at(0));
3378
+
3379
+ Label materialize_true, materialize_false;
3380
+ Label* if_true = NULL;
3381
+ Label* if_false = NULL;
3382
+ Label* fall_through = NULL;
3383
+ context()->PrepareTest(&materialize_true, &materialize_false,
3384
+ &if_true, &if_false, &fall_through);
3385
+
3386
+ __ lw(a0, FieldMemOperand(v0, String::kHashFieldOffset));
3387
+ __ And(a0, a0, Operand(String::kContainsCachedArrayIndexMask));
3388
+
3389
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3390
+ Split(eq, a0, Operand(zero_reg), if_true, if_false, fall_through);
3391
+
3392
+ context()->Plug(if_true, if_false);
3393
+ }
3394
+
3395
+
3396
+ void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) {
3397
+ ASSERT(args->length() == 1);
3398
+ VisitForAccumulatorValue(args->at(0));
3399
+
3400
+ if (FLAG_debug_code) {
3401
+ __ AbortIfNotString(v0);
3402
+ }
3403
+
3404
+ __ lw(v0, FieldMemOperand(v0, String::kHashFieldOffset));
3405
+ __ IndexFromHash(v0, v0);
3406
+
3407
+ context()->Plug(v0);
3408
+ }
3409
+
3410
+
3411
+ void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) {
3412
+ Label bailout, done, one_char_separator, long_separator,
3413
+ non_trivial_array, not_size_one_array, loop,
3414
+ empty_separator_loop, one_char_separator_loop,
3415
+ one_char_separator_loop_entry, long_separator_loop;
3416
+
3417
+ ASSERT(args->length() == 2);
3418
+ VisitForStackValue(args->at(1));
3419
+ VisitForAccumulatorValue(args->at(0));
3420
+
3421
+ // All aliases of the same register have disjoint lifetimes.
3422
+ Register array = v0;
3423
+ Register elements = no_reg; // Will be v0.
3424
+ Register result = no_reg; // Will be v0.
3425
+ Register separator = a1;
3426
+ Register array_length = a2;
3427
+ Register result_pos = no_reg; // Will be a2.
3428
+ Register string_length = a3;
3429
+ Register string = t0;
3430
+ Register element = t1;
3431
+ Register elements_end = t2;
3432
+ Register scratch1 = t3;
3433
+ Register scratch2 = t5;
3434
+ Register scratch3 = t4;
3435
+ Register scratch4 = v1;
3436
+
3437
+ // Separator operand is on the stack.
3438
+ __ pop(separator);
3439
+
3440
+ // Check that the array is a JSArray.
3441
+ __ JumpIfSmi(array, &bailout);
3442
+ __ GetObjectType(array, scratch1, scratch2);
3443
+ __ Branch(&bailout, ne, scratch2, Operand(JS_ARRAY_TYPE));
3444
+
3445
+ // Check that the array has fast elements.
3446
+ __ lbu(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset));
3447
+ __ And(scratch3, scratch2, Operand(1 << Map::kHasFastElements));
3448
+ __ Branch(&bailout, eq, scratch3, Operand(zero_reg));
3449
+
3450
+ // If the array has length zero, return the empty string.
3451
+ __ lw(array_length, FieldMemOperand(array, JSArray::kLengthOffset));
3452
+ __ SmiUntag(array_length);
3453
+ __ Branch(&non_trivial_array, ne, array_length, Operand(zero_reg));
3454
+ __ LoadRoot(v0, Heap::kEmptyStringRootIndex);
3455
+ __ Branch(&done);
3456
+
3457
+ __ bind(&non_trivial_array);
3458
+
3459
+ // Get the FixedArray containing array's elements.
3460
+ elements = array;
3461
+ __ lw(elements, FieldMemOperand(array, JSArray::kElementsOffset));
3462
+ array = no_reg; // End of array's live range.
3463
+
3464
+ // Check that all array elements are sequential ASCII strings, and
3465
+ // accumulate the sum of their lengths, as a smi-encoded value.
3466
+ __ mov(string_length, zero_reg);
3467
+ __ Addu(element,
3468
+ elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3469
+ __ sll(elements_end, array_length, kPointerSizeLog2);
3470
+ __ Addu(elements_end, element, elements_end);
3471
+ // Loop condition: while (element < elements_end).
3472
+ // Live values in registers:
3473
+ // elements: Fixed array of strings.
3474
+ // array_length: Length of the fixed array of strings (not smi)
3475
+ // separator: Separator string
3476
+ // string_length: Accumulated sum of string lengths (smi).
3477
+ // element: Current array element.
3478
+ // elements_end: Array end.
3479
+ if (FLAG_debug_code) {
3480
+ __ Assert(gt, "No empty arrays here in EmitFastAsciiArrayJoin",
3481
+ array_length, Operand(zero_reg));
3482
+ }
3483
+ __ bind(&loop);
3484
+ __ lw(string, MemOperand(element));
3485
+ __ Addu(element, element, kPointerSize);
3486
+ __ JumpIfSmi(string, &bailout);
3487
+ __ lw(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
3488
+ __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3489
+ __ JumpIfInstanceTypeIsNotSequentialAscii(scratch1, scratch2, &bailout);
3490
+ __ lw(scratch1, FieldMemOperand(string, SeqAsciiString::kLengthOffset));
3491
+ __ AdduAndCheckForOverflow(string_length, string_length, scratch1, scratch3);
3492
+ __ BranchOnOverflow(&bailout, scratch3);
3493
+ __ Branch(&loop, lt, element, Operand(elements_end));
3494
+
3495
+ // If array_length is 1, return elements[0], a string.
3496
+ __ Branch(&not_size_one_array, ne, array_length, Operand(1));
3497
+ __ lw(v0, FieldMemOperand(elements, FixedArray::kHeaderSize));
3498
+ __ Branch(&done);
3499
+
3500
+ __ bind(&not_size_one_array);
3501
+
3502
+ // Live values in registers:
3503
+ // separator: Separator string
3504
+ // array_length: Length of the array.
3505
+ // string_length: Sum of string lengths (smi).
3506
+ // elements: FixedArray of strings.
3507
+
3508
+ // Check that the separator is a flat ASCII string.
3509
+ __ JumpIfSmi(separator, &bailout);
3510
+ __ lw(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
3511
+ __ lbu(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3512
+ __ JumpIfInstanceTypeIsNotSequentialAscii(scratch1, scratch2, &bailout);
3513
+
3514
+ // Add (separator length times array_length) - separator length to the
3515
+ // string_length to get the length of the result string. array_length is not
3516
+ // smi but the other values are, so the result is a smi.
3517
+ __ lw(scratch1, FieldMemOperand(separator, SeqAsciiString::kLengthOffset));
3518
+ __ Subu(string_length, string_length, Operand(scratch1));
3519
+ __ Mult(array_length, scratch1);
3520
+ // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
3521
+ // zero.
3522
+ __ mfhi(scratch2);
3523
+ __ Branch(&bailout, ne, scratch2, Operand(zero_reg));
3524
+ __ mflo(scratch2);
3525
+ __ And(scratch3, scratch2, Operand(0x80000000));
3526
+ __ Branch(&bailout, ne, scratch3, Operand(zero_reg));
3527
+ __ AdduAndCheckForOverflow(string_length, string_length, scratch2, scratch3);
3528
+ __ BranchOnOverflow(&bailout, scratch3);
3529
+ __ SmiUntag(string_length);
3530
+
3531
+ // Get first element in the array to free up the elements register to be used
3532
+ // for the result.
3533
+ __ Addu(element,
3534
+ elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3535
+ result = elements; // End of live range for elements.
3536
+ elements = no_reg;
3537
+ // Live values in registers:
3538
+ // element: First array element
3539
+ // separator: Separator string
3540
+ // string_length: Length of result string (not smi)
3541
+ // array_length: Length of the array.
3542
+ __ AllocateAsciiString(result,
3543
+ string_length,
3544
+ scratch1,
3545
+ scratch2,
3546
+ elements_end,
3547
+ &bailout);
3548
+ // Prepare for looping. Set up elements_end to end of the array. Set
3549
+ // result_pos to the position of the result where to write the first
3550
+ // character.
3551
+ __ sll(elements_end, array_length, kPointerSizeLog2);
3552
+ __ Addu(elements_end, element, elements_end);
3553
+ result_pos = array_length; // End of live range for array_length.
3554
+ array_length = no_reg;
3555
+ __ Addu(result_pos,
3556
+ result,
3557
+ Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag));
3558
+
3559
+ // Check the length of the separator.
3560
+ __ lw(scratch1, FieldMemOperand(separator, SeqAsciiString::kLengthOffset));
3561
+ __ li(at, Operand(Smi::FromInt(1)));
3562
+ __ Branch(&one_char_separator, eq, scratch1, Operand(at));
3563
+ __ Branch(&long_separator, gt, scratch1, Operand(at));
3564
+
3565
+ // Empty separator case.
3566
+ __ bind(&empty_separator_loop);
3567
+ // Live values in registers:
3568
+ // result_pos: the position to which we are currently copying characters.
3569
+ // element: Current array element.
3570
+ // elements_end: Array end.
3571
+
3572
+ // Copy next array element to the result.
3573
+ __ lw(string, MemOperand(element));
3574
+ __ Addu(element, element, kPointerSize);
3575
+ __ lw(string_length, FieldMemOperand(string, String::kLengthOffset));
3576
+ __ SmiUntag(string_length);
3577
+ __ Addu(string, string, SeqAsciiString::kHeaderSize - kHeapObjectTag);
3578
+ __ CopyBytes(string, result_pos, string_length, scratch1);
3579
+ // End while (element < elements_end).
3580
+ __ Branch(&empty_separator_loop, lt, element, Operand(elements_end));
3581
+ ASSERT(result.is(v0));
3582
+ __ Branch(&done);
3583
+
3584
+ // One-character separator case.
3585
+ __ bind(&one_char_separator);
3586
+ // Replace separator with its ascii character value.
3587
+ __ lbu(separator, FieldMemOperand(separator, SeqAsciiString::kHeaderSize));
3588
+ // Jump into the loop after the code that copies the separator, so the first
3589
+ // element is not preceded by a separator.
3590
+ __ jmp(&one_char_separator_loop_entry);
3591
+
3592
+ __ bind(&one_char_separator_loop);
3593
+ // Live values in registers:
3594
+ // result_pos: the position to which we are currently copying characters.
3595
+ // element: Current array element.
3596
+ // elements_end: Array end.
3597
+ // separator: Single separator ascii char (in lower byte).
3598
+
3599
+ // Copy the separator character to the result.
3600
+ __ sb(separator, MemOperand(result_pos));
3601
+ __ Addu(result_pos, result_pos, 1);
3602
+
3603
+ // Copy next array element to the result.
3604
+ __ bind(&one_char_separator_loop_entry);
3605
+ __ lw(string, MemOperand(element));
3606
+ __ Addu(element, element, kPointerSize);
3607
+ __ lw(string_length, FieldMemOperand(string, String::kLengthOffset));
3608
+ __ SmiUntag(string_length);
3609
+ __ Addu(string, string, SeqAsciiString::kHeaderSize - kHeapObjectTag);
3610
+ __ CopyBytes(string, result_pos, string_length, scratch1);
3611
+ // End while (element < elements_end).
3612
+ __ Branch(&one_char_separator_loop, lt, element, Operand(elements_end));
3613
+ ASSERT(result.is(v0));
3614
+ __ Branch(&done);
3615
+
3616
+ // Long separator case (separator is more than one character). Entry is at the
3617
+ // label long_separator below.
3618
+ __ bind(&long_separator_loop);
3619
+ // Live values in registers:
3620
+ // result_pos: the position to which we are currently copying characters.
3621
+ // element: Current array element.
3622
+ // elements_end: Array end.
3623
+ // separator: Separator string.
3624
+
3625
+ // Copy the separator to the result.
3626
+ __ lw(string_length, FieldMemOperand(separator, String::kLengthOffset));
3627
+ __ SmiUntag(string_length);
3628
+ __ Addu(string,
3629
+ separator,
3630
+ Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag));
3631
+ __ CopyBytes(string, result_pos, string_length, scratch1);
3632
+
3633
+ __ bind(&long_separator);
3634
+ __ lw(string, MemOperand(element));
3635
+ __ Addu(element, element, kPointerSize);
3636
+ __ lw(string_length, FieldMemOperand(string, String::kLengthOffset));
3637
+ __ SmiUntag(string_length);
3638
+ __ Addu(string, string, SeqAsciiString::kHeaderSize - kHeapObjectTag);
3639
+ __ CopyBytes(string, result_pos, string_length, scratch1);
3640
+ // End while (element < elements_end).
3641
+ __ Branch(&long_separator_loop, lt, element, Operand(elements_end));
3642
+ ASSERT(result.is(v0));
3643
+ __ Branch(&done);
3644
+
3645
+ __ bind(&bailout);
3646
+ __ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
3647
+ __ bind(&done);
3648
+ context()->Plug(v0);
3649
+ }
3650
+
3651
+
3652
+ void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
3653
+ Handle<String> name = expr->name();
3654
+ if (name->length() > 0 && name->Get(0) == '_') {
3655
+ Comment cmnt(masm_, "[ InlineRuntimeCall");
3656
+ EmitInlineRuntimeCall(expr);
3657
+ return;
3658
+ }
3659
+
3660
+ Comment cmnt(masm_, "[ CallRuntime");
3661
+ ZoneList<Expression*>* args = expr->arguments();
3662
+
3663
+ if (expr->is_jsruntime()) {
3664
+ // Prepare for calling JS runtime function.
3665
+ __ lw(a0, GlobalObjectOperand());
3666
+ __ lw(a0, FieldMemOperand(a0, GlobalObject::kBuiltinsOffset));
3667
+ __ push(a0);
3668
+ }
3669
+
3670
+ // Push the arguments ("left-to-right").
3671
+ int arg_count = args->length();
3672
+ for (int i = 0; i < arg_count; i++) {
3673
+ VisitForStackValue(args->at(i));
3674
+ }
3675
+
3676
+ if (expr->is_jsruntime()) {
3677
+ // Call the JS runtime function.
3678
+ __ li(a2, Operand(expr->name()));
3679
+ RelocInfo::Mode mode = RelocInfo::CODE_TARGET;
3680
+ Handle<Code> ic =
3681
+ isolate()->stub_cache()->ComputeCallInitialize(arg_count,
3682
+ NOT_IN_LOOP,
3683
+ mode);
3684
+ EmitCallIC(ic, mode, expr->id());
3685
+ // Restore context register.
3686
+ __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
3687
+ } else {
3688
+ // Call the C runtime function.
3689
+ __ CallRuntime(expr->function(), arg_count);
3690
+ }
3691
+ context()->Plug(v0);
3692
+ }
3693
+
3694
+
3695
+ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
3696
+ switch (expr->op()) {
3697
+ case Token::DELETE: {
3698
+ Comment cmnt(masm_, "[ UnaryOperation (DELETE)");
3699
+ Property* prop = expr->expression()->AsProperty();
3700
+ Variable* var = expr->expression()->AsVariableProxy()->AsVariable();
3701
+
3702
+ if (prop != NULL) {
3703
+ if (prop->is_synthetic()) {
3704
+ // Result of deleting parameters is false, even when they rewrite
3705
+ // to accesses on the arguments object.
3706
+ context()->Plug(false);
3707
+ } else {
3708
+ VisitForStackValue(prop->obj());
3709
+ VisitForStackValue(prop->key());
3710
+ __ li(a1, Operand(Smi::FromInt(strict_mode_flag())));
3711
+ __ push(a1);
3712
+ __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
3713
+ context()->Plug(v0);
3714
+ }
3715
+ } else if (var != NULL) {
3716
+ // Delete of an unqualified identifier is disallowed in strict mode
3717
+ // but "delete this" is.
3718
+ ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this());
3719
+ if (var->is_global()) {
3720
+ __ lw(a2, GlobalObjectOperand());
3721
+ __ li(a1, Operand(var->name()));
3722
+ __ li(a0, Operand(Smi::FromInt(kNonStrictMode)));
3723
+ __ Push(a2, a1, a0);
3724
+ __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION);
3725
+ context()->Plug(v0);
3726
+ } else if (var->AsSlot() != NULL &&
3727
+ var->AsSlot()->type() != Slot::LOOKUP) {
3728
+ // Result of deleting non-global, non-dynamic variables is false.
3729
+ // The subexpression does not have side effects.
3730
+ context()->Plug(false);
3731
+ } else {
3732
+ // Non-global variable. Call the runtime to try to delete from the
3733
+ // context where the variable was introduced.
3734
+ __ push(context_register());
3735
+ __ li(a2, Operand(var->name()));
3736
+ __ push(a2);
3737
+ __ CallRuntime(Runtime::kDeleteContextSlot, 2);
3738
+ context()->Plug(v0);
3739
+ }
3740
+ } else {
3741
+ // Result of deleting non-property, non-variable reference is true.
3742
+ // The subexpression may have side effects.
3743
+ VisitForEffect(expr->expression());
3744
+ context()->Plug(true);
3745
+ }
3746
+ break;
3747
+ }
3748
+
3749
+ case Token::VOID: {
3750
+ Comment cmnt(masm_, "[ UnaryOperation (VOID)");
3751
+ VisitForEffect(expr->expression());
3752
+ context()->Plug(Heap::kUndefinedValueRootIndex);
3753
+ break;
3754
+ }
3755
+
3756
+ case Token::NOT: {
3757
+ Comment cmnt(masm_, "[ UnaryOperation (NOT)");
3758
+ if (context()->IsEffect()) {
3759
+ // Unary NOT has no side effects so it's only necessary to visit the
3760
+ // subexpression. Match the optimizing compiler by not branching.
3761
+ VisitForEffect(expr->expression());
3762
+ } else {
3763
+ Label materialize_true, materialize_false;
3764
+ Label* if_true = NULL;
3765
+ Label* if_false = NULL;
3766
+ Label* fall_through = NULL;
3767
+
3768
+ // Notice that the labels are swapped.
3769
+ context()->PrepareTest(&materialize_true, &materialize_false,
3770
+ &if_false, &if_true, &fall_through);
3771
+ if (context()->IsTest()) ForwardBailoutToChild(expr);
3772
+ VisitForControl(expr->expression(), if_true, if_false, fall_through);
3773
+ context()->Plug(if_false, if_true); // Labels swapped.
3774
+ }
3775
+ break;
3776
+ }
3777
+
3778
+ case Token::TYPEOF: {
3779
+ Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
3780
+ { StackValueContext context(this);
3781
+ VisitForTypeofValue(expr->expression());
3782
+ }
3783
+ __ CallRuntime(Runtime::kTypeof, 1);
3784
+ context()->Plug(v0);
3785
+ break;
3786
+ }
3787
+
3788
+ case Token::ADD: {
3789
+ Comment cmt(masm_, "[ UnaryOperation (ADD)");
3790
+ VisitForAccumulatorValue(expr->expression());
3791
+ Label no_conversion;
3792
+ __ JumpIfSmi(result_register(), &no_conversion);
3793
+ __ mov(a0, result_register());
3794
+ ToNumberStub convert_stub;
3795
+ __ CallStub(&convert_stub);
3796
+ __ bind(&no_conversion);
3797
+ context()->Plug(result_register());
3798
+ break;
3799
+ }
3800
+
3801
+ case Token::SUB:
3802
+ EmitUnaryOperation(expr, "[ UnaryOperation (SUB)");
3803
+ break;
3804
+
3805
+ case Token::BIT_NOT:
3806
+ EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)");
3807
+ break;
3808
+
3809
+ default:
3810
+ UNREACHABLE();
3811
+ }
3812
+ }
3813
+
3814
+
3815
+ void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr,
3816
+ const char* comment) {
3817
+ // TODO(svenpanne): Allowing format strings in Comment would be nice here...
3818
+ Comment cmt(masm_, comment);
3819
+ bool can_overwrite = expr->expression()->ResultOverwriteAllowed();
3820
+ UnaryOverwriteMode overwrite =
3821
+ can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE;
3822
+ UnaryOpStub stub(expr->op(), overwrite);
3823
+ // GenericUnaryOpStub expects the argument to be in a0.
3824
+ VisitForAccumulatorValue(expr->expression());
3825
+ SetSourcePosition(expr->position());
3826
+ __ mov(a0, result_register());
3827
+ EmitCallIC(stub.GetCode(), NULL, expr->id());
3828
+ context()->Plug(v0);
3829
+ }
3830
+
3831
+
3832
+ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
3833
+ Comment cmnt(masm_, "[ CountOperation");
3834
+ SetSourcePosition(expr->position());
3835
+
3836
+ // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
3837
+ // as the left-hand side.
3838
+ if (!expr->expression()->IsValidLeftHandSide()) {
3839
+ VisitForEffect(expr->expression());
3840
+ return;
3841
+ }
3842
+
3843
+ // Expression can only be a property, a global or a (parameter or local)
3844
+ // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY.
3845
+ enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY };
3846
+ LhsKind assign_type = VARIABLE;
3847
+ Property* prop = expr->expression()->AsProperty();
3848
+ // In case of a property we use the uninitialized expression context
3849
+ // of the key to detect a named property.
3850
+ if (prop != NULL) {
3851
+ assign_type =
3852
+ (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY;
3853
+ }
3854
+
3855
+ // Evaluate expression and get value.
3856
+ if (assign_type == VARIABLE) {
3857
+ ASSERT(expr->expression()->AsVariableProxy()->var() != NULL);
3858
+ AccumulatorValueContext context(this);
3859
+ EmitVariableLoad(expr->expression()->AsVariableProxy()->var());
3860
+ } else {
3861
+ // Reserve space for result of postfix operation.
3862
+ if (expr->is_postfix() && !context()->IsEffect()) {
3863
+ __ li(at, Operand(Smi::FromInt(0)));
3864
+ __ push(at);
3865
+ }
3866
+ if (assign_type == NAMED_PROPERTY) {
3867
+ // Put the object both on the stack and in the accumulator.
3868
+ VisitForAccumulatorValue(prop->obj());
3869
+ __ push(v0);
3870
+ EmitNamedPropertyLoad(prop);
3871
+ } else {
3872
+ if (prop->is_arguments_access()) {
3873
+ VariableProxy* obj_proxy = prop->obj()->AsVariableProxy();
3874
+ __ lw(v0, EmitSlotSearch(obj_proxy->var()->AsSlot(), v0));
3875
+ __ push(v0);
3876
+ __ li(v0, Operand(prop->key()->AsLiteral()->handle()));
3877
+ } else {
3878
+ VisitForStackValue(prop->obj());
3879
+ VisitForAccumulatorValue(prop->key());
3880
+ }
3881
+ __ lw(a1, MemOperand(sp, 0));
3882
+ __ push(v0);
3883
+ EmitKeyedPropertyLoad(prop);
3884
+ }
3885
+ }
3886
+
3887
+ // We need a second deoptimization point after loading the value
3888
+ // in case evaluating the property load my have a side effect.
3889
+ if (assign_type == VARIABLE) {
3890
+ PrepareForBailout(expr->expression(), TOS_REG);
3891
+ } else {
3892
+ PrepareForBailoutForId(expr->CountId(), TOS_REG);
3893
+ }
3894
+
3895
+ // Call ToNumber only if operand is not a smi.
3896
+ Label no_conversion;
3897
+ __ JumpIfSmi(v0, &no_conversion);
3898
+ __ mov(a0, v0);
3899
+ ToNumberStub convert_stub;
3900
+ __ CallStub(&convert_stub);
3901
+ __ bind(&no_conversion);
3902
+
3903
+ // Save result for postfix expressions.
3904
+ if (expr->is_postfix()) {
3905
+ if (!context()->IsEffect()) {
3906
+ // Save the result on the stack. If we have a named or keyed property
3907
+ // we store the result under the receiver that is currently on top
3908
+ // of the stack.
3909
+ switch (assign_type) {
3910
+ case VARIABLE:
3911
+ __ push(v0);
3912
+ break;
3913
+ case NAMED_PROPERTY:
3914
+ __ sw(v0, MemOperand(sp, kPointerSize));
3915
+ break;
3916
+ case KEYED_PROPERTY:
3917
+ __ sw(v0, MemOperand(sp, 2 * kPointerSize));
3918
+ break;
3919
+ }
3920
+ }
3921
+ }
3922
+ __ mov(a0, result_register());
3923
+
3924
+ // Inline smi case if we are in a loop.
3925
+ Label stub_call, done;
3926
+ JumpPatchSite patch_site(masm_);
3927
+
3928
+ int count_value = expr->op() == Token::INC ? 1 : -1;
3929
+ __ li(a1, Operand(Smi::FromInt(count_value)));
3930
+
3931
+ if (ShouldInlineSmiCase(expr->op())) {
3932
+ __ AdduAndCheckForOverflow(v0, a0, a1, t0);
3933
+ __ BranchOnOverflow(&stub_call, t0); // Do stub on overflow.
3934
+
3935
+ // We could eliminate this smi check if we split the code at
3936
+ // the first smi check before calling ToNumber.
3937
+ patch_site.EmitJumpIfSmi(v0, &done);
3938
+ __ bind(&stub_call);
3939
+ }
3940
+
3941
+ // Record position before stub call.
3942
+ SetSourcePosition(expr->position());
3943
+
3944
+ BinaryOpStub stub(Token::ADD, NO_OVERWRITE);
3945
+ EmitCallIC(stub.GetCode(), &patch_site, expr->CountId());
3946
+ __ bind(&done);
3947
+
3948
+ // Store the value returned in v0.
3949
+ switch (assign_type) {
3950
+ case VARIABLE:
3951
+ if (expr->is_postfix()) {
3952
+ { EffectContext context(this);
3953
+ EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
3954
+ Token::ASSIGN);
3955
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3956
+ context.Plug(v0);
3957
+ }
3958
+ // For all contexts except EffectConstant we have the result on
3959
+ // top of the stack.
3960
+ if (!context()->IsEffect()) {
3961
+ context()->PlugTOS();
3962
+ }
3963
+ } else {
3964
+ EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
3965
+ Token::ASSIGN);
3966
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3967
+ context()->Plug(v0);
3968
+ }
3969
+ break;
3970
+ case NAMED_PROPERTY: {
3971
+ __ mov(a0, result_register()); // Value.
3972
+ __ li(a2, Operand(prop->key()->AsLiteral()->handle())); // Name.
3973
+ __ pop(a1); // Receiver.
3974
+ Handle<Code> ic = is_strict_mode()
3975
+ ? isolate()->builtins()->StoreIC_Initialize_Strict()
3976
+ : isolate()->builtins()->StoreIC_Initialize();
3977
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
3978
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3979
+ if (expr->is_postfix()) {
3980
+ if (!context()->IsEffect()) {
3981
+ context()->PlugTOS();
3982
+ }
3983
+ } else {
3984
+ context()->Plug(v0);
3985
+ }
3986
+ break;
3987
+ }
3988
+ case KEYED_PROPERTY: {
3989
+ __ mov(a0, result_register()); // Value.
3990
+ __ pop(a1); // Key.
3991
+ __ pop(a2); // Receiver.
3992
+ Handle<Code> ic = is_strict_mode()
3993
+ ? isolate()->builtins()->KeyedStoreIC_Initialize_Strict()
3994
+ : isolate()->builtins()->KeyedStoreIC_Initialize();
3995
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
3996
+ PrepareForBailoutForId(expr->AssignmentId(), TOS_REG);
3997
+ if (expr->is_postfix()) {
3998
+ if (!context()->IsEffect()) {
3999
+ context()->PlugTOS();
4000
+ }
4001
+ } else {
4002
+ context()->Plug(v0);
4003
+ }
4004
+ break;
4005
+ }
4006
+ }
4007
+ }
4008
+
4009
+
4010
+ void FullCodeGenerator::VisitForTypeofValue(Expression* expr) {
4011
+ VariableProxy* proxy = expr->AsVariableProxy();
4012
+ if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) {
4013
+ Comment cmnt(masm_, "Global variable");
4014
+ __ lw(a0, GlobalObjectOperand());
4015
+ __ li(a2, Operand(proxy->name()));
4016
+ Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
4017
+ // Use a regular load, not a contextual load, to avoid a reference
4018
+ // error.
4019
+ EmitCallIC(ic, RelocInfo::CODE_TARGET, AstNode::kNoNumber);
4020
+ PrepareForBailout(expr, TOS_REG);
4021
+ context()->Plug(v0);
4022
+ } else if (proxy != NULL &&
4023
+ proxy->var()->AsSlot() != NULL &&
4024
+ proxy->var()->AsSlot()->type() == Slot::LOOKUP) {
4025
+ Label done, slow;
4026
+
4027
+ // Generate code for loading from variables potentially shadowed
4028
+ // by eval-introduced variables.
4029
+ Slot* slot = proxy->var()->AsSlot();
4030
+ EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done);
4031
+
4032
+ __ bind(&slow);
4033
+ __ li(a0, Operand(proxy->name()));
4034
+ __ Push(cp, a0);
4035
+ __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2);
4036
+ PrepareForBailout(expr, TOS_REG);
4037
+ __ bind(&done);
4038
+
4039
+ context()->Plug(v0);
4040
+ } else {
4041
+ // This expression cannot throw a reference error at the top level.
4042
+ context()->HandleExpression(expr);
4043
+ }
4044
+ }
4045
+
4046
+
4047
+ bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
4048
+ Expression* left,
4049
+ Expression* right,
4050
+ Label* if_true,
4051
+ Label* if_false,
4052
+ Label* fall_through) {
4053
+ if (op != Token::EQ && op != Token::EQ_STRICT) return false;
4054
+
4055
+ // Check for the pattern: typeof <expression> == <string literal>.
4056
+ Literal* right_literal = right->AsLiteral();
4057
+ if (right_literal == NULL) return false;
4058
+ Handle<Object> right_literal_value = right_literal->handle();
4059
+ if (!right_literal_value->IsString()) return false;
4060
+ UnaryOperation* left_unary = left->AsUnaryOperation();
4061
+ if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false;
4062
+ Handle<String> check = Handle<String>::cast(right_literal_value);
4063
+
4064
+ { AccumulatorValueContext context(this);
4065
+ VisitForTypeofValue(left_unary->expression());
4066
+ }
4067
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4068
+
4069
+ if (check->Equals(isolate()->heap()->number_symbol())) {
4070
+ __ JumpIfSmi(v0, if_true);
4071
+ __ lw(v0, FieldMemOperand(v0, HeapObject::kMapOffset));
4072
+ __ LoadRoot(at, Heap::kHeapNumberMapRootIndex);
4073
+ Split(eq, v0, Operand(at), if_true, if_false, fall_through);
4074
+ } else if (check->Equals(isolate()->heap()->string_symbol())) {
4075
+ __ JumpIfSmi(v0, if_false);
4076
+ // Check for undetectable objects => false.
4077
+ __ GetObjectType(v0, v0, a1);
4078
+ __ Branch(if_false, ge, a1, Operand(FIRST_NONSTRING_TYPE));
4079
+ __ lbu(a1, FieldMemOperand(v0, Map::kBitFieldOffset));
4080
+ __ And(a1, a1, Operand(1 << Map::kIsUndetectable));
4081
+ Split(eq, a1, Operand(zero_reg),
4082
+ if_true, if_false, fall_through);
4083
+ } else if (check->Equals(isolate()->heap()->boolean_symbol())) {
4084
+ __ LoadRoot(at, Heap::kTrueValueRootIndex);
4085
+ __ Branch(if_true, eq, v0, Operand(at));
4086
+ __ LoadRoot(at, Heap::kFalseValueRootIndex);
4087
+ Split(eq, v0, Operand(at), if_true, if_false, fall_through);
4088
+ } else if (check->Equals(isolate()->heap()->undefined_symbol())) {
4089
+ __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
4090
+ __ Branch(if_true, eq, v0, Operand(at));
4091
+ __ JumpIfSmi(v0, if_false);
4092
+ // Check for undetectable objects => true.
4093
+ __ lw(v0, FieldMemOperand(v0, HeapObject::kMapOffset));
4094
+ __ lbu(a1, FieldMemOperand(v0, Map::kBitFieldOffset));
4095
+ __ And(a1, a1, Operand(1 << Map::kIsUndetectable));
4096
+ Split(ne, a1, Operand(zero_reg), if_true, if_false, fall_through);
4097
+ } else if (check->Equals(isolate()->heap()->function_symbol())) {
4098
+ __ JumpIfSmi(v0, if_false);
4099
+ __ GetObjectType(v0, a1, v0); // Leave map in a1.
4100
+ Split(ge, v0, Operand(FIRST_FUNCTION_CLASS_TYPE),
4101
+ if_true, if_false, fall_through);
4102
+
4103
+ } else if (check->Equals(isolate()->heap()->object_symbol())) {
4104
+ __ JumpIfSmi(v0, if_false);
4105
+ __ LoadRoot(at, Heap::kNullValueRootIndex);
4106
+ __ Branch(if_true, eq, v0, Operand(at));
4107
+ // Check for JS objects => true.
4108
+ __ GetObjectType(v0, v0, a1);
4109
+ __ Branch(if_false, lo, a1, Operand(FIRST_JS_OBJECT_TYPE));
4110
+ __ lbu(a1, FieldMemOperand(v0, Map::kInstanceTypeOffset));
4111
+ __ Branch(if_false, hs, a1, Operand(FIRST_FUNCTION_CLASS_TYPE));
4112
+ // Check for undetectable objects => false.
4113
+ __ lbu(a1, FieldMemOperand(v0, Map::kBitFieldOffset));
4114
+ __ And(a1, a1, Operand(1 << Map::kIsUndetectable));
4115
+ Split(eq, a1, Operand(zero_reg), if_true, if_false, fall_through);
4116
+ } else {
4117
+ if (if_false != fall_through) __ jmp(if_false);
4118
+ }
4119
+
4120
+ return true;
4121
+ }
4122
+
4123
+
4124
+ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
4125
+ Comment cmnt(masm_, "[ CompareOperation");
4126
+ SetSourcePosition(expr->position());
4127
+
4128
+ // Always perform the comparison for its control flow. Pack the result
4129
+ // into the expression's context after the comparison is performed.
4130
+
4131
+ Label materialize_true, materialize_false;
4132
+ Label* if_true = NULL;
4133
+ Label* if_false = NULL;
4134
+ Label* fall_through = NULL;
4135
+ context()->PrepareTest(&materialize_true, &materialize_false,
4136
+ &if_true, &if_false, &fall_through);
4137
+
4138
+ // First we try a fast inlined version of the compare when one of
4139
+ // the operands is a literal.
4140
+ Token::Value op = expr->op();
4141
+ Expression* left = expr->left();
4142
+ Expression* right = expr->right();
4143
+ if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) {
4144
+ context()->Plug(if_true, if_false);
4145
+ return;
4146
+ }
4147
+
4148
+ VisitForStackValue(expr->left());
4149
+ switch (op) {
4150
+ case Token::IN:
4151
+ VisitForStackValue(expr->right());
4152
+ __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4153
+ PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
4154
+ __ LoadRoot(t0, Heap::kTrueValueRootIndex);
4155
+ Split(eq, v0, Operand(t0), if_true, if_false, fall_through);
4156
+ break;
4157
+
4158
+ case Token::INSTANCEOF: {
4159
+ VisitForStackValue(expr->right());
4160
+ InstanceofStub stub(InstanceofStub::kNoFlags);
4161
+ __ CallStub(&stub);
4162
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4163
+ // The stub returns 0 for true.
4164
+ Split(eq, v0, Operand(zero_reg), if_true, if_false, fall_through);
4165
+ break;
4166
+ }
4167
+
4168
+ default: {
4169
+ VisitForAccumulatorValue(expr->right());
4170
+ Condition cc = eq;
4171
+ bool strict = false;
4172
+ switch (op) {
4173
+ case Token::EQ_STRICT:
4174
+ strict = true;
4175
+ // Fall through.
4176
+ case Token::EQ:
4177
+ cc = eq;
4178
+ __ mov(a0, result_register());
4179
+ __ pop(a1);
4180
+ break;
4181
+ case Token::LT:
4182
+ cc = lt;
4183
+ __ mov(a0, result_register());
4184
+ __ pop(a1);
4185
+ break;
4186
+ case Token::GT:
4187
+ // Reverse left and right sides to obtain ECMA-262 conversion order.
4188
+ cc = lt;
4189
+ __ mov(a1, result_register());
4190
+ __ pop(a0);
4191
+ break;
4192
+ case Token::LTE:
4193
+ // Reverse left and right sides to obtain ECMA-262 conversion order.
4194
+ cc = ge;
4195
+ __ mov(a1, result_register());
4196
+ __ pop(a0);
4197
+ break;
4198
+ case Token::GTE:
4199
+ cc = ge;
4200
+ __ mov(a0, result_register());
4201
+ __ pop(a1);
4202
+ break;
4203
+ case Token::IN:
4204
+ case Token::INSTANCEOF:
4205
+ default:
4206
+ UNREACHABLE();
4207
+ }
4208
+
4209
+ bool inline_smi_code = ShouldInlineSmiCase(op);
4210
+ JumpPatchSite patch_site(masm_);
4211
+ if (inline_smi_code) {
4212
+ Label slow_case;
4213
+ __ Or(a2, a0, Operand(a1));
4214
+ patch_site.EmitJumpIfNotSmi(a2, &slow_case);
4215
+ Split(cc, a1, Operand(a0), if_true, if_false, NULL);
4216
+ __ bind(&slow_case);
4217
+ }
4218
+ // Record position and call the compare IC.
4219
+ SetSourcePosition(expr->position());
4220
+ Handle<Code> ic = CompareIC::GetUninitialized(op);
4221
+ EmitCallIC(ic, &patch_site, expr->id());
4222
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4223
+ Split(cc, v0, Operand(zero_reg), if_true, if_false, fall_through);
4224
+ }
4225
+ }
4226
+
4227
+ // Convert the result of the comparison into one expected for this
4228
+ // expression's context.
4229
+ context()->Plug(if_true, if_false);
4230
+ }
4231
+
4232
+
4233
+ void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) {
4234
+ Comment cmnt(masm_, "[ CompareToNull");
4235
+ Label materialize_true, materialize_false;
4236
+ Label* if_true = NULL;
4237
+ Label* if_false = NULL;
4238
+ Label* fall_through = NULL;
4239
+ context()->PrepareTest(&materialize_true, &materialize_false,
4240
+ &if_true, &if_false, &fall_through);
4241
+
4242
+ VisitForAccumulatorValue(expr->expression());
4243
+ PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
4244
+ __ mov(a0, result_register());
4245
+ __ LoadRoot(a1, Heap::kNullValueRootIndex);
4246
+ if (expr->is_strict()) {
4247
+ Split(eq, a0, Operand(a1), if_true, if_false, fall_through);
4248
+ } else {
4249
+ __ Branch(if_true, eq, a0, Operand(a1));
4250
+ __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
4251
+ __ Branch(if_true, eq, a0, Operand(a1));
4252
+ __ And(at, a0, Operand(kSmiTagMask));
4253
+ __ Branch(if_false, eq, at, Operand(zero_reg));
4254
+ // It can be an undetectable object.
4255
+ __ lw(a1, FieldMemOperand(a0, HeapObject::kMapOffset));
4256
+ __ lbu(a1, FieldMemOperand(a1, Map::kBitFieldOffset));
4257
+ __ And(a1, a1, Operand(1 << Map::kIsUndetectable));
4258
+ Split(ne, a1, Operand(zero_reg), if_true, if_false, fall_through);
4259
+ }
4260
+ context()->Plug(if_true, if_false);
4261
+ }
4262
+
4263
+
4264
+ void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) {
4265
+ __ lw(v0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
4266
+ context()->Plug(v0);
4267
+ }
4268
+
4269
+
4270
+ Register FullCodeGenerator::result_register() {
4271
+ return v0;
4272
+ }
4273
+
4274
+
4275
+ Register FullCodeGenerator::context_register() {
4276
+ return cp;
4277
+ }
4278
+
4279
+
4280
+ void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4281
+ RelocInfo::Mode mode,
4282
+ unsigned ast_id) {
4283
+ ASSERT(mode == RelocInfo::CODE_TARGET ||
4284
+ mode == RelocInfo::CODE_TARGET_CONTEXT);
4285
+ Counters* counters = isolate()->counters();
4286
+ switch (ic->kind()) {
4287
+ case Code::LOAD_IC:
4288
+ __ IncrementCounter(counters->named_load_full(), 1, a1, a2);
4289
+ break;
4290
+ case Code::KEYED_LOAD_IC:
4291
+ __ IncrementCounter(counters->keyed_load_full(), 1, a1, a2);
4292
+ break;
4293
+ case Code::STORE_IC:
4294
+ __ IncrementCounter(counters->named_store_full(), 1, a1, a2);
4295
+ break;
4296
+ case Code::KEYED_STORE_IC:
4297
+ __ IncrementCounter(counters->keyed_store_full(), 1, a1, a2);
4298
+ default:
4299
+ break;
4300
+ }
4301
+ if (ast_id == kNoASTId || mode == RelocInfo::CODE_TARGET_CONTEXT) {
4302
+ __ Call(ic, mode);
4303
+ } else {
4304
+ ASSERT(mode == RelocInfo::CODE_TARGET);
4305
+ mode = RelocInfo::CODE_TARGET_WITH_ID;
4306
+ __ CallWithAstId(ic, mode, ast_id);
4307
+ }
4308
+ }
4309
+
4310
+
4311
+ void FullCodeGenerator::EmitCallIC(Handle<Code> ic,
4312
+ JumpPatchSite* patch_site,
4313
+ unsigned ast_id) {
4314
+ Counters* counters = isolate()->counters();
4315
+ switch (ic->kind()) {
4316
+ case Code::LOAD_IC:
4317
+ __ IncrementCounter(counters->named_load_full(), 1, a1, a2);
4318
+ break;
4319
+ case Code::KEYED_LOAD_IC:
4320
+ __ IncrementCounter(counters->keyed_load_full(), 1, a1, a2);
4321
+ break;
4322
+ case Code::STORE_IC:
4323
+ __ IncrementCounter(counters->named_store_full(), 1, a1, a2);
4324
+ break;
4325
+ case Code::KEYED_STORE_IC:
4326
+ __ IncrementCounter(counters->keyed_store_full(), 1, a1, a2);
4327
+ default:
4328
+ break;
4329
+ }
4330
+
4331
+ if (ast_id == kNoASTId) {
4332
+ __ Call(ic, RelocInfo::CODE_TARGET);
4333
+ } else {
4334
+ __ CallWithAstId(ic, RelocInfo::CODE_TARGET_WITH_ID, ast_id);
4335
+ }
4336
+ if (patch_site != NULL && patch_site->is_bound()) {
4337
+ patch_site->EmitPatchInfo();
4338
+ } else {
4339
+ __ nop(); // Signals no inlined code.
4340
+ }
4341
+ }
4342
+
4343
+
4344
+ void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) {
4345
+ ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset);
4346
+ __ sw(value, MemOperand(fp, frame_offset));
4347
+ }
4348
+
4349
+
4350
+ void FullCodeGenerator::LoadContextField(Register dst, int context_index) {
4351
+ __ lw(dst, ContextOperand(cp, context_index));
4352
+ }
4353
+
4354
+
4355
+ // ----------------------------------------------------------------------------
4356
+ // Non-local control flow support.
4357
+
4358
+ void FullCodeGenerator::EnterFinallyBlock() {
4359
+ ASSERT(!result_register().is(a1));
4360
+ // Store result register while executing finally block.
4361
+ __ push(result_register());
4362
+ // Cook return address in link register to stack (smi encoded Code* delta).
4363
+ __ Subu(a1, ra, Operand(masm_->CodeObject()));
4364
+ ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize);
4365
+ ASSERT_EQ(0, kSmiTag);
4366
+ __ Addu(a1, a1, Operand(a1)); // Convert to smi.
4367
+ __ push(a1);
4368
+ }
4369
+
4370
+
4371
+ void FullCodeGenerator::ExitFinallyBlock() {
4372
+ ASSERT(!result_register().is(a1));
4373
+ // Restore result register from stack.
4374
+ __ pop(a1);
4375
+ // Uncook return address and return.
4376
+ __ pop(result_register());
4377
+ ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize);
4378
+ __ sra(a1, a1, 1); // Un-smi-tag value.
4379
+ __ Addu(at, a1, Operand(masm_->CodeObject()));
4380
+ __ Jump(at);
4381
+ }
4382
+
4383
+
4384
+ #undef __
4385
+
4386
+ } } // namespace v8::internal
4387
+
4388
+ #endif // V8_TARGET_ARCH_MIPS