| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | #include <stdio.h> |
| 5 | 5 | |
| 6 | 6 | #include <llvm-c/Core.h> |
| 7 | #include <llvm-c/Analysis.h> |
| 7 | 8 | |
| 8 | 9 | struct FnTableEntry { |
| 9 | 10 | LLVMValueRef fn_value; |
| ... | ... | @@ -235,9 +236,10 @@ static LLVMValueRef find_or_create_string(CodeGen *g, Buf *str) { |
| 235 | 236 | } |
| 236 | 237 | LLVMValueRef text = LLVMConstString(buf_ptr(str), buf_len(str), false); |
| 237 | 238 | LLVMValueRef global_value = LLVMAddGlobal(g->mod, LLVMTypeOf(text), ""); |
| 238 | | LLVMSetLinkage(global_value, LLVMInternalLinkage); |
| 239 | LLVMSetLinkage(global_value, LLVMPrivateLinkage); |
| 239 | 240 | LLVMSetInitializer(global_value, text); |
| 240 | 241 | LLVMSetGlobalConstant(global_value, true); |
| 242 | LLVMSetUnnamedAddr(global_value, true); |
| 241 | 243 | g->str_table.put(str, global_value); |
| 242 | 244 | |
| 243 | 245 | return global_value; |
| ... | ... | @@ -257,8 +259,15 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *expr_node) { |
| 257 | 259 | case AstNodeExpressionTypeString: |
| 258 | 260 | { |
| 259 | 261 | Buf *str = &expr_node->data.expression.data.string; |
| 260 | | fprintf(stderr, "str = '%s'\n", buf_ptr(str)); |
| 261 | | return find_or_create_string(g, str); |
| 262 | LLVMValueRef str_val = find_or_create_string(g, str); |
| 263 | LLVMValueRef indices[] = { |
| 264 | LLVMConstInt(LLVMInt32Type(), 0, false), |
| 265 | LLVMConstInt(LLVMInt32Type(), 0, false) |
| 266 | }; |
| 267 | LLVMValueRef ptr_val = LLVMBuildInBoundsGEP(g->builder, str_val, |
| 268 | indices, 2, ""); |
| 269 | |
| 270 | return ptr_val; |
| 262 | 271 | } |
| 263 | 272 | case AstNodeExpressionTypeFnCall: |
| 264 | 273 | return gen_fn_call(g, expr_node->data.expression.data.fn_call); |
| ... | ... | @@ -322,6 +331,9 @@ void code_gen(CodeGen *g) { |
| 322 | 331 | } |
| 323 | 332 | |
| 324 | 333 | LLVMDumpModule(g->mod); |
| 334 | |
| 335 | char *error = nullptr; |
| 336 | LLVMVerifyModule(g->mod, LLVMAbortProcessAction, &error); |
| 325 | 337 | } |
| 326 | 338 | |
| 327 | 339 | ZigList<ErrorMsg> *codegen_error_messages(CodeGen *g) { |