authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-09-30 19:51:05+01:00
committergravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-10-16 21:55:51+01:00
log023e4b9fedbbd2e81ec684a359b040a3a6fd065e
tree6500ad412d9a063bd5245fc687c55b6c3c43ed11
parent1e942211901f0c8bc2f857b48dc8254e57a00ef4

stage2 - add llvm bindings to create attributes with string values


2 files changed, 23 insertions(+), 0 deletions(-)

src/codegen/llvm.zig+20
...@@ -1389,10 +1389,30 @@ pub const DeclGen = struct {...@@ -1389,10 +1389,30 @@ pub const DeclGen = struct {
1389 val.addAttributeAtIndex(index, llvm_attr);1389 val.addAttributeAtIndex(index, llvm_attr);
1390 }1390 }
13911391
1392 fn addAttrString(
1393 dg: *DeclGen,
1394 val: *const llvm.Value,
1395 index: llvm.AttributeIndex,
1396 name: []const u8,
1397 value: []const u8,
1398 ) void {
1399 const llvm_attr = dg.context.createStringAttribute(
1400 name.ptr,
1401 @intCast(c_uint, name.len),
1402 value.ptr,
1403 @intCast(c_uint, value.len),
1404 );
1405 val.addAttributeAtIndex(index, llvm_attr);
1406 }
1407
1392 fn addFnAttr(dg: DeclGen, val: *const llvm.Value, name: []const u8) void {1408 fn addFnAttr(dg: DeclGen, val: *const llvm.Value, name: []const u8) void {
1393 dg.addAttr(val, std.math.maxInt(llvm.AttributeIndex), name);1409 dg.addAttr(val, std.math.maxInt(llvm.AttributeIndex), name);
1394 }1410 }
13951411
1412 fn addFnAttrString(dg: *DeclGen, val: *const llvm.Value, name: []const u8, value: []const u8) void {
1413 dg.addAttrString(val, std.math.maxInt(llvm.AttributeIndex), name, value);
1414 }
1415
1396 fn removeFnAttr(fn_val: *const llvm.Value, name: []const u8) void {1416 fn removeFnAttr(fn_val: *const llvm.Value, name: []const u8) void {
1397 removeAttr(fn_val, std.math.maxInt(llvm.AttributeIndex), name);1417 removeAttr(fn_val, std.math.maxInt(llvm.AttributeIndex), name);
1398 }1418 }
src/codegen/llvm/bindings.zig+3
...@@ -28,6 +28,9 @@ pub const Context = opaque {...@@ -28,6 +28,9 @@ pub const Context = opaque {
28 pub const createEnumAttribute = LLVMCreateEnumAttribute;28 pub const createEnumAttribute = LLVMCreateEnumAttribute;
29 extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute;29 extern fn LLVMCreateEnumAttribute(*const Context, KindID: c_uint, Val: u64) *const Attribute;
3030
31 pub const createStringAttribute = LLVMCreateStringAttribute;
32 extern fn LLVMCreateStringAttribute(*const Context, Key: [*]const u8, Key_Len: c_uint, Value: [*]const u8, Value_Len: c_uint) *const Attribute;
33
31 pub const intType = LLVMIntTypeInContext;34 pub const intType = LLVMIntTypeInContext;
32 extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;35 extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;
3336