mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
add struct example
This commit is contained in:
19
examples/c/struct4.c
Normal file
19
examples/c/struct4.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
int nonce = 1; // For random input
|
||||||
|
|
||||||
|
struct Foo
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Foo f()
|
||||||
|
{
|
||||||
|
struct Foo x;
|
||||||
|
x.x = nonce;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int x = f().x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
39
examples/ir0/struct4.ir
Normal file
39
examples/ir0/struct4.ir
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
|
||||||
|
block b1:
|
||||||
|
ret undef:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:i32:x
|
||||||
|
%l1:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
%b0:i4:unit = store %b0:i3:i32 %l0:i32*
|
||||||
|
%b0:i5:i32 = load %l0:i32*
|
||||||
|
ret %b0:i5:i32
|
||||||
|
|
||||||
|
block b1:
|
||||||
|
ret 0:i32
|
||||||
|
}
|
||||||
33
examples/ir1/struct4.ir
Normal file
33
examples/ir1/struct4.ir
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:i32:x
|
||||||
|
%l1:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
%b0:i4:unit = store %b0:i3:i32 %l0:i32*
|
||||||
|
%b0:i5:i32 = load %l0:i32*
|
||||||
|
ret %b0:i5:i32
|
||||||
|
}
|
||||||
33
examples/ir2/struct4.ir
Normal file
33
examples/ir2/struct4.ir
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:i32:x
|
||||||
|
%l1:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
%b0:i4:unit = nop
|
||||||
|
%b0:i5:unit = nop
|
||||||
|
ret %b0:i3:i32
|
||||||
|
}
|
||||||
30
examples/ir3/struct4.ir
Normal file
30
examples/ir3/struct4.ir
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
ret %b0:i3:i32
|
||||||
|
}
|
||||||
30
examples/ir4/struct4.ir
Normal file
30
examples/ir4/struct4.ir
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
ret %b0:i3:i32
|
||||||
|
}
|
||||||
30
examples/opt/struct4.ir
Normal file
30
examples/opt/struct4.ir
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
struct Foo : { x:i32 }
|
||||||
|
var i32 @nonce = 1
|
||||||
|
|
||||||
|
fun struct Foo @f () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:x
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i1:i32 = load @nonce:i32*
|
||||||
|
%b0:i2:unit = store %b0:i1:i32 %b0:i0:i32*
|
||||||
|
%b0:i3:struct Foo = load %l0:struct Foo*
|
||||||
|
ret %b0:i3:struct Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
fun i32 @main () {
|
||||||
|
init:
|
||||||
|
bid: b0
|
||||||
|
allocations:
|
||||||
|
%l0:struct Foo:t0
|
||||||
|
|
||||||
|
block b0:
|
||||||
|
%b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*()
|
||||||
|
%b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo*
|
||||||
|
%b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64
|
||||||
|
%b0:i3:i32 = load %b0:i2:i32*
|
||||||
|
ret %b0:i3:i32
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ fn test_opt_between_dirs<O: Optimize<ir::TranslationUnit>>(from: &Path, to: &Pat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [
|
const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [
|
||||||
"examples/c/array.c",
|
"examples/c/array.c",
|
||||||
"examples/c/array2.c",
|
"examples/c/array2.c",
|
||||||
"examples/c/array3.c",
|
"examples/c/array3.c",
|
||||||
@@ -57,6 +57,7 @@ const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [
|
|||||||
"examples/c/struct.c",
|
"examples/c/struct.c",
|
||||||
"examples/c/struct2.c",
|
"examples/c/struct2.c",
|
||||||
"examples/c/struct3.c",
|
"examples/c/struct3.c",
|
||||||
|
"examples/c/struct4.c",
|
||||||
"examples/c/temp2.c",
|
"examples/c/temp2.c",
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ const ASMGEN_TEST_DIR_LIST: [&str; 5] = [
|
|||||||
"examples/ir4",
|
"examples/ir4",
|
||||||
];
|
];
|
||||||
|
|
||||||
const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [
|
const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [
|
||||||
"array.ir",
|
"array.ir",
|
||||||
"array2.ir",
|
"array2.ir",
|
||||||
"array3.ir",
|
"array3.ir",
|
||||||
@@ -79,6 +80,7 @@ const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [
|
|||||||
"struct.ir",
|
"struct.ir",
|
||||||
"struct2.ir",
|
"struct2.ir",
|
||||||
"struct3.ir",
|
"struct3.ir",
|
||||||
|
"struct4.ir",
|
||||||
"temp2.ir",
|
"temp2.ir",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user