Commit 47bfc80c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Create a very simple analysis unittest

parent c2a99e50
......@@ -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 -"
......
......@@ -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;
}
};
......
......@@ -16,6 +16,7 @@
#define PYSTON_ANALYSIS_FUNCTIONANALYSIS_H
#include <unordered_set>
#include <unordered_map>
namespace pyston {
......
......@@ -19,6 +19,7 @@
namespace pyston {
class AST;
class AST_Module;
class ScopeInfo {
......
......@@ -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()
#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);
}
def f():
a = 1
b = 2
if 1:
pass
a += b
if 1:
pass
return a
print f()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment