Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
47bfc80c
Commit
47bfc80c
authored
Apr 16, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a very simple analysis unittest
parent
c2a99e50
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
88 additions
and
12 deletions
+88
-12
src/Makefile
src/Makefile
+17
-9
src/analysis/function_analysis.cpp
src/analysis/function_analysis.cpp
+14
-1
src/analysis/function_analysis.h
src/analysis/function_analysis.h
+1
-0
src/analysis/scoping_analysis.h
src/analysis/scoping_analysis.h
+1
-0
test/tests/augassign_analysis.py
test/tests/augassign_analysis.py
+12
-0
test/unittests/analysis.cpp
test/unittests/analysis.cpp
+30
-2
test/unittests/analysis_listcomp.py
test/unittests/analysis_listcomp.py
+13
-0
No files found.
src/Makefile
View file @
47bfc80c
...
...
@@ -251,15 +251,23 @@ tags: $(SRCS) $(OPTIONAL_SRCS) $(ALL_HEADERS)
$(UNITTEST_SRCS
:
.cpp=.o): CXXFLAGS := $(CXXFLAGS) -I$(GTEST_DIR)/include
NON_ENTRY_OBJS
:=
$(
filter-out
jit.o,
$(OBJS)
)
$(UNITTEST_DIR)/gc
:
$(GTEST_DIR)/src/gtest-all.o $(NON_ENTRY_OBJS) $(BUILD_SYSTEM_DEPS) $(UNITTEST_DIR)/gc.o
$(ECHO)
Linking
$@
$(VERB)
$(CXX)
$(NON_ENTRY_OBJS)
$(GTEST_DIR)
/src/gtest-all.o
$(GTEST_DIR)
/src/gtest_main.o
$(UNITTEST_DIR)
/gc.o
$(LDFLAGS)
-o
$@
dbg_gcunittests
:
$(UNITTEST_DIR)/gc
zsh
-c
'ulimit -v
$(MAX_MEM_KB)
; ulimit -d
$(MAX_MEM_KB)
; time gdb
$(GDB_CMDS)
--args ./
$(UNITTEST_DIR)
/gc --gtest_break_on_failure
$(ARGS)
'
run_gcunittests
:
$(UNITTEST_DIR)/gc
zsh
-c
'ulimit -v
$(MAX_MEM_KB)
; ulimit -d
$(MAX_MEM_KB)
; time ./
$(UNITTEST_DIR)
/gc
$(ARGS)
'
run_unittests
::
run_gcunittests
dbg_unittests
::
dbg_gcunittests
define
add_unittest
$(eval
\
$(UNITTEST_DIR)/$1
:
$(GTEST_DIR)/src/gtest-all.o $(NON_ENTRY_OBJS) $(BUILD_SYSTEM_DEPS) $(UNITTEST_DIR)/$1.o
$(ECHO)
Linking
$$
@
$(VERB)
$(CXX)
$(NON_ENTRY_OBJS)
$(GTEST_DIR)
/src/gtest-all.o
$(GTEST_DIR)
/src/gtest_main.o
$(UNITTEST_DIR)
/
$1
.o
$(LDFLAGS)
-o
$$
@
dbg_$1_unittests
:
$(UNITTEST_DIR)/$1
zsh
-c
'ulimit -v
$(MAX_MEM_KB)
; ulimit -d
$(MAX_MEM_KB)
; time gdb
$(GDB_CMDS)
--args ./
$(UNITTEST_DIR)
/$1 --gtest_break_on_failure
$(ARGS)
'
run_$1_unittests
:
$(UNITTEST_DIR)/$1
zsh
-c
'ulimit -v
$(MAX_MEM_KB)
; ulimit -d
$(MAX_MEM_KB)
; time ./
$(UNITTEST_DIR)
/$1
$(ARGS)
'
run_unittests
::
run_$1_unittests
)
endef
$(call
add_unittest,gc)
$(call
add_unittest,analysis)
define
checksha
test
"$$($1 | sha1sum)"
=
"$2 -"
...
...
src/analysis/function_analysis.cpp
View file @
47bfc80c
...
...
@@ -74,7 +74,20 @@ class LivenessBBVisitor : public NoopASTVisitor {
}
bool
visit_augassign
(
AST_AugAssign
*
node
)
{
assert
(
0
&&
"need to set it as a load"
);
AST
*
target
=
node
->
target
;
switch
(
target
->
type
)
{
case
AST_TYPE
:
:
Name
:
{
AST_Name
*
n
=
static_cast
<
AST_Name
*>
(
target
);
_doLoad
(
n
->
id
);
_doStore
(
n
->
id
);
break
;
}
default:
RELEASE_ASSERT
(
0
,
"%d"
,
target
->
type
);
}
node
->
value
->
accept
(
this
);
return
true
;
}
};
...
...
src/analysis/function_analysis.h
View file @
47bfc80c
...
...
@@ -16,6 +16,7 @@
#define PYSTON_ANALYSIS_FUNCTIONANALYSIS_H
#include <unordered_set>
#include <unordered_map>
namespace
pyston
{
...
...
src/analysis/scoping_analysis.h
View file @
47bfc80c
...
...
@@ -19,6 +19,7 @@
namespace
pyston
{
class
AST
;
class
AST_Module
;
class
ScopeInfo
{
...
...
test/tests/augassign_analysis.py
View file @
47bfc80c
...
...
@@ -40,3 +40,15 @@ def f4():
print
lists
print
l
f4
()
def
f5
():
# Not very sensical, but this works:
[
x
for
x
in
xrange
(
5
)][
0
]
+=
x
print
x
f5
()
def
f6
():
# This should error: the lhs is evaluated first
x
+=
[
x
for
x
in
xrange
(
5
)][
0
]
print
x
f6
()
test/unittests/analysis.cpp
View file @
47bfc80c
#include <memory>
#include <unordered_map>
#include <vector>
#include <unordered_set>
#include "gtest/gtest.h"
#include "gc/gc_alloc.h"
#include "analysis/function_analysis.h"
#include "analysis/scoping_analysis.h"
#include "codegen/parser.h"
#include "core/ast.h"
#include "core/cfg.h"
using
namespace
pyston
;
using
namespace
pyston
::
gc
;
TEST
(
func_analysis
,
augassign
)
{
AST_Module
*
module
=
caching_parse
(
"../test/unittests/analysis_listcomp.py"
);
assert
(
module
);
ScopingAnalysis
*
scoping
=
runScopingAnalysis
(
module
);
assert
(
module
->
body
[
0
]
->
type
==
AST_TYPE
::
FunctionDef
);
AST_FunctionDef
*
func
=
static_cast
<
AST_FunctionDef
*>
(
module
->
body
[
0
]);
ScopeInfo
*
scope_info
=
scoping
->
getScopeInfoForNode
(
func
);
ASSERT_FALSE
(
scope_info
->
refersToGlobal
(
"a"
));
ASSERT_FALSE
(
scope_info
->
refersToGlobal
(
"b"
));
CFG
*
cfg
=
computeCFG
(
func
->
type
,
func
->
body
);
LivenessAnalysis
*
liveness
=
computeLivenessInfo
(
cfg
);
//cfg->print();
for
(
CFGBlock
*
block
:
cfg
->
blocks
)
{
//printf("%d\n", block->idx);
if
(
block
->
body
.
back
()
->
type
!=
AST_TYPE
::
Return
)
ASSERT_TRUE
(
liveness
->
isLiveAtEnd
(
"a"
,
block
));
}
PhiAnalysis
*
phis
=
computeRequiredPhis
(
func
->
args
,
cfg
,
liveness
,
scope_info
);
}
test/unittests/analysis_listcomp.py
0 → 100644
View file @
47bfc80c
def
f
():
a
=
1
b
=
2
if
1
:
pass
a
+=
b
if
1
:
pass
return
a
print
f
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment