Commit 023e4b9fed
Changed files (2)
src
codegen
src/codegen/llvm/bindings.zig
@@ -28,6 +28,9 @@ pub const Context = opaque {
pub const createEnumAttribute = LLVMCreateEnumAttribute;
extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute;
+ pub const createStringAttribute = LLVMCreateStringAttribute;
+ extern fn LLVMCreateStringAttribute(*const Context, Key: [*]const u8, Key_Len: c_uint, Value: [*]const u8, Value_Len: c_uint) *const Attribute;
+
pub const intType = LLVMIntTypeInContext;
extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;
src/codegen/llvm.zig
@@ -1389,10 +1389,30 @@ pub const DeclGen = struct {
val.addAttributeAtIndex(index, llvm_attr);
}
+ fn addAttrString(
+ dg: *DeclGen,
+ val: *const llvm.Value,
+ index: llvm.AttributeIndex,
+ name: []const u8,
+ value: []const u8,
+ ) void {
+ const llvm_attr = dg.context.createStringAttribute(
+ name.ptr,
+ @intCast(c_uint, name.len),
+ value.ptr,
+ @intCast(c_uint, value.len),
+ );
+ val.addAttributeAtIndex(index, llvm_attr);
+ }
+
fn addFnAttr(dg: DeclGen, val: *const llvm.Value, name: []const u8) void {
dg.addAttr(val, std.math.maxInt(llvm.AttributeIndex), name);
}
+ fn addFnAttrString(dg: *DeclGen, val: *const llvm.Value, name: []const u8, value: []const u8) void {
+ dg.addAttrString(val, std.math.maxInt(llvm.AttributeIndex), name, value);
+ }
+
fn removeFnAttr(fn_val: *const llvm.Value, name: []const u8) void {
removeAttr(fn_val, std.math.maxInt(llvm.AttributeIndex), name);
}