CaVM/src/AttributeParser.cpp

52 lines
1.6 KiB
C++
Raw Normal View History

#include "ConstantPoolTags/Tags.h"
#include <Globals.h>
#include <Utils/Utils.h>
#include <Attributes.h>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <string>
#include <Utils/CRC32_CompileTime.hpp>
attribute_info Attributes::AttributesParser(JavaClassFormat& jc)
{
attribute_info ret;
ret.attribute_name_index = Utils::ReadFromStartIntoVal<uint16_t>(Globals::buffer());
ret.attribute_length = Utils::ReadFromStartIntoVal<uint32_t>(Globals::buffer());
ASSERT(ret.attribute_length.ToHostFormat() > 0);
for (int i = 0; i < ret.attribute_length.ToHostFormat(); i++)
{
ret.info.push_back(Utils::ReadFromStartIntoVal<uint8_t>(Globals::buffer(), 1));
}
std::reverse(ret.info.begin(), ret.info.end());
int idx = ret.info.data()->ToHostFormat();
ASSERT(VEC_ELEM_TYPE(jc.constant_pool[ret.attribute_name_index.ToHostFormat() - 1]) == TYPE(ConstantPoolTags::ConstantUtf8Info));
std::string str = reinterpret_cast<const char*>(std::any_cast<ConstantPoolTags::ConstantUtf8Info>(jc.constant_pool[ret.attribute_name_index.ToHostFormat() - 1]).bytes);
switch ((ClassAttributes)crc32_rec(CRC32, str.c_str()))
{
case ClassAttributes::SOURCE_FILE:
{
ASSERT(VEC_ELEM_TYPE(jc.constant_pool[idx - 1]) == TYPE(ConstantPoolTags::ConstantUtf8Info));
std::cout << "Source File: "
<< std::any_cast<ConstantPoolTags::ConstantUtf8Info>(jc.constant_pool[idx - 1]).bytes
<< std::endl;
SOURCE_FILE_Attribute attr;
// attr.
break;
}
default:
std::cerr << "Unknown attribute: \"" << str << "\"" << std::endl;
exit(EXIT_FAILURE);
}
// switch ()
return ret;
}