mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Better compatibility with LLVM < 13 (#319)
* Update wrapper to add type attribute on LLVM < 13
This commit is contained in:
committed by
GitHub
parent
137b474f44
commit
df0b1df1df
@@ -122,6 +122,7 @@ to C3 and compiled with the c3c compiler:
|
||||
- [x] Subarray initializers
|
||||
- [x] `$switch`
|
||||
- [x] Windows support
|
||||
- [x] Bitstructs
|
||||
- [ ] Anonymous structs
|
||||
- [ ] Complete C ABI conformance *in progress*
|
||||
- [ ] Debug info *in progress*
|
||||
@@ -133,7 +134,6 @@ to C3 and compiled with the c3c compiler:
|
||||
- [ ] `global` / `shared` for globals
|
||||
- [ ] Escape macros
|
||||
- [ ] Implicit capturing macros
|
||||
- [ ] Bitstructs
|
||||
- [ ] `asm` section *in progress*
|
||||
- [ ] `$for`
|
||||
- [ ] Pre-post conditions
|
||||
|
||||
@@ -1100,11 +1100,7 @@ void llvm_attribute_add_int(GenContext *context, LLVMValueRef value_to_add_attri
|
||||
|
||||
void llvm_attribute_add_type(GenContext *c, LLVMValueRef value_to_add_attribute_to, unsigned attribute_id, LLVMTypeRef type, int index)
|
||||
{
|
||||
#if LLVM_VERSION_MAJOR < 13
|
||||
LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(c->context, attribute_id, 0);
|
||||
#else
|
||||
LLVMAttributeRef llvm_attr = LLVMCreateTypeAttribute(c->context, attribute_id, type);
|
||||
#endif
|
||||
LLVMAddAttributeAtIndex(value_to_add_attribute_to, index, llvm_attr);
|
||||
}
|
||||
|
||||
@@ -1115,11 +1111,7 @@ void llvm_attribute_add(GenContext *context, LLVMValueRef value_to_add_attribute
|
||||
|
||||
void llvm_attribute_add_call_type(GenContext *c, LLVMValueRef call, unsigned attribute_id, int index, LLVMTypeRef type)
|
||||
{
|
||||
#if LLVM_VERSION_MAJOR < 13
|
||||
LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(c->context, attribute_id, 0);
|
||||
#else
|
||||
LLVMAttributeRef llvm_attr = LLVMCreateTypeAttribute(c->context, attribute_id, type);
|
||||
#endif
|
||||
LLVMAddCallSiteAttribute(call, index, llvm_attr);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +187,10 @@ void gencontext_end_file_emit(GenContext *c, Context *ast);
|
||||
void gencontext_end_module(GenContext *context);
|
||||
|
||||
LLVMValueRef LLVMConstBswap(LLVMValueRef ConstantVal);
|
||||
#ifndef LLVMCreateTypeAttribute
|
||||
LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
|
||||
LLVMTypeRef type_ref);
|
||||
#endif
|
||||
|
||||
// BE value
|
||||
void llvm_value_addr(GenContext *c, BEValue *value);
|
||||
|
||||
@@ -111,6 +111,20 @@ static bool llvm_link(ObjFormat format, const char **args, int arg_count, const
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if LLVM_VERSION_MAJOR < 13
|
||||
#if _MSC_VER
|
||||
__declspec(selectany)
|
||||
#else
|
||||
__attribute__((weak))
|
||||
#endif
|
||||
LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
|
||||
LLVMTypeRef type_ref)
|
||||
{
|
||||
auto &Ctx = *llvm::unwrap(C);
|
||||
auto AttrKind = (llvm::Attribute::AttrKind)KindID;
|
||||
return wrap(llvm::Attribute::get(Ctx, AttrKind, llvm::unwrap(type_ref)));
|
||||
}
|
||||
#endif
|
||||
LLVMValueRef LLVMConstBswap(LLVMValueRef ConstantVal)
|
||||
{
|
||||
llvm::Constant *Val = llvm::unwrap<llvm::Constant>(ConstantVal);
|
||||
|
||||
Reference in New Issue
Block a user