Skip to content

Conversation

2over12
Copy link
Contributor

@2over12 2over12 commented Aug 15, 2022

No description provided.

@2over12 2over12 marked this pull request as ready for review August 15, 2022 13:51
@2over12 2over12 requested a review from lkorenc August 15, 2022 13:51
@@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce type alias?

inst.in_delay_slot = true;
return this->DecodeInstruction(address, instr_bytes, inst);
return this->DecodeInstruction(address, instr_bytes, inst, context);
Copy link
Contributor

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.

protected:

/// A simple mixin for a default decoder with a null context and the default insdtruction lifter;
class DefaultContextAndLifter : virtual public remill::Arch {
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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


DecodingContext::ContextMap
DecodingContext::UniformContextMapping(DecodingContext cst) {
return [cst](uint64_t ctx) -> DecodingContext { return cst; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx is simply ignored?

Copy link
Contributor

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.

@@ -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,
Copy link
Contributor

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()

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(); };
Copy link
Contributor

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.

return this->ArchDecodeInstruction(address, instr_bytes, inst);
if (const_cast<SleighArch *>(this)->DecodeInstructionImpl(
address, instr_bytes, inst)) {
return [this](uint64_t x) -> DecodingContext {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop name of x.

@2over12 2over12 requested a review from lkorenc August 16, 2022 18:18
@@ -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(); };
Copy link
Contributor

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.

@2over12 2over12 merged commit c0f90b9 into master Aug 17, 2022
@pgoodman pgoodman deleted the ian/contextual_lifting branch August 22, 2022 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants