Skip to content

Commit e0fcf37

Browse files
committed
unbreak tests with typechecker enabled
1 parent 2c32ac3 commit e0fcf37

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class Compiler : public Visitor {
236236
void optimizeModule(ExecutionEngine * ee) {
237237
auto *pm = new legacy::FunctionPassManager(m);
238238
m->setDataLayout(*ee->getDataLayout());
239-
//pm->add(new TypeChecker());
239+
pm->add(new TypeChecker());
240240
pm->add(new TypeAnalysis());
241241
pm->add(new Unboxing());
242242
pm->add(new BoxingRemoval());

type_checker.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ bool TypeChecker::runOnFunction(llvm::Function & f) {
1616
if (CallInst * ci = dyn_cast<CallInst>(&i)) {
1717
StringRef s = ci->getCalledFunction()->getName();
1818
if (s == "doubleVectorLiteral") {
19-
state.upddate(ci, Type::D);
19+
state.update(ci, Type::D);
2020
} else if (s == "fromDoubleVector") {
21-
state.upddate(ci, Type::D);
21+
state.update(ci, Type::D);
2222
} else if (s == "characterVectorLiteral") {
23-
state.upddate(ci, Type::C);
23+
state.update(ci, Type::C);
2424
} else if (s == "fromCharacterVector") {
25-
state.upddate(ci, Type::C);
25+
state.update(ci, Type::C);
2626
} else if (s == "genericSub") {
2727
Type t1 = state.get(ci->getOperand(0));
2828
Type t2 = state.get(ci->getOperand(1));
@@ -32,14 +32,45 @@ bool TypeChecker::runOnFunction(llvm::Function & f) {
3232
switch (t2) {
3333
case Type::D:
3434
case Type::T:
35-
state.upddate(ci, Type::D);
35+
state.update(ci, Type::D);
3636
break;
3737
default:
38-
throw "Invalid types for binary subtraction";
38+
throw "TypeErr: Invalid types for binary subtraction";
3939
}
4040
break;
4141
default:
42-
throw "Invalid types for binary subtraction";
42+
throw "TypeErr: Invalid types for binary subtraction";
43+
}
44+
} else if (s == "fromFunction") {
45+
state.update(ci, Type::F);
46+
} else if (s == "genericGetElement") {
47+
Type vector_t = state.get(ci->getOperand(0));
48+
Type index_t = state.get(ci->getOperand(1));
49+
if (vector_t == Type::F) {
50+
throw "TypeErr: Cannot index functions";
51+
}
52+
switch (index_t) {
53+
case Type::C:
54+
throw "TypeErr: character is not a valid index";
55+
case Type::F:
56+
throw "TypeErr: A function is not a valid index";
57+
case Type::T:
58+
case Type::D:
59+
state.update(ci, vector_t);
60+
break;
61+
default:
62+
assert(false);
63+
}
64+
65+
//Complete me
66+
67+
} else {
68+
// If we still don't know nothing about the instruction
69+
// set it to T, since it could be anything. If we handle
70+
// all cases above this case should not be reached
71+
// anymore.
72+
if (state.get(ci) == Type::B) {
73+
state.update(ci, Type::T);
4374
}
4475
}
4576
}

type_checker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TypeChecker : public llvm::FunctionPass {
3939
return Type::B;
4040
}
4141

42-
void upddate(llvm::Value * v, Type t) {
42+
void update(llvm::Value * v, Type t) {
4343
Type prev = get(v);
4444
if (prev < t) {
4545
type[v] = t;

0 commit comments

Comments
 (0)