-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1564 from GaloisInc/pointer-cast
Pointer cast
- Loading branch information
Showing
27 changed files
with
351 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test.bc : test.c | ||
clang -c -emit-llvm -g -o test.bc test.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This example is derived from an older union example | ||
from `examples/llvm/union`. It is intended to demonstrate | ||
the use of the `llvm_pointer_cast` operation for selecting | ||
the branches of unions. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdint.h> | ||
|
||
typedef enum { INC_1 , INC_2 } alg; | ||
|
||
typedef struct { | ||
uint32_t x; | ||
} inc_1_st; | ||
|
||
typedef struct { | ||
uint32_t x; | ||
uint32_t y; | ||
} inc_2_st; | ||
|
||
typedef struct { | ||
alg alg; | ||
union { | ||
inc_1_st inc_1_st; | ||
inc_2_st inc_2_st; | ||
} inc_st; | ||
} st; | ||
|
||
uint32_t inc(st *st) { | ||
switch (st->alg) { | ||
case INC_1: | ||
st->inc_st.inc_1_st.x += 1; | ||
break; | ||
case INC_2: | ||
st->inc_st.inc_2_st.x += 1; | ||
st->inc_st.inc_2_st.y += 1; | ||
break; | ||
default: | ||
return 1/0; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
m <- llvm_load_module "test.bc"; | ||
|
||
let {{ | ||
INC_1 = 0 : [32] | ||
INC_2 = 1 : [32] | ||
}}; | ||
|
||
|
||
// The argument 'INC' specifies which 'alg' enum to test. | ||
let inc_spec INC = do { | ||
|
||
stp <- llvm_alloc (llvm_alias "struct.st"); | ||
llvm_points_to (llvm_field stp "alg") (llvm_term {{ INC }}); | ||
|
||
if eval_bool {{ INC == INC_1 }} then | ||
do { | ||
let p = llvm_cast_pointer (llvm_field stp "inc_st") (llvm_alias "struct.inc_1_st"); | ||
|
||
x0 <- llvm_fresh_var "x0" (llvm_int 32); | ||
llvm_points_to (llvm_field p "x") (llvm_term x0); | ||
|
||
llvm_execute_func [stp]; | ||
|
||
llvm_points_to (llvm_field p "x") (llvm_term {{ x0 + 1 }}); | ||
} | ||
else if eval_bool {{ INC == INC_2 }} then | ||
do { | ||
let p = llvm_cast_pointer (llvm_field stp "inc_st") (llvm_alias "struct.inc_2_st"); | ||
|
||
x0 <- llvm_fresh_var "x0" (llvm_int 32); | ||
y0 <- llvm_fresh_var "y0" (llvm_int 32); | ||
|
||
llvm_points_to (llvm_field p "x") (llvm_term x0); | ||
llvm_points_to (llvm_field p "y") (llvm_term y0); | ||
|
||
llvm_execute_func [stp]; | ||
|
||
llvm_points_to (llvm_field p "x") (llvm_term {{ x0 + 1 }}); | ||
llvm_points_to (llvm_field p "y") (llvm_term {{ y0 + 1 }}); | ||
} | ||
else return (); // Unknown INC value | ||
|
||
llvm_return (llvm_term {{ 0 : [32] }}); | ||
}; | ||
|
||
print "Verifying 'inc_1' using 'llvm_verify':"; | ||
llvm_verify m "inc" [] true (inc_spec {{ INC_1 }}) abc; | ||
print ""; | ||
|
||
print "Verifying 'inc_2' using 'llvm_verify':"; | ||
llvm_verify m "inc" [] true (inc_spec {{ INC_2 }}) abc; | ||
print ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$SAW test.saw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.