stage2 - add llvm bindings to create attributes with string values

This commit is contained in:
Lee Cannon 2021-09-30 19:51:05 +01:00
parent 1e94221190
commit 023e4b9fed
2 changed files with 23 additions and 0 deletions

View File

@ -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);
}

View File

@ -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;