mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
77 lines
2.9 KiB
C
77 lines
2.9 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] }
|
|
|
|
@"ct$foo_$anon" = linkonce constant %.introspect { i8 10, i64 16, i64 0, i64 4, [0 x i64] zeroinitializer }, align 8
|
|
@"ct$foo_$anon.3" = linkonce constant %.introspect { i8 11, i64 16, i64 0, i64 2, [0 x i64] zeroinitializer }, align 8
|
|
@"ct$foo_Matrix2x2" = linkonce constant %.introspect { i8 10, i64 16, i64 0, i64 1, [0 x i64] zeroinitializer }, align 8
|
|
@"ct$foo_$anon.6" = linkonce constant %.introspect { i8 10, i64 16, i64 0, i64 4, [0 x i64] zeroinitializer }, align 8
|
|
@"ct$foo_$anon.7" = linkonce constant %.introspect { i8 11, i64 16, i64 0, i64 2, [0 x i64] zeroinitializer }, align 8
|
|
@"ct$foo_Matrix2x2_b" = linkonce constant %.introspect { i8 10, i64 16, i64 0, i64 1, [0 x i64] zeroinitializer }, 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.8 = 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
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %m, ptr align 4 @.__const, i32 16, i1 false)
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %m2, ptr align 4 @.__const.8, i32 16, i1 false)
|
|
%0 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
|
|
%1 = getelementptr inbounds %.anon.0, ptr %0, i32 0, i32 0
|
|
%2 = load float, ptr %1, align 4
|
|
%fpfpext = fpext float %2 to double
|
|
%3 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
|
|
%4 = getelementptr inbounds [4 x float], ptr %3, i64 0, i64 1
|
|
%5 = load float, ptr %4, align 4
|
|
%fpfpext1 = fpext float %5 to double
|
|
%6 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
|
|
%7 = getelementptr inbounds %.anon.0, ptr %6, i32 0, i32 2
|
|
%8 = load float, ptr %7, align 4
|
|
%fpfpext2 = fpext float %8 to double
|
|
%9 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
|
|
%10 = getelementptr inbounds [4 x float], ptr %9, i64 0, i64 3
|
|
%11 = load float, ptr %10, align 4
|
|
%fpfpext3 = fpext float %11 to double
|
|
%12 = call i32 (ptr, ...) @printf(ptr @.str, double %fpfpext, double %fpfpext1, double %fpfpext2, double %fpfpext3)
|
|
ret void
|
|
}
|