-
Notifications
You must be signed in to change notification settings - Fork 155
Add Context Structure to Affect State Dependent Liftings #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
include/remill/Arch/Arch.h
Outdated
@@ -281,14 +285,16 @@ class Arch { | |||
// walk up, one byte at a time, to `MaxInstructionSize(false)` | |||
// bytes being passed to the decoder, until you successfully decode | |||
// or ultimately fail. | |||
virtual bool DecodeInstruction(uint64_t address, std::string_view instr_bytes, | |||
Instruction &inst) const = 0; | |||
virtual std::optional<DecodingContext::ContextMap> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce type alias?
include/remill/Arch/Arch.h
Outdated
inst.in_delay_slot = true; | ||
return this->DecodeInstruction(address, instr_bytes, inst); | ||
return this->DecodeInstruction(address, instr_bytes, inst, context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy on context
, move it.
include/remill/Arch/ArchBase.h
Outdated
protected: | ||
|
||
/// A simple mixin for a default decoder with a null context and the default insdtruction lifter; | ||
class DefaultContextAndLifter : virtual public remill::Arch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
virtual
inheritance is a big hammer we may not need here - think how to make it without.
uint64_t GetContextValue(const std::string &context_reg) const; | ||
DecodingContext PutContextReg(std::string creg, uint64_t value) const; | ||
|
||
static ContextMap UniformContextMapping(DecodingContext cst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the advantage of using this compared to simply passing the "raw" unordered_map
around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context map? the lambda allows the decoders to encode arbitrary computations over successor addresses
lib/Arch/Context.cpp
Outdated
|
||
DecodingContext::ContextMap | ||
DecodingContext::UniformContextMapping(DecodingContext cst) { | ||
return [cst](uint64_t ctx) -> DecodingContext { return cst; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx
is simply ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are doing two copies, move cst
into lambda.
lib/BC/TraceLifter.cpp
Outdated
@@ -345,7 +345,9 @@ bool TraceLifter::Impl::Lift( | |||
|
|||
inst.Reset(); | |||
|
|||
(void) arch->DecodeInstruction(inst_addr, inst_bytes, inst); | |||
// TODO(Ian): not passing context around in trace lifter | |||
(void) arch->DecodeInstruction(inst_addr, inst_bytes, inst, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::ignore = value_dont_care_about()
lib/Arch/Arch.cpp
Outdated
inst.SetLifter(std::make_unique<remill::InstructionLifter>( | ||
this, this->GetInstrinsicTable())); | ||
return this->ArchDecodeInstruction(address, instr_bytes, inst); | ||
if (this->ArchDecodeInstruction(address, instr_bytes, inst)) { | ||
return [](uint64_t x) -> DecodingContext { return DecodingContext(); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop x
- unused arguments do not need names.
lib/Arch/Sleigh/Arch.cpp
Outdated
return this->ArchDecodeInstruction(address, instr_bytes, inst); | ||
if (const_cast<SleighArch *>(this)->DecodeInstructionImpl( | ||
address, instr_bytes, inst)) { | ||
return [this](uint64_t x) -> DecodingContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop name of x
.
lib/Arch/Arch.cpp
Outdated
@@ -863,7 +863,7 @@ DefaultContextAndLifter::DecodeInstruction(uint64_t address, | |||
inst.SetLifter(std::make_unique<remill::InstructionLifter>( | |||
this, this->GetInstrinsicTable())); | |||
if (this->ArchDecodeInstruction(address, instr_bytes, inst)) { | |||
return [](uint64_t x) -> DecodingContext { return DecodingContext(); }; | |||
return [](uint64_t _) -> DecodingContext { return DecodingContext(); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just [](uint64_t) -> DecodingContext { ... }
.
No need for _
. (In other changes as well)
As a sidenote, -> DecodingContext
can also be dropped, I think compiler should be able to deduce this, but I can understand if you want to keep it as part of docs.
No description provided.