mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Bitstruct implementation.
This commit is contained in:
committed by
Christoffer Lerno
parent
29e7af843a
commit
4f09b0c351
15
test/test_suite/bitstruct/address_of_bitstruct.c3
Normal file
15
test/test_suite/bitstruct/address_of_bitstruct.c3
Normal file
@@ -0,0 +1,15 @@
|
||||
bitstruct BitField : char
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 4..5;
|
||||
int c : 6..7;
|
||||
}
|
||||
|
||||
fn void test()
|
||||
{
|
||||
BitField x;
|
||||
BitField* z = &x;
|
||||
x.a;
|
||||
z.a;
|
||||
&x.a; // #error: You cannot take the address of a bitstruct member
|
||||
}
|
||||
71
test/test_suite/bitstruct/array_with_boolean.c3t
Normal file
71
test/test_suite/bitstruct/array_with_boolean.c3t
Normal file
@@ -0,0 +1,71 @@
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitField : char[3]
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 3..8;
|
||||
int c : 9..18;
|
||||
bool d : 19;
|
||||
bool e : 20;
|
||||
}
|
||||
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
BitField xx = { 2, 3, 15, true, false };
|
||||
BitField xy = { 2, 3, 15, false, true };
|
||||
printf("%x, %x, %x, %d, %d\n", xx.a, xx.b, xx.c, xx.d, xx.e);
|
||||
}
|
||||
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
%xx = alloca [3 x i8], align 1
|
||||
%xy = alloca [3 x i8], align 1
|
||||
store [3 x i8] c"\1A\1E\08", [3 x i8]* %xx, align 1
|
||||
store [3 x i8] c"\1A\1E\10", [3 x i8]* %xy, align 1
|
||||
%0 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 0
|
||||
%1 = load i8, i8* %0, align 1
|
||||
%2 = zext i8 %1 to i32
|
||||
%3 = shl i32 %2, 29
|
||||
%4 = ashr i32 %3, 29
|
||||
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 0
|
||||
%6 = load i8, i8* %5, align 1
|
||||
%7 = zext i8 %6 to i32
|
||||
%8 = lshr i32 %7, 3
|
||||
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 1
|
||||
%10 = load i8, i8* %9, align 1
|
||||
%11 = zext i8 %10 to i32
|
||||
%12 = shl i32 %11, 5
|
||||
%13 = or i32 %12, %8
|
||||
%14 = shl i32 %13, 26
|
||||
%15 = ashr i32 %14, 26
|
||||
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 1
|
||||
%17 = load i8, i8* %16, align 1
|
||||
%18 = zext i8 %17 to i32
|
||||
%19 = lshr i32 %18, 1
|
||||
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 2
|
||||
%21 = load i8, i8* %20, align 1
|
||||
%22 = zext i8 %21 to i32
|
||||
%23 = shl i32 %22, 7
|
||||
%24 = or i32 %23, %19
|
||||
%25 = shl i32 %24, 22
|
||||
%26 = ashr i32 %25, 22
|
||||
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 2
|
||||
%28 = load i8, i8* %27, align 1
|
||||
%29 = lshr i8 %28, 3
|
||||
%30 = trunc i8 %29 to i1
|
||||
%boolsi = zext i1 %30 to i32
|
||||
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 2
|
||||
%32 = load i8, i8* %31, align 1
|
||||
%33 = lshr i8 %32, 4
|
||||
%34 = trunc i8 %33 to i1
|
||||
%boolsi1 = zext i1 %34 to i32
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), i32 %4, i32 %15, i32 %26, i32 %boolsi, i32 %boolsi1)
|
||||
ret void
|
||||
}
|
||||
180
test/test_suite/bitstruct/bitfield_access.c3t
Normal file
180
test/test_suite/bitstruct/bitfield_access.c3t
Normal file
@@ -0,0 +1,180 @@
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitField : char
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 4..5;
|
||||
int c : 6..7;
|
||||
}
|
||||
|
||||
bitstruct BitFieldI : ushort
|
||||
{
|
||||
int a : 0..4;
|
||||
int b : 5..10;
|
||||
int c : 11..15;
|
||||
}
|
||||
|
||||
|
||||
struct Packet
|
||||
{
|
||||
bitstruct : int
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 3..5;
|
||||
int c : 6..10;
|
||||
}
|
||||
int packet_id;
|
||||
}
|
||||
|
||||
bitstruct BitField3 : char[3]
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 3..8;
|
||||
int c : 9..18;
|
||||
int d : 19..23;
|
||||
}
|
||||
|
||||
bitstruct BitField3u : char[3]
|
||||
{
|
||||
uint a : 0..2;
|
||||
uint b : 3..8;
|
||||
uint c : 9..18;
|
||||
uint d : 19..23;
|
||||
}
|
||||
|
||||
bitstruct BitField4 : char[3]
|
||||
{
|
||||
int a : 0..2;
|
||||
int b : 3..7;
|
||||
int c : 8..15;
|
||||
int d : 16..19;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCross : char[5]
|
||||
{
|
||||
uint a : 5..22;
|
||||
}
|
||||
|
||||
BitField c = { 2, 4, 5 };
|
||||
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
BitField b = { 5, -3, 1 };
|
||||
BitFieldI c1 = { 5, 0, 0 };
|
||||
BitFieldI c2 = { 0, 3, 0 };
|
||||
BitFieldI c3 = { 0, 0, 9 };
|
||||
BitFieldI c4 = { -5, 7, 9 };
|
||||
BitFieldI c5 = { -5, 0, 0 };
|
||||
BitFieldI c6 = { 5, 0, 0 };
|
||||
BitFieldI c7 = { 0, 0, 5 };
|
||||
|
||||
BitField3 e1 = { 3, 1, 3, 4 };
|
||||
BitField3 e2 = { 4, 1, 3, 4 };
|
||||
BitField3 e3 = { 5, 1, 3, 4 };
|
||||
BitField d = { };
|
||||
|
||||
printf("%d\n", e1.a);
|
||||
printf("%d\n", e2.a);
|
||||
printf("%d\n", e3.a);
|
||||
|
||||
BitField3u z1 = { 3, 1, 3, 4 };
|
||||
BitField3u z2 = { 4, 1, 3, 4 };
|
||||
BitField3u z3 = { 9, 1, 3, 4 };
|
||||
printf("%u\n", z1.a);
|
||||
printf("%u\n", z2.a);
|
||||
printf("%u\n", z3.a);
|
||||
BitFieldCross xx = { 0x12345678 };
|
||||
printf("%x\n", xx.a);
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
%b = alloca i8, align 1
|
||||
%c1 = alloca i16, align 2
|
||||
%c2 = alloca i16, align 2
|
||||
%c3 = alloca i16, align 2
|
||||
%c4 = alloca i16, align 2
|
||||
%c5 = alloca i16, align 2
|
||||
%c6 = alloca i16, align 2
|
||||
%c7 = alloca i16, align 2
|
||||
%e1 = alloca [3 x i8], align 1
|
||||
%e2 = alloca [3 x i8], align 1
|
||||
%e3 = alloca [3 x i8], align 1
|
||||
%d = alloca i8, align 1
|
||||
%z1 = alloca [3 x i8], align 1
|
||||
%z2 = alloca [3 x i8], align 1
|
||||
%z3 = alloca [3 x i8], align 1
|
||||
%xx = alloca [5 x i8], align 1
|
||||
store i8 85, i8* %b, align 1
|
||||
store i16 5, i16* %c1, align 2
|
||||
store i16 96, i16* %c2, align 2
|
||||
store i16 18432, i16* %c3, align 2
|
||||
store i16 18683, i16* %c4, align 2
|
||||
store i16 27, i16* %c5, align 2
|
||||
store i16 5, i16* %c6, align 2
|
||||
store i16 10240, i16* %c7, align 2
|
||||
store [3 x i8] c"\0B\06 ", [3 x i8]* %e1, align 1
|
||||
store [3 x i8] c"\0C\06 ", [3 x i8]* %e2, align 1
|
||||
store [3 x i8] c"\0D\06 ", [3 x i8]* %e3, align 1
|
||||
store i8 0, i8* %d, align 1
|
||||
%0 = getelementptr inbounds [3 x i8], [3 x i8]* %e1, i64 0, i64 0
|
||||
%1 = load i8, i8* %0, align 1
|
||||
%2 = zext i8 %1 to i32
|
||||
%3 = shl i32 %2, 29
|
||||
%4 = ashr i32 %3, 29
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %4)
|
||||
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %e2, i64 0, i64 0
|
||||
%6 = load i8, i8* %5, align 1
|
||||
%7 = zext i8 %6 to i32
|
||||
%8 = shl i32 %7, 29
|
||||
%9 = ashr i32 %8, 29
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %9)
|
||||
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %e3, i64 0, i64 0
|
||||
%11 = load i8, i8* %10, align 1
|
||||
%12 = zext i8 %11 to i32
|
||||
%13 = shl i32 %12, 29
|
||||
%14 = ashr i32 %13, 29
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i32 %14)
|
||||
store [3 x i8] c"\0B\06 ", [3 x i8]* %z1, align 1
|
||||
store [3 x i8] c"\0C\06 ", [3 x i8]* %z2, align 1
|
||||
store [3 x i8] c"\09\06 ", [3 x i8]* %z3, align 1
|
||||
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %z1, i64 0, i64 0
|
||||
%16 = load i8, i8* %15, align 1
|
||||
%17 = zext i8 %16 to i32
|
||||
%18 = and i32 7, %17
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %18)
|
||||
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %z2, i64 0, i64 0
|
||||
%20 = load i8, i8* %19, align 1
|
||||
%21 = zext i8 %20 to i32
|
||||
%22 = and i32 7, %21
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i32 %22)
|
||||
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %z3, i64 0, i64 0
|
||||
%24 = load i8, i8* %23, align 1
|
||||
%25 = zext i8 %24 to i32
|
||||
%26 = and i32 7, %25
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i32 %26)
|
||||
store [5 x i8] c"\00\CF\0A\00\00", [5 x i8]* %xx, align 1
|
||||
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %xx, i64 0, i64 0
|
||||
%28 = load i8, i8* %27, align 1
|
||||
%29 = zext i8 %28 to i32
|
||||
%30 = lshr i32 %29, 5
|
||||
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %xx, i64 0, i64 1
|
||||
%32 = load i8, i8* %31, align 1
|
||||
%33 = zext i8 %32 to i32
|
||||
%34 = shl i32 %33, 3
|
||||
%35 = or i32 %34, %30
|
||||
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %xx, i64 0, i64 2
|
||||
%37 = load i8, i8* %36, align 1
|
||||
%38 = zext i8 %37 to i32
|
||||
%39 = shl i32 %38, 11
|
||||
%40 = or i32 %39, %35
|
||||
%41 = and i32 262143, %40
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i32 %41)
|
||||
ret void
|
||||
}
|
||||
92
test/test_suite/bitstruct/bitstruct_access_signed.c3t
Normal file
92
test/test_suite/bitstruct/bitstruct_access_signed.c3t
Normal file
@@ -0,0 +1,92 @@
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitFieldCross : char[3]
|
||||
{
|
||||
uint d : 0..4;
|
||||
int a : 5..22;
|
||||
uint c : 23..23;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossU : char[3]
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..23;
|
||||
}
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
BitFieldCross xx = { 0, -177, 0 };
|
||||
printf("%d\n", xx.a);
|
||||
xx = { 0xff, -177, 0xff };
|
||||
printf("%d\n", xx.a);
|
||||
BitFieldCrossU xxu = { 0xff, 0x12345678, 0xff };
|
||||
printf("%x\n", xxu.a);
|
||||
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
%xx = alloca [3 x i8], align 1
|
||||
%xxu = alloca [3 x i8], align 1
|
||||
store [3 x i8] c"\E0\E9\7F", [3 x i8]* %xx, align 1
|
||||
%0 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 0
|
||||
%1 = load i8, i8* %0, align 1
|
||||
%2 = zext i8 %1 to i32
|
||||
%3 = lshr i32 %2, 5
|
||||
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 1
|
||||
%5 = load i8, i8* %4, align 1
|
||||
%6 = zext i8 %5 to i32
|
||||
%7 = shl i32 %6, 3
|
||||
%8 = or i32 %7, %3
|
||||
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 2
|
||||
%10 = load i8, i8* %9, align 1
|
||||
%11 = zext i8 %10 to i32
|
||||
%12 = shl i32 %11, 11
|
||||
%13 = or i32 %12, %8
|
||||
%14 = shl i32 %13, 14
|
||||
%15 = ashr i32 %14, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %15)
|
||||
store [3 x i8] c"\FF\E9\FF", [3 x i8]* %xx, align 1
|
||||
%16 = load [3 x i8], [3 x i8]* %xx, align 1
|
||||
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 0
|
||||
%18 = load i8, i8* %17, align 1
|
||||
%19 = zext i8 %18 to i32
|
||||
%20 = lshr i32 %19, 5
|
||||
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 1
|
||||
%22 = load i8, i8* %21, align 1
|
||||
%23 = zext i8 %22 to i32
|
||||
%24 = shl i32 %23, 3
|
||||
%25 = or i32 %24, %20
|
||||
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %xx, i64 0, i64 2
|
||||
%27 = load i8, i8* %26, align 1
|
||||
%28 = zext i8 %27 to i32
|
||||
%29 = shl i32 %28, 11
|
||||
%30 = or i32 %29, %25
|
||||
%31 = shl i32 %30, 14
|
||||
%32 = ashr i32 %31, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %32)
|
||||
store [3 x i8] c"\1F\CF\8A", [3 x i8]* %xxu, align 1
|
||||
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %xxu, i64 0, i64 0
|
||||
%34 = load i8, i8* %33, align 1
|
||||
%35 = zext i8 %34 to i32
|
||||
%36 = lshr i32 %35, 5
|
||||
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %xxu, i64 0, i64 1
|
||||
%38 = load i8, i8* %37, align 1
|
||||
%39 = zext i8 %38 to i32
|
||||
%40 = shl i32 %39, 3
|
||||
%41 = or i32 %40, %36
|
||||
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %xxu, i64 0, i64 2
|
||||
%43 = load i8, i8* %42, align 1
|
||||
%44 = zext i8 %43 to i32
|
||||
%45 = shl i32 %44, 11
|
||||
%46 = or i32 %45, %41
|
||||
%47 = and i32 262143, %46
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i32 %47)
|
||||
ret void
|
||||
}
|
||||
1146
test/test_suite/bitstruct/bitstruct_arrays.c3t
Normal file
1146
test/test_suite/bitstruct/bitstruct_arrays.c3t
Normal file
File diff suppressed because it is too large
Load Diff
146
test/test_suite/bitstruct/bitstruct_arrays_be.c3t
Normal file
146
test/test_suite/bitstruct/bitstruct_arrays_be.c3t
Normal file
@@ -0,0 +1,146 @@
|
||||
// #target: x64-darwin
|
||||
module foo;
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitField3 : char[4] @bigendian
|
||||
{
|
||||
uint c : 4..19;
|
||||
}
|
||||
|
||||
bitstruct BitField4 : char[4]
|
||||
{
|
||||
uint c : 4..19;
|
||||
}
|
||||
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
test3();
|
||||
}
|
||||
fn void test3()
|
||||
{
|
||||
//BitField3 xx = { 0xdeadbeef };
|
||||
BitField3 xx = { 0xbeaf };
|
||||
printf("%x = beaf\n", xx.c);
|
||||
BitField4 xy = { 0xbeaf };
|
||||
void *abc = &xy;
|
||||
char[4]* z = abc;
|
||||
printf("%x = beaf\n", xy.c);
|
||||
xy.c = 0xbeef;
|
||||
printf("%x = beef\n", xy.c);
|
||||
xx.c = 0xbeef;
|
||||
printf("%x = beef\n", xx.c);
|
||||
}
|
||||
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @foo.test3() #0 {
|
||||
entry:
|
||||
%xx = alloca [4 x i8], align 1
|
||||
%xy = alloca [4 x i8], align 1
|
||||
%abc = alloca i8*, align 8
|
||||
%z = alloca [4 x i8]*, align 8
|
||||
store [4 x i8] c"\E0\FB\0A\00", [4 x i8]* %xx, align 1
|
||||
%0 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 0
|
||||
%1 = load i8, i8* %0, align 1
|
||||
%2 = zext i8 %1 to i32
|
||||
%3 = lshr i32 %2, 4
|
||||
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 1
|
||||
%5 = load i8, i8* %4, align 1
|
||||
%6 = zext i8 %5 to i32
|
||||
%7 = shl i32 %6, 4
|
||||
%8 = or i32 %7, %3
|
||||
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 2
|
||||
%10 = load i8, i8* %9, align 1
|
||||
%11 = zext i8 %10 to i32
|
||||
%12 = shl i32 %11, 12
|
||||
%13 = or i32 %12, %8
|
||||
%14 = shl i32 %13, 16
|
||||
%15 = call i32 @llvm.bswap.i32(i32 %14)
|
||||
%16 = and i32 65535, %15
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 %16)
|
||||
store [4 x i8] c"\F0\EA\0B\00", [4 x i8]* %xy, align 1
|
||||
%ptrptr = bitcast [4 x i8]* %xy to i8*
|
||||
store i8* %ptrptr, i8** %abc, align 8
|
||||
%17 = load i8*, i8** %abc, align 8
|
||||
%ptrptr1 = bitcast i8* %17 to [4 x i8]*
|
||||
store [4 x i8]* %ptrptr1, [4 x i8]** %z, align 8
|
||||
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 0
|
||||
%19 = load i8, i8* %18, align 1
|
||||
%20 = zext i8 %19 to i32
|
||||
%21 = lshr i32 %20, 4
|
||||
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 1
|
||||
%23 = load i8, i8* %22, align 1
|
||||
%24 = zext i8 %23 to i32
|
||||
%25 = shl i32 %24, 4
|
||||
%26 = or i32 %25, %21
|
||||
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 2
|
||||
%28 = load i8, i8* %27, align 1
|
||||
%29 = zext i8 %28 to i32
|
||||
%30 = shl i32 %29, 12
|
||||
%31 = or i32 %30, %26
|
||||
%32 = and i32 65535, %31
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 %32)
|
||||
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 0
|
||||
%34 = load i8, i8* %33, align 1
|
||||
%35 = and i8 %34, 15
|
||||
%36 = or i8 %35, -16
|
||||
store i8 %36, i8* %33, align 1
|
||||
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 1
|
||||
store i8 -18, i8* %37, align 1
|
||||
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 2
|
||||
%39 = load i8, i8* %38, align 1
|
||||
%40 = and i8 %39, -16
|
||||
%41 = or i8 %40, 11
|
||||
store i8 %41, i8* %38, align 1
|
||||
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 0
|
||||
%43 = load i8, i8* %42, align 1
|
||||
%44 = zext i8 %43 to i32
|
||||
%45 = lshr i32 %44, 4
|
||||
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 1
|
||||
%47 = load i8, i8* %46, align 1
|
||||
%48 = zext i8 %47 to i32
|
||||
%49 = shl i32 %48, 4
|
||||
%50 = or i32 %49, %45
|
||||
%51 = getelementptr inbounds [4 x i8], [4 x i8]* %xy, i64 0, i64 2
|
||||
%52 = load i8, i8* %51, align 1
|
||||
%53 = zext i8 %52 to i32
|
||||
%54 = shl i32 %53, 12
|
||||
%55 = or i32 %54, %50
|
||||
%56 = and i32 65535, %55
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i32 %56)
|
||||
%57 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 0
|
||||
%58 = load i8, i8* %57, align 1
|
||||
%59 = and i8 %58, 15
|
||||
%60 = or i8 %59, -32
|
||||
store i8 %60, i8* %57, align 1
|
||||
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 1
|
||||
store i8 -5, i8* %61, align 1
|
||||
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 2
|
||||
%63 = load i8, i8* %62, align 1
|
||||
%64 = and i8 %63, -16
|
||||
%65 = or i8 %64, 14
|
||||
store i8 %65, i8* %62, align 1
|
||||
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 0
|
||||
%67 = load i8, i8* %66, align 1
|
||||
%68 = zext i8 %67 to i32
|
||||
%69 = lshr i32 %68, 4
|
||||
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 1
|
||||
%71 = load i8, i8* %70, align 1
|
||||
%72 = zext i8 %71 to i32
|
||||
%73 = shl i32 %72, 4
|
||||
%74 = or i32 %73, %69
|
||||
%75 = getelementptr inbounds [4 x i8], [4 x i8]* %xx, i64 0, i64 2
|
||||
%76 = load i8, i8* %75, align 1
|
||||
%77 = zext i8 %76 to i32
|
||||
%78 = shl i32 %77, 12
|
||||
%79 = or i32 %78, %74
|
||||
%80 = shl i32 %79, 16
|
||||
%81 = call i32 @llvm.bswap.i32(i32 %80)
|
||||
%82 = and i32 65535, %81
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i32 %82)
|
||||
ret void
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
// #skip
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
|
||||
bitstruct BitField
|
||||
{
|
||||
int a : 3;
|
||||
int b : 3;
|
||||
int c : 2;
|
||||
{// #error: followed by bitstruct type
|
||||
int a : 0..2;
|
||||
int b : 4..6;
|
||||
int c : 7..8;
|
||||
}
|
||||
|
||||
|
||||
bitstruct BitField2 : char
|
||||
{
|
||||
int a : 3;
|
||||
int b : 3;
|
||||
int c : 2;
|
||||
int a : 0..2;
|
||||
int b : 4..6;
|
||||
int c : 7..8;
|
||||
}
|
||||
|
||||
struct Packet
|
||||
@@ -31,17 +31,16 @@ struct Packet
|
||||
|
||||
bitstruct BitField3 : char[3]
|
||||
{
|
||||
int a : 3;
|
||||
int b : 6;
|
||||
int c : 10;
|
||||
int d : 5;
|
||||
int a : 0..2;
|
||||
int b : 3..8;
|
||||
int c : 9..18;
|
||||
int d : 19..23;
|
||||
}
|
||||
|
||||
bitstruct BitField3 : char[3] @aligned
|
||||
bitstruct BitField4 : char[3] @aligned
|
||||
{
|
||||
int a : 3;
|
||||
int b : 5;
|
||||
int c : 8;
|
||||
int d : 5;
|
||||
void : 5;
|
||||
int a : 0..2;
|
||||
int b : 3..7;
|
||||
int c : 8..15;
|
||||
int d : 16..19;
|
||||
}
|
||||
|
||||
106
test/test_suite/bitstruct/bitstruct_intcontainer.c3t
Normal file
106
test/test_suite/bitstruct/bitstruct_intcontainer.c3t
Normal file
@@ -0,0 +1,106 @@
|
||||
// #target: x64-darwin
|
||||
|
||||
module foo;
|
||||
|
||||
bitstruct BitFieldCross : uint
|
||||
{
|
||||
uint d : 0..4;
|
||||
int a : 5..22;
|
||||
uint c : 23..31;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossU : int
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..31;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossUL : long
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..40;
|
||||
uint e : 41..61;
|
||||
}
|
||||
|
||||
bitstruct BitFieldCrossULBE : long @bigendian
|
||||
{
|
||||
uint d : 0..4;
|
||||
uint a : 5..22;
|
||||
uint c : 23..40;
|
||||
uint e : 41..61;
|
||||
}
|
||||
extern fn void printf(char*, ...);
|
||||
|
||||
fn void main()
|
||||
{
|
||||
BitFieldCross xx = { 0, -177, 0 };
|
||||
printf("%d\n", xx.a);
|
||||
xx = { 0xff, -177, 0xff };
|
||||
printf("%d\n", xx.a);
|
||||
BitFieldCrossU xxu = { 0xff, 0x12345678, 0xffffffff };
|
||||
printf("%x\n", xxu.a);
|
||||
BitFieldCrossUL xxy = { 0xff, 0x12345678, 0xefff_fffe, 0xfdca9597 };
|
||||
printf("%x, %x, %x\n", xxy.a, xxy.c, xxy.e);
|
||||
BitFieldCrossULBE xxybe = { 0xff, 0x12345678, 0xefff_fffe, 0xfdca9597 };
|
||||
printf("%x, %x, %x\n", xxybe.a, xxybe.c, xxybe.e);
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
define void @main() #0 {
|
||||
entry:
|
||||
%xx = alloca i32, align 4
|
||||
%xxu = alloca i32, align 4
|
||||
%xxy = alloca i64, align 8
|
||||
%xxybe = alloca i64, align 8
|
||||
store i32 8382944, i32* %xx, align 4
|
||||
%0 = load i32, i32* %xx, align 4
|
||||
%1 = shl i32 %0, 9
|
||||
%2 = ashr i32 %1, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %2)
|
||||
store i32 2147478015, i32* %xx, align 4
|
||||
%3 = load i32, i32* %xx, align 4
|
||||
%4 = load i32, i32* %xx, align 4
|
||||
%5 = shl i32 %4, 9
|
||||
%6 = ashr i32 %5, 14
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %6)
|
||||
store i32 -7680225, i32* %xxu, align 4
|
||||
%7 = load i32, i32* %xxu, align 4
|
||||
%8 = lshr i32 %7, 5
|
||||
%9 = and i32 %8, 524287
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i32 %9)
|
||||
store i64 1525365675337109279, i64* %xxy, align 8
|
||||
%10 = load i64, i64* %xxy, align 8
|
||||
%11 = lshr i64 %10, 5
|
||||
%12 = and i64 %11, 524287
|
||||
%13 = trunc i64 %12 to i32
|
||||
%14 = load i64, i64* %xxy, align 8
|
||||
%15 = lshr i64 %14, 23
|
||||
%16 = and i64 %15, 524287
|
||||
%17 = trunc i64 %16 to i32
|
||||
%18 = load i64, i64* %xxy, align 8
|
||||
%19 = lshr i64 %18, 41
|
||||
%20 = and i64 %19, 4194303
|
||||
%21 = trunc i64 %20 to i32
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i32 0, i32 0), i32 %13, i32 %17, i32 %21)
|
||||
store i64 2292062829969091349, i64* %xxybe, align 8
|
||||
%22 = load i64, i64* %xxybe, align 8
|
||||
%23 = call i64 @llvm.bswap.i64(i64 %22)
|
||||
%24 = lshr i64 %23, 5
|
||||
%25 = and i64 %24, 524287
|
||||
%26 = trunc i64 %25 to i32
|
||||
%27 = load i64, i64* %xxybe, align 8
|
||||
%28 = call i64 @llvm.bswap.i64(i64 %27)
|
||||
%29 = lshr i64 %28, 23
|
||||
%30 = and i64 %29, 524287
|
||||
%31 = trunc i64 %30 to i32
|
||||
%32 = load i64, i64* %xxybe, align 8
|
||||
%33 = call i64 @llvm.bswap.i64(i64 %32)
|
||||
%34 = lshr i64 %33, 41
|
||||
%35 = and i64 %34, 4194303
|
||||
%36 = trunc i64 %35 to i32
|
||||
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0), i32 %26, i32 %31, i32 %36)
|
||||
ret void
|
||||
}
|
||||
47
test/test_suite/bitstruct/bitstruct_overlap.c3
Normal file
47
test/test_suite/bitstruct/bitstruct_overlap.c3
Normal file
@@ -0,0 +1,47 @@
|
||||
bitstruct Foo1 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 5..6; // #error: Overlapping members
|
||||
}
|
||||
|
||||
bitstruct Foo2 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 4..6; // #error: Overlapping members
|
||||
}
|
||||
|
||||
bitstruct Foo3 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 2..6; // #error: Overlapping members
|
||||
}
|
||||
|
||||
bitstruct Foo4 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 1..6; // #error: Overlapping members
|
||||
}
|
||||
|
||||
bitstruct Foo5 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 1..3; // #error: Overlapping members
|
||||
}
|
||||
|
||||
bitstruct Foo6 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 1..1;
|
||||
}
|
||||
|
||||
bitstruct Foo7 : char @overlap
|
||||
{
|
||||
int a : 2..5;
|
||||
int b : 1..3;
|
||||
}
|
||||
|
||||
bitstruct Foo8 : char
|
||||
{
|
||||
int a : 2..5;
|
||||
bool b : 3; // #error: Overlapping members
|
||||
}
|
||||
19
test/test_suite/bitstruct/bitstruct_single_error.c3
Normal file
19
test/test_suite/bitstruct/bitstruct_single_error.c3
Normal file
@@ -0,0 +1,19 @@
|
||||
bitstruct Foo1 : char
|
||||
{
|
||||
char x : 1..1;
|
||||
}
|
||||
|
||||
bitstruct Foo2 : char
|
||||
{
|
||||
char x : 1; // #error: Only booleans may use non-range indices
|
||||
}
|
||||
|
||||
bitstruct Foo3 : char
|
||||
{
|
||||
bool x : 0..2; // #error: The bit width of 'bool'
|
||||
}
|
||||
|
||||
bitstruct Foo4 : int
|
||||
{
|
||||
char x : 0..15; // #error: The bit width of 'char'
|
||||
}
|
||||
3
test/test_suite/bitstruct/missing_bitstruct_type.c3
Normal file
3
test/test_suite/bitstruct/missing_bitstruct_type.c3
Normal file
@@ -0,0 +1,3 @@
|
||||
bitstruct BitField
|
||||
{ // #error: followed by bitstruct
|
||||
}
|
||||
Reference in New Issue
Block a user