| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef DEX_BUILDER_H_ |
| 17 |
#define DEX_BUILDER_H_ |
| 18 |
|
| 19 |
#include <array> |
| 20 |
#include <forward_list> |
| 21 |
#include <map> |
| 22 |
#include <optional> |
| 23 |
#include <string> |
| 24 |
#include <unordered_map> |
| 25 |
#include <vector> |
| 26 |
|
| 27 |
#include "android-base/logging.h" |
| 28 |
|
| 29 |
#include "slicer/dex_bytecode.h" |
| 30 |
#include "slicer/dex_ir.h" |
| 31 |
#include "slicer/writer.h" |
| 32 |
|
| 33 |
namespace startop { |
| 34 |
namespace dex { |
| 35 |
|
| 36 |
|
| 37 |
void WriteTestDexFile(const std::string& filename); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class DexBuilder; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
class TrackingAllocator : public ::dex::Writer::Allocator { |
| 50 |
public: |
| 51 |
virtual void* Allocate(size_t size); |
| 52 |
virtual void Free(void* ptr); |
| 53 |
|
| 54 |
private: |
| 55 |
std::unordered_map<void*, std::unique_ptr<uint8_t[]>> allocations_; |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
class TypeDescriptor { |
| 62 |
public: |
| 63 |
|
| 64 |
static const TypeDescriptor Int(); |
| 65 |
static const TypeDescriptor Void(); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
static TypeDescriptor FromClassname(const std::string& name); |
| 70 |
|
| 71 |
|
| 72 |
const std::string& descriptor() const { return descriptor_; } |
| 73 |
|
| 74 |
std::string short_descriptor() const { return descriptor().substr(0, 1); } |
| 75 |
|
| 76 |
bool is_object() const { return short_descriptor() == "L"; } |
| 77 |
|
| 78 |
bool operator<(const TypeDescriptor& rhs) const { return descriptor_ < rhs.descriptor_; } |
| 79 |
|
| 80 |
private: |
| 81 |
explicit TypeDescriptor(std::string descriptor) : descriptor_{descriptor} {} |
| 82 |
|
| 83 |
const std::string descriptor_; |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
class Prototype { |
| 89 |
public: |
| 90 |
template <typename... TypeDescriptors> |
| 91 |
explicit Prototype(TypeDescriptor return_type, TypeDescriptors... param_types) |
| 92 |
: return_type_{return_type}, param_types_{param_types...} {} |
| 93 |
|
| 94 |
|
| 95 |
ir::Proto* Encode(DexBuilder* dex) const; |
| 96 |
|
| 97 |
|
| 98 |
std::string Shorty() const; |
| 99 |
|
| 100 |
const TypeDescriptor& ArgType(size_t index) const; |
| 101 |
|
| 102 |
bool operator<(const Prototype& rhs) const { |
| 103 |
return std::make_tuple(return_type_, param_types_) < |
| 104 |
std::make_tuple(rhs.return_type_, rhs.param_types_); |
| 105 |
} |
| 106 |
|
| 107 |
private: |
| 108 |
const TypeDescriptor return_type_; |
| 109 |
const std::vector<TypeDescriptor> param_types_; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
class Value { |
| 116 |
public: |
| 117 |
static constexpr Value Local(size_t id) { return Value{id, Kind::kLocalRegister}; } |
| 118 |
static constexpr Value Parameter(size_t id) { return Value{id, Kind::kParameter}; } |
| 119 |
static constexpr Value Immediate(size_t value) { return Value{value, Kind::kImmediate}; } |
| 120 |
static constexpr Value String(size_t value) { return Value{value, Kind::kString}; } |
| 121 |
static constexpr Value Label(size_t id) { return Value{id, Kind::kLabel}; } |
| 122 |
static constexpr Value Type(size_t id) { return Value{id, Kind::kType}; } |
| 123 |
|
| 124 |
bool is_register() const { return kind_ == Kind::kLocalRegister; } |
| 125 |
bool is_parameter() const { return kind_ == Kind::kParameter; } |
| 126 |
bool is_variable() const { return is_register() || is_parameter(); } |
| 127 |
bool is_immediate() const { return kind_ == Kind::kImmediate; } |
| 128 |
bool is_string() const { return kind_ == Kind::kString; } |
| 129 |
bool is_label() const { return kind_ == Kind::kLabel; } |
| 130 |
bool is_type() const { return kind_ == Kind::kType; } |
| 131 |
|
| 132 |
size_t value() const { return value_; } |
| 133 |
|
| 134 |
constexpr Value() : value_{0}, kind_{Kind::kInvalid} {} |
| 135 |
|
| 136 |
private: |
| 137 |
enum class Kind { kInvalid, kLocalRegister, kParameter, kImmediate, kString, kLabel, kType }; |
| 138 |
|
| 139 |
size_t value_; |
| 140 |
Kind kind_; |
| 141 |
|
| 142 |
constexpr Value(size_t value, Kind kind) : value_{value}, kind_{kind} {} |
| 143 |
}; |
| 144 |
|
| 145 |
|
| 146 |
class LiveRegister { |
| 147 |
friend class MethodBuilder; |
| 148 |
|
| 149 |
public: |
| 150 |
LiveRegister(LiveRegister&& other) : liveness_{other.liveness_}, index_{other.index_} { |
| 151 |
other.index_ = {}; |
| 152 |
}; |
| 153 |
~LiveRegister() { |
| 154 |
if (index_.has_value()) { |
| 155 |
(*liveness_)[*index_] = false; |
| 156 |
} |
| 157 |
}; |
| 158 |
|
| 159 |
operator const Value() const { return Value::Local(*index_); } |
| 160 |
|
| 161 |
private: |
| 162 |
LiveRegister(std::vector<bool>* liveness, size_t index) : liveness_{liveness}, index_{index} {} |
| 163 |
|
| 164 |
std::vector<bool>* const liveness_; |
| 165 |
std::optional<size_t> index_; |
| 166 |
}; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
class Instruction { |
| 173 |
public: |
| 174 |
|
| 175 |
|
| 176 |
enum class Op { |
| 177 |
kBindLabel, |
| 178 |
kBranchEqz, |
| 179 |
kBranchNEqz, |
| 180 |
kCheckCast, |
| 181 |
kGetInstanceField, |
| 182 |
kGetStaticField, |
| 183 |
kInvokeDirect, |
| 184 |
kInvokeInterface, |
| 185 |
kInvokeStatic, |
| 186 |
kInvokeVirtual, |
| 187 |
kMove, |
| 188 |
kMoveObject, |
| 189 |
kNew, |
| 190 |
kReturn, |
| 191 |
kReturnObject, |
| 192 |
kSetInstanceField, |
| 193 |
kSetStaticField |
| 194 |
}; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
static inline Instruction OpNoArgs(Op opcode) { |
| 202 |
return Instruction{opcode, 0, {}}; |
| 203 |
} |
| 204 |
|
| 205 |
template <typename... T> |
| 206 |
static inline Instruction OpWithArgs(Op opcode, std::optional<const Value> dest, |
| 207 |
const T&... args) { |
| 208 |
return Instruction{opcode, 0, false, dest, args...}; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
static inline Instruction Cast(Value val, Value type) { |
| 213 |
CHECK(type.is_type()); |
| 214 |
return OpWithArgs(Op::kCheckCast, val, type); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
template <typename... T> |
| 219 |
static inline Instruction InvokeVirtual(size_t index_argument, std::optional<const Value> dest, |
| 220 |
Value this_arg, T... args) { |
| 221 |
return Instruction{ |
| 222 |
Op::kInvokeVirtual, index_argument, false, dest, this_arg, args...}; |
| 223 |
} |
| 224 |
|
| 225 |
template <typename... T> |
| 226 |
static inline Instruction InvokeVirtualObject(size_t index_argument, |
| 227 |
std::optional<const Value> dest, Value this_arg, |
| 228 |
const T&... args) { |
| 229 |
return Instruction{ |
| 230 |
Op::kInvokeVirtual, index_argument, true, dest, this_arg, args...}; |
| 231 |
} |
| 232 |
|
| 233 |
template <typename... T> |
| 234 |
static inline Instruction InvokeDirect(size_t index_argument, std::optional<const Value> dest, |
| 235 |
Value this_arg, const T&... args) { |
| 236 |
return Instruction{ |
| 237 |
Op::kInvokeDirect, index_argument, false, dest, this_arg, args...}; |
| 238 |
} |
| 239 |
|
| 240 |
template <typename... T> |
| 241 |
static inline Instruction InvokeDirectObject(size_t index_argument, |
| 242 |
std::optional<const Value> dest, Value this_arg, |
| 243 |
T... args) { |
| 244 |
return Instruction{ |
| 245 |
Op::kInvokeDirect, index_argument, true, dest, this_arg, args...}; |
| 246 |
} |
| 247 |
|
| 248 |
template <typename... T> |
| 249 |
static inline Instruction InvokeStatic(size_t index_argument, std::optional<const Value> dest, |
| 250 |
T... args) { |
| 251 |
return Instruction{ |
| 252 |
Op::kInvokeStatic, index_argument, false, dest, args...}; |
| 253 |
} |
| 254 |
|
| 255 |
template <typename... T> |
| 256 |
static inline Instruction InvokeStaticObject(size_t index_argument, |
| 257 |
std::optional<const Value> dest, T... args) { |
| 258 |
return Instruction{Op::kInvokeStatic, index_argument, true, dest, args...}; |
| 259 |
} |
| 260 |
|
| 261 |
template <typename... T> |
| 262 |
static inline Instruction InvokeInterface(size_t index_argument, std::optional<const Value> dest, |
| 263 |
const T&... args) { |
| 264 |
return Instruction{ |
| 265 |
Op::kInvokeInterface, index_argument, false, dest, args...}; |
| 266 |
} |
| 267 |
|
| 268 |
static inline Instruction GetStaticField(size_t field_id, Value dest) { |
| 269 |
return Instruction{Op::kGetStaticField, field_id, dest}; |
| 270 |
} |
| 271 |
|
| 272 |
static inline Instruction SetStaticField(size_t field_id, Value value) { |
| 273 |
return Instruction{ |
| 274 |
Op::kSetStaticField, field_id, false, {}, value}; |
| 275 |
} |
| 276 |
|
| 277 |
static inline Instruction GetField(size_t field_id, Value dest, Value object) { |
| 278 |
return Instruction{Op::kGetInstanceField, field_id, false, dest, object}; |
| 279 |
} |
| 280 |
|
| 281 |
static inline Instruction SetField(size_t field_id, Value object, Value value) { |
| 282 |
return Instruction{ |
| 283 |
Op::kSetInstanceField, field_id, false, {}, object, value}; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
Op opcode() const { return opcode_; } |
| 291 |
size_t index_argument() const { return index_argument_; } |
| 292 |
bool result_is_object() const { return result_is_object_; } |
| 293 |
const std::optional<const Value>& dest() const { return dest_; } |
| 294 |
const std::vector<const Value>& args() const { return args_; } |
| 295 |
|
| 296 |
private: |
| 297 |
inline Instruction(Op opcode, size_t index_argument, std::optional<const Value> dest) |
| 298 |
: opcode_{opcode}, |
| 299 |
index_argument_{index_argument}, |
| 300 |
result_is_object_{false}, |
| 301 |
dest_{dest}, |
| 302 |
args_{} {} |
| 303 |
|
| 304 |
template <typename... T> |
| 305 |
inline Instruction(Op opcode, size_t index_argument, bool result_is_object, |
| 306 |
std::optional<const Value> dest, const T&... args) |
| 307 |
: opcode_{opcode}, |
| 308 |
index_argument_{index_argument}, |
| 309 |
result_is_object_{result_is_object}, |
| 310 |
dest_{dest}, |
| 311 |
args_{args...} {} |
| 312 |
|
| 313 |
const Op opcode_; |
| 314 |
|
| 315 |
const size_t index_argument_{0}; |
| 316 |
const bool result_is_object_; |
| 317 |
const std::optional<const Value> dest_; |
| 318 |
const std::vector<const Value> args_; |
| 319 |
}; |
| 320 |
|
| 321 |
|
| 322 |
std::ostream& operator<<(std::ostream& out, const Instruction::Op& opcode); |
| 323 |
|
| 324 |
|
| 325 |
struct MethodDeclData { |
| 326 |
size_t id; |
| 327 |
ir::MethodDecl* decl; |
| 328 |
}; |
| 329 |
|
| 330 |
|
| 331 |
class MethodBuilder { |
| 332 |
public: |
| 333 |
MethodBuilder(DexBuilder* dex, ir::Class* class_def, ir::MethodDecl* decl); |
| 334 |
|
| 335 |
|
| 336 |
ir::EncodedMethod* Encode(); |
| 337 |
|
| 338 |
|
| 339 |
LiveRegister AllocRegister(); |
| 340 |
|
| 341 |
Value MakeLabel(); |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
void AddInstruction(Instruction instruction); |
| 348 |
|
| 349 |
|
| 350 |
void BuildReturn(); |
| 351 |
void BuildReturn(Value src, bool is_object = false); |
| 352 |
|
| 353 |
void BuildConst4(Value target, int value); |
| 354 |
void BuildConstString(Value target, const std::string& value); |
| 355 |
template <typename... T> |
| 356 |
void BuildNew(Value target, TypeDescriptor type, Prototype constructor, const T&... args); |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
DexBuilder* dex_file() const { return dex_; } |
| 361 |
|
| 362 |
private: |
| 363 |
void EncodeInstructions(); |
| 364 |
void EncodeInstruction(const Instruction& instruction); |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
void EncodeReturn(const Instruction& instruction, ::dex::Opcode opcode); |
| 370 |
|
| 371 |
void EncodeMove(const Instruction& instruction); |
| 372 |
void EncodeInvoke(const Instruction& instruction, ::dex::Opcode opcode); |
| 373 |
void EncodeBranch(::dex::Opcode op, const Instruction& instruction); |
| 374 |
void EncodeNew(const Instruction& instruction); |
| 375 |
void EncodeCast(const Instruction& instruction); |
| 376 |
void EncodeFieldOp(const Instruction& instruction); |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
inline uint8_t ToBits(::dex::Opcode opcode) { |
| 383 |
static_assert(sizeof(uint8_t) == sizeof(::dex::Opcode)); |
| 384 |
return static_cast<uint8_t>(opcode); |
| 385 |
} |
| 386 |
|
| 387 |
inline void Encode10x(::dex::Opcode opcode) { |
| 388 |
|
| 389 |
static_assert(sizeof(uint8_t) == sizeof(::dex::Opcode)); |
| 390 |
buffer_.push_back(ToBits(opcode)); |
| 391 |
} |
| 392 |
|
| 393 |
inline void Encode11x(::dex::Opcode opcode, uint8_t a) { |
| 394 |
|
| 395 |
buffer_.push_back((a << 8) | ToBits(opcode)); |
| 396 |
} |
| 397 |
|
| 398 |
inline void Encode11n(::dex::Opcode opcode, uint8_t a, int8_t b) { |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
CHECK_LT(a, 16); |
| 403 |
CHECK_LE(-8, b); |
| 404 |
CHECK_LT(b, 8); |
| 405 |
|
| 406 |
buffer_.push_back(((b & 0xf) << 12) | (a << 8) | ToBits(opcode)); |
| 407 |
} |
| 408 |
|
| 409 |
inline void Encode21c(::dex::Opcode opcode, uint8_t a, uint16_t b) { |
| 410 |
|
| 411 |
buffer_.push_back((a << 8) | ToBits(opcode)); |
| 412 |
buffer_.push_back(b); |
| 413 |
} |
| 414 |
|
| 415 |
inline void Encode22c(::dex::Opcode opcode, uint8_t a, uint8_t b, uint16_t c) { |
| 416 |
|
| 417 |
CHECK(IsShortRegister(a)); |
| 418 |
CHECK(IsShortRegister(b)); |
| 419 |
buffer_.push_back((b << 12) | (a << 8) | ToBits(opcode)); |
| 420 |
buffer_.push_back(c); |
| 421 |
} |
| 422 |
|
| 423 |
inline void Encode32x(::dex::Opcode opcode, uint16_t a, uint16_t b) { |
| 424 |
buffer_.push_back(ToBits(opcode)); |
| 425 |
buffer_.push_back(a); |
| 426 |
buffer_.push_back(b); |
| 427 |
} |
| 428 |
|
| 429 |
inline void Encode35c(::dex::Opcode opcode, size_t a, uint16_t b, uint8_t c, uint8_t d, |
| 430 |
uint8_t e, uint8_t f, uint8_t g) { |
| 431 |
|
| 432 |
|
| 433 |
CHECK_LE(a, 5); |
| 434 |
CHECK(IsShortRegister(c)); |
| 435 |
CHECK(IsShortRegister(d)); |
| 436 |
CHECK(IsShortRegister(e)); |
| 437 |
CHECK(IsShortRegister(f)); |
| 438 |
CHECK(IsShortRegister(g)); |
| 439 |
buffer_.push_back((a << 12) | (g << 8) | ToBits(opcode)); |
| 440 |
buffer_.push_back(b); |
| 441 |
buffer_.push_back((f << 12) | (e << 8) | (d << 4) | c); |
| 442 |
} |
| 443 |
|
| 444 |
inline void Encode3rc(::dex::Opcode opcode, size_t a, uint16_t b, uint16_t c) { |
| 445 |
CHECK_LE(a, 255); |
| 446 |
buffer_.push_back((a << 8) | ToBits(opcode)); |
| 447 |
buffer_.push_back(b); |
| 448 |
buffer_.push_back(c); |
| 449 |
} |
| 450 |
|
| 451 |
static constexpr bool IsShortRegister(size_t register_value) { return register_value < 16; } |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
template <int num_regs> |
| 456 |
std::array<Value, num_regs> GetScratchRegisters() const { |
| 457 |
static_assert(num_regs <= kMaxScratchRegisters); |
| 458 |
std::array<Value, num_regs> regs; |
| 459 |
for (size_t i = 0; i < num_regs; ++i) { |
| 460 |
regs[i] = std::move(Value::Local(NumRegisters() + i)); |
| 461 |
} |
| 462 |
return regs; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
size_t RegisterValue(const Value& value) const; |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
void BindLabel(const Value& label); |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
::dex::u2 LabelValue(const Value& label, size_t instruction_offset, size_t field_offset); |
| 475 |
|
| 476 |
DexBuilder* dex_; |
| 477 |
ir::Class* class_; |
| 478 |
ir::MethodDecl* decl_; |
| 479 |
|
| 480 |
|
| 481 |
std::vector<Instruction> instructions_; |
| 482 |
|
| 483 |
|
| 484 |
std::vector<::dex::u2> buffer_; |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
static constexpr size_t kMaxScratchRegisters = 5; |
| 489 |
|
| 490 |
size_t NumRegisters() const { |
| 491 |
return register_liveness_.size(); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
struct LabelReference { |
| 498 |
size_t instruction_offset; |
| 499 |
size_t field_offset; |
| 500 |
}; |
| 501 |
|
| 502 |
struct LabelData { |
| 503 |
std::optional<size_t> bound_address; |
| 504 |
std::forward_list<LabelReference> references; |
| 505 |
}; |
| 506 |
|
| 507 |
std::vector<LabelData> labels_; |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
size_t max_args_{0}; |
| 512 |
|
| 513 |
std::vector<bool> register_liveness_; |
| 514 |
}; |
| 515 |
|
| 516 |
|
| 517 |
class ClassBuilder { |
| 518 |
public: |
| 519 |
ClassBuilder(DexBuilder* parent, const std::string& name, ir::Class* class_def); |
| 520 |
|
| 521 |
void set_source_file(const std::string& source); |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
MethodBuilder CreateMethod(const std::string& name, Prototype prototype); |
| 526 |
|
| 527 |
private: |
| 528 |
DexBuilder* const parent_; |
| 529 |
const TypeDescriptor type_descriptor_; |
| 530 |
ir::Class* const class_; |
| 531 |
}; |
| 532 |
|
| 533 |
|
| 534 |
class DexBuilder { |
| 535 |
public: |
| 536 |
DexBuilder(); |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
slicer::MemView CreateImage(); |
| 541 |
|
| 542 |
template <typename T> |
| 543 |
T* Alloc() { |
| 544 |
return dex_file_->Alloc<T>(); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
ir::String* GetOrAddString(const std::string& string); |
| 549 |
|
| 550 |
ClassBuilder MakeClass(const std::string& name); |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
ir::Type* GetOrAddType(const std::string& descriptor); |
| 556 |
inline ir::Type* GetOrAddType(TypeDescriptor descriptor) { |
| 557 |
return GetOrAddType(descriptor.descriptor()); |
| 558 |
} |
| 559 |
|
| 560 |
ir::FieldDecl* GetOrAddField(TypeDescriptor parent, const std::string& name, TypeDescriptor type); |
| 561 |
|
| 562 |
|
| 563 |
const MethodDeclData& GetOrDeclareMethod(TypeDescriptor type, const std::string& name, |
| 564 |
Prototype prototype); |
| 565 |
|
| 566 |
std::optional<const Prototype> GetPrototypeByMethodId(size_t method_id) const; |
| 567 |
|
| 568 |
private: |
| 569 |
|
| 570 |
|
| 571 |
ir::Proto* GetOrEncodeProto(Prototype prototype); |
| 572 |
|
| 573 |
std::shared_ptr<ir::DexFile> dex_file_; |
| 574 |
|
| 575 |
|
| 576 |
TrackingAllocator allocator_; |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
std::vector<std::unique_ptr<uint8_t[]>> string_data_; |
| 581 |
|
| 582 |
|
| 583 |
std::unordered_map<std::string, ir::Type*> types_by_descriptor_; |
| 584 |
|
| 585 |
struct MethodDescriptor { |
| 586 |
TypeDescriptor type; |
| 587 |
std::string name; |
| 588 |
Prototype prototype; |
| 589 |
|
| 590 |
inline bool operator<(const MethodDescriptor& rhs) const { |
| 591 |
return std::make_tuple(type, name, prototype) < |
| 592 |
std::make_tuple(rhs.type, rhs.name, rhs.prototype); |
| 593 |
} |
| 594 |
}; |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
std::map<MethodDescriptor, MethodDeclData> method_id_map_; |
| 600 |
|
| 601 |
|
| 602 |
std::unordered_map<std::string, ir::String*> strings_; |
| 603 |
|
| 604 |
|
| 605 |
std::map<Prototype, ir::Proto*> proto_map_; |
| 606 |
|
| 607 |
|
| 608 |
std::map<std::tuple<TypeDescriptor, std::string>, ir::FieldDecl*> field_decls_by_key_; |
| 609 |
}; |
| 610 |
|
| 611 |
template <typename... T> |
| 612 |
void MethodBuilder::BuildNew(Value target, TypeDescriptor type, Prototype constructor, |
| 613 |
const T&... args) { |
| 614 |
MethodDeclData constructor_data{dex_->GetOrDeclareMethod(type, "<init>", constructor)}; |
| 615 |
|
| 616 |
ir::Type* type_def = dex_->GetOrAddType(type.descriptor()); |
| 617 |
AddInstruction( |
| 618 |
Instruction::OpWithArgs(Instruction::Op::kNew, target, Value::Type(type_def->orig_index))); |
| 619 |
|
| 620 |
AddInstruction(Instruction::InvokeDirect(constructor_data.id, {}, target, args...)); |
| 621 |
}; |
| 622 |
|
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
#endif |