diff --git a/README.md b/README.md index df8bf9dce..0a18b8834 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 8d4405765..0952768a5 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -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); } diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 6e05824c4..63e8be41c 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -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); diff --git a/wrapper/src/wrapper.cpp b/wrapper/src/wrapper.cpp index 2470fb2cb..49fdf8aee 100644 --- a/wrapper/src/wrapper.cpp +++ b/wrapper/src/wrapper.cpp @@ -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(ConstantVal);