Z / libzlang 0.29.0
C99 runtime library and the Zlang 0.29 source-to-source compiler
Loading...
Searching...
No Matches
emitter.h
Go to the documentation of this file.
1
4
5#ifndef ZLANG_COMPILER_EMITTER_H
6#define ZLANG_COMPILER_EMITTER_H
7
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
16#define ZLANG_EMITTED_SYMBOL_CAPACITY 128U
17#define ZLANG_EMITTED_SEQUENCE_CAPACITY 32U
18#define ZLANG_EMITTED_LITERAL_CAPACITY 64U
19#define ZLANG_EMITTED_USER_TYPE_CAPACITY 32U
20#define ZLANG_EMITTED_VTABLE_CAPACITY 8U
21#define ZLANG_EMITTED_VTABLE_SLOT_CAPACITY 16U
22#define ZLANG_EMITTED_TYPE_TAG_CAPACITY 8U
23#define ZLANG_EMITTED_ENUM_ITEM_CAPACITY 128U
24#define ZLANG_EMITTED_COMMENT_CAPACITY 128U
25#define ZLANG_EMITTED_CSE_CAPACITY 16U
26#define ZLANG_MAX_ARRAY_SPECIALIZATIONS 16U
27#define ZLANG_EMITTED_ARRAY_HELPER_CAPACITY 64U
28#define ZLANG_EMITTED_NAME_CAPACITY 64U
29
30/* The emitter owns no memory. The caller supplies the output buffer and the
31 diagnostic sink, which keeps the compiler core free of hidden state. */
32
46
55
64
69
74
83
88
94
101
108
115
116typedef struct zlang_emitter_t {
117 char *buffer_;
118 size_t capacity_;
119 size_t length_;
122 uint32_t next_index_;
169
170void zlang_emitter_init(zlang_emitter_t *emitter, char *buffer, size_t capacity,
171 zlang_diagnostics_t *diagnostics, const zlang_memory_plan_t *plan);
172
173bool zlang_emit_program(const zlang_program_t *program, zlang_emitter_t *emitter);
174
175#endif /* ZLANG_COMPILER_EMITTER_H */
Flat abstract syntax tree used by the compiler.
#define ZLANG_ARRAY_MAX_RANK
Definition ast.h:19
Stable diagnostic codes and source locations.
#define ZLANG_EMITTED_TYPE_TAG_CAPACITY
Definition emitter.h:22
bool zlang_emit_program(const zlang_program_t *program, zlang_emitter_t *emitter)
Definition emitter.c:6959
void zlang_emitter_init(zlang_emitter_t *emitter, char *buffer, size_t capacity, zlang_diagnostics_t *diagnostics, const zlang_memory_plan_t *plan)
Definition emitter.c:65
#define ZLANG_EMITTED_USER_TYPE_CAPACITY
Definition emitter.h:19
#define ZLANG_EMITTED_SEQUENCE_CAPACITY
Definition emitter.h:17
#define ZLANG_EMITTED_ARRAY_HELPER_CAPACITY
Definition emitter.h:27
#define ZLANG_EMITTED_VTABLE_SLOT_CAPACITY
Definition emitter.h:21
#define ZLANG_EMITTED_VTABLE_CAPACITY
Definition emitter.h:20
#define ZLANG_EMITTED_LITERAL_CAPACITY
Definition emitter.h:18
#define ZLANG_EMITTED_NAME_CAPACITY
Definition emitter.h:28
#define ZLANG_EMITTED_ENUM_ITEM_CAPACITY
Definition emitter.h:23
#define ZLANG_EMITTED_COMMENT_CAPACITY
Definition emitter.h:24
#define ZLANG_EMITTED_SYMBOL_CAPACITY
Definition emitter.h:16
#define ZLANG_EMITTED_CSE_CAPACITY
Definition emitter.h:25
#define ZLANG_MAX_ARRAY_SPECIALIZATIONS
Definition emitter.h:26
Compile-time memory placement API.
Definition emitter.h:95
const char * type_name_
Definition emitter.h:97
uint32_t rank_
Definition emitter.h:98
uint32_t extents_[ZLANG_ARRAY_MAX_RANK]
Definition emitter.h:99
size_t function_statement_
Definition emitter.h:96
Definition ast.h:126
Definition diagnostics.h:36
Definition emitter.h:102
char name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:103
uint32_t rank_
Definition emitter.h:105
bool is_set_
Definition emitter.h:106
char type_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:104
Definition emitter.h:65
char macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:67
const zlang_ast_statement_t * statement_
Definition emitter.h:66
Definition emitter.h:89
char generated_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:92
const char * type_name_
Definition emitter.h:91
const char * source_name_
Definition emitter.h:90
Definition emitter.h:109
char generated_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:112
const zlang_array_specialization_t * specialization_
Definition emitter.h:111
const zlang_ast_statement_t * statement_
Definition emitter.h:110
bool needs_state_
Definition emitter.h:113
Definition emitter.h:56
size_t primary_expression_index_
Definition emitter.h:58
bool is_primary_
Definition emitter.h:62
char length_macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:61
size_t expression_index_
Definition emitter.h:57
char view_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:60
char data_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:59
Definition emitter.h:47
char capacity_macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:50
char type_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:49
const zlang_ast_statement_t * statement_
Definition emitter.h:48
char length_macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:52
char extent_macros_[ZLANG_ARRAY_MAX_RANK][ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:53
char element_macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:51
Definition emitter.h:33
const char * type_name_
Definition emitter.h:35
uint32_t array_extents_[ZLANG_ARRAY_MAX_RANK]
Definition emitter.h:44
bool is_array_
Definition emitter.h:42
const char * source_name_
Definition emitter.h:34
uint32_t capacity_
Definition emitter.h:38
bool is_sequence_
Definition emitter.h:40
uint32_t array_rank_
Definition emitter.h:43
char generated_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:36
bool is_reference_
Definition emitter.h:41
bool has_explicit_capacity_
Definition emitter.h:39
char storage_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:37
Definition emitter.h:84
char macro_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:86
const zlang_ast_statement_t * statement_
Definition emitter.h:85
Definition emitter.h:70
const zlang_ast_statement_t * statement_
Definition emitter.h:71
char type_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:72
Definition emitter.h:75
const zlang_ast_statement_t * statement_
Definition emitter.h:76
size_t slot_count_
Definition emitter.h:81
char type_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:77
char instance_name_[ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:78
const zlang_ast_statement_t * slot_methods_[ZLANG_EMITTED_VTABLE_SLOT_CAPACITY]
Definition emitter.h:79
char slot_names_[ZLANG_EMITTED_VTABLE_SLOT_CAPACITY][ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:80
Definition emitter.h:116
size_t emitted_sequence_count_
Definition emitter.h:127
char * buffer_
Definition emitter.h:117
size_t cse_count_
Definition emitter.h:142
const char * cse_pointer_dependency_names_[ZLANG_EMITTED_CSE_CAPACITY]
Definition emitter.h:146
size_t length_
Definition emitter.h:119
const char * cse_pointer_base_names_[ZLANG_EMITTED_CSE_CAPACITY]
Definition emitter.h:145
size_t emitted_capacity_count_
Definition emitter.h:131
size_t emitted_vtable_count_
Definition emitter.h:135
size_t capacity_
Definition emitter.h:118
char activated_macros_[ZLANG_EMITTED_SYMBOL_CAPACITY][ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:166
bool emitted_comments_[ZLANG_EMITTED_COMMENT_CAPACITY]
Definition emitter.h:148
char cse_pointer_names_[ZLANG_EMITTED_CSE_CAPACITY][ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:144
size_t emitted_user_type_count_
Definition emitter.h:133
zlang_emitted_symbol_t emitted_symbols_[ZLANG_EMITTED_SYMBOL_CAPACITY]
Definition emitter.h:123
const zlang_memory_plan_t * plan_
Definition emitter.h:121
zlang_emitted_user_type_t emitted_user_types_[ZLANG_EMITTED_USER_TYPE_CAPACITY]
Definition emitter.h:132
char cse_names_[ZLANG_EMITTED_CSE_CAPACITY][ZLANG_EMITTED_NAME_CAPACITY]
Definition emitter.h:141
bool has_explicit_main_
Definition emitter.h:160
uint32_t next_index_
Definition emitter.h:122
size_t requested_array_helper_count_
Definition emitter.h:151
size_t cse_expression_indices_[ZLANG_EMITTED_CSE_CAPACITY]
Definition emitter.h:140
size_t emitted_function_count_
Definition emitter.h:154
size_t cse_pointer_indices_[ZLANG_EMITTED_CSE_CAPACITY]
Definition emitter.h:143
zlang_diagnostics_t * diagnostics_
Definition emitter.h:120
size_t emitted_literal_count_
Definition emitter.h:129
size_t cse_pointer_count_
Definition emitter.h:147
bool uses_stateful_std_
Definition emitter.h:158
const zlang_program_t * program_
Definition emitter.h:161
size_t emitted_symbol_count_
Definition emitter.h:124
const char * current_self_name_
Definition emitter.h:164
size_t active_symbol_count_
Definition emitter.h:125
const char * current_return_type_
Definition emitter.h:163
const zlang_array_specialization_t * active_specialization_
Definition emitter.h:157
zlang_emitted_capacity_t emitted_capacities_[ZLANG_EMITTED_SEQUENCE_CAPACITY]
Definition emitter.h:130
zlang_emitted_sequence_t emitted_sequences_[ZLANG_EMITTED_SEQUENCE_CAPACITY]
Definition emitter.h:126
const zlang_ast_statement_t * current_struct_
Definition emitter.h:162
zlang_emitted_vtable_t emitted_vtables_[ZLANG_EMITTED_VTABLE_CAPACITY]
Definition emitter.h:134
bool emit_comments_
Definition emitter.h:149
zlang_emitted_function_t emitted_functions_[ZLANG_EMITTED_SYMBOL_CAPACITY]
Definition emitter.h:153
zlang_emitted_literal_t emitted_literals_[ZLANG_EMITTED_LITERAL_CAPACITY]
Definition emitter.h:128
bool current_self_is_pointer_
Definition emitter.h:165
size_t emitted_enum_item_count_
Definition emitter.h:139
zlang_emitted_enum_item_t emitted_enum_items_[ZLANG_EMITTED_ENUM_ITEM_CAPACITY]
Definition emitter.h:138
size_t emitted_type_tag_count_
Definition emitter.h:137
bool in_function_
Definition emitter.h:159
size_t array_specialization_count_
Definition emitter.h:156
zlang_emitted_type_tag_t emitted_type_tags_[ZLANG_EMITTED_TYPE_TAG_CAPACITY]
Definition emitter.h:136
zlang_array_specialization_t array_specializations_[ZLANG_MAX_ARRAY_SPECIALIZATIONS]
Definition emitter.h:155
bool collecting_array_helpers_
Definition emitter.h:152
size_t activated_macro_count_
Definition emitter.h:167
zlang_emitted_array_helper_t requested_array_helpers_[ZLANG_EMITTED_ARRAY_HELPER_CAPACITY]
Definition emitter.h:150
Definition planner.h:27
Definition ast.h:189