| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 // If the provided buffer is NULL, the assembler allocates and grows its own | 694 // If the provided buffer is NULL, the assembler allocates and grows its own |
| 695 // buffer, and buffer_size determines the initial buffer size. The buffer is | 695 // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 696 // owned by the assembler and deallocated upon destruction of the assembler. | 696 // owned by the assembler and deallocated upon destruction of the assembler. |
| 697 // | 697 // |
| 698 // If the provided buffer is not NULL, the assembler uses the provided buffer | 698 // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 699 // for code generation and assumes its size to be buffer_size. If the buffer | 699 // for code generation and assumes its size to be buffer_size. If the buffer |
| 700 // is too small, a fatal error occurs. No deallocation of the buffer is done | 700 // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 701 // upon destruction of the assembler. | 701 // upon destruction of the assembler. |
| 702 Assembler(Isolate* arg_isolate, void* buffer, int buffer_size); | 702 Assembler(Isolate* arg_isolate, void* buffer, int buffer_size); |
| 703 | 703 |
| 704 // The default destructor asserts that one of the following is true: | |
| 705 // * The Assembler object has not been used. | |
| 706 // * Nothing has been emitted since the last Reset() call. | |
| 707 // * Nothing has been emitted since the last GetCode() call. | |
| 708 virtual ~Assembler(); | 704 virtual ~Assembler(); |
| 709 | 705 |
| 710 // System functions --------------------------------------------------------- | 706 // System functions --------------------------------------------------------- |
| 711 // Start generating code from the beginning of the buffer, discarding any code | 707 // Start generating code from the beginning of the buffer, discarding any code |
| 712 // and data that has already been emitted into the buffer. | 708 // and data that has already been emitted into the buffer. |
| 713 // | 709 // |
| 714 // In order to avoid any accidental transfer of state, Reset ASSERTs that the | 710 // In order to avoid any accidental transfer of state, Reset ASSERTs that the |
| 715 // constant pool is not blocked. | 711 // constant pool is not blocked. |
| 716 void Reset(); | 712 void Reset(); |
| 717 | 713 |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 // Postpone the generation of the constant pool for the specified number of | 1871 // Postpone the generation of the constant pool for the specified number of |
| 1876 // instructions. | 1872 // instructions. |
| 1877 void BlockConstPoolFor(int instructions); | 1873 void BlockConstPoolFor(int instructions); |
| 1878 | 1874 |
| 1879 // Emit the instruction at pc_. | 1875 // Emit the instruction at pc_. |
| 1880 void Emit(Instr instruction) { | 1876 void Emit(Instr instruction) { |
| 1881 STATIC_ASSERT(sizeof(*pc_) == 1); | 1877 STATIC_ASSERT(sizeof(*pc_) == 1); |
| 1882 STATIC_ASSERT(sizeof(instruction) == kInstructionSize); | 1878 STATIC_ASSERT(sizeof(instruction) == kInstructionSize); |
| 1883 ASSERT((pc_ + sizeof(instruction)) <= (buffer_ + buffer_size_)); | 1879 ASSERT((pc_ + sizeof(instruction)) <= (buffer_ + buffer_size_)); |
| 1884 | 1880 |
| 1885 #ifdef DEBUG | |
| 1886 finalized_ = false; | |
| 1887 #endif | |
| 1888 | |
| 1889 memcpy(pc_, &instruction, sizeof(instruction)); | 1881 memcpy(pc_, &instruction, sizeof(instruction)); |
| 1890 pc_ += sizeof(instruction); | 1882 pc_ += sizeof(instruction); |
| 1891 CheckBuffer(); | 1883 CheckBuffer(); |
| 1892 } | 1884 } |
| 1893 | 1885 |
| 1894 // Emit data inline in the instruction stream. | 1886 // Emit data inline in the instruction stream. |
| 1895 void EmitData(void const * data, unsigned size) { | 1887 void EmitData(void const * data, unsigned size) { |
| 1896 ASSERT(sizeof(*pc_) == 1); | 1888 ASSERT(sizeof(*pc_) == 1); |
| 1897 ASSERT((pc_ + size) <= (buffer_ + buffer_size_)); | 1889 ASSERT((pc_ + size) <= (buffer_ + buffer_size_)); |
| 1898 | 1890 |
| 1899 #ifdef DEBUG | |
| 1900 finalized_ = false; | |
| 1901 #endif | |
| 1902 | |
| 1903 // TODO(all): Somehow register we have some data here. Then we can | 1891 // TODO(all): Somehow register we have some data here. Then we can |
| 1904 // disassemble it correctly. | 1892 // disassemble it correctly. |
| 1905 memcpy(pc_, data, size); | 1893 memcpy(pc_, data, size); |
| 1906 pc_ += size; | 1894 pc_ += size; |
| 1907 CheckBuffer(); | 1895 CheckBuffer(); |
| 1908 } | 1896 } |
| 1909 | 1897 |
| 1910 void GrowBuffer(); | 1898 void GrowBuffer(); |
| 1911 void CheckBuffer(); | 1899 void CheckBuffer(); |
| 1912 | 1900 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 } | 1975 } |
| 1988 | 1976 |
| 1989 // Code generation | 1977 // Code generation |
| 1990 // The relocation writer's position is at least kGap bytes below the end of | 1978 // The relocation writer's position is at least kGap bytes below the end of |
| 1991 // the generated instructions. This is so that multi-instruction sequences do | 1979 // the generated instructions. This is so that multi-instruction sequences do |
| 1992 // not have to check for overflow. The same is true for writes of large | 1980 // not have to check for overflow. The same is true for writes of large |
| 1993 // relocation info entries, and debug strings encoded in the instruction | 1981 // relocation info entries, and debug strings encoded in the instruction |
| 1994 // stream. | 1982 // stream. |
| 1995 static const int kGap = 128; | 1983 static const int kGap = 128; |
| 1996 | 1984 |
| 1997 #ifdef DEBUG | |
| 1998 bool finalized_; | |
| 1999 #endif | |
| 2000 | |
| 2001 private: | 1985 private: |
| 2002 // TODO(jbramley): VIXL uses next_literal_pool_check_ and | 1986 // TODO(jbramley): VIXL uses next_literal_pool_check_ and |
| 2003 // literal_pool_monitor_ to determine when to consider emitting a literal | 1987 // literal_pool_monitor_ to determine when to consider emitting a literal |
| 2004 // pool. V8 doesn't use them, so they should either not be here at all, or | 1988 // pool. V8 doesn't use them, so they should either not be here at all, or |
| 2005 // should replace or be merged with next_buffer_check_ and | 1989 // should replace or be merged with next_buffer_check_ and |
| 2006 // const_pool_blocked_nesting_. | 1990 // const_pool_blocked_nesting_. |
| 2007 Instruction* next_literal_pool_check_; | 1991 Instruction* next_literal_pool_check_; |
| 2008 unsigned literal_pool_monitor_; | 1992 unsigned literal_pool_monitor_; |
| 2009 | 1993 |
| 2010 PositionsRecorder positions_recorder_; | 1994 PositionsRecorder positions_recorder_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2040 // Const pool should still be blocked. | 2024 // Const pool should still be blocked. |
| 2041 ASSERT(is_const_pool_blocked()); | 2025 ASSERT(is_const_pool_blocked()); |
| 2042 EndBlockConstPool(); | 2026 EndBlockConstPool(); |
| 2043 // Verify we have generated the number of instruction we expected. | 2027 // Verify we have generated the number of instruction we expected. |
| 2044 ASSERT((pc_offset() + kGap) == buffer_size_); | 2028 ASSERT((pc_offset() + kGap) == buffer_size_); |
| 2045 // Verify no relocation information has been emitted. | 2029 // Verify no relocation information has been emitted. |
| 2046 ASSERT(num_pending_reloc_info() == 0); | 2030 ASSERT(num_pending_reloc_info() == 0); |
| 2047 // Flush the Instruction cache. | 2031 // Flush the Instruction cache. |
| 2048 size_t length = buffer_size_ - kGap; | 2032 size_t length = buffer_size_ - kGap; |
| 2049 CPU::FlushICache(buffer_, length); | 2033 CPU::FlushICache(buffer_, length); |
| 2050 | |
| 2051 #ifdef DEBUG | |
| 2052 // The Patching Assembler doesn't need to be finalized, but the Assembler | |
| 2053 // class's destructor will check the finalized_ flag. | |
| 2054 finalized_ = true; | |
| 2055 #endif | |
| 2056 } | 2034 } |
| 2057 }; | 2035 }; |
| 2058 | 2036 |
| 2059 | 2037 |
| 2060 class EnsureSpace BASE_EMBEDDED { | 2038 class EnsureSpace BASE_EMBEDDED { |
| 2061 public: | 2039 public: |
| 2062 explicit EnsureSpace(Assembler* assembler) { | 2040 explicit EnsureSpace(Assembler* assembler) { |
| 2063 assembler->CheckBuffer(); | 2041 assembler->CheckBuffer(); |
| 2064 } | 2042 } |
| 2065 }; | 2043 }; |
| 2066 | 2044 |
| 2067 } } // namespace v8::internal | 2045 } } // namespace v8::internal |
| 2068 | 2046 |
| 2069 #endif // V8_A64_ASSEMBLER_A64_H_ | 2047 #endif // V8_A64_ASSEMBLER_A64_H_ |
| OLD | NEW |