stage2 llvm backend improvements working towards zig test

* properly set global variables to const if they are not a global
   variable.
 * implement global variable initializations.
 * initial implementation of llvmType() for structs and functions.
 * implement genTypedValue for variable tags
 * implement more AIR instructions: varptr, slice_ptr, slice_len,
   slice_elem_val, ptr_slice_elem_val, unwrap_errunion_payload,
   unwrap_errunion_payload_ptr, unwrap_errunion_err,
   unwrap_errunion_err_ptr.
This commit is contained in:
Andrew Kelley
2021-07-25 22:38:50 -07:00
parent c3d10dbda1
commit 14d8a1c10d
3 changed files with 211 additions and 32 deletions

View File

@@ -42,6 +42,9 @@ pub const Context = opaque {
Packed: Bool,
) *const Type;
const structCreateNamed = LLVMStructCreateNamed;
extern fn LLVMStructCreateNamed(C: *const Context, Name: [*:0]const u8) *const Type;
pub const constString = LLVMConstStringInContext;
extern fn LLVMConstStringInContext(C: *const Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *const Value;
@@ -76,6 +79,9 @@ pub const Value = opaque {
pub const typeOf = LLVMTypeOf;
extern fn LLVMTypeOf(Val: *const Value) *const Type;
pub const setGlobalConstant = LLVMSetGlobalConstant;
extern fn LLVMSetGlobalConstant(GlobalVar: *const Value, IsConstant: Bool) void;
};
pub const Type = opaque {
@@ -99,6 +105,14 @@ pub const Type = opaque {
pub const arrayType = LLVMArrayType;
extern fn LLVMArrayType(ElementType: *const Type, ElementCount: c_uint) *const Type;
pub const structSetBody = LLVMStructSetBody;
extern fn LLVMStructSetBody(
StructTy: *const Type,
ElementTypes: [*]*const Type,
ElementCount: c_uint,
Packed: Bool,
) void;
};
pub const Module = opaque {
@@ -257,7 +271,13 @@ pub const Builder = opaque {
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 Value, NumIndices: c_uint, Name: [*:0]const u8) *const Value;
extern fn LLVMBuildInBoundsGEP(
B: *const Builder,
Pointer: *const Value,
Indices: [*]const *const Value,
NumIndices: c_uint,
Name: [*:0]const u8,
) *const Value;
pub const buildICmp = LLVMBuildICmp;
extern fn LLVMBuildICmp(*const Builder, Op: IntPredicate, LHS: *const Value, RHS: *const Value, Name: [*:0]const u8) *const Value;