1
0
mirror of synced 2024-11-12 10:10:53 +01:00

pattern: Added left_to_right and right_to_left attribute for bitfields

This commit is contained in:
WerWolv 2022-02-07 20:08:19 +01:00
parent 97db5e9698
commit 94506848e0
2 changed files with 23 additions and 3 deletions

View File

@ -89,7 +89,7 @@ namespace hex::pl {
}
public:
void addAttribute(ASTNodeAttribute *attribute) {
virtual void addAttribute(ASTNodeAttribute *attribute) {
this->m_attributes.push_back(attribute);
}
@ -482,6 +482,13 @@ namespace hex::pl {
return patterns;
}
void addAttribute(ASTNodeAttribute *attribute) override {
Attributable::addAttribute(attribute);
if (auto attributable = dynamic_cast<Attributable *>(this->m_type); attributable != nullptr)
attributable->addAttribute(static_cast<ASTNodeAttribute *>(attribute->clone()));
}
private:
std::string m_name;
ASTNode *m_type;
@ -1517,6 +1524,15 @@ namespace hex::pl {
delete field;
};
auto &attributes = this->getAttributes();
bool isLeftToRight = false;
if (std::any_of(attributes.begin(), attributes.end(), [](ASTNodeAttribute *attribute) { return attribute->getAttribute() == "left_to_right" && !attribute->getValue().has_value(); }))
isLeftToRight = true;
else if (std::any_of(attributes.begin(), attributes.end(), [](ASTNodeAttribute *attribute) { return attribute->getAttribute() == "right_to_left" && !attribute->getValue().has_value(); }))
isLeftToRight = false;
evaluator->pushScope(pattern, fields);
for (auto [name, bitSizeNode] : this->m_entries) {
auto literal = bitSizeNode->evaluate(evaluator);
@ -1532,7 +1548,11 @@ namespace hex::pl {
if (name != "padding") {
auto field = new PatternDataBitfieldField(evaluator, evaluator->dataOffset(), bitOffset, bitSize, pattern);
field->setVariableName(name);
fields.push_back(field);
if (isLeftToRight)
fields.insert(fields.begin(), field);
else
fields.push_back(field);
}
bitOffset += bitSize;

View File

@ -1469,7 +1469,7 @@ namespace hex::pl {
std::vector<u8> value(this->m_bitField->getSize(), 0);
provider->read(this->m_bitField->getOffset(), &value[0], value.size());
if (this->m_bitField->getEndian() == std::endian::little)
if (this->m_bitField->getEndian() != std::endian::native)
std::reverse(value.begin(), value.end());
ImGui::TableNextRow();