Add complement example

This commit is contained in:
Minseong Jang
2022-03-25 14:40:59 +09:00
parent 448335dc39
commit c8813ac7a2
6 changed files with 80 additions and 0 deletions

6
examples/c/complement.c Normal file
View File

@@ -0,0 +1,6 @@
int nonce = 1; // For random input
int main() {
int a = ~nonce;
return a;
}

View File

@@ -0,0 +1,18 @@
var i32 @nonce = 1
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:a
block b0:
%b0:i0:i32 = load @nonce:i32*
%b0:i1:i32 = xor %b0:i0:i32 -1:i32
%b0:i2:unit = store %b0:i1:i32 %l0:i32*
%b0:i3:i32 = load %l0:i32*
ret %b0:i3:i32
block b1:
ret 0:i32
}

View File

@@ -0,0 +1,15 @@
var i32 @nonce = 1
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:a
block b0:
%b0:i0:i32 = load @nonce:i32*
%b0:i1:i32 = xor %b0:i0:i32 -1:i32
%b0:i2:unit = store %b0:i1:i32 %l0:i32*
%b0:i3:i32 = load %l0:i32*
ret %b0:i3:i32
}

View File

@@ -0,0 +1,15 @@
var i32 @nonce = 1
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:a
block b0:
%b0:i0:i32 = load @nonce:i32*
%b0:i1:i32 = xor %b0:i0:i32 -1:i32
%b0:i2:unit = nop
%b0:i3:unit = nop
ret %b0:i1:i32
}

View File

@@ -0,0 +1,13 @@
var i32 @nonce = 1
fun i32 @main () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32 = load @nonce:i32*
%b0:i1:i32 = xor %b0:i0:i32 -1:i32
ret %b0:i1:i32
}

View File

@@ -0,0 +1,13 @@
var i32 @nonce = 1
fun i32 @main () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32 = load @nonce:i32*
%b0:i1:i32 = xor %b0:i0:i32 -1:i32
ret %b0:i1:i32
}