aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-03-15 14:37:39 +0000
committergingerBill <bill@gingerbill.org>2020-03-15 14:37:39 +0000
commit5169dc07c7c2d34e5170279433e6557d40b3afb8 (patch)
tree1c95438283dfda2e83795f76d785922c8dc1c471 /src/llvm_backend.cpp
parent18fb6a4be41f30de75b445266b958e153ecc16d9 (diff)
Fix `lb_add_proc_attribute_at_index`
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 3b3fe4985..7e7080f55 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -1082,10 +1082,21 @@ void lb_add_procedure_value(lbModule *m, lbProcedure *p) {
lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) {
- lbAddr res = lb_add_local_generated(p, t_string, false);
- lb_emit_store(p, lb_emit_struct_ep(p, res.addr, 0), str_elem);
- lb_emit_store(p, lb_emit_struct_ep(p, res.addr, 1), str_len);
- return lb_addr_load(p, res);
+ if (lb_is_const(str_elem) && lb_is_const(str_len)) {
+ LLVMValueRef values[2] = {
+ str_elem.value,
+ str_len.value,
+ };
+ lbValue res = {};
+ res.type = t_string;
+ res.value = LLVMConstNamedStruct(lb_type(p->module, t_string), values, gb_count_of(values));
+ return res;
+ } else {
+ lbAddr res = lb_add_local_generated(p, t_string, false);
+ lb_emit_store(p, lb_emit_struct_ep(p, res.addr, 0), str_elem);
+ lb_emit_store(p, lb_emit_struct_ep(p, res.addr, 1), str_len);
+ return lb_addr_load(p, res);
+ }
}
LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) {
@@ -1094,12 +1105,11 @@ LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name,
}
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value) {
- LLVMContextRef ctx = LLVMGetModuleContext(p->module->mod);
- // LLVMAddAttributeAtIndex(p->value, cast(unsigned)index, lb_create_enum_attribute(ctx, name, value));
+ LLVMAddAttributeAtIndex(p->value, cast(unsigned)index, lb_create_enum_attribute(p->module->ctx, name, value));
}
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) {
- lb_add_proc_attribute_at_index(p, index, name, true);
+ lb_add_proc_attribute_at_index(p, index, name, cast(u64)true);
}