OLD | NEW |
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
2 // All Rights Reserved. | 2 // All Rights Reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
10 // | 10 // |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 // If the provided buffer is NULL, the assembler allocates and grows its own | 575 // If the provided buffer is NULL, the assembler allocates and grows its own |
576 // buffer, and buffer_size determines the initial buffer size. The buffer is | 576 // buffer, and buffer_size determines the initial buffer size. The buffer is |
577 // owned by the assembler and deallocated upon destruction of the assembler. | 577 // owned by the assembler and deallocated upon destruction of the assembler. |
578 // | 578 // |
579 // If the provided buffer is not NULL, the assembler uses the provided buffer | 579 // If the provided buffer is not NULL, the assembler uses the provided buffer |
580 // for code generation and assumes its size to be buffer_size. If the buffer | 580 // for code generation and assumes its size to be buffer_size. If the buffer |
581 // is too small, a fatal error occurs. No deallocation of the buffer is done | 581 // is too small, a fatal error occurs. No deallocation of the buffer is done |
582 // upon destruction of the assembler. | 582 // upon destruction of the assembler. |
583 // TODO(vitalyr): the assembler does not need an isolate. | 583 // TODO(vitalyr): the assembler does not need an isolate. |
584 Assembler(Isolate* isolate, void* buffer, int buffer_size); | 584 Assembler(Isolate* isolate, void* buffer, int buffer_size); |
585 ~Assembler(); | 585 virtual ~Assembler() { } |
586 | 586 |
587 // GetCode emits any pending (non-emitted) code and fills the descriptor | 587 // GetCode emits any pending (non-emitted) code and fills the descriptor |
588 // desc. GetCode() is idempotent; it returns the same result if no other | 588 // desc. GetCode() is idempotent; it returns the same result if no other |
589 // Assembler functions are invoked in between GetCode() calls. | 589 // Assembler functions are invoked in between GetCode() calls. |
590 void GetCode(CodeDesc* desc); | 590 void GetCode(CodeDesc* desc); |
591 | 591 |
592 // Read/Modify the code target in the branch/call instruction at pc. | 592 // Read/Modify the code target in the branch/call instruction at pc. |
593 inline static Address target_address_at(Address pc); | 593 inline static Address target_address_at(Address pc); |
594 inline static void set_target_address_at(Address pc, Address target); | 594 inline static void set_target_address_at(Address pc, Address target); |
595 | 595 |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 // Record a comment relocation entry that can be used by a disassembler. | 1084 // Record a comment relocation entry that can be used by a disassembler. |
1085 // Use --code-comments to enable, or provide "force = true" flag to always | 1085 // Use --code-comments to enable, or provide "force = true" flag to always |
1086 // write a comment. | 1086 // write a comment. |
1087 void RecordComment(const char* msg, bool force = false); | 1087 void RecordComment(const char* msg, bool force = false); |
1088 | 1088 |
1089 // Writes a single byte or word of data in the code stream. Used for | 1089 // Writes a single byte or word of data in the code stream. Used for |
1090 // inline tables, e.g., jump-tables. | 1090 // inline tables, e.g., jump-tables. |
1091 void db(uint8_t data); | 1091 void db(uint8_t data); |
1092 void dd(uint32_t data); | 1092 void dd(uint32_t data); |
1093 | 1093 |
1094 int pc_offset() const { return pc_ - buffer_; } | |
1095 | |
1096 // Check if there is less than kGap bytes available in the buffer. | 1094 // Check if there is less than kGap bytes available in the buffer. |
1097 // If this is the case, we need to grow the buffer before emitting | 1095 // If this is the case, we need to grow the buffer before emitting |
1098 // an instruction or relocation information. | 1096 // an instruction or relocation information. |
1099 inline bool overflow() const { return pc_ >= reloc_info_writer.pos() - kGap; } | 1097 inline bool overflow() const { return pc_ >= reloc_info_writer.pos() - kGap; } |
1100 | 1098 |
1101 // Get the number of bytes available in the buffer. | 1099 // Get the number of bytes available in the buffer. |
1102 inline int available_space() const { return reloc_info_writer.pos() - pc_; } | 1100 inline int available_space() const { return reloc_info_writer.pos() - pc_; } |
1103 | 1101 |
1104 static bool IsNop(Address addr); | 1102 static bool IsNop(Address addr); |
1105 | 1103 |
1106 PositionsRecorder* positions_recorder() { return &positions_recorder_; } | 1104 PositionsRecorder* positions_recorder() { return &positions_recorder_; } |
1107 | 1105 |
1108 int relocation_writer_size() { | 1106 int relocation_writer_size() { |
1109 return (buffer_ + buffer_size_) - reloc_info_writer.pos(); | 1107 return (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
1110 } | 1108 } |
1111 | 1109 |
1112 // Avoid overflows for displacements etc. | 1110 // Avoid overflows for displacements etc. |
1113 static const int kMaximalBufferSize = 512*MB; | 1111 static const int kMaximalBufferSize = 512*MB; |
1114 static const int kMinimalBufferSize = 4*KB; | |
1115 | 1112 |
1116 byte byte_at(int pos) { return buffer_[pos]; } | 1113 byte byte_at(int pos) { return buffer_[pos]; } |
1117 void set_byte_at(int pos, byte value) { buffer_[pos] = value; } | 1114 void set_byte_at(int pos, byte value) { buffer_[pos] = value; } |
1118 | 1115 |
1119 protected: | 1116 protected: |
1120 void movsd(XMMRegister dst, const Operand& src); | 1117 void movsd(XMMRegister dst, const Operand& src); |
1121 void movsd(const Operand& dst, XMMRegister src); | 1118 void movsd(const Operand& dst, XMMRegister src); |
1122 | 1119 |
1123 void emit_sse_operand(XMMRegister reg, const Operand& adr); | 1120 void emit_sse_operand(XMMRegister reg, const Operand& adr); |
1124 void emit_sse_operand(XMMRegister dst, XMMRegister src); | 1121 void emit_sse_operand(XMMRegister dst, XMMRegister src); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 inline void disp_at_put(Label* L, Displacement disp); | 1167 inline void disp_at_put(Label* L, Displacement disp); |
1171 inline void emit_disp(Label* L, Displacement::Type type); | 1168 inline void emit_disp(Label* L, Displacement::Type type); |
1172 inline void emit_near_disp(Label* L); | 1169 inline void emit_near_disp(Label* L); |
1173 | 1170 |
1174 // record reloc info for current pc_ | 1171 // record reloc info for current pc_ |
1175 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0); | 1172 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0); |
1176 | 1173 |
1177 friend class CodePatcher; | 1174 friend class CodePatcher; |
1178 friend class EnsureSpace; | 1175 friend class EnsureSpace; |
1179 | 1176 |
1180 // Code buffer: | |
1181 // The buffer into which code and relocation info are generated. | |
1182 byte* buffer_; | |
1183 int buffer_size_; | |
1184 // True if the assembler owns the buffer, false if buffer is external. | |
1185 bool own_buffer_; | |
1186 | |
1187 // code generation | 1177 // code generation |
1188 byte* pc_; // the program counter; moves forward | |
1189 RelocInfoWriter reloc_info_writer; | 1178 RelocInfoWriter reloc_info_writer; |
1190 | 1179 |
1191 PositionsRecorder positions_recorder_; | 1180 PositionsRecorder positions_recorder_; |
1192 friend class PositionsRecorder; | 1181 friend class PositionsRecorder; |
1193 }; | 1182 }; |
1194 | 1183 |
1195 | 1184 |
1196 // Helper class that ensures that there is enough space for generating | 1185 // Helper class that ensures that there is enough space for generating |
1197 // instructions and relocation information. The constructor makes | 1186 // instructions and relocation information. The constructor makes |
1198 // sure that there is enough space and (in debug mode) the destructor | 1187 // sure that there is enough space and (in debug mode) the destructor |
(...skipping 17 matching lines...) Expand all Loading... |
1216 private: | 1205 private: |
1217 Assembler* assembler_; | 1206 Assembler* assembler_; |
1218 #ifdef DEBUG | 1207 #ifdef DEBUG |
1219 int space_before_; | 1208 int space_before_; |
1220 #endif | 1209 #endif |
1221 }; | 1210 }; |
1222 | 1211 |
1223 } } // namespace v8::internal | 1212 } } // namespace v8::internal |
1224 | 1213 |
1225 #endif // V8_IA32_ASSEMBLER_IA32_H_ | 1214 #endif // V8_IA32_ASSEMBLER_IA32_H_ |
OLD | NEW |