@@ -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 }
0 commit comments