#ifndef DATA_H #define DATA_H #include #include "../limits.h" #include "../resolver.h" #include "../types.h" /* Data section offsets in memory */ #define DATA_RO_OFFSET 0x10000 #define DATA_RW_OFFSET 0xFFFFF0 /* String literal data in the data section */ typedef struct { const char *data; /* String content */ usize length; /* String length */ usize offset; /* Offset in data section */ } string_data_t; /* Kind of data item in the rw data section */ typedef enum { DATA_ARRAY, /* Array backing data for slices */ DATA_CONST, /* Named constant */ } data_kind_t; /* Unified data item for the rw data section */ typedef struct { data_kind_t kind; usize offset; /* Offset in data section */ node_t *node; struct parser_t *parser; /* Parser that owns this node's spans */ union { struct { usize length; /* Number of elements */ type_t *elem; /* Element type */ } array; struct { const char *name; /* Constant name */ usize name_len; /* Length of name */ } constant; } as; } data_item_t; /* Data section for static data (strings, constants, etc.) */ typedef struct { string_data_t strings[MAX_STRING_LITERALS]; usize nstrings; data_item_t items[MAX_CONSTANTS * 2]; /* Arrays and constants */ usize nitems; usize ro_size; /* Total size of read-only data section */ usize ro_offset; /* Data section offset */ usize rw_offset; /* Data section offset */ usize rw_init_total; /* Pre-computed total size */ usize rw_init_size; /* Current init cursor */ usize rw_bss_size; /* Current BSS cursor */ } data_section_t; /* Initialize the data section management. */ void data_init(data_section_t *d); /* Add a string literal to the data section. * Returns the data section offset where the string is stored. */ usize data_string(data_section_t *d, const char *str, usize len); /* Add array data for a slice to the data section. * Returns the offset in the data section. */ usize data_array(data_section_t *d, struct parser_t *p, node_t *array_node); /* Add a node to the data section. */ usize data_node( data_section_t *d, struct parser_t *p, node_t *node, const char *name, usize name_len ); /* Emit the data section to the output. */ void data_emit_ro(data_section_t *d, FILE *out); void data_emit_rw(data_section_t *d, FILE *out); #endif