Skip to content

Commit 1af3c78

Browse files
authored
Merge pull request #1133 from GaloisInc/wip/T1132
Add llvm_pointer to SAWScript, fix Python's `ptr`
2 parents 2609895 + 9f966ff commit 1af3c78

File tree

12 files changed

+210
-1
lines changed

12 files changed

+210
-1
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ To avoid confusion, a new `llvm_alias` function has been introduced, and
2424
`llvm_struct` is now a synonym for `llvm_alias`. The `llvm_struct` function
2525
continues to be available for now.
2626

27+
SAWScript includes a new `llvm_pointer : LLVMType -> LLVMType` function for
28+
constructing LLVM pointer types.
29+
2730
# Version 0.7
2831

2932
## New Features

intTests/test1132/test.bc

3.3 KB
Binary file not shown.

intTests/test1132/test.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
void f(uint8_t **x) {
5+
*x = malloc(sizeof(uint8_t));
6+
**x = 42;
7+
}

intTests/test1132/test.saw

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bc <- llvm_load_module "test.bc";
2+
3+
let f_contract = do {
4+
x <- llvm_alloc (llvm_pointer (llvm_int 8));
5+
llvm_execute_func [x];
6+
p <- llvm_alloc (llvm_int 8);
7+
llvm_points_to x p;
8+
llvm_points_to p (llvm_term {{ 42 : [8] }});
9+
};
10+
11+
llvm_verify bc "f" [] false f_contract abc;

intTests/test1132/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set -e
2+
3+
$SAW test.saw

saw-remote-api/python/.gitignore

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

saw-remote-api/python/saw/llvm_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, points_to : 'LLVMType') -> None:
2727
self.points_to = points_to
2828

2929
def to_json(self) -> Any:
30-
return {'type': 'pointer', 'points to': self.points_to.to_json()}
30+
return {'type': 'pointer', 'to type': self.points_to.to_json()}
3131

3232
class LLVMAliasType(LLVMType):
3333
def __init__(self, name : str) -> None:
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
void f(uint8_t **x) {
5+
*x = malloc(sizeof(uint8_t));
6+
**x = 42;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pathlib import Path
2+
import unittest
3+
from saw import *
4+
from saw.llvm import Contract, cryptol, void
5+
import saw.llvm_types as ty
6+
7+
8+
class FContract(Contract):
9+
def specification(self):
10+
x = self.alloc(ty.ptr(ty.i8))
11+
12+
self.execute_func(x)
13+
14+
p = self.alloc(ty.i8)
15+
self.points_to(x, p)
16+
self.points_to(p, cryptol("42 : [8]"))
17+
self.returns(void)
18+
19+
20+
class LLVMPointerTest(unittest.TestCase):
21+
22+
@classmethod
23+
def setUpClass(self):
24+
connect(reset_server=True)
25+
26+
@classmethod
27+
def tearDownClass(self):
28+
disconnect()
29+
30+
def test_llvm_pointer(self):
31+
if __name__ == "__main__": view(LogResults())
32+
bcname = str(Path('tests','saw','test-files', 'llvm_pointer.bc'))
33+
mod = llvm_load_module(bcname)
34+
35+
result = llvm_verify(mod, 'f', FContract())
36+
self.assertIs(result.is_success(), True)
37+
38+
39+
if __name__ == "__main__":
40+
unittest.main()

src/SAWScript/Interpreter.hs

+6
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,12 @@ primitives = Map.fromList
17461746
[ "Legacy alternative name for `llvm_alias`."
17471747
]
17481748

1749+
, prim "llvm_pointer" "LLVMType -> LLVMType"
1750+
(pureVal llvm_pointer)
1751+
Current
1752+
[ "The type of an LLVM pointer that points to the given type."
1753+
]
1754+
17491755
, prim "llvm_load_module" "String -> TopLevel LLVMModule"
17501756
(pureVal llvm_load_module)
17511757
Current

src/SAWScript/LLVMBuiltins.hs

+3
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@ llvm_alias n = LLVM.Alias (fromString n)
6767
llvm_packed_struct_type :: [LLVM.Type] -> LLVM.Type
6868
llvm_packed_struct_type = LLVM.PackedStruct
6969

70+
llvm_pointer :: LLVM.Type -> LLVM.Type
71+
llvm_pointer = LLVM.PtrTo
72+
7073
llvm_struct_type :: [LLVM.Type] -> LLVM.Type
7174
llvm_struct_type = LLVM.Struct

0 commit comments

Comments
 (0)