diff options
author | Eric Holk <eholk@google.com> | 2019-07-30 14:47:06 -0700 |
---|---|---|
committer | Eric Holk <eholk@google.com> | 2019-07-30 14:47:06 -0700 |
commit | f3b9589e7b0ece086a2342a007850e7ef9b4ccde (patch) | |
tree | 598685ef3cf01265f6e73ee062402e71e17dc3f8 /startop/view_compiler/dex_builder.cc | |
parent | 8052fac1b134008efb33569d4523b8e06984a8fa (diff) |
[view compiler] Add DexBuilder support for getting and setting instance fields
Bug: 111895153
Change-Id: I5fa2936501c79e30a66f3863b76229ec83433928
Diffstat (limited to 'startop/view_compiler/dex_builder.cc')
-rw-r--r-- | startop/view_compiler/dex_builder.cc | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/startop/view_compiler/dex_builder.cc b/startop/view_compiler/dex_builder.cc index 09f9c04d9e2c..499c42e2888b 100644 --- a/startop/view_compiler/dex_builder.cc +++ b/startop/view_compiler/dex_builder.cc @@ -108,6 +108,12 @@ std::ostream& operator<<(std::ostream& out, const Instruction::Op& opcode) { case Instruction::Op::kSetStaticField: out << "kSetStaticField"; return out; + case Instruction::Op::kGetInstanceField: + out << "kGetInstanceField"; + return out; + case Instruction::Op::kSetInstanceField: + out << "kSetInstanceField"; + return out; } } @@ -246,6 +252,7 @@ ir::FieldDecl* DexBuilder::GetOrAddField(TypeDescriptor parent, const std::strin field->parent = GetOrAddType(parent); field->name = GetOrAddString(name); field->type = GetOrAddType(type); + field->orig_index = dex_file_->fields_indexes.AllocateIndex(); dex_file_->fields_map[field->orig_index] = field; field_decls_by_key_[key] = field; return field; @@ -384,7 +391,9 @@ void MethodBuilder::EncodeInstruction(const Instruction& instruction) { return EncodeCast(instruction); case Instruction::Op::kGetStaticField: case Instruction::Op::kSetStaticField: - return EncodeStaticFieldOp(instruction); + case Instruction::Op::kGetInstanceField: + case Instruction::Op::kSetInstanceField: + return EncodeFieldOp(instruction); } } @@ -539,7 +548,8 @@ void MethodBuilder::EncodeCast(const Instruction& instruction) { Encode21c(::art::Instruction::CHECK_CAST, RegisterValue(*instruction.dest()), type.value()); } -void MethodBuilder::EncodeStaticFieldOp(const Instruction& instruction) { +void MethodBuilder::EncodeFieldOp(const Instruction& instruction) { + const auto& args = instruction.args(); switch (instruction.opcode()) { case Instruction::Op::kGetStaticField: { CHECK(instruction.dest().has_value()); @@ -553,18 +563,36 @@ void MethodBuilder::EncodeStaticFieldOp(const Instruction& instruction) { } case Instruction::Op::kSetStaticField: { CHECK(!instruction.dest().has_value()); - const auto& args = instruction.args(); CHECK_EQ(1, args.size()); CHECK(args[0].is_variable()); - Encode21c(::art::Instruction::SPUT, + Encode21c(::art::Instruction::SPUT, RegisterValue(args[0]), instruction.index_argument()); + break; + } + case Instruction::Op::kGetInstanceField: { + CHECK(instruction.dest().has_value()); + CHECK(instruction.dest()->is_variable()); + CHECK_EQ(1, instruction.args().size()); + + Encode22c(::art::Instruction::IGET, + RegisterValue(*instruction.dest()), RegisterValue(args[0]), instruction.index_argument()); break; } - default: { - LOG(FATAL) << "Unsupported static field operation"; + case Instruction::Op::kSetInstanceField: { + CHECK(!instruction.dest().has_value()); + CHECK_EQ(2, args.size()); + CHECK(args[0].is_variable()); + CHECK(args[1].is_variable()); + + Encode22c(::art::Instruction::IPUT, + RegisterValue(args[1]), + RegisterValue(args[0]), + instruction.index_argument()); + break; } + default: { LOG(FATAL) << "Unsupported field operation"; } } } |