mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
86 lines
3.2 KiB
C
86 lines
3.2 KiB
C
// #target: macos-x64
|
|
module foo;
|
|
import libc;
|
|
|
|
struct Matrix2x2
|
|
{
|
|
union
|
|
{
|
|
struct {
|
|
float m00, m01, m10, m11;
|
|
}
|
|
float[4] m;
|
|
}
|
|
}
|
|
|
|
struct Matrix2x2_b
|
|
{
|
|
union
|
|
{
|
|
float[4] m;
|
|
struct {
|
|
float m00, m01, m10, m11;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn void main()
|
|
{
|
|
Matrix2x2 m = { 1, 2, 3, 4 };
|
|
Matrix2x2_b m2 = { { 1, 2, 3, 4 } };
|
|
libc::printf("%f %f %f %f\n", m.m00, m.m[1], m.m10, m.m[3]);
|
|
}
|
|
/* #expect: foo.ll
|
|
|
|
%Matrix2x2 = type { %anon }
|
|
%anon = type { %anon.0 }
|
|
%anon.0 = type { float, float, float, float }
|
|
%Matrix2x2_b = type { %anon.1 }
|
|
%anon.1 = type { [4 x float] }
|
|
@.typeid.foo.anon = linkonce constant { i8, i64 } { i8 10, i64 4 }, align 8
|
|
@.typeid.foo.anon.1 = linkonce constant { i8, i64 } { i8 11, i64 2 }, align 8
|
|
@.typeid.foo.Matrix2x2 = linkonce constant { i8, i64 } { i8 10, i64 1 }, align 8
|
|
@.typeid.foo.anon.2 = linkonce constant { i8, i64 } { i8 10, i64 4 }, align 8
|
|
@.typeid.foo.anon.3 = linkonce constant { i8, i64 } { i8 11, i64 2 }, align 8
|
|
@.typeid.foo.Matrix2x2_b = linkonce constant { i8, i64 } { i8 10, i64 1 }, align 8
|
|
@.__const = private unnamed_addr constant %Matrix2x2 { %anon { %anon.0 { float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 } } }, align 4
|
|
@.__const.4 = private unnamed_addr constant %Matrix2x2_b { %anon.1 { [4 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00] } }, align 4
|
|
@.str = private unnamed_addr constant [13 x i8] c"%f %f %f %f\0A\00", align 1
|
|
; Function Attrs: nounwind
|
|
define void @foo.main() #0 {
|
|
entry:
|
|
%m = alloca %Matrix2x2, align 4
|
|
%m2 = alloca %Matrix2x2_b, align 4
|
|
%0 = bitcast %Matrix2x2* %m to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %0, i8* align 4 bitcast (%Matrix2x2* @.__const to i8*), i32 16, i1 false)
|
|
%1 = bitcast %Matrix2x2_b* %m2 to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Matrix2x2_b* @.__const.4 to i8*), i32 16, i1 false)
|
|
%2 = getelementptr inbounds %Matrix2x2, %Matrix2x2* %m, i32 0, i32 0
|
|
%3 = bitcast %anon* %2 to %anon.0*
|
|
%4 = getelementptr inbounds %anon.0, %anon.0* %3, i32 0, i32 0
|
|
%5 = load float, float* %4, align 4
|
|
%fpfpext = fpext float %5 to double
|
|
%6 = getelementptr inbounds %Matrix2x2, %Matrix2x2* %m, i32 0, i32 0
|
|
%7 = bitcast %anon* %6 to [4 x float]*
|
|
%8 = getelementptr inbounds [4 x float], [4 x float]* %7, i64 0, i64 1
|
|
%9 = load float, float* %8, align 4
|
|
%fpfpext1 = fpext float %9 to double
|
|
%10 = getelementptr inbounds %Matrix2x2, %Matrix2x2* %m, i32 0, i32 0
|
|
%11 = bitcast %anon* %10 to %anon.0*
|
|
%12 = getelementptr inbounds %anon.0, %anon.0* %11, i32 0, i32 2
|
|
%13 = load float, float* %12, align 4
|
|
%fpfpext2 = fpext float %13 to double
|
|
%14 = getelementptr inbounds %Matrix2x2, %Matrix2x2* %m, i32 0, i32 0
|
|
%15 = bitcast %anon* %14 to [4 x float]*
|
|
%16 = getelementptr inbounds [4 x float], [4 x float]* %15, i64 0, i64 3
|
|
%17 = load float, float* %16, align 4
|
|
%fpfpext3 = fpext float %17 to double
|
|
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), double %fpfpext, double %fpfpext1, double %fpfpext2, double %fpfpext3)
|
|
ret void
|
|
}
|
|
; Function Attrs: nounwind
|
|
define i32 @main(i32 %0, i8** %1) #0 {
|
|
entry:
|
|
call void @foo.main()
|
|
ret i32 0
|
|
}
|