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
763cc656
Commit
763cc656
authored
Sep 02, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CFG changes
parent
5e76425d
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
666 additions
and
472 deletions
+666
-472
Makefile
Makefile
+0
-1
src/analysis/scoping_analysis.cpp
src/analysis/scoping_analysis.cpp
+7
-0
src/analysis/scoping_analysis.h
src/analysis/scoping_analysis.h
+2
-0
src/codegen/codegen.cpp
src/codegen/codegen.cpp
+8
-18
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+1
-1
src/codegen/cpython_ast.cpp
src/codegen/cpython_ast.cpp
+3
-0
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+4
-7
src/core/ast.cpp
src/core/ast.cpp
+4
-19
src/core/ast.h
src/core/ast.h
+1
-10
src/core/bst.cpp
src/core/bst.cpp
+18
-2
src/core/bst.h
src/core/bst.h
+0
-6
src/core/cfg.cpp
src/core/cfg.cpp
+588
-390
src/core/cfg.h
src/core/cfg.h
+2
-1
src/core/types.h
src/core/types.h
+3
-3
src/runtime/exceptions.cpp
src/runtime/exceptions.cpp
+1
-1
test/tests/augassign_analysis.py
test/tests/augassign_analysis.py
+8
-0
test/unittests/CMakeLists.txt
test/unittests/CMakeLists.txt
+1
-0
test/unittests/analysis.cpp
test/unittests/analysis.cpp
+15
-13
No files found.
Makefile
View file @
763cc656
...
@@ -425,7 +425,6 @@ ARGS ?=
...
@@ -425,7 +425,6 @@ ARGS ?=
ifneq
($(BR),)
ifneq
($(BR),)
override GDB_CMDS
:
= --ex "break $(BR)" $(GDB_CMDS)
override GDB_CMDS
:
= --ex "break $(BR)" $(GDB_CMDS)
endif
endif
$(call
add_unittest,gc)
$(call
add_unittest,analysis)
$(call
add_unittest,analysis)
...
...
src/analysis/scoping_analysis.cpp
View file @
763cc656
...
@@ -73,6 +73,13 @@ bool containsYield(AST* ast) {
...
@@ -73,6 +73,13 @@ bool containsYield(AST* ast) {
return
visitor
.
contains_yield
;
return
visitor
.
contains_yield
;
}
}
bool
containsYield
(
llvm
::
ArrayRef
<
AST_stmt
*>
body
)
{
for
(
auto
e
:
body
)
if
(
containsYield
(
e
))
return
true
;
return
false
;
}
// TODO
// TODO
// Combine this with the below? Basically the same logic with different string types...
// Combine this with the below? Basically the same logic with different string types...
// Also should this go in this file?
// Also should this go in this file?
...
...
src/analysis/scoping_analysis.h
View file @
763cc656
...
@@ -159,7 +159,9 @@ public:
...
@@ -159,7 +159,9 @@ public:
bool
areGlobalsFromModule
()
{
return
globals_from_module
;
}
bool
areGlobalsFromModule
()
{
return
globals_from_module
;
}
};
};
class
AST_stmt
;
bool
containsYield
(
AST
*
ast
);
bool
containsYield
(
AST
*
ast
);
bool
containsYield
(
llvm
::
ArrayRef
<
AST_stmt
*>
ast
);
class
BoxedString
;
class
BoxedString
;
BoxedString
*
mangleNameBoxedString
(
BoxedString
*
id
,
BoxedString
*
private_name
);
BoxedString
*
mangleNameBoxedString
(
BoxedString
*
id
,
BoxedString
*
private_name
);
...
...
src/codegen/codegen.cpp
View file @
763cc656
...
@@ -58,24 +58,14 @@ void BoxedCode::addVersion(CompiledFunction* compiled) {
...
@@ -58,24 +58,14 @@ void BoxedCode::addVersion(CompiledFunction* compiled) {
}
}
}
}
SourceInfo
::
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
)
SourceInfo
::
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
int
ast_type
,
:
parent_module
(
m
),
scoping
(
std
::
move
(
scoping
)),
cfg
(
NULL
),
future_flags
(
future_flags
),
ast_type
(
ast
->
type
)
{
bool
is_generator
)
:
parent_module
(
m
),
switch
(
ast_type
)
{
scoping
(
std
::
move
(
scoping
)),
case
AST_TYPE
:
:
ClassDef
:
cfg
(
NULL
),
case
AST_TYPE
:
:
Module
:
future_flags
(
future_flags
),
case
AST_TYPE
:
:
Expression
:
is_generator
(
is_generator
),
case
AST_TYPE
:
:
Suite
:
ast_type
(
ast_type
)
{
is_generator
=
false
;
break
;
case
AST_TYPE
:
:
FunctionDef
:
case
AST_TYPE
:
:
Lambda
:
is_generator
=
containsYield
(
ast
);
break
;
default:
RELEASE_ASSERT
(
0
,
"Unknown type: %d"
,
ast_type
);
break
;
}
}
}
SourceInfo
::~
SourceInfo
()
{
SourceInfo
::~
SourceInfo
()
{
...
...
src/codegen/compvars.cpp
View file @
763cc656
...
@@ -21,12 +21,12 @@
...
@@ -21,12 +21,12 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/raw_ostream.h"
#include "core/bst.h"
#include "codegen/codegen.h"
#include "codegen/codegen.h"
#include "codegen/gcbuilder.h"
#include "codegen/gcbuilder.h"
#include "codegen/irgen.h"
#include "codegen/irgen.h"
#include "codegen/irgen/util.h"
#include "codegen/irgen/util.h"
#include "codegen/patchpoints.h"
#include "codegen/patchpoints.h"
#include "core/bst.h"
#include "core/options.h"
#include "core/options.h"
#include "core/types.h"
#include "core/types.h"
#include "runtime/float.h"
#include "runtime/float.h"
...
...
src/codegen/cpython_ast.cpp
View file @
763cc656
...
@@ -724,6 +724,7 @@ public:
...
@@ -724,6 +724,7 @@ public:
switch
(
mod
->
kind
)
{
switch
(
mod
->
kind
)
{
case
Module_kind
:
{
case
Module_kind
:
{
AST_Module
*
rtn
=
new
AST_Module
(
llvm
::
make_unique
<
InternedStringPool
>
());
AST_Module
*
rtn
=
new
AST_Module
(
llvm
::
make_unique
<
InternedStringPool
>
());
rtn
->
lineno
=
1
;
assert
(
!
this
->
pool
);
assert
(
!
this
->
pool
);
this
->
pool
=
rtn
->
interned_strings
.
get
();
this
->
pool
=
rtn
->
interned_strings
.
get
();
convertAll
<
stmt_ty
>
(
mod
->
v
.
Module
.
body
,
rtn
->
body
);
convertAll
<
stmt_ty
>
(
mod
->
v
.
Module
.
body
,
rtn
->
body
);
...
@@ -732,6 +733,7 @@ public:
...
@@ -732,6 +733,7 @@ public:
case
Interactive_kind
:
{
case
Interactive_kind
:
{
this
->
interactive
=
1
;
this
->
interactive
=
1
;
AST_Module
*
rtn
=
new
AST_Module
(
llvm
::
make_unique
<
InternedStringPool
>
());
AST_Module
*
rtn
=
new
AST_Module
(
llvm
::
make_unique
<
InternedStringPool
>
());
rtn
->
lineno
=
1
;
assert
(
!
this
->
pool
);
assert
(
!
this
->
pool
);
this
->
pool
=
rtn
->
interned_strings
.
get
();
this
->
pool
=
rtn
->
interned_strings
.
get
();
convertAll
<
stmt_ty
>
(
mod
->
v
.
Interactive
.
body
,
rtn
->
body
);
convertAll
<
stmt_ty
>
(
mod
->
v
.
Interactive
.
body
,
rtn
->
body
);
...
@@ -739,6 +741,7 @@ public:
...
@@ -739,6 +741,7 @@ public:
}
}
case
Expression_kind
:
{
case
Expression_kind
:
{
AST_Expression
*
rtn
=
new
AST_Expression
(
llvm
::
make_unique
<
InternedStringPool
>
());
AST_Expression
*
rtn
=
new
AST_Expression
(
llvm
::
make_unique
<
InternedStringPool
>
());
rtn
->
lineno
=
1
;
this
->
pool
=
rtn
->
interned_strings
.
get
();
this
->
pool
=
rtn
->
interned_strings
.
get
();
// instead of storing the expression inside the AST node we convert it directly to a return statement
// instead of storing the expression inside the AST node we convert it directly to a return statement
...
...
src/codegen/irgen/hooks.cpp
View file @
763cc656
...
@@ -231,10 +231,8 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
...
@@ -231,10 +231,8 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
RELEASE_ASSERT
(
fn
,
""
);
RELEASE_ASSERT
(
fn
,
""
);
FutureFlags
future_flags
=
getFutureFlags
(
m
->
body
,
fn
);
FutureFlags
future_flags
=
getFutureFlags
(
m
->
body
,
fn
);
computeAllCFGs
(
m
,
/* globals_from_module */
true
,
future_flags
,
autoDecref
(
boxString
(
fn
)),
bm
);
BoxedCode
*
code
=
computeAllCFGs
(
m
,
/* globals_from_module */
true
,
future_flags
,
autoDecref
(
boxString
(
fn
)),
bm
);
AUTO_DECREF
(
code
);
BoxedCode
*
code
=
m
->
getCode
();
assert
(
code
);
static
BoxedString
*
doc_str
=
getStaticString
(
"__doc__"
);
static
BoxedString
*
doc_str
=
getStaticString
(
"__doc__"
);
bm
->
setattr
(
doc_str
,
code
->
_doc
,
NULL
);
bm
->
setattr
(
doc_str
,
code
->
_doc
,
NULL
);
...
@@ -279,8 +277,7 @@ static BoxedCode* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_stmt*> bo
...
@@ -279,8 +277,7 @@ static BoxedCode* compileForEvalOrExec(AST* source, llvm::ArrayRef<AST_stmt*> bo
flags
->
cf_flags
=
future_flags
;
flags
->
cf_flags
=
future_flags
;
}
}
computeAllCFGs
(
source
,
/* globals_from_module */
false
,
future_flags
,
fn
,
getCurrentModule
());
return
computeAllCFGs
(
source
,
/* globals_from_module */
false
,
future_flags
,
fn
,
getCurrentModule
());
return
source
->
getCode
();
}
}
static
BoxedCode
*
compileExec
(
AST_Module
*
parsedModule
,
BoxedString
*
fn
,
PyCompilerFlags
*
flags
)
{
static
BoxedCode
*
compileExec
(
AST_Module
*
parsedModule
,
BoxedString
*
fn
,
PyCompilerFlags
*
flags
)
{
...
@@ -319,7 +316,7 @@ extern "C" PyCodeObject* PyAST_Compile(struct _mod* _mod, const char* filename,
...
@@ -319,7 +316,7 @@ extern "C" PyCodeObject* PyAST_Compile(struct _mod* _mod, const char* filename,
return
NULL
;
return
NULL
;
}
}
return
(
PyCodeObject
*
)
incref
(
code
)
;
return
(
PyCodeObject
*
)
code
;
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
setCAPIException
(
e
);
return
NULL
;
return
NULL
;
...
...
src/core/ast.cpp
View file @
763cc656
...
@@ -2138,22 +2138,6 @@ void flatten(AST_expr* root, std::vector<AST*>& output, bool expand_scopes) {
...
@@ -2138,22 +2138,6 @@ void flatten(AST_expr* root, std::vector<AST*>& output, bool expand_scopes) {
root
->
accept
(
&
visitor
);
root
->
accept
(
&
visitor
);
}
}
BoxedCode
*&
AST
::
getCode
()
{
switch
(
this
->
type
)
{
case
AST_TYPE
:
:
Expression
:
return
ast_cast
<
AST_Expression
>
(
this
)
->
code
;
case
AST_TYPE
:
:
FunctionDef
:
return
ast_cast
<
AST_FunctionDef
>
(
this
)
->
code
;
case
AST_TYPE
:
:
ClassDef
:
return
ast_cast
<
AST_ClassDef
>
(
this
)
->
code
;
case
AST_TYPE
:
:
Module
:
return
ast_cast
<
AST_Module
>
(
this
)
->
code
;
default:
break
;
}
RELEASE_ASSERT
(
0
,
"%d"
,
this
->
type
);
}
InternedStringPool
&
AST
::
getStringpool
()
{
InternedStringPool
&
AST
::
getStringpool
()
{
switch
(
this
->
type
)
{
switch
(
this
->
type
)
{
case
AST_TYPE
:
:
Expression
:
case
AST_TYPE
:
:
Expression
:
...
@@ -2181,11 +2165,12 @@ llvm::ArrayRef<AST_stmt*> AST::getBody() {
...
@@ -2181,11 +2165,12 @@ llvm::ArrayRef<AST_stmt*> AST::getBody() {
};
};
}
}
Box
*
AST
::
getDocString
()
{
Box
*
getDocString
(
llvm
::
ArrayRef
<
AST_stmt
*>
body
)
{
auto
body
=
this
->
getBody
();
if
(
body
.
size
()
>
0
&&
body
[
0
]
->
type
==
AST_TYPE
::
Expr
if
(
body
.
size
()
>
0
&&
body
[
0
]
->
type
==
AST_TYPE
::
Expr
&&
static_cast
<
AST_Expr
*>
(
body
[
0
])
->
value
->
type
==
AST_TYPE
::
Str
)
{
&&
static_cast
<
AST_Expr
*>
(
body
[
0
])
->
value
->
type
==
AST_TYPE
::
Str
)
{
return
boxString
(
static_cast
<
AST_Str
*>
(
static_cast
<
AST_Expr
*>
(
body
[
0
])
->
value
)
->
str_data
);
auto
expr
=
static_cast
<
AST_Expr
*>
(
body
[
0
]);
auto
str
=
static_cast
<
AST_Str
*>
(
expr
->
value
);
return
boxString
(
str
->
str_data
);
}
}
return
incref
(
Py_None
);
return
incref
(
Py_None
);
...
...
src/core/ast.h
View file @
763cc656
...
@@ -190,12 +190,11 @@ public:
...
@@ -190,12 +190,11 @@ public:
// These could be virtual methods, but since we already keep track of the type use a switch statement
// These could be virtual methods, but since we already keep track of the type use a switch statement
// like everywhere else.
// like everywhere else.
BoxedCode
*&
getCode
();
InternedStringPool
&
getStringpool
();
InternedStringPool
&
getStringpool
();
llvm
::
ArrayRef
<
AST_stmt
*>
getBody
();
llvm
::
ArrayRef
<
AST_stmt
*>
getBody
();
Box
*
getDocString
();
BORROWED
(
BoxedString
*
)
getName
()
noexcept
;
BORROWED
(
BoxedString
*
)
getName
()
noexcept
;
};
};
Box
*
getDocString
(
llvm
::
ArrayRef
<
AST_stmt
*>
body
);
class
AST_expr
:
public
AST
{
class
AST_expr
:
public
AST
{
public:
public:
...
@@ -398,8 +397,6 @@ public:
...
@@ -398,8 +397,6 @@ public:
std
::
vector
<
AST_stmt
*>
body
;
std
::
vector
<
AST_stmt
*>
body
;
InternedString
name
;
InternedString
name
;
BoxedCode
*
code
;
AST_ClassDef
()
:
AST_stmt
(
AST_TYPE
::
ClassDef
)
{}
AST_ClassDef
()
:
AST_stmt
(
AST_TYPE
::
ClassDef
)
{}
static
const
AST_TYPE
::
AST_TYPE
TYPE
=
AST_TYPE
::
ClassDef
;
static
const
AST_TYPE
::
AST_TYPE
TYPE
=
AST_TYPE
::
ClassDef
;
...
@@ -506,8 +503,6 @@ public:
...
@@ -506,8 +503,6 @@ public:
// this should be an expr but we convert it into a AST_Return(AST_expr) to make the code simpler
// this should be an expr but we convert it into a AST_Return(AST_expr) to make the code simpler
AST_stmt
*
body
;
AST_stmt
*
body
;
BoxedCode
*
code
;
virtual
void
accept
(
ASTVisitor
*
v
);
virtual
void
accept
(
ASTVisitor
*
v
);
AST_Expression
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
AST_Expression
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
...
@@ -547,8 +542,6 @@ public:
...
@@ -547,8 +542,6 @@ public:
InternedString
name
;
// if the name is not set this is a lambda
InternedString
name
;
// if the name is not set this is a lambda
AST_arguments
*
args
;
AST_arguments
*
args
;
BoxedCode
*
code
;
virtual
void
accept
(
ASTVisitor
*
v
);
virtual
void
accept
(
ASTVisitor
*
v
);
virtual
void
accept_stmt
(
ASTStmtVisitor
*
v
);
virtual
void
accept_stmt
(
ASTStmtVisitor
*
v
);
...
@@ -698,8 +691,6 @@ public:
...
@@ -698,8 +691,6 @@ public:
// no lineno, col_offset attributes
// no lineno, col_offset attributes
std
::
vector
<
AST_stmt
*>
body
;
std
::
vector
<
AST_stmt
*>
body
;
BoxedCode
*
code
;
virtual
void
accept
(
ASTVisitor
*
v
);
virtual
void
accept
(
ASTVisitor
*
v
);
AST_Module
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
AST_Module
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
...
...
src/core/bst.cpp
View file @
763cc656
...
@@ -43,6 +43,12 @@ template <class T> static void visitVector(const std::vector<T*>& vec, BSTVisito
...
@@ -43,6 +43,12 @@ template <class T> static void visitVector(const std::vector<T*>& vec, BSTVisito
}
}
}
}
static
void
visitCFG
(
CFG
*
cfg
,
BSTVisitor
*
v
)
{
for
(
auto
bb
:
cfg
->
blocks
)
for
(
auto
e
:
bb
->
body
)
e
->
accept
(
v
);
}
void
BST_alias
::
accept
(
BSTVisitor
*
v
)
{
void
BST_alias
::
accept
(
BSTVisitor
*
v
)
{
bool
skip
=
v
->
visit_alias
(
this
);
bool
skip
=
v
->
visit_alias
(
this
);
if
(
skip
)
if
(
skip
)
...
@@ -218,7 +224,7 @@ void BST_ClassDef::accept(BSTVisitor* v) {
...
@@ -218,7 +224,7 @@ void BST_ClassDef::accept(BSTVisitor* v) {
visitVector
(
this
->
bases
,
v
);
visitVector
(
this
->
bases
,
v
);
visitVector
(
this
->
decorator_list
,
v
);
visitVector
(
this
->
decorator_list
,
v
);
visit
Vector
(
this
->
body
,
v
);
visit
CFG
(
this
->
code
->
source
->
cfg
,
v
);
}
}
void
BST_ClassDef
::
accept_stmt
(
StmtVisitor
*
v
)
{
void
BST_ClassDef
::
accept_stmt
(
StmtVisitor
*
v
)
{
...
@@ -364,7 +370,7 @@ void BST_FunctionDef::accept(BSTVisitor* v) {
...
@@ -364,7 +370,7 @@ void BST_FunctionDef::accept(BSTVisitor* v) {
visitVector
(
decorator_list
,
v
);
visitVector
(
decorator_list
,
v
);
args
->
accept
(
v
);
args
->
accept
(
v
);
visit
Vector
(
body
,
v
);
visit
CFG
(
code
->
source
->
cfg
,
v
);
}
}
void
BST_FunctionDef
::
accept_stmt
(
StmtVisitor
*
v
)
{
void
BST_FunctionDef
::
accept_stmt
(
StmtVisitor
*
v
)
{
...
@@ -1084,11 +1090,16 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) {
...
@@ -1084,11 +1090,16 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) {
stream
<<
")"
;
stream
<<
")"
;
indent
+=
4
;
indent
+=
4
;
stream
<<
'\n'
;
printIndent
();
stream
<<
"..."
;
#if 0
for (int i = 0, n = node->body.size(); i < n; i++) {
for (int i = 0, n = node->body.size(); i < n; i++) {
stream << "\n";
stream << "\n";
printIndent();
printIndent();
node->body[i]->accept(this);
node->body[i]->accept(this);
}
}
#endif
indent
-=
4
;
indent
-=
4
;
return
true
;
return
true
;
...
@@ -1215,11 +1226,16 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
...
@@ -1215,11 +1226,16 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
stream
<<
")"
;
stream
<<
")"
;
indent
+=
4
;
indent
+=
4
;
stream
<<
'\n'
;
printIndent
();
stream
<<
"..."
;
#if 0
for (int i = 0; i < node->body.size(); i++) {
for (int i = 0; i < node->body.size(); i++) {
stream << "\n";
stream << "\n";
printIndent();
printIndent();
node->body[i]->accept(this);
node->body[i]->accept(this);
}
}
#endif
indent
-=
4
;
indent
-=
4
;
return
true
;
return
true
;
}
}
...
...
src/core/bst.h
View file @
763cc656
...
@@ -398,7 +398,6 @@ public:
...
@@ -398,7 +398,6 @@ public:
virtual
void
accept_stmt
(
StmtVisitor
*
v
);
virtual
void
accept_stmt
(
StmtVisitor
*
v
);
std
::
vector
<
BST_expr
*>
bases
,
decorator_list
;
std
::
vector
<
BST_expr
*>
bases
,
decorator_list
;
std
::
vector
<
BST_stmt
*>
body
;
InternedString
name
;
InternedString
name
;
BoxedCode
*
code
;
BoxedCode
*
code
;
...
@@ -512,8 +511,6 @@ public:
...
@@ -512,8 +511,6 @@ public:
// this should be an expr but we convert it into a BST_Return(BST_expr) to make the code simpler
// this should be an expr but we convert it into a BST_Return(BST_expr) to make the code simpler
BST_stmt
*
body
;
BST_stmt
*
body
;
BoxedCode
*
code
;
virtual
void
accept
(
BSTVisitor
*
v
);
virtual
void
accept
(
BSTVisitor
*
v
);
BST_Expression
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
BST_Expression
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
...
@@ -549,7 +546,6 @@ public:
...
@@ -549,7 +546,6 @@ public:
class
BST_FunctionDef
:
public
BST_stmt
{
class
BST_FunctionDef
:
public
BST_stmt
{
public:
public:
std
::
vector
<
BST_stmt
*>
body
;
std
::
vector
<
BST_expr
*>
decorator_list
;
std
::
vector
<
BST_expr
*>
decorator_list
;
InternedString
name
;
// if the name is not set this is a lambda
InternedString
name
;
// if the name is not set this is a lambda
BST_arguments
*
args
;
BST_arguments
*
args
;
...
@@ -711,8 +707,6 @@ public:
...
@@ -711,8 +707,6 @@ public:
// no lineno, col_offset attributes
// no lineno, col_offset attributes
std
::
vector
<
BST_stmt
*>
body
;
std
::
vector
<
BST_stmt
*>
body
;
BoxedCode
*
code
;
virtual
void
accept
(
BSTVisitor
*
v
);
virtual
void
accept
(
BSTVisitor
*
v
);
BST_Module
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
BST_Module
(
std
::
unique_ptr
<
InternedStringPool
>
interned_strings
)
...
...
src/core/cfg.cpp
View file @
763cc656
This diff is collapsed.
Click to expand it.
src/core/cfg.h
View file @
763cc656
...
@@ -330,7 +330,8 @@ public:
...
@@ -330,7 +330,8 @@ public:
iterator
end
()
const
{
return
iterator
(
*
this
,
this
->
v
.
size
());
}
iterator
end
()
const
{
return
iterator
(
*
this
,
this
->
v
.
size
());
}
};
};
void
computeAllCFGs
(
AST
*
ast
,
bool
globals_from_module
,
FutureFlags
future_flags
,
BoxedString
*
fn
,
BoxedModule
*
bm
);
BoxedCode
*
computeAllCFGs
(
AST
*
ast
,
bool
globals_from_module
,
FutureFlags
future_flags
,
BoxedString
*
fn
,
BoxedModule
*
bm
);
void
printCFG
(
CFG
*
cfg
);
void
printCFG
(
CFG
*
cfg
);
}
}
...
...
src/core/types.h
View file @
763cc656
...
@@ -156,7 +156,7 @@ class CFG;
...
@@ -156,7 +156,7 @@ class CFG;
class
AST
;
class
AST
;
class
BST
;
class
BST
;
class
BST_FunctionDef
;
class
BST_FunctionDef
;
class
B
ST_arguments
;
class
A
ST_arguments
;
class
BST_expr
;
class
BST_expr
;
class
BST_Name
;
class
BST_Name
;
class
BST_stmt
;
class
BST_stmt
;
...
@@ -234,7 +234,7 @@ struct ParamNames {
...
@@ -234,7 +234,7 @@ struct ParamNames {
unsigned
char
has_vararg_name
:
1
;
unsigned
char
has_vararg_name
:
1
;
unsigned
char
has_kwarg_name
:
1
;
unsigned
char
has_kwarg_name
:
1
;
explicit
ParamNames
(
AST
*
ast
,
InternedStringPool
&
pool
);
explicit
ParamNames
(
AST
_arguments
*
ast
,
InternedStringPool
&
pool
);
ParamNames
(
const
std
::
vector
<
const
char
*>&
args
,
const
char
*
vararg
,
const
char
*
kwarg
);
ParamNames
(
const
std
::
vector
<
const
char
*>&
args
,
const
char
*
vararg
,
const
char
*
kwarg
);
static
ParamNames
empty
()
{
return
ParamNames
();
}
static
ParamNames
empty
()
{
return
ParamNames
();
}
...
@@ -502,7 +502,7 @@ public:
...
@@ -502,7 +502,7 @@ public:
LivenessAnalysis
*
getLiveness
();
LivenessAnalysis
*
getLiveness
();
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
AST
*
ast
);
SourceInfo
(
BoxedModule
*
m
,
ScopingResults
scoping
,
FutureFlags
future_flags
,
int
ast_type
,
bool
is_generator
);
~
SourceInfo
();
~
SourceInfo
();
};
};
...
...
src/runtime/exceptions.cpp
View file @
763cc656
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
#include <cstdarg>
#include <cstdarg>
#include <dlfcn.h>
#include <dlfcn.h>
#include "core/ast.h"
#include "codegen/unwinding.h"
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "core/options.h"
#include "core/options.h"
#include "runtime/objmodel.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
#include "runtime/types.h"
...
...
test/tests/augassign_analysis.py
View file @
763cc656
...
@@ -118,3 +118,11 @@ try:
...
@@ -118,3 +118,11 @@ try:
f10
()
f10
()
except
UnboundLocalError
,
e
:
except
UnboundLocalError
,
e
:
print
e
print
e
def
f11
():
class
C
(
object
):
def
__init__
(
self
):
self
.
__x
=
1
self
.
__x
+=
2
print
C
().
_C__x
f11
()
test/unittests/CMakeLists.txt
View file @
763cc656
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-undef -D_PYSTON_API"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-undef -D_PYSTON_API"
)
set
(
CMAKE_CXX_FLAGS_DEBUG
"-g -O0"
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
)
add_definitions
(
-DGTEST_HAS_RTTI=0
${
LLVM_DEFINITIONS
}
)
add_definitions
(
-DGTEST_HAS_RTTI=0
${
LLVM_DEFINITIONS
}
)
...
...
test/unittests/analysis.cpp
View file @
763cc656
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include "codegen/osrentry.h"
#include "codegen/osrentry.h"
#include "codegen/parser.h"
#include "codegen/parser.h"
#include "core/ast.h"
#include "core/ast.h"
#include "core/bst.h"
#include "core/cfg.h"
#include "core/cfg.h"
#include "runtime/types.h"
#include "runtime/types.h"
#include "unittests.h"
#include "unittests.h"
...
@@ -34,7 +35,7 @@ TEST_F(AnalysisTest, augassign) {
...
@@ -34,7 +35,7 @@ TEST_F(AnalysisTest, augassign) {
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
auto
scoping
=
std
::
make_shared
<
ScopingAnalysis
>
(
module
,
true
);
auto
scoping
=
std
::
make_shared
<
ScopingAnalysis
>
(
module
,
true
);
computeAllCFGs
(
module
,
true
,
future_flags
,
boxString
(
fn
),
NULL
);
auto
module_code
=
computeAllCFGs
(
module
,
true
,
future_flags
,
boxString
(
fn
),
NULL
);
assert
(
module
->
body
[
0
]
->
type
==
AST_TYPE
::
FunctionDef
);
assert
(
module
->
body
[
0
]
->
type
==
AST_TYPE
::
FunctionDef
);
AST_FunctionDef
*
func
=
static_cast
<
AST_FunctionDef
*>
(
module
->
body
[
0
]);
AST_FunctionDef
*
func
=
static_cast
<
AST_FunctionDef
*>
(
module
->
body
[
0
]);
...
@@ -44,11 +45,12 @@ TEST_F(AnalysisTest, augassign) {
...
@@ -44,11 +45,12 @@ TEST_F(AnalysisTest, augassign) {
ASSERT_NE
(
scope_info
->
getScopeTypeOfName
(
module
->
interned_strings
->
get
(
"a"
)),
ScopeInfo
::
VarScopeType
::
GLOBAL
);
ASSERT_NE
(
scope_info
->
getScopeTypeOfName
(
module
->
interned_strings
->
get
(
"a"
)),
ScopeInfo
::
VarScopeType
::
GLOBAL
);
ASSERT_FALSE
(
scope_info
->
getScopeTypeOfName
(
module
->
interned_strings
->
get
(
"b"
))
==
ScopeInfo
::
VarScopeType
::
GLOBAL
);
ASSERT_FALSE
(
scope_info
->
getScopeTypeOfName
(
module
->
interned_strings
->
get
(
"b"
))
==
ScopeInfo
::
VarScopeType
::
GLOBAL
);
ParamNames
param_names
(
func
,
*
module
->
interned_strings
.
get
());
AST_arguments
*
args
=
new
AST_arguments
();
ParamNames
param_names
(
args
,
*
module
->
interned_strings
.
get
());
// Hack to get at the cfg:
// Hack to get at the cfg:
auto
node
=
module
->
code
->
source
->
cfg
->
blocks
[
0
]
->
body
[
0
];
auto
node
=
module
_
code
->
source
->
cfg
->
blocks
[
0
]
->
body
[
0
];
CFG
*
cfg
=
ast_cast
<
AST_MakeFunction
>
(
ast_cast
<
A
ST_Assign
>
(
node
)
->
value
)
->
function_def
->
code
->
source
->
cfg
;
CFG
*
cfg
=
bst_cast
<
BST_MakeFunction
>
(
bst_cast
<
B
ST_Assign
>
(
node
)
->
value
)
->
function_def
->
code
->
source
->
cfg
;
std
::
unique_ptr
<
LivenessAnalysis
>
liveness
=
computeLivenessInfo
(
cfg
);
std
::
unique_ptr
<
LivenessAnalysis
>
liveness
=
computeLivenessInfo
(
cfg
);
auto
&&
vregs
=
cfg
->
getVRegInfo
();
auto
&&
vregs
=
cfg
->
getVRegInfo
();
...
@@ -57,11 +59,11 @@ TEST_F(AnalysisTest, augassign) {
...
@@ -57,11 +59,11 @@ TEST_F(AnalysisTest, augassign) {
for
(
CFGBlock
*
block
:
cfg
->
blocks
)
{
for
(
CFGBlock
*
block
:
cfg
->
blocks
)
{
//printf("%d\n", block->idx);
//printf("%d\n", block->idx);
if
(
block
->
body
.
back
()
->
type
!=
A
ST_TYPE
::
Return
)
if
(
block
->
body
.
back
()
->
type
!=
B
ST_TYPE
::
Return
)
ASSERT_TRUE
(
liveness
->
isLiveAtEnd
(
vregs
.
getVReg
(
module
->
interned_strings
->
get
(
"a"
)),
block
));
ASSERT_TRUE
(
liveness
->
isLiveAtEnd
(
vregs
.
getVReg
(
module
->
interned_strings
->
get
(
"a"
)),
block
));
}
}
std
::
unique_ptr
<
PhiAnalysis
>
phis
=
computeRequiredPhis
(
ParamNames
(
func
,
*
module
->
interned_strings
.
get
()),
cfg
,
liveness
.
get
());
std
::
unique_ptr
<
PhiAnalysis
>
phis
=
computeRequiredPhis
(
ParamNames
(
args
,
*
module
->
interned_strings
.
get
()),
cfg
,
liveness
.
get
());
}
}
void
doOsrTest
(
bool
is_osr
,
bool
i_maybe_undefined
)
{
void
doOsrTest
(
bool
is_osr
,
bool
i_maybe_undefined
)
{
...
@@ -69,7 +71,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
...
@@ -69,7 +71,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
AST_Module
*
module
=
caching_parse_file
(
fn
.
c_str
(),
0
);
AST_Module
*
module
=
caching_parse_file
(
fn
.
c_str
(),
0
);
assert
(
module
);
assert
(
module
);
ParamNames
param_names
(
module
,
*
module
->
interned_strings
.
get
());
ParamNames
param_names
(
NULL
,
*
module
->
interned_strings
.
get
());
assert
(
module
->
body
[
0
]
->
type
==
AST_TYPE
::
FunctionDef
);
assert
(
module
->
body
[
0
]
->
type
==
AST_TYPE
::
FunctionDef
);
AST_FunctionDef
*
func
=
static_cast
<
AST_FunctionDef
*>
(
module
->
body
[
0
]);
AST_FunctionDef
*
func
=
static_cast
<
AST_FunctionDef
*>
(
module
->
body
[
0
]);
...
@@ -79,11 +81,11 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
...
@@ -79,11 +81,11 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
FutureFlags
future_flags
=
getFutureFlags
(
module
->
body
,
fn
.
c_str
());
computeAllCFGs
(
module
,
true
,
future_flags
,
boxString
(
fn
),
NULL
);
auto
module_code
=
computeAllCFGs
(
module
,
true
,
future_flags
,
boxString
(
fn
),
NULL
);
// Hack to get at the cfg:
// Hack to get at the cfg:
auto
node
=
module
->
code
->
source
->
cfg
->
blocks
[
0
]
->
body
[
0
];
auto
node
=
module
_
code
->
source
->
cfg
->
blocks
[
0
]
->
body
[
0
];
auto
code
=
ast_cast
<
AST_MakeFunction
>
(
ast_cast
<
A
ST_Assign
>
(
node
)
->
value
)
->
function_def
->
code
;
auto
code
=
bst_cast
<
BST_MakeFunction
>
(
bst_cast
<
B
ST_Assign
>
(
node
)
->
value
)
->
function_def
->
code
;
CFG
*
cfg
=
code
->
source
->
cfg
;
CFG
*
cfg
=
code
->
source
->
cfg
;
std
::
unique_ptr
<
LivenessAnalysis
>
liveness
=
computeLivenessInfo
(
cfg
);
std
::
unique_ptr
<
LivenessAnalysis
>
liveness
=
computeLivenessInfo
(
cfg
);
...
@@ -99,8 +101,8 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
...
@@ -99,8 +101,8 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
ASSERT_EQ
(
6
,
loop_backedge
->
idx
);
ASSERT_EQ
(
6
,
loop_backedge
->
idx
);
ASSERT_EQ
(
1
,
loop_backedge
->
body
.
size
());
ASSERT_EQ
(
1
,
loop_backedge
->
body
.
size
());
ASSERT_EQ
(
A
ST_TYPE
::
Jump
,
loop_backedge
->
body
[
0
]
->
type
);
ASSERT_EQ
(
B
ST_TYPE
::
Jump
,
loop_backedge
->
body
[
0
]
->
type
);
AST_Jump
*
backedge
=
ast_cast
<
A
ST_Jump
>
(
loop_backedge
->
body
[
0
]);
BST_Jump
*
backedge
=
bst_cast
<
B
ST_Jump
>
(
loop_backedge
->
body
[
0
]);
ASSERT_LE
(
backedge
->
target
->
idx
,
loop_backedge
->
idx
);
ASSERT_LE
(
backedge
->
target
->
idx
,
loop_backedge
->
idx
);
std
::
unique_ptr
<
PhiAnalysis
>
phis
;
std
::
unique_ptr
<
PhiAnalysis
>
phis
;
...
@@ -116,7 +118,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
...
@@ -116,7 +118,7 @@ void doOsrTest(bool is_osr, bool i_maybe_undefined) {
entry_descriptor
->
args
[
vregs
.
getVReg
(
iter_str
)]
=
fake_type
;
entry_descriptor
->
args
[
vregs
.
getVReg
(
iter_str
)]
=
fake_type
;
phis
=
computeRequiredPhis
(
entry_descriptor
,
liveness
.
get
());
phis
=
computeRequiredPhis
(
entry_descriptor
,
liveness
.
get
());
}
else
{
}
else
{
phis
=
computeRequiredPhis
(
ParamNames
(
func
,
*
module
->
interned_strings
),
cfg
,
liveness
.
get
());
phis
=
computeRequiredPhis
(
ParamNames
(
func
->
args
,
*
module
->
interned_strings
),
cfg
,
liveness
.
get
());
}
}
// First, verify that we require phi nodes for the block we enter into.
// First, verify that we require phi nodes for the block we enter into.
...
...
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