gen/
data.c
10.9 KiB
data.h
2.5 KiB
emit.c
37.2 KiB
emit.h
4.6 KiB
.clang-format
570 B
.gitignore
30 B
.gitsigners
112 B
LICENSE
1.1 KiB
Makefile
911 B
README
1.8 KiB
ast.c
5.0 KiB
ast.h
15.1 KiB
desugar.c
23.1 KiB
desugar.h
286 B
gen.c
108.5 KiB
gen.h
4.9 KiB
io.c
1.1 KiB
io.h
444 B
limits.h
1.3 KiB
module.c
10.0 KiB
module.h
2.2 KiB
options.c
1.4 KiB
options.h
472 B
parser.c
68.3 KiB
parser.h
942 B
radiance.c
3.7 KiB
ralloc.c
2.0 KiB
ralloc.h
1.1 KiB
resolver.c
109.7 KiB
resolver.h
5.6 KiB
riscv.c
12.0 KiB
riscv.h
12.0 KiB
scanner.c
10.2 KiB
scanner.h
3.2 KiB
strings.c
2.6 KiB
strings.h
407 B
symtab.c
5.7 KiB
symtab.h
4.6 KiB
types.h
1.0 KiB
util.h
1.5 KiB
gen/data.h
raw
| 1 | #ifndef DATA_H |
| 2 | #define DATA_H |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include "../limits.h" |
| 7 | #include "../resolver.h" |
| 8 | #include "../types.h" |
| 9 | |
| 10 | /* Data section offsets in memory */ |
| 11 | #define DATA_RO_OFFSET 0x10000 |
| 12 | #define DATA_RW_OFFSET 0xFFFFF0 |
| 13 | |
| 14 | /* String literal data in the data section */ |
| 15 | typedef struct { |
| 16 | const char *data; /* String content */ |
| 17 | usize length; /* String length */ |
| 18 | usize offset; /* Offset in data section */ |
| 19 | } string_data_t; |
| 20 | |
| 21 | /* Kind of data item in the rw data section */ |
| 22 | typedef enum { |
| 23 | DATA_ARRAY, /* Array backing data for slices */ |
| 24 | DATA_CONST, /* Named constant */ |
| 25 | } data_kind_t; |
| 26 | |
| 27 | /* Unified data item for the rw data section */ |
| 28 | typedef struct { |
| 29 | data_kind_t kind; |
| 30 | usize offset; /* Offset in data section */ |
| 31 | node_t *node; |
| 32 | struct parser_t *parser; /* Parser that owns this node's spans */ |
| 33 | union { |
| 34 | struct { |
| 35 | usize length; /* Number of elements */ |
| 36 | type_t *elem; /* Element type */ |
| 37 | } array; |
| 38 | struct { |
| 39 | const char *name; /* Constant name */ |
| 40 | usize name_len; /* Length of name */ |
| 41 | } constant; |
| 42 | } as; |
| 43 | } data_item_t; |
| 44 | |
| 45 | /* Data section for static data (strings, constants, etc.) */ |
| 46 | typedef struct { |
| 47 | string_data_t strings[MAX_STRING_LITERALS]; |
| 48 | usize nstrings; |
| 49 | data_item_t items[MAX_CONSTANTS * 2]; /* Arrays and constants */ |
| 50 | usize nitems; |
| 51 | usize ro_size; /* Total size of read-only data section */ |
| 52 | usize ro_offset; /* Data section offset */ |
| 53 | usize rw_offset; /* Data section offset */ |
| 54 | usize rw_init_total; /* Pre-computed total size */ |
| 55 | usize rw_init_size; /* Current init cursor */ |
| 56 | usize rw_bss_size; /* Current BSS cursor */ |
| 57 | } data_section_t; |
| 58 | |
| 59 | /* Initialize the data section management. */ |
| 60 | void data_init(data_section_t *d); |
| 61 | /* Add a string literal to the data section. |
| 62 | * Returns the data section offset where the string is stored. */ |
| 63 | usize data_string(data_section_t *d, const char *str, usize len); |
| 64 | /* Add array data for a slice to the data section. |
| 65 | * Returns the offset in the data section. */ |
| 66 | usize data_array(data_section_t *d, struct parser_t *p, node_t *array_node); |
| 67 | /* Add a node to the data section. */ |
| 68 | usize data_node( |
| 69 | data_section_t *d, |
| 70 | struct parser_t *p, |
| 71 | node_t *node, |
| 72 | const char *name, |
| 73 | usize name_len |
| 74 | ); |
| 75 | /* Emit the data section to the output. */ |
| 76 | void data_emit_ro(data_section_t *d, FILE *out); |
| 77 | void data_emit_rw(data_section_t *d, FILE *out); |
| 78 | |
| 79 | #endif |