mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 00:35:10 +00:00
stage1: LLVM lowering to opaque pointers API
This commit is contained in:
parent
70d3912390
commit
0f793840ae
@ -858,7 +858,7 @@ endif()
|
||||
if(MSVC)
|
||||
set(EXE_CFLAGS "${EXE_CFLAGS}")
|
||||
else()
|
||||
set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces -Wno-comment -Wno-deprecated-declarations")
|
||||
set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces -Wno-comment")
|
||||
if(MINGW)
|
||||
set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")
|
||||
endif()
|
||||
|
||||
@ -31,6 +31,9 @@ pub const Context = opaque {
|
||||
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 pointerType = LLVMPointerTypeInContext;
|
||||
extern fn LLVMPointerTypeInContext(C: *const Context, AddressSpace: c_uint) *const Type;
|
||||
|
||||
pub const intType = LLVMIntTypeInContext;
|
||||
extern fn LLVMIntTypeInContext(C: *const Context, NumBits: c_uint) *const Type;
|
||||
|
||||
@ -138,8 +141,9 @@ pub const Value = opaque {
|
||||
pub const setAliasee = LLVMAliasSetAliasee;
|
||||
extern fn LLVMAliasSetAliasee(Alias: *const Value, Aliasee: *const Value) void;
|
||||
|
||||
pub const constInBoundsGEP = LLVMConstInBoundsGEP;
|
||||
extern fn LLVMConstInBoundsGEP(
|
||||
pub const constInBoundsGEP = LLVMConstInBoundsGEP2;
|
||||
extern fn LLVMConstInBoundsGEP2(
|
||||
Ty: *const Type,
|
||||
ConstantVal: *const Value,
|
||||
ConstantIndices: [*]const *const Value,
|
||||
NumIndices: c_uint,
|
||||
@ -276,9 +280,6 @@ pub const Type = opaque {
|
||||
pub const getUndef = LLVMGetUndef;
|
||||
extern fn LLVMGetUndef(Ty: *const Type) *const Value;
|
||||
|
||||
pub const pointerType = LLVMPointerType;
|
||||
extern fn LLVMPointerType(ElementType: *const Type, AddressSpace: c_uint) *const Type;
|
||||
|
||||
pub const arrayType = LLVMArrayType;
|
||||
extern fn LLVMArrayType(ElementType: *const Type, ElementCount: c_uint) *const Type;
|
||||
|
||||
@ -506,6 +507,7 @@ pub const Builder = opaque {
|
||||
pub const buildCall = ZigLLVMBuildCall;
|
||||
extern fn ZigLLVMBuildCall(
|
||||
*const Builder,
|
||||
*const Type,
|
||||
Fn: *const Value,
|
||||
Args: [*]const *const Value,
|
||||
NumArgs: c_uint,
|
||||
@ -529,8 +531,8 @@ pub const Builder = opaque {
|
||||
pub const buildStore = LLVMBuildStore;
|
||||
extern fn LLVMBuildStore(*const Builder, Val: *const Value, Ptr: *const Value) *const Value;
|
||||
|
||||
pub const buildLoad = LLVMBuildLoad;
|
||||
extern fn LLVMBuildLoad(*const Builder, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
|
||||
pub const buildLoad = LLVMBuildLoad2;
|
||||
extern fn LLVMBuildLoad2(*const Builder, Ty: *const Type, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
|
||||
|
||||
pub const buildNeg = LLVMBuildNeg;
|
||||
extern fn LLVMBuildNeg(*const Builder, V: *const Value, Name: [*:0]const u8) *const Value;
|
||||
@ -655,16 +657,7 @@ pub const Builder = opaque {
|
||||
pub const buildBitCast = LLVMBuildBitCast;
|
||||
extern fn LLVMBuildBitCast(*const Builder, Val: *const Value, DestTy: *const Type, Name: [*:0]const u8) *const Value;
|
||||
|
||||
pub const buildInBoundsGEP = LLVMBuildInBoundsGEP;
|
||||
extern fn LLVMBuildInBoundsGEP(
|
||||
B: *const Builder,
|
||||
Pointer: *const Value,
|
||||
Indices: [*]const *const Value,
|
||||
NumIndices: c_uint,
|
||||
Name: [*:0]const u8,
|
||||
) *const Value;
|
||||
|
||||
pub const buildInBoundsGEP2 = LLVMBuildInBoundsGEP2;
|
||||
pub const buildInBoundsGEP = LLVMBuildInBoundsGEP2;
|
||||
extern fn LLVMBuildInBoundsGEP2(
|
||||
B: *const Builder,
|
||||
Ty: *const Type,
|
||||
@ -741,9 +734,10 @@ pub const Builder = opaque {
|
||||
Name: [*:0]const u8,
|
||||
) *const Value;
|
||||
|
||||
pub const buildStructGEP = LLVMBuildStructGEP;
|
||||
extern fn LLVMBuildStructGEP(
|
||||
pub const buildStructGEP = LLVMBuildStructGEP2;
|
||||
extern fn LLVMBuildStructGEP2(
|
||||
B: *const Builder,
|
||||
Ty: *const Type,
|
||||
Pointer: *const Value,
|
||||
Idx: c_uint,
|
||||
Name: [*:0]const u8,
|
||||
|
||||
@ -2043,6 +2043,7 @@ struct CodeGen {
|
||||
LLVMValueRef wasm_memory_grow;
|
||||
LLVMValueRef prefetch;
|
||||
LLVMTypeRef anyframe_fn_type;
|
||||
LLVMTypeRef any_frame_header_llvm_ty;
|
||||
|
||||
// reminder: hash tables must be initialized before use
|
||||
HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> import_table;
|
||||
|
||||
@ -9746,6 +9746,7 @@ static void resolve_llvm_types_any_frame(CodeGen *g, ZigType *any_frame_type, Re
|
||||
|
||||
Buf *name = buf_sprintf("(%s header)", buf_ptr(&any_frame_type->name));
|
||||
LLVMTypeRef frame_header_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(name));
|
||||
g->any_frame_header_llvm_ty = frame_header_type;
|
||||
any_frame_type->llvm_type = LLVMPointerType(frame_header_type, 0);
|
||||
|
||||
unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -417,12 +417,13 @@ LLVMValueRef ZigLLVMAddFunctionInAddressSpace(LLVMModuleRef M, const char *Name,
|
||||
return wrap(func);
|
||||
}
|
||||
|
||||
LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
|
||||
unsigned NumArgs, ZigLLVM_CallingConv CC, ZigLLVM_CallAttr attr, const char *Name)
|
||||
LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
|
||||
LLVMValueRef *Args, unsigned NumArgs, ZigLLVM_CallingConv CC, ZigLLVM_CallAttr attr,
|
||||
const char *Name)
|
||||
{
|
||||
Value *V = unwrap(Fn);
|
||||
FunctionType *FnT = cast<FunctionType>(V->getType()->getNonOpaquePointerElementType());
|
||||
CallInst *call_inst = CallInst::Create(FnT, V, makeArrayRef(unwrap(Args), NumArgs), Name);
|
||||
FunctionType *FTy = unwrap<FunctionType>(Ty);
|
||||
CallInst *call_inst = unwrap(B)->CreateCall(FTy, unwrap(Fn), makeArrayRef(unwrap(Args),
|
||||
NumArgs), Name);
|
||||
call_inst->setCallingConv(static_cast<CallingConv::ID>(CC));
|
||||
switch (attr) {
|
||||
case ZigLLVM_CallAttrAuto:
|
||||
@ -440,7 +441,7 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
|
||||
call_inst->addFnAttr(Attribute::AlwaysInline);
|
||||
break;
|
||||
}
|
||||
return wrap(unwrap(B)->Insert(call_inst));
|
||||
return wrap(call_inst);
|
||||
}
|
||||
|
||||
LLVMValueRef ZigLLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign,
|
||||
|
||||
@ -125,8 +125,9 @@ enum ZigLLVM_CallAttr {
|
||||
ZigLLVM_CallAttrAlwaysTail,
|
||||
ZigLLVM_CallAttrAlwaysInline,
|
||||
};
|
||||
ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
|
||||
unsigned NumArgs, enum ZigLLVM_CallingConv CC, enum ZigLLVM_CallAttr attr, const char *Name);
|
||||
ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMTypeRef function_type,
|
||||
LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, enum ZigLLVM_CallingConv CC,
|
||||
enum ZigLLVM_CallAttr attr, const char *Name);
|
||||
|
||||
ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign,
|
||||
LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size, bool isVolatile);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user