class Decoder : public V {
public:
Decoder() {}
+ virtual ~Decoder() {}
// Top-level instruction decoder function. Decodes an instruction and calls
// the visitor functions registered with the Decoder class.
- void Decode(Instruction *instr);
+ virtual void Decode(Instruction *instr);
private:
// Decode the PC relative addressing instruction, and call the corresponding
Simulator* sim = isolate_data->simulator();
if (sim == NULL) {
- // TODO(146): delete the simulator object when a thread/isolate goes away.
- sim = new Simulator(new Decoder<DispatchingDecoderVisitor>(), isolate);
+ if (FLAG_trace_sim || FLAG_log_instruction_stats || FLAG_debug_sim) {
+ sim = new Simulator(new Decoder<DispatchingDecoderVisitor>(), isolate);
+ } else {
+ sim = new Decoder<Simulator>();
+ sim->isolate_ = isolate;
+ }
isolate_data->set_simulator(sim);
}
return sim;
// Setup the decoder.
decoder_->AppendVisitor(this);
+ Init(stream);
+
+ if (FLAG_trace_sim) {
+ decoder_->InsertVisitorBefore(print_disasm_, this);
+ log_parameters_ = LOG_ALL;
+ }
+
+ if (FLAG_log_instruction_stats) {
+ instrument_ = new Instrument(FLAG_log_instruction_file,
+ FLAG_log_instruction_period);
+ decoder_->AppendVisitor(instrument_);
+ }
+}
+
+
+Simulator::Simulator()
+ : decoder_(NULL),
+ last_debugger_input_(NULL),
+ log_parameters_(NO_PARAM),
+ isolate_(NULL) {
+ Init(NULL);
+ CHECK(!FLAG_trace_sim && !FLAG_log_instruction_stats);
+}
+
+
+void Simulator::Init(FILE* stream) {
ResetState();
// Allocate and setup the simulator stack.
stream_ = stream;
print_disasm_ = new PrintDisassembler(stream_);
- if (FLAG_trace_sim) {
- decoder_->InsertVisitorBefore(print_disasm_, this);
- log_parameters_ = LOG_ALL;
- }
-
// The debugger needs to disassemble code without the simulator executing an
// instruction, so we create a dedicated decoder.
disassembler_decoder_ = new Decoder<DispatchingDecoderVisitor>();
disassembler_decoder_->AppendVisitor(print_disasm_);
-
- if (FLAG_log_instruction_stats) {
- instrument_ = new Instrument(FLAG_log_instruction_file,
- FLAG_log_instruction_period);
- decoder_->AppendVisitor(instrument_);
- }
}
delete disassembler_decoder_;
delete print_disasm_;
DeleteArray(last_debugger_input_);
+ delete decoder_;
}
explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
Isolate* isolate = NULL,
FILE* stream = stderr);
+ Simulator();
~Simulator();
// System functions.
pc_modified_ = false;
}
+ virtual void Decode(Instruction* instr) {
+ decoder_->Decode(instr);
+ }
+
void ExecuteInstruction() {
ASSERT(IsAligned(reinterpret_cast<uintptr_t>(pc_), kInstructionSize));
CheckBreakNext();
- decoder_->Decode(pc_);
+ Decode(pc_);
LogProcessorState();
increment_pc();
CheckBreakpoints();
int log_parameters() { return log_parameters_; }
void set_log_parameters(int new_parameters) {
+ log_parameters_ = new_parameters;
+ if (!decoder_) {
+ if (new_parameters & LOG_DISASM) {
+ PrintF("Run --debug-sim to dynamically turn on disassembler\n");
+ }
+ return;
+ }
if (new_parameters & LOG_DISASM) {
decoder_->InsertVisitorBefore(print_disasm_, this);
} else {
decoder_->RemoveVisitor(print_disasm_);
}
- log_parameters_ = new_parameters;
}
static inline const char* WRegNameForCode(unsigned code,
char* last_debugger_input_;
private:
+ void Init(FILE* stream);
+
int log_parameters_;
Isolate* isolate_;
};
// simulator-arm.cc, simulator-a64.cc and simulator-mips.cc
DEFINE_bool(trace_sim, false, "Trace simulator execution")
+DEFINE_bool(debug_sim, false, "Enable debugging the simulator")
DEFINE_bool(check_icache, false,
"Check icache flushes in ARM and MIPS simulator")
DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions")