mirror of
https://github.com/open-goal/jak-project
synced 2026-05-24 15:21:12 -04:00
d56540f8c0
* add some more tests for let * support static strings * add function calling * add prints for windows debgu * one test only * try swapping r14 and r15 in windows * swap back * disable defun for now * fix massive bug * fix formatting
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "third-party/fmt/core.h"
|
|
#include "StaticObject.h"
|
|
#include "common/goal_constants.h"
|
|
|
|
namespace {
|
|
template <typename T>
|
|
uint32_t push_data_to_byte_vector(T data, std::vector<uint8_t>& v) {
|
|
auto* ptr = (uint8_t*)(&data);
|
|
for (std::size_t i = 0; i < sizeof(T); i++) {
|
|
v.push_back(ptr[i]);
|
|
}
|
|
return sizeof(T);
|
|
}
|
|
} // namespace
|
|
|
|
StaticString::StaticString(std::string data, int _seg) : text(std::move(data)), seg(_seg) {}
|
|
|
|
std::string StaticString::print() const {
|
|
return fmt::format("static-string \"{}\"", text);
|
|
}
|
|
|
|
StaticObject::LoadInfo StaticString::get_load_info() const {
|
|
LoadInfo info;
|
|
info.requires_load = false;
|
|
info.prefer_xmm = false;
|
|
return info;
|
|
}
|
|
|
|
void StaticString::generate(emitter::ObjectGenerator* gen) {
|
|
rec = gen->add_static_to_seg(seg, 16);
|
|
auto& d = gen->get_static_data(rec);
|
|
|
|
// add "string" type tag:
|
|
gen->link_static_type_ptr(rec, d.size(), "string");
|
|
for (int i = 0; i < POINTER_SIZE; i++) {
|
|
d.push_back(0xbe);
|
|
}
|
|
|
|
// add allocated size
|
|
push_data_to_byte_vector<u32>(text.size() + 1, d);
|
|
|
|
// add chars
|
|
for (auto c : text) {
|
|
d.push_back(c);
|
|
}
|
|
d.push_back(0);
|
|
}
|
|
|
|
int StaticString::get_addr_offset() const {
|
|
return BASIC_OFFSET;
|
|
} |