OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 | 1632 |
1633 return GENERIC; | 1633 return GENERIC; |
1634 } | 1634 } |
1635 | 1635 |
1636 | 1636 |
1637 // defined in codegen-<arch>.cc | 1637 // defined in codegen-<arch>.cc |
1638 Handle<Code> GetBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info); | 1638 Handle<Code> GetBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info); |
1639 | 1639 |
1640 | 1640 |
1641 Object* BinaryOp_Patch(Arguments args) { | 1641 Object* BinaryOp_Patch(Arguments args) { |
1642 ASSERT(args.length() == 6); | 1642 ASSERT(args.length() == 5); |
1643 | 1643 |
1644 Handle<Object> left = args.at<Object>(0); | 1644 Handle<Object> left = args.at<Object>(0); |
1645 Handle<Object> right = args.at<Object>(1); | 1645 Handle<Object> right = args.at<Object>(1); |
1646 Handle<Object> result = args.at<Object>(2); | 1646 int key = Smi::cast(args[2])->value(); |
1647 int key = Smi::cast(args[3])->value(); | 1647 Token::Value op = static_cast<Token::Value>(Smi::cast(args[3])->value()); |
1648 #ifdef DEBUG | 1648 #ifdef DEBUG |
1649 Token::Value op = static_cast<Token::Value>(Smi::cast(args[4])->value()); | |
1650 BinaryOpIC::TypeInfo prev_type_info = | 1649 BinaryOpIC::TypeInfo prev_type_info = |
1651 static_cast<BinaryOpIC::TypeInfo>(Smi::cast(args[5])->value()); | 1650 static_cast<BinaryOpIC::TypeInfo>(Smi::cast(args[4])->value()); |
1652 #endif // DEBUG | 1651 #endif // DEBUG |
1653 { HandleScope scope; | 1652 { HandleScope scope; |
1654 BinaryOpIC::TypeInfo type_info = BinaryOpIC::GetTypeInfo(*left, *right); | 1653 BinaryOpIC::TypeInfo type_info = BinaryOpIC::GetTypeInfo(*left, *right); |
1655 Handle<Code> code = GetBinaryOpStub(key, type_info); | 1654 Handle<Code> code = GetBinaryOpStub(key, type_info); |
1656 if (!code.is_null()) { | 1655 if (!code.is_null()) { |
1657 BinaryOpIC ic; | 1656 BinaryOpIC ic; |
1658 ic.patch(*code); | 1657 ic.patch(*code); |
1659 #ifdef DEBUG | 1658 #ifdef DEBUG |
1660 if (FLAG_trace_ic) { | 1659 if (FLAG_trace_ic) { |
1661 PrintF("[BinaryOpIC (%s->%s)#%s]\n", | 1660 PrintF("[BinaryOpIC (%s->%s)#%s]\n", |
1662 BinaryOpIC::GetName(prev_type_info), | 1661 BinaryOpIC::GetName(prev_type_info), |
1663 BinaryOpIC::GetName(type_info), | 1662 BinaryOpIC::GetName(type_info), |
1664 Token::Name(op)); | 1663 Token::Name(op)); |
1665 } | 1664 } |
1666 #endif // DEBUG | 1665 #endif // DEBUG |
1667 } | 1666 } |
1668 } | 1667 } |
1669 | 1668 |
| 1669 HandleScope scope; |
| 1670 Handle<JSBuiltinsObject> builtins = Top::builtins(); |
| 1671 |
| 1672 Object* builtin = NULL; // Initialization calms down the compiler. |
| 1673 |
| 1674 switch (op) { |
| 1675 case Token::ADD: |
| 1676 builtin = builtins->javascript_builtin(Builtins::ADD); |
| 1677 break; |
| 1678 case Token::SUB: |
| 1679 builtin = builtins->javascript_builtin(Builtins::SUB); |
| 1680 break; |
| 1681 case Token::MUL: |
| 1682 builtin = builtins->javascript_builtin(Builtins::MUL); |
| 1683 break; |
| 1684 case Token::DIV: |
| 1685 builtin = builtins->javascript_builtin(Builtins::DIV); |
| 1686 break; |
| 1687 case Token::MOD: |
| 1688 builtin = builtins->javascript_builtin(Builtins::MOD); |
| 1689 break; |
| 1690 case Token::BIT_AND: |
| 1691 builtin = builtins->javascript_builtin(Builtins::BIT_AND); |
| 1692 break; |
| 1693 case Token::BIT_OR: |
| 1694 builtin = builtins->javascript_builtin(Builtins::BIT_OR); |
| 1695 break; |
| 1696 case Token::BIT_XOR: |
| 1697 builtin = builtins->javascript_builtin(Builtins::BIT_XOR); |
| 1698 break; |
| 1699 case Token::SHR: |
| 1700 builtin = builtins->javascript_builtin(Builtins::SHR); |
| 1701 break; |
| 1702 case Token::SAR: |
| 1703 builtin = builtins->javascript_builtin(Builtins::SAR); |
| 1704 break; |
| 1705 case Token::SHL: |
| 1706 builtin = builtins->javascript_builtin(Builtins::SHL); |
| 1707 break; |
| 1708 default: |
| 1709 UNREACHABLE(); |
| 1710 } |
| 1711 |
| 1712 Handle<JSFunction> builtin_function(JSFunction::cast(builtin)); |
| 1713 |
| 1714 bool caught_exception; |
| 1715 Object** builtin_args[] = { right.location() }; |
| 1716 Handle<Object> result = Execution::Call(builtin_function, |
| 1717 left, |
| 1718 ARRAY_SIZE(builtin_args), |
| 1719 builtin_args, |
| 1720 &caught_exception); |
| 1721 if (caught_exception) { |
| 1722 return Failure::Exception(); |
| 1723 } |
1670 return *result; | 1724 return *result; |
1671 } | 1725 } |
1672 | 1726 |
1673 | 1727 |
1674 static Address IC_utilities[] = { | 1728 static Address IC_utilities[] = { |
1675 #define ADDR(name) FUNCTION_ADDR(name), | 1729 #define ADDR(name) FUNCTION_ADDR(name), |
1676 IC_UTIL_LIST(ADDR) | 1730 IC_UTIL_LIST(ADDR) |
1677 NULL | 1731 NULL |
1678 #undef ADDR | 1732 #undef ADDR |
1679 }; | 1733 }; |
1680 | 1734 |
1681 | 1735 |
1682 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 1736 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
1683 return IC_utilities[id]; | 1737 return IC_utilities[id]; |
1684 } | 1738 } |
1685 | 1739 |
1686 | 1740 |
1687 } } // namespace v8::internal | 1741 } } // namespace v8::internal |
OLD | NEW |