Skip to content

Commit

Permalink
update demo and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrusch committed May 11, 2023
1 parent 3c5d982 commit 04c1558
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://{server-url}/v2/

```bash
# install dependencies
pip install -q -r requirements.txt
pip install -r requirements.txt

# run the server
python main.py
Expand Down
2 changes: 1 addition & 1 deletion c_files/original_paper/example3_1_a.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

int foo(int X1, int X2, int X3){
X1 = X2 + X3;
X1 = X1 + X1;
X1 = X2 + X3;
}
2 changes: 1 addition & 1 deletion c_files/original_paper/example3_1_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

int foo(int X1, int X2, int X3){
while (X > 0){
while (0){
X1 = X2 + X3;
}
}
4 changes: 4 additions & 0 deletions c_files/original_paper/example3_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/

int foo(int X1, int X2, int X3, int X4, int X5){
/*
* The original analysis uses loop,
* which changes outcome of the analysis.
*/
while (X1 > 0){
/*
* The original example reads
Expand Down
6 changes: 0 additions & 6 deletions c_files/other/for_loop.c

This file was deleted.

23 changes: 23 additions & 0 deletions c_files/other/xnu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
int nondet();

void xnu(int len, int beg, int end, int i, int k) {
beg = 0;
end = 0;
i = 0;
while (i < len) {
i = i + 1;
if (nondet())
end = i;
if (nondet()) {
k = beg;
while (k < end)
k = k + 1;
end = i;
beg = end;
} else if (nondet()) {
end = i;
beg = end;
}
}
}

9 changes: 9 additions & 0 deletions c_files/tool_paper/t19_c4b.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void t19(int i, int k)
{
while (i > 100)
i = i - 1;
i = i + k;
i = i + 50;
while (i >= 0)
i = i - 1;
}
7 changes: 7 additions & 0 deletions c_files/tool_paper/t20_c4b.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void t20(int x, int y)
{
while (x < y)
x = x + 1;
while (y < x)
y = y + 1;
}
12 changes: 12 additions & 0 deletions c_files/tool_paper/t47_c4b.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void t47(int n, int flag)
{
flag = 1;

while (flag>0) {
if (n>0) {
n = n - 1;
flag=1;
} else
flag=0;
}
}
7 changes: 7 additions & 0 deletions c_files/tool_paper/tool_ex_1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Tool paper section 1, example 1.
*/
void increasing(int X1, int X2, int X3) {
while (X2 < X1) { X2 = X1 + X1; }
while (X3 < X2) { X3 = X2 + X2; }
}
7 changes: 7 additions & 0 deletions c_files/tool_paper/tool_ex_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Tool paper section 2.1, example 2.
*/
void ex2(int X2, int X3)
{
while (X3<X2) X3 = X3*X3;
}
9 changes: 9 additions & 0 deletions c_files/tool_paper/tool_ex_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Tool paper section 2.1, example 3.
*/
void ex3(int X1, int X2, int X3)
{
while(X2 < X1) { X2 = X1 + X1; }
while(X3 < X2) { X3 = X2 + X2; }
X3 = X3 * X3;
}
16 changes: 14 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask_cors import CORS
from pymwp import __version__
from pymwp.parser import parse_file
from pymwp.analysis import Analysis
from pymwp.analysis import Analysis, Result

app = Flask(__name__)
CORS(app)
Expand Down Expand Up @@ -43,7 +43,19 @@ def analyze_v2(category, filename):
result['program'] = file_text(file) or ""
ast = parse_file(file, use_cpp=True, cpp_path=pre_parser,
cpp_args='-E')
result['result'] = Analysis.run(ast, no_save=True)
analysis_result = Result()
analysis_result.program.program_path = sample
analysis_result.program.n_lines = \
len(result['program'].split("\n"))
res = Analysis.run(
ast, no_save=True, res=analysis_result, fin=True)
result['fail'] = dict([
(r, vals.relation.infty_vars())
for r, vals in res.relations.items() if vals.infinite])
result['bounds'] = dict([
(r, vals.bound.show_poly())
for r, vals in res.relations.items() if not vals.infinite])
result['result'] = res
except:
type_, value, tb = sys.exc_info()
result['error'] = True
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask
flask-cors
pymwp==0.3.0
pymwp==0.4.2
jsons

0 comments on commit 04c1558

Please sign in to comment.