Commit d3657206 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add some extra error checking during irgen

parent 204b1da6
......@@ -50,3 +50,5 @@ compile.log
*.swp
*.swo
*.out
......@@ -528,8 +528,7 @@ llvm_install: llvm_release
# Clear OPTIONAL_DIRS and OPTIONAL_PARALLEL_DIRS to make sure that clang doesn't get built+tested
llvm_test: llvm_test_quick
$(MAKE) llvm_test_release
llvm_test_quick: llvm_test_quick
llvm_test_quick: llvm_quick llvm/quick/tools/opt
$(MAKE) -C $(LLVM_BUILD) OPTIONAL_DIRS= OPTIONAL_PARALLEL_DIRS= ENABLE_OPTIMIZED=1 check
llvm_test_release: llvm_release
$(MAKE) -C $(LLVM_BUILD) OPTIONAL_DIRS= OPTIONAL_PARALLEL_DIRS= ENABLE_OPTIMIZED=1 DISABLE_ASSERTIONS=1 check
......
......@@ -64,6 +64,10 @@ private:
}
public:
void assertMatches(RawInstanceMethod* im) override {
assert(obj_type == im->obj->getType() && function_type == im->func->getType());
}
static InstanceMethodType* get(CompilerType* obj_type, CompilerType* function_type) {
InstanceMethodType* rtn = made[std::make_pair(obj_type, function_type)];
if (rtn == NULL)
......@@ -1154,6 +1158,8 @@ private:
public:
virtual std::string debugName() { return "class '" + *getNameOfClass(cls) + "'"; }
void assertMatches(BoxedClass* cls) override { assert(cls == this->cls); }
static KnownClassobjType* fromClass(BoxedClass* cls) {
KnownClassobjType*& rtn = made[cls];
if (rtn == NULL) {
......@@ -1544,6 +1550,8 @@ class StrConstantType : public ValuedCompilerType<const std::string*> {
public:
std::string debugName() { return "str_constant"; }
void assertMatches(const std::string* v) override {}
virtual ConcreteCompilerType* getConcreteType() { return STR; }
virtual ConcreteCompilerType* getBoxType() { return STR; }
......@@ -1721,6 +1729,14 @@ private:
public:
typedef const std::vector<CompilerVariable*> VEC;
void assertMatches(const std::vector<CompilerVariable*>* v) override {
assert(v->size() == elt_types.size());
for (int i = 0; i < v->size(); i++) {
assert((*v)[i]->getType() == elt_types[i]);
}
}
std::string debugName() { return name; }
virtual void drop(IREmitter& emitter, VAR* var) {
......
......@@ -18,6 +18,9 @@
#include <stdint.h>
#include <vector>
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "core/ast.h"
#include "core/types.h"
......@@ -53,6 +56,8 @@ template <class V> class _ValuedCompilerType : public CompilerType {
public:
typedef ValuedCompilerVariable<V> VAR;
virtual void assertMatches(V v) = 0;
virtual CompilerVariable* dup(VAR* v, DupCache& cache) {
printf("dup not defined for %s\n", debugName().c_str());
abort();
......@@ -156,6 +161,15 @@ public:
virtual llvm::Type* llvmType() = 0;
virtual std::string debugName();
void assertMatches(llvm::Value* v) override final {
if (v->getType() != llvmType()) {
v->getType()->dump();
llvmType()->dump();
fprintf(stderr, "\n");
}
assert(v->getType() == llvmType());
}
virtual bool isFitBy(BoxedClass*) {
printf("isFitBy not defined for %s\n", debugName().c_str());
abort();
......@@ -253,7 +267,11 @@ protected:
virtual void grab(IREmitter& emmitter) { type->grab(emmitter, this); }
public:
ValuedCompilerVariable(T* type, V value, bool grabbed) : CompilerVariable(grabbed), type(type), value(value) {}
ValuedCompilerVariable(T* type, V value, bool grabbed) : CompilerVariable(grabbed), type(type), value(value) {
#ifndef NDEBUG
type->assertMatches(value);
#endif
}
virtual T* getType() { return type; }
virtual V getValue() { return value; }
......
# expected: fail
# - locals not supported
def f1():
l = []
for i in xrange(5):
l.append(i ** 2)
print sorted(locals().items())
f1()
def f():
total = 0
i = 1 or ''
while i < 200:
while i < 20:
i = i + 1
j = 2
while j * j <= i:
if i % j == 0:
break
j = j + 1
print locals()
print sorted(locals().items())
else:
total = total + i
print total
f()
def f3():
"""Testing unboxed values"""
x = 1.0
y = 1
z = 123456789123456789
s = "hello world"
t = (1.0, "asdf")
print sorted(locals().items())
f3()
def f4():
"""testing synthetic 'is_defined' variables"""
if 0:
x = 1
else:
y = 2
print sorted(locals().items())
# f4()
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