Commit fc9ad920 authored by Travis Hance's avatar Travis Hance

inline the assert check

parent de5fde04
......@@ -917,8 +917,30 @@ private:
llvm::ConstantInt::get(g.i32, deref_info.offset) });
llvm::Value* lookupResult = emitter.getBuilder()->CreateLoad(gep);
emitter.createCall(unw_info, g.funcs.assertDerefNameDefined,
{ lookupResult, getStringConstantPtr(node->id.str() + '\0') });
// If the value is NULL, it is undefined.
// Create a branch on if the value is NULL
llvm::BasicBlock* success_bb
= llvm::BasicBlock::Create(g.context, "deref_defined", irstate->getLLVMFunction());
success_bb->moveAfter(curblock);
llvm::BasicBlock* fail_bb
= llvm::BasicBlock::Create(g.context, "deref_undefined", irstate->getLLVMFunction());
llvm::Value* check_val
= emitter.getBuilder()->CreateICmpEQ(lookupResult, embedConstantPtr(NULL, g.llvm_value_type_ptr));
llvm::BranchInst* non_null_check = emitter.getBuilder()->CreateCondBr(check_val, fail_bb, success_bb);
// In the case that it failed, call the assert fail function
curblock = fail_bb;
emitter.getBuilder()->SetInsertPoint(curblock);
llvm::CallSite call = emitter.createCall(unw_info, g.funcs.assertFailDerefNameDefined,
getStringConstantPtr(node->id.str() + '\0'));
call.setDoesNotReturn();
emitter.getBuilder()->CreateUnreachable();
// Carry on in the case that it succeeded
curblock = success_bb;
emitter.getBuilder()->SetInsertPoint(curblock);
return new ConcreteCompilerVariable(UNKNOWN, lookupResult, true);
} else if (vst == ScopeInfo::VarScopeType::NAME) {
......@@ -1459,13 +1481,6 @@ private:
closureValue, { llvm::ConstantInt::get(g.i32, 0), llvm::ConstantInt::get(g.i32, 3),
llvm::ConstantInt::get(g.i32, offset) });
emitter.getBuilder()->CreateStore(val->makeConverted(emitter, UNKNOWN)->getValue(), gep);
/*
CompilerVariable* closure = symbol_table[internString(CREATED_CLOSURE_NAME)];
assert(closure);
closure->setattr(emitter, getEmptyOpInfo(unw_info), &name.str(), val);
*/
}
}
}
......
......@@ -216,7 +216,7 @@ void initGlobalFuncs(GlobalState& g) {
GET(raiseAttributeErrorStr);
GET(raiseNotIterableError);
GET(assertNameDefined);
GET(assertDerefNameDefined);
GET(assertFailDerefNameDefined);
GET(assertFail);
GET(printFloat);
......
......@@ -41,7 +41,7 @@ struct GlobalFuncs {
*exceptionMatches, *yield, *getiterHelper, *hasnext;
llvm::Value* unpackIntoArray, *raiseAttributeError, *raiseAttributeErrorStr, *raiseNotIterableError,
*assertNameDefined, *assertFail, *assertDerefNameDefined;
*assertNameDefined, *assertFail, *assertFailDerefNameDefined;
llvm::Value* printFloat, *listAppendInternal, *getSysStdout;
llvm::Value* runtimeCall0, *runtimeCall1, *runtimeCall2, *runtimeCall3, *runtimeCall, *runtimeCallN;
llvm::Value* callattr0, *callattr1, *callattr2, *callattr3, *callattr, *callattrN;
......
......@@ -98,7 +98,7 @@ void force() {
FORCE(raiseAttributeErrorStr);
FORCE(raiseNotIterableError);
FORCE(assertNameDefined);
FORCE(assertDerefNameDefined);
FORCE(assertFailDerefNameDefined);
FORCE(assertFail);
FORCE(printFloat);
......
......@@ -233,10 +233,8 @@ extern "C" void assertNameDefined(bool b, const char* name, BoxedClass* exc_cls,
}
}
extern "C" void assertDerefNameDefined(Box* b, const char* name) {
if (b == NULL) {
extern "C" void assertFailDerefNameDefined(const char* name) {
raiseExcHelper(NameError, "free variable '%s' referenced before assignment in enclosing scope", name);
}
}
extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) {
......
......@@ -83,7 +83,7 @@ extern "C" Box* importFrom(Box* obj, const std::string* attr);
extern "C" Box* importStar(Box* from_module, BoxedModule* to_module);
extern "C" Box** unpackIntoArray(Box* obj, int64_t expected_size);
extern "C" void assertNameDefined(bool b, const char* name, BoxedClass* exc_cls, bool local_var_msg);
extern "C" void assertDerefNameDefined(Box* b, const char* name);
extern "C" void assertFailDerefNameDefined(const char* name);
extern "C" void assertFail(BoxedModule* inModule, Box* msg);
extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent);
extern "C" BoxedClosure* createClosure(BoxedClosure* parent_closure, size_t size);
......
......@@ -158,6 +158,8 @@ def run_test(fn, check_stats, run_memcheck):
skip = eval(skip_if)
if skip:
return r + " (skipped due to 'skip-if: %s')" % skip_if[:30]
elif fn.split('.')[0] in TESTS_TO_SKIP:
return r + " (skipped due to command line option)"
elif l.startswith("# allow-warning:"):
allow_warnings.append("Warning: " + l.split(':', 1)[1].strip())
elif l.startswith("# no-collect-stats"):
......@@ -386,6 +388,8 @@ parser.add_argument('-a', '--extra-args', default=[], action='append',
help="additional arguments to pyston (must be invoked with equal sign: -a=-ARG)")
parser.add_argument('-t', '--time-limit', type=int, default=TIME_LIMIT,
help='set time limit in seconds for each test')
parser.add_argument('-s', '--skip-tests', type=str, default='',
help='tests to skip (comma-separated)')
parser.add_argument('test_dir')
parser.add_argument('patterns', nargs='*')
......@@ -397,6 +401,7 @@ def main(orig_dir):
global TIME_LIMIT
global TEST_DIR
global FN_JUST_SIZE
global TESTS_TO_SKIP
run_memcheck = False
start = 1
......@@ -408,6 +413,7 @@ def main(orig_dir):
KEEP_GOING = opts.keep_going
EXTRA_JIT_ARGS += opts.extra_args
TIME_LIMIT = opts.time_limit
TESTS_TO_SKIP = opts.skip_tests.split(',')
TEST_DIR = os.path.join(orig_dir, opts.test_dir)
patterns = opts.patterns
......
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