progress on full dump
This commit is contained in:
parent
48802b5f73
commit
5a1ae41716
170
demo.str_cache.c
170
demo.str_cache.c
@ -42,6 +42,7 @@ int main()
|
||||
// #define DEMO__FILE_READ_CONTENTS_V1
|
||||
// #define DEMO__WATL_LEX_V1
|
||||
// #define DEMO__WATL_PARSE_V1
|
||||
// #define DEMO__WATL_DUMP_PREREQ_V1
|
||||
#define DEMO__WATL_DUMP_V1
|
||||
|
||||
/*
|
||||
@ -68,9 +69,6 @@ So we'll setup the the minimum for that when dealing with immutable constructs.
|
||||
// We'll need some minimum set of dependencies to adequately define the constructs.
|
||||
// ASSUMING MODERN MSVC TOOLCHAIN.
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <intrin.h>
|
||||
#include <tmmintrin.h>
|
||||
#include <wmmintrin.h>
|
||||
@ -249,8 +247,9 @@ They will having the following format:
|
||||
typedef U8 FMem_<size>KB [ <U8 amount> ];
|
||||
*/
|
||||
|
||||
typedef U8 FMem_16KB [ KILOBTYES(16) ];
|
||||
typedef U8 FMem_64KB [ KILOBTYES(64) ];
|
||||
typedef U8 FMem_16KB [ KILOBTYES(16) ];
|
||||
typedef U8 FMem_64KB [ KILOBTYES(64) ];
|
||||
typedef U8 FMem_128KB [ KILOBTYES(128) ];
|
||||
|
||||
#define typeof __typeof__
|
||||
#define fmem_slice(mem) (SliceByte) { mem, size_of(mem) }
|
||||
@ -291,7 +290,7 @@ char* str8_to_cstr_capped(Str8 content, SliceByte mem) {
|
||||
}
|
||||
|
||||
// To support zeroing slices we'll utilize an intrinisc.
|
||||
B32 memory_zero(void* dest, USIZE const length) {
|
||||
B32 memory_zero(void* dest, USIZE length) {
|
||||
if (dest == nullptr || length <= 0) {
|
||||
return false;
|
||||
}
|
||||
@ -307,7 +306,7 @@ void slice__zero(SliceByte mem, SSIZE typewidth) {
|
||||
|
||||
// Now for our "Version 1"
|
||||
|
||||
#if defined(DEMO__FILE_READ_CONTENTS_V1) || defined(DEMO__WATL_LEX_V1) || defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
#if defined(DEMO__FILE_READ_CONTENTS_V1) || defined(DEMO__WATL_LEX_V1) || defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_PREREQ_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
|
||||
struct FileOpResult
|
||||
{
|
||||
@ -535,7 +534,7 @@ inline void farena_reset(FArena* arena) { arena->used = 0; }
|
||||
inline ArenaSP farena_save (FArena arena) { ArenaSP savepoint; savepoint.ptr = arena.start; return savepoint; }
|
||||
#pragma endregion FArena
|
||||
|
||||
#if defined(DEMO__WATL_LEX_V1) || defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
#if defined(DEMO__WATL_LEX_V1) || defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_PREREQ_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
|
||||
struct WATL_LexInfo {
|
||||
// For now just the tokens
|
||||
@ -869,7 +868,7 @@ struct WATL_SliceLine {
|
||||
SSIZE len;
|
||||
};
|
||||
|
||||
#if defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
#if defined(DEMO__WATL_PARSE_V1) || defined(DEMO__WATL_DUMP_PREREQ_V1) || defined(DEMO__WATL_DUMP_V1)
|
||||
|
||||
struct Opts__watl_parse {
|
||||
SliceByte backing_nodes;
|
||||
@ -1158,7 +1157,7 @@ Str8 mappings [][2] = {
|
||||
*/
|
||||
#define fmt_entry(key, value) lit(key), lit(value)
|
||||
|
||||
#ifdef DEMO__WATL_DUMP_V1
|
||||
#ifdef DEMO__WATL_DUMP_PREREQ_V1
|
||||
int main()
|
||||
{
|
||||
set_utf8_codepage();
|
||||
@ -1179,11 +1178,158 @@ int main()
|
||||
#endif
|
||||
|
||||
/*
|
||||
We now have what we need to create the debug dump and the structural listing for WATL's data structures.
|
||||
We'll need to do some integer serialization for our dump listing's metrics.
|
||||
*/
|
||||
Str8 str8_from_u32(SliceByte mem, U32 num, U32 radix, U8 min_digits, U8 digit_group_separator)
|
||||
{
|
||||
Str8 result = {.ptr = mem.ptr, .len = 0};
|
||||
Str8 prefix = {0};
|
||||
switch (radix)
|
||||
{
|
||||
case 16:{prefix = lit("0x");}break;
|
||||
case 8: {prefix = lit("0o");}break;
|
||||
case 2: {prefix = lit("0b");}break;
|
||||
}
|
||||
|
||||
U32 needed_leading_zeros = 0;
|
||||
{
|
||||
U32 needed_digits = 1;
|
||||
{
|
||||
U32 u32_reduce = num;
|
||||
for(;;)
|
||||
{
|
||||
u32_reduce /= radix;
|
||||
if (u32_reduce == 0) {
|
||||
break;
|
||||
}
|
||||
needed_digits += 1;
|
||||
}
|
||||
}
|
||||
|
||||
needed_leading_zeros = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
|
||||
U32 needed_separators = 0;
|
||||
if (digit_group_separator != 0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Lastly: Writting to file using the Win API.
|
||||
*/
|
||||
void file_write_str8(Str8 path, Str8 content)
|
||||
{
|
||||
slice_assert(path);
|
||||
slice_assert(content);
|
||||
|
||||
FMem_16KB scratch = {0};
|
||||
char const* path_cstr = str8_to_cstr_capped(path, fmem_slice(scratch));
|
||||
|
||||
HANDLE id_file = CreateFileA(
|
||||
path_cstr,
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL
|
||||
);
|
||||
|
||||
B32 open_failed = id_file == INVALID_HANDLE_VALUE;
|
||||
if (open_failed) {
|
||||
DWORD error_code = GetLastError();
|
||||
assert(error_code != 0);
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD bytes_written = 0;
|
||||
B32 status = WriteFile(id_file
|
||||
, cast(void*, content.ptr)
|
||||
, cast(USIZE, content.len)
|
||||
, & bytes_written
|
||||
, NULL
|
||||
);
|
||||
assert(status != 0);
|
||||
assert(bytes_written == content.len);
|
||||
}
|
||||
|
||||
/*
|
||||
We now have what we need to create the structural listing dump for WATL's data structures.
|
||||
*/
|
||||
|
||||
Str8 watl_debug_dmp(SliceByte buffer, WATL_SliceLine lines)
|
||||
Str8 watl_dump_listing(SliceByte buffer, WATL_SliceLine lines)
|
||||
{
|
||||
local_persist FMem_64KB scratch = {0};
|
||||
|
||||
Str8Gen result = str8gen_make(buffer);
|
||||
U32 line_num = 0;
|
||||
for (slice_iter(lines, line))
|
||||
{
|
||||
#define fmt_entry_u32(label, num) lit(label), str8_from_u32(fmem_slice(scratch), num, 10, 0, 0)
|
||||
++ line_num;
|
||||
str8gen_append_fmt(result, "Line <line_num> - Chunks <chunk_num>:\n", {(
|
||||
fmt_entry_u32("line_num", line_num)
|
||||
, fmt_entry_u32("chunk_num", line->len)
|
||||
)});
|
||||
for (slice_iter(* line, chunk))
|
||||
{
|
||||
str8gen_append_str8(& result, lit("\t"));
|
||||
Str8 id;
|
||||
switch (* chunk->ptr)
|
||||
{
|
||||
case WATL_Tok_Space:
|
||||
id = lit("Space");
|
||||
break;
|
||||
|
||||
case WATL_Tok_Tab:
|
||||
id = lit("Tab");
|
||||
break;
|
||||
|
||||
default:
|
||||
id = lit("Visible");
|
||||
break;
|
||||
}
|
||||
|
||||
str8gen_append_fmt(result, "<id>(<size>): '<spaces>'", {(
|
||||
lit("id"), id
|
||||
, fmt_entry_u32("size", chunk->len)
|
||||
, lit("spaces"), * chunk
|
||||
)});
|
||||
|
||||
str8gen_append_str8(& result, lit("\n"));
|
||||
}
|
||||
#undef fmt_entry_u32
|
||||
}
|
||||
return (Str8){ result.ptr, result.len };
|
||||
}
|
||||
|
||||
#ifdef DEMO__WATL_DUMP_V1
|
||||
int main()
|
||||
{
|
||||
set_utf8_codepage();
|
||||
|
||||
// This will limit for our V1 read to 64kb at most.
|
||||
FMem_128KB read_mem = {0};
|
||||
FileOpResult read_res = file_read_contents(lit("demo.str_cache.c"), .backing = fmem_slice(read_mem) );
|
||||
|
||||
// This will limit our V1 lex to only 8 megs worth of token tracking on a file.
|
||||
SliceByte mem_toks = slicemem_alloc(MEGABYTES(16));
|
||||
WATL_LexInfo lex_res = watl_lex(pcast(Str8, read_res.content), .pool_toks = mem_toks);
|
||||
|
||||
SliceByte mem_cache_strs = slicemem_alloc(MEGABYTES(64));
|
||||
SliceByte mem_cache_slots = slicemem_alloc(1024 * 1024 * 16 * size_of(Str8Cache_SliceSlot));
|
||||
SliceByte mem_cache_table = slicemem_alloc(1024 * 16 * size_of(Str8Cache_SliceSlot));
|
||||
Str8Cache str_cache = str8cache_init(mem_cache_strs, mem_cache_slots, mem_cache_table);
|
||||
|
||||
SliceByte mem_parse_nodes = slicemem_alloc(MEGABYTES(4));
|
||||
SliceByte mem_parse_lines = slicemem_alloc(MEGABYTES(4));
|
||||
WATL_ParseInfo parse_res = watl_parse(lex_res.tokens, .backing_nodes = mem_parse_nodes, .backing_lines = mem_parse_lines, .str_cache = & str_cache);
|
||||
|
||||
SliceByte scratch_dmp = slicemem_alloc(MEGABYTES(16));
|
||||
Str8 listing = watl_dump_listing(scratch_dmp, parse_res.lines);
|
||||
file_write_str8(lit("demo.str_cache.listing.txt"), listing);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user