-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement global_lvalue and global_initializer in Python bindings
This checks off the first two bullet points of #1153. The third bullet point, related to `llvm_alloc_global`, is left as future work.
- Loading branch information
1 parent
99a0dad
commit 6462adf
Showing
4 changed files
with
71 additions
and
0 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
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,5 @@ | ||
const int x = 0; | ||
|
||
int f() { | ||
return x; | ||
} |
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,38 @@ | ||
from pathlib import Path | ||
import unittest | ||
from saw import * | ||
from saw.llvm import Contract, global_lvalue, global_initializer | ||
import saw.llvm_types as ty | ||
|
||
|
||
class FContract(Contract): | ||
def specification(self): | ||
x_init = global_initializer("x") | ||
self.points_to(global_lvalue("x"), x_init) | ||
|
||
self.execute_func() | ||
|
||
self.returns(x_init) | ||
|
||
|
||
class LLVMGlobalTest(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(self): | ||
connect(reset_server=True) | ||
|
||
@classmethod | ||
def tearDownClass(self): | ||
disconnect() | ||
|
||
def test_llvm_global(self): | ||
if __name__ == "__main__": view(LogResults()) | ||
bcname = str(Path('tests','saw','test-files', 'llvm_global.bc')) | ||
mod = llvm_load_module(bcname) | ||
|
||
result = llvm_verify(mod, 'f', FContract()) | ||
self.assertIs(result.is_success(), True) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |