Reviewers: Rodolph Perfetta (ARM), ulan,
Description:
A64: Hardwire the decoder and the simulator
If one of --trace-sim --debug-sim or --log-instruction-stats flags is
given, we use the decoder dispatcher instead.
BUG=none
[email protected],[email protected]
LOG=n
Please review this at https://codereview.chromium.org/177533023/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+51, -16 lines):
M src/a64/decoder-a64.h
M src/a64/simulator-a64.h
M src/a64/simulator-a64.cc
M src/flag-definitions.h
Index: src/a64/decoder-a64.h
diff --git a/src/a64/decoder-a64.h b/src/a64/decoder-a64.h
index
8ad6b44b119e7a2c571bbd55bd5f2eabbc83c04c..22a7e3547bed232672af16a5a66e3b36344e977e
100644
--- a/src/a64/decoder-a64.h
+++ b/src/a64/decoder-a64.h
@@ -146,10 +146,11 @@ template<typename V>
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
Index: src/a64/simulator-a64.cc
diff --git a/src/a64/simulator-a64.cc b/src/a64/simulator-a64.cc
index
f33769079d66185c37aa2c41f55dfd94a2f7cca9..1ae0bf01a480181c0bd30e1a1f8b09e984930948
100644
--- a/src/a64/simulator-a64.cc
+++ b/src/a64/simulator-a64.cc
@@ -105,8 +105,12 @@ Simulator* Simulator::current(Isolate* isolate) {
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;
@@ -343,6 +347,32 @@
Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
// 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.
@@ -356,21 +386,10 @@
Simulator::Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
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_);
- }
}
@@ -405,6 +424,7 @@ Simulator::~Simulator() {
delete disassembler_decoder_;
delete print_disasm_;
DeleteArray(last_debugger_input_);
+ delete decoder_;
}
Index: src/a64/simulator-a64.h
diff --git a/src/a64/simulator-a64.h b/src/a64/simulator-a64.h
index
73d7a85e240fe35b255ddea5e038855781af2ab5..c4f1472bab231bc0b7ab4545a7d40ba45925c476
100644
--- a/src/a64/simulator-a64.h
+++ b/src/a64/simulator-a64.h
@@ -195,6 +195,7 @@ class Simulator : public DecoderVisitor {
explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder,
Isolate* isolate = NULL,
FILE* stream = stderr);
+ Simulator();
~Simulator();
// System functions.
@@ -334,10 +335,14 @@ class Simulator : public DecoderVisitor {
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();
@@ -582,12 +587,18 @@ class Simulator : public DecoderVisitor {
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,
@@ -819,6 +830,8 @@ class Simulator : public DecoderVisitor {
char* last_debugger_input_;
private:
+ void Init(FILE* stream);
+
int log_parameters_;
Isolate* isolate_;
};
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index
e7da42e6e0b7573162c9688270c5e7b97839e1e0..bd8cbe39f04a0743dc47fd5307915a15ce4eb842
100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -585,6 +585,7 @@ DEFINE_bool(trace_parse, false, "trace parsing and
preparsing")
// 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")
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.