Lines Matching refs:sym

28 static LLVMTypeRef symbol_type(struct symbol *sym);
30 static LLVMTypeRef func_return_type(struct symbol *sym)
32 return symbol_type(sym->ctype.base_type);
35 static LLVMTypeRef sym_func_type(struct symbol *sym)
37 int n_arg = symbol_list_size(sym->arguments);
39 LLVMTypeRef ret_type = func_return_type(sym);
43 FOR_EACH_PTR(sym->arguments, arg) {
49 return LLVMFunctionType(ret_type, arg_type, n_arg, sym->variadic);
52 static LLVMTypeRef sym_array_type(struct symbol *sym)
57 base_type = sym->ctype.base_type;
65 return LLVMArrayType(elem_type, sym->bit_size / base_type->bit_size);
70 static LLVMTypeRef sym_struct_type(struct symbol *sym)
78 snprintf(buffer, sizeof(buffer), "struct.%s", sym->ident ? sym->ident->name : "anno");
81 sym->aux = ret;
83 FOR_EACH_PTR(sym->symbol_list, member) {
97 static LLVMTypeRef sym_union_type(struct symbol *sym)
107 union_size = sym->bit_size / 8;
114 static LLVMTypeRef sym_ptr_type(struct symbol *sym)
119 if (is_void_type(sym->ctype.base_type))
122 type = symbol_type(sym->ctype.base_type);
127 static LLVMTypeRef sym_basetype_type(struct symbol *sym)
131 if (is_float_type(sym)) {
132 switch (sym->bit_size) {
143 die("invalid bit size %d for type %d", sym->bit_size, sym->type);
147 switch (sym->bit_size) {
167 die("invalid bit size %d for type %d", sym->bit_size, sym->type);
175 static LLVMTypeRef symbol_type(struct symbol *sym)
180 if (sym->type == SYM_NODE)
181 return symbol_type(sym->ctype.base_type);
183 if (sym->aux)
184 return sym->aux;
186 switch (sym->type) {
188 ret = LLVMIntType(sym->bit_size);
192 ret = symbol_type(sym->ctype.base_type);
195 ret = sym_basetype_type(sym);
198 ret = sym_ptr_type(sym);
201 ret = sym_union_type(sym);
204 ret = sym_struct_type(sym);
207 ret = sym_array_type(sym);
210 ret = sym_func_type(sym);
217 sym->aux = ret;
240 static LLVMLinkage data_linkage(struct symbol *sym)
242 if (sym->ctype.modifiers & MOD_STATIC)
248 static LLVMLinkage function_linkage(struct symbol *sym)
250 if (sym->ctype.modifiers & MOD_STATIC)
283 static LLVMValueRef get_sym_value(LLVMModuleRef module, struct symbol *sym)
285 const char *name = show_ident(sym->ident);
286 LLVMTypeRef type = symbol_type(sym);
290 assert(sym->bb_target == NULL);
292 expr = sym->initializer;
293 if (expr && !sym->ident) {
378 result = get_sym_value(fn->module, pseudo->sym);
1120 struct symbol *sym = ep->name;
1121 struct symbol *base_type = sym->ctype.base_type;
1127 function.fn = get_sym_value(module, sym);
1129 LLVMSetLinkage(function.fn, function_linkage(sym));
1190 static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym)
1192 struct expression *initializer = sym->initializer;
1200 initial_value = LLVMConstInt(symbol_type(sym), initializer->value, 1);
1203 initial_value = LLVMConstReal(symbol_type(sym), initializer->fvalue);
1206 struct symbol *sym = initializer->symbol;
1208 initial_value = LLVMGetNamedGlobal(module, show_ident(sym->ident));
1210 initial_value = output_data(module, sym);
1220 warning(initializer->pos, "can't initialize type: %s", show_typename(sym));
1225 LLVMTypeRef type = symbol_type(sym);
1233 name = sym->ident ? show_ident(sym->ident) : "" ;
1237 LLVMSetLinkage(data, data_linkage(sym));
1238 if (sym->ctype.modifiers & MOD_CONST)
1240 if (sym->ctype.modifiers & MOD_TLS)
1242 if (sym->ctype.alignment)
1243 LLVMSetAlignment(data, sym->ctype.alignment);
1245 if (!(sym->ctype.modifiers & MOD_EXTERN))
1251 static int is_prototype(struct symbol *sym)
1253 if (sym->type == SYM_NODE)
1254 sym = sym->ctype.base_type;
1255 return sym && sym->type == SYM_FN && !sym->stmt;
1260 struct symbol *sym;
1262 FOR_EACH_PTR(list, sym) {
1264 expand_symbol(sym);
1266 if (is_prototype(sym)) {
1268 get_sym_value(module, sym);
1272 ep = linearize_symbol(sym);
1276 output_data(module, sym);
1278 END_FOR_EACH_PTR(sym);