mt_embed_file
This commit is contained in:
@@ -95,4 +95,31 @@ fn void cg_list_files_recursive(sb8_t *sb, s8_t path) {
|
||||
sb8_append(sb, iter.absolute_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn void cg_byte_array_from_data_ex(sb8_t *sb, s8_t file, s8_t var_name) {
|
||||
sb8_printf(sb, "u8 %S[] = {", var_name);
|
||||
for (i64 i = 0; i < file.len; i += 1) {
|
||||
if ((i % 64) == 0) sb8_printf(sb, "\n");
|
||||
u8 byte = *(u8 *)(file.str + i);
|
||||
sb8_printf(sb, "%u,", byte);
|
||||
}
|
||||
sb8_printf(sb, "\n};\n");
|
||||
}
|
||||
|
||||
fn s8_t cg_byte_array_from_data(ma_arena_t *arena, s8_t file, s8_t var_name) {
|
||||
ma_temp_t scratch = ma_begin_scratch1(arena);
|
||||
sb8_t *sb = sb8_serial_begin(scratch.arena);
|
||||
cg_byte_array_from_data_ex(sb, file, var_name);
|
||||
s8_t result = sb8_serial_end(arena, sb);
|
||||
ma_end_scratch(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
#define cg_cpath(arena) cg_gen_filename(arena, s8_lit(__FILE__), s8_lit("c"))
|
||||
#define cg_hpath(arena) cg_gen_filename(arena, s8_lit(__FILE__), s8_lit("h"))
|
||||
s8_t cg_gen_filename(ma_arena_t *arena, s8_t lit_file, s8_t ext) {
|
||||
s8_t file_noext = s8_chop_last_period(s8_chop_last_period(lit_file));
|
||||
s8_t file = s8_printf(arena, "%S.gen.%S", file_noext, ext);
|
||||
return file;
|
||||
}
|
||||
@@ -232,11 +232,3 @@ void sb8_serial_table_enum(sb8_t *c, sb8_t *h, ast_t *table, s8_t decl) {
|
||||
c->indent -= 1;
|
||||
sb8_stmtf(c, "};");
|
||||
}
|
||||
|
||||
#define gen_c(arena) _gen_filename(arena, s8_lit(__FILE__), s8_lit("c"))
|
||||
#define gen_h(arena) _gen_filename(arena, s8_lit(__FILE__), s8_lit("h"))
|
||||
s8_t _gen_filename(ma_arena_t *arena, s8_t lit_file, s8_t ext) {
|
||||
s8_t file_noext = s8_chop_last_period(s8_chop_last_period(lit_file));
|
||||
s8_t file = s8_printf(arena, "%S.gen.%S", file_noext, ext);
|
||||
return file;
|
||||
}
|
||||
Reference in New Issue
Block a user