Commit 0999d34a authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Move is_defined names out of the symbol table

parent 061e994b
......@@ -51,12 +51,30 @@ public:
return v[vreg];
}
void clear() {
int n = v.size();
for (int i = 0; i < n; i++) {
v[i] = T();
}
}
int numSet() {
int n = v.size();
int r = 0;
for (int i = 0; i < n; i++) {
if (v[i] != T())
r++;
}
return r;
}
class iterator {
public:
const VRegMap<T>& map;
int i;
iterator(const VRegMap<T>& map, int i) : map(map), i(i) {}
// TODO: make this skip unset values?
iterator& operator++() {
i++;
return *this;
......@@ -66,6 +84,8 @@ public:
bool operator!=(const iterator& rhs) const { return !(*this == rhs); }
std::pair<int, const T&> operator*() { return std::pair<int, const T&>(i, map[i]); }
int first() const { return i; }
const T& second() const { return map[i]; }
};
int numVregs() const { return v.size(); }
......
......@@ -2429,8 +2429,11 @@ public:
}
};
ConcreteCompilerType* BOOL = new BoolType();
llvm::Value* makeLLVMBool(bool b) {
return llvm::ConstantInt::get(BOOL->llvmType(), b, false);
}
ConcreteCompilerVariable* makeBool(bool b) {
return new ConcreteCompilerVariable(BOOL, llvm::ConstantInt::get(BOOL->llvmType(), b, false));
return new ConcreteCompilerVariable(BOOL, makeLLVMBool(b));
}
ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate) {
......@@ -2858,6 +2861,17 @@ llvm::Value* i1FromBool(IREmitter& emitter, ConcreteCompilerVariable* v) {
}
}
llvm::Value* i1FromLLVMBool(IREmitter& emitter, llvm::Value* v) {
if (BOOLS_AS_I64) {
assert(v->getType() == BOOL->llvmType());
assert(BOOL->llvmType() == g.i64);
llvm::Value* v2 = emitter.getBuilder()->CreateTrunc(v, g.i1);
return v2;
} else {
return v;
}
}
ConcreteCompilerType* LIST, *SLICE, *MODULE, *DICT, *SET, *FROZENSET, *LONG, *BOXED_COMPLEX;
......
......@@ -346,6 +346,7 @@ CompilerVariable* makeFloat(double);
CompilerVariable* makeUnboxedFloat(IREmitter&, ConcreteCompilerVariable*);
CompilerVariable* makeUnboxedFloat(IREmitter&, llvm::Value*);
llvm::Value* makeLLVMBool(bool b);
ConcreteCompilerVariable* makeBool(bool);
ConcreteCompilerVariable* makeLong(IREmitter&, Box*);
ConcreteCompilerVariable* makePureImaginary(IREmitter&, Box*);
......@@ -372,6 +373,7 @@ CompilerType* makeFuncType(ConcreteCompilerType* rtn_type, const std::vector<Con
ConcreteCompilerVariable* boolFromI1(IREmitter&, llvm::Value*);
llvm::Value* i1FromBool(IREmitter&, ConcreteCompilerVariable*);
llvm::Value* i1FromLLVMBool(IREmitter&, llvm::Value*);
template <typename V>
CompilerVariable* _ValuedCompilerType<V>::getPystonIter(IREmitter& emitter, const OpInfo& info, VAR* var) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -21,6 +21,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Instructions.h"
#include "analysis/function_analysis.h"
#include "core/stringpool.h"
#include "core/types.h"
......@@ -43,9 +44,10 @@ class TypeAnalysis;
class RefcountTracker;
class UnwindInfo;
typedef std::unordered_map<InternedString, CompilerVariable*> SymbolTable;
typedef std::map<InternedString, CompilerVariable*> SortedSymbolTable;
typedef std::unordered_map<InternedString, ConcreteCompilerVariable*> ConcreteSymbolTable;
typedef VRegMap<CompilerVariable*> SymbolTable;
typedef VRegMap<llvm::Value*> DefinednessTable;
typedef VRegMap<CompilerVariable*> SortedSymbolTable;
typedef VRegMap<ConcreteCompilerVariable*> ConcreteSymbolTable;
extern const std::string CREATED_CLOSURE_NAME;
extern const std::string PASSED_CLOSURE_NAME;
......@@ -153,15 +155,20 @@ public:
// symbol_table records which Python variables are bound to what CompilerVariables at the end of this block.
// phi_symbol_table records the ones that will need to be `phi'd.
// both only record non-globals.
// TODO: switch these to unique_ptr's
SymbolTable* symbol_table;
ConcreteSymbolTable* phi_symbol_table;
DefinednessTable* definedness_vars;
llvm::BasicBlock* ending_block;
llvm::SmallVector<ExceptionState, 2> exception_state;
EndingState(SymbolTable* symbol_table, ConcreteSymbolTable* phi_symbol_table, llvm::BasicBlock* ending_block,
EndingState(SymbolTable* symbol_table, ConcreteSymbolTable* phi_symbol_table,
DefinednessTable* definedness_vars, llvm::BasicBlock* ending_block,
llvm::ArrayRef<ExceptionState> exception_state)
: symbol_table(symbol_table),
phi_symbol_table(phi_symbol_table),
definedness_vars(definedness_vars),
ending_block(ending_block),
exception_state(exception_state.begin(), exception_state.end()) {}
};
......@@ -172,6 +179,8 @@ public:
= 0;
virtual void giveLocalSymbol(InternedString name, CompilerVariable* var) = 0;
virtual void giveLocalSymbol(int vreg, CompilerVariable* var) = 0;
virtual void giveDefinednessVar(int vreg, llvm::Value* val) = 0;
virtual void copySymbolsFrom(SymbolTable* st) = 0;
virtual void run(const CFGBlock* block) = 0; // primary entry point
virtual EndingState getEndingSymbolTable() = 0;
......
......@@ -95,19 +95,19 @@ void removeDirectoryIfExists(const std::string& path);
// Checks that lhs and rhs, which are iterables of InternedStrings, have the
// same set of names in them.
template <class T1, class T2> bool sameKeyset(T1* lhs, T2* rhs) {
std::vector<InternedString> lv, rv;
for (typename T1::iterator it = lhs->begin(); it != lhs->end(); it++) {
lv.push_back(it->first);
std::vector<int> lv, rv;
for (typename T1::iterator it = lhs->begin(); it != lhs->end(); ++it) {
lv.push_back((*it).first);
}
for (typename T2::iterator it = rhs->begin(); it != rhs->end(); it++) {
rv.push_back(it->first);
for (typename T2::iterator it = rhs->begin(); it != rhs->end(); ++it) {
rv.push_back((*it).first);
}
std::sort(lv.begin(), lv.end());
std::sort(rv.begin(), rv.end());
std::vector<InternedString> lextra(lv.size());
std::vector<InternedString>::iterator diffend
std::vector<int> lextra(lv.size());
std::vector<int>::iterator diffend
= std::set_difference(lv.begin(), lv.end(), rv.begin(), rv.end(), lextra.begin());
lextra.resize(diffend - lextra.begin());
......@@ -115,19 +115,19 @@ template <class T1, class T2> bool sameKeyset(T1* lhs, T2* rhs) {
if (lextra.size()) {
printf("Only in lhs:\n");
for (int i = 0; i < lextra.size(); i++) {
printf("%s\n", lextra[i].c_str());
printf("%d\n", lextra[i]);
}
good = false;
}
std::vector<InternedString> rextra(rv.size());
std::vector<int> rextra(rv.size());
diffend = std::set_difference(rv.begin(), rv.end(), lv.begin(), lv.end(), rextra.begin());
rextra.resize(diffend - rextra.begin());
if (rextra.size()) {
printf("Only in rhs:\n");
for (int i = 0; i < rextra.size(); i++) {
printf("%s\n", rextra[i].c_str());
printf("%d\n", rextra[i]);
}
good = false;
}
......
# I think we have some other similar tests to this, but it's hard to find them.
def f(x):
if x:
y = 1
if '':
pass
print y
for i in xrange(10000):
f(1)
try:
f(0)
assert 0
except UnboundLocalError:
pass
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