const uint8_t* ImmVector::findLastMember() const { assert(m_length > 0); // Loop that does basically the same as numStackValues(), except // stop at the last. const uint8_t* vec = m_start; const LocationCode locCode = LocationCode(*vec++); const int numLocImms = numLocationCodeImms(locCode); for (int i = 0; i < numLocImms; ++i) { decodeVariableSizeImm(&vec); } for (;;) { const uint8_t* ret = vec; MemberCode code = MemberCode(*vec++); if (memberCodeHasImm(code)) { decodeMemberCodeImm(&vec, code); } if (vec - m_start == m_length) { return ret; } assert(vec - m_start < m_length); } NOT_REACHED(); }
std::vector<uchar> read_immvector(AsmState& as, int& stackCount) { std::vector<uchar> ret; as.in.skipSpaceTab(); as.in.expect('<'); std::string word; if (!as.in.readword(word)) { as.error("expected location code in immediate vector"); } LocationCode lcode = parseLocationCode(word.c_str()); if (lcode == InvalidLocationCode) { as.error("expected location code, saw `" + word + "'"); } ret.push_back(uint8_t(lcode)); if (word[word.size() - 1] == 'L') { if (as.in.getc() != ':') { as.error("expected `:' after location code `" + word + "'"); } } for (int i = 0; i < numLocationCodeImms(lcode); ++i) { read_immvector_immediate(as, ret); } stackCount = numLocationCodeStackVals(lcode); // Read all the member entries. for (;;) { as.in.skipWhitespace(); if (as.in.peek() == '>') { as.in.getc(); break; } if (!as.in.readword(word)) { as.error("expected member code in immediate vector"); } MemberCode mcode = parseMemberCode(word.c_str()); if (mcode == InvalidMemberCode) { as.error("unrecognized member code `" + word + "'"); } ret.push_back(uint8_t(mcode)); if (memberCodeHasImm(mcode)) { if (as.in.getc() != ':') { as.error("expected `:' after member code `" + word + "'"); } read_immvector_immediate(as, ret, mcode); } else if (mcode != MW) { ++stackCount; } } return ret; }
std::vector<MVectorItem> getMVector(const Op* opcode) { auto immVec = getImmVector(opcode); std::vector<MVectorItem> result; auto it = immVec.vec(); auto end = it + immVec.size(); // Skip the LocationCode and its immediate auto const lcode = LocationCode(*it++); if (numLocationCodeImms(lcode)) decodeVariableSizeImm(&it); while (it < end) { auto const mcode = MemberCode(*it++); auto const imm = memberCodeHasImm(mcode) ? decodeMemberCodeImm(&it, mcode) : 0; result.push_back({mcode, imm}); } return result; }