case '#': {
if (parse_possible_directive(parser, "file_contents")) {
- AstPointerType* fc_type = make_node(AstPointerType, Ast_Kind_Pointer_Type);
- fc_type->flags |= Basic_Flag_Pointer;
- fc_type->elem = (AstType *) &basic_type_u8;
-
AstFileContents* fc = make_node(AstFileContents, Ast_Kind_File_Contents);
fc->token = parser->prev - 1;
fc->filename = expect_token(parser, Token_Type_Literal_String);
- fc->type_node = (AstType *) fc_type;
+ fc->type = type_make_slice(parser->allocator, &basic_types[Basic_Kind_U8]);
add_node_to_process(parser, (AstNode *) fc);
case Ast_Kind_File_Contents: {
AstFileContents* fc = (AstFileContents *) expr;
- token_toggle_end(fc->filename);
- u32 offset = bh_table_get(u32, mod->loaded_file_offsets, fc->filename->text);
- WID(WI_I32_CONST, offset);
-
- token_toggle_end(fc->filename);
+ WID(WI_I32_CONST, fc->addr);
+ WID(WI_I32_CONST, fc->size);
break;
}
static void emit_file_contents(OnyxWasmModule* mod, AstFileContents* fc) {
token_toggle_end(fc->filename);
- if (bh_table_has(u32, mod->loaded_file_offsets, fc->filename->text)) {
+ if (bh_table_has(StrLitInfo, mod->loaded_file_info, fc->filename->text)) {
+ StrLitInfo info = bh_table_get(StrLitInfo, mod->loaded_file_info, fc->filename->text);
+ fc->addr = info.addr;
+ fc->size = info.len;
+
token_toggle_end(fc->filename);
return;
}
u32 offset = mod->next_datum_offset;
if (offset % 16 != 0)
offset += 16 - (offset % 16);
- bh_table_put(u32, mod->loaded_file_offsets, fc->filename->text, offset);
if (!bh_file_exists(fc->filename->text)) {
onyx_report_error(fc->filename->pos,
actual_data[contents.length] = 0;
bh_file_contents_free(&contents);
+ bh_table_put(StrLitInfo, mod->loaded_file_info, fc->filename->text, ((StrLitInfo) {
+ .addr = offset,
+ .len = length - 1,
+ }));
+
+ fc->addr = offset;
+ fc->size = length - 1;
+
WasmDatum datum = {
.offset = offset,
.length = length,
bh_table_init(global_heap_allocator, module.type_map, 61);
bh_table_init(global_heap_allocator, module.exports, 61);
- bh_table_init(global_heap_allocator, module.loaded_file_offsets, 7);
+ bh_table_init(global_heap_allocator, module.loaded_file_info, 7);
bh_table_init(global_heap_allocator, module.string_literals, 16);
bh_imap_init(&module.index_map, global_heap_allocator, 128);