OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_PLATFORM_GLOBALS_H_ | 5 #ifndef RUNTIME_PLATFORM_GLOBALS_H_ |
6 #define RUNTIME_PLATFORM_GLOBALS_H_ | 6 #define RUNTIME_PLATFORM_GLOBALS_H_ |
7 | 7 |
8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
9 // enable platform independent printf format specifiers. | 9 // enable platform independent printf format specifiers. |
10 #ifndef __STDC_FORMAT_MACROS | 10 #ifndef __STDC_FORMAT_MACROS |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 template <class D, class S> | 656 template <class D, class S> |
657 inline D bit_copy(const S& source) { | 657 inline D bit_copy(const S& source) { |
658 D destination; | 658 D destination; |
659 // This use of memcpy is safe: source and destination cannot overlap. | 659 // This use of memcpy is safe: source and destination cannot overlap. |
660 memcpy(&destination, reinterpret_cast<const void*>(&source), | 660 memcpy(&destination, reinterpret_cast<const void*>(&source), |
661 sizeof(destination)); | 661 sizeof(destination)); |
662 return destination; | 662 return destination; |
663 } | 663 } |
664 | 664 |
665 | 665 |
| 666 #if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_MIPS) || \ |
| 667 defined(HOST_ARCH_ARM64) |
666 // Similar to bit_copy and bit_cast, but does take the type from the argument. | 668 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
667 template <typename T> | 669 template <typename T> |
668 static inline T ReadUnaligned(const T* ptr) { | 670 static inline T ReadUnaligned(const T* ptr) { |
669 T value; | 671 T value; |
670 memcpy(&value, ptr, sizeof(value)); | 672 memcpy(&value, ptr, sizeof(value)); |
671 return value; | 673 return value; |
672 } | 674 } |
673 | 675 |
674 | 676 |
| 677 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
| 678 template <typename T> |
| 679 static inline void StoreUnaligned(T* ptr, T value) { |
| 680 memcpy(ptr, &value, sizeof(value)); |
| 681 } |
| 682 #else // !(HOST_ARCH_ARM || HOST_ARCH_MIPS || HOST_ARCH_ARM64) |
| 683 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
| 684 template <typename T> |
| 685 static inline T ReadUnaligned(const T* ptr) { |
| 686 return *ptr; |
| 687 } |
| 688 |
| 689 |
| 690 // Similar to bit_copy and bit_cast, but does take the type from the argument. |
| 691 template <typename T> |
| 692 static inline void StoreUnaligned(T* ptr, T value) { |
| 693 *ptr = value; |
| 694 } |
| 695 #endif // !(HOST_ARCH_ARM || HOST_ARCH_MIPS || HOST_ARCH_ARM64) |
| 696 |
| 697 |
675 // On Windows the reentrent version of strtok is called | 698 // On Windows the reentrent version of strtok is called |
676 // strtok_s. Unify on the posix name strtok_r. | 699 // strtok_s. Unify on the posix name strtok_r. |
677 #if defined(HOST_OS_WINDOWS) | 700 #if defined(HOST_OS_WINDOWS) |
678 #define snprintf _snprintf | 701 #define snprintf _snprintf |
679 #define strtok_r strtok_s | 702 #define strtok_r strtok_s |
680 #endif | 703 #endif |
681 | 704 |
682 #if !defined(HOST_OS_WINDOWS) | 705 #if !defined(HOST_OS_WINDOWS) |
683 #if defined(TEMP_FAILURE_RETRY) | 706 #if defined(TEMP_FAILURE_RETRY) |
684 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. We should | 707 // TEMP_FAILURE_RETRY is defined in unistd.h on some platforms. We should |
(...skipping 27 matching lines...) Expand all Loading... |
712 // tag in the ICData and check it when recreating the flow graph in | 735 // tag in the ICData and check it when recreating the flow graph in |
713 // optimizing compiler. Enable it for other modes (product, release) if needed | 736 // optimizing compiler. Enable it for other modes (product, release) if needed |
714 // for debugging. | 737 // for debugging. |
715 #if defined(DEBUG) | 738 #if defined(DEBUG) |
716 #define TAG_IC_DATA | 739 #define TAG_IC_DATA |
717 #endif | 740 #endif |
718 | 741 |
719 } // namespace dart | 742 } // namespace dart |
720 | 743 |
721 #endif // RUNTIME_PLATFORM_GLOBALS_H_ | 744 #endif // RUNTIME_PLATFORM_GLOBALS_H_ |
OLD | NEW |