diff --git a/ccc/data_refinement.cpp b/ccc/data_refinement.cpp index d2269f04..d9b7b20b 100644 --- a/ccc/data_refinement.cpp +++ b/ccc/data_refinement.cpp @@ -14,6 +14,8 @@ static std::unique_ptr refine_builtin(s32 virtual_address, BuiltInCla static std::unique_ptr refine_pointer_or_reference(s32 virtual_address, const ast::Node& type, const DataRefinementContext& context); static const char* generate_format_string(s32 size, bool is_signed); static std::string single_precision_float_to_string(float value); +static std::string string_format(const char* format, va_list args); +static std::string stringf(const char* format, ...); void refine_variables(HighSymbolTable& high, const std::vector& modules) { // Build a map of where all functions and globals are in memory, so that we @@ -305,4 +307,18 @@ static std::string single_precision_float_to_string(float value) { return result; } +static std::string string_format(const char* format, va_list args) { + static char buffer[16 * 1024]; + vsnprintf(buffer, sizeof(buffer), format, args); + return std::string(buffer); +} + +static std::string stringf(const char* format, ...) { + va_list args; + va_start(args, format); + std::string string = string_format(format, args); + va_end(args); + return string; +} + } diff --git a/ccc/print_json.cpp b/ccc/print_json.cpp index efe79be9..66bb6e9f 100644 --- a/ccc/print_json.cpp +++ b/ccc/print_json.cpp @@ -275,7 +275,8 @@ static void print_json_ast_node(JsonPrinter& json, const ast::Node* ptr) { json.property("stabs_type_number_to_deduplicated_type_index"); json.begin_object(); for(const auto [stabs_type_number, deduplicated_type_index] : source_file.stabs_type_number_to_deduplicated_type_index) { - json.number_property(stringf("%lld", merge_stabs_type_number_parts(stabs_type_number)).c_str(), deduplicated_type_index); + s64 merged_type_number = merge_stabs_type_number_parts(stabs_type_number); + json.number_property(std::to_string(merged_type_number).c_str(), deduplicated_type_index); } json.end_object(); break; diff --git a/ccc/stabs.cpp b/ccc/stabs.cpp index ba92c29d..185e00be 100644 --- a/ccc/stabs.cpp +++ b/ccc/stabs.cpp @@ -713,9 +713,13 @@ std::optional eat_dodgy_stabs_identifier(const char*& input) { return std::nullopt; } -STABS_DEBUG(static void print_field(const StabsField& field) { +STABS_DEBUG( + +static void print_field(const StabsField& field) { printf("\t%04x %04x %04x %04x %s\n", field.offset_bits / 8, field.size_bits / 8, field.offset_bits, field.size_bits, field.name.c_str()); -}) +} + +) const char* builtin_class_to_string(BuiltInClass bclass) { switch(bclass) { diff --git a/ccc/stabs_to_ast.cpp b/ccc/stabs_to_ast.cpp index 4263e824..ded10cc3 100644 --- a/ccc/stabs_to_ast.cpp +++ b/ccc/stabs_to_ast.cpp @@ -84,7 +84,11 @@ Result> stabs_type_to_ast(const StabsType& type, cons if(type.anonymous || stabs_type == state.stabs_types->end()) { auto type_name = std::make_unique(); type_name->source = ast::TypeNameSource::ERROR; - type_name->type_name = stringf("CCC_BADTYPELOOKUP(%d,%d)", type.type_number.file, type.type_number.type); + type_name->type_name += "CCC_BADTYPELOOKUP("; + type_name->type_name += std::to_string(type.type_number.file); + type_name->type_name += ","; + type_name->type_name += std::to_string(type.type_number.type); + type_name->type_name += ")"; return std::unique_ptr(std::move(type_name)); } return stabs_type_to_ast(*stabs_type->second, state, abs_parent_offset_bytes, depth + 1, substitute_type_name, force_substitute); diff --git a/ccc/util.cpp b/ccc/util.cpp index 7307773c..437ac6bb 100644 --- a/ccc/util.cpp +++ b/ccc/util.cpp @@ -1,13 +1,4 @@ -#include "ccc.h" - -#include -#include -#include -#include -#include -#include -#include -#include +#include "util.h" namespace ccc { @@ -54,20 +45,6 @@ Result get_string(const std::vector& bytes, u64 offset) { return CCC_FAILURE("Unexpected end of buffer while reading string."); } -std::string string_format(const char* format, va_list args) { - static char buffer[16 * 1024]; - vsnprintf(buffer, 16 * 1024, format, args); - return std::string(buffer); -} - -std::string stringf(const char* format, ...) { - va_list args; - va_start(args, format); - std::string string = string_format(format, args); - va_end(args); - return string; -} - std::string merge_paths(const std::string& base, const std::string& path) { // Try to figure out if we're dealing with a Windows path of a UNIX path. bool is_windows_path = false; diff --git a/ccc/util.h b/ccc/util.h index 80486ec7..606d0f2b 100644 --- a/ccc/util.h +++ b/ccc/util.h @@ -184,9 +184,6 @@ Result get_string(const std::vector& bytes, u64 offset); #define CCC_BEGIN_END(x) (x).begin(), (x).end() #define CCC_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -std::string string_format(const char* format, va_list args); -std::string stringf(const char* format, ...); - // These functions are to be used only for source file paths present in the // symbol table, since we want them to be handled consistently across different // platforms, which with std::filesystem::path doesn't seem to be possible.