static void displayCompileContext() { if (contextStack.empty()) return; fprintf(stderr, "\n"); fprintf(stderr, "compilation context: \n"); for (unsigned i = contextStack.size(); i > 0; --i) { ObjectPtr obj = contextStack[i-1].first; const vector<ObjectPtr> ¶ms = contextStack[i-1].second; ostringstream sout; if (obj->objKind == GLOBAL_VARIABLE) { sout << "global "; printName(sout, obj); if (!params.empty()) { sout << "["; printNameList(sout, params); sout << "]"; } } else { printName(sout, obj); sout << "("; printNameList(sout, params); sout << ")"; } fprintf(stderr, " %s\n", sout.str().c_str()); } }
void typePrint(llvm::raw_ostream &out, TypePtr t) { switch (t->typeKind) { case BOOL_TYPE : out << "Bool"; break; case INTEGER_TYPE : { IntegerType *x = (IntegerType *)t.ptr(); if (!x->isSigned) out << "U"; out << "Int" << x->bits; break; } case FLOAT_TYPE : { FloatType *x = (FloatType *)t.ptr(); if(x->isImaginary) { out << "Imag" << x->bits; } else { out << "Float" << x->bits; } break; } case COMPLEX_TYPE : { ComplexType *x = (ComplexType *)t.ptr(); out << "Complex" << x->bits; break; } case POINTER_TYPE : { PointerType *x = (PointerType *)t.ptr(); out << "Pointer[" << x->pointeeType << "]"; break; } case CODE_POINTER_TYPE : { CodePointerType *x = (CodePointerType *)t.ptr(); out << "CodePointer[["; for (size_t i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << "], ["; for (size_t i = 0; i < x->returnTypes.size(); ++i) { if (i != 0) out << ", "; if (x->returnIsRef[i]) out << "ByRef[" << x->returnTypes[i] << "]"; else out << x->returnTypes[i]; } out << "]]"; break; } case CCODE_POINTER_TYPE : { CCodePointerType *x = (CCodePointerType *)t.ptr(); out << "ExternalCodePointer["; #define CALLING_CONV_PRINT(e, str) case e: out << str << ", "; break; switch (x->callingConv) { CALLING_CONV_MAP(CALLING_CONV_PRINT) default: assert(false); } #undef CALLING_CONV_PRINT if (x->hasVarArgs) out << "true, "; else out << "false, "; out << "["; for (size_t i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << "], ["; if (x->returnType.ptr()) out << x->returnType; out << "]]"; break; } case ARRAY_TYPE : { ArrayType *x = (ArrayType *)t.ptr(); out << "Array[" << x->elementType << ", " << x->size << "]"; break; } case VEC_TYPE : { VecType *x = (VecType *)t.ptr(); out << "Vec[" << x->elementType << ", " << x->size << "]"; break; } case TUPLE_TYPE : { TupleType *x = (TupleType *)t.ptr(); out << "Tuple" << x->elementTypes; break; } case UNION_TYPE : { UnionType *x = (UnionType *)t.ptr(); out << "Union" << x->memberTypes; break; } case RECORD_TYPE : { RecordType *x = (RecordType *)t.ptr(); out << x->record->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case VARIANT_TYPE : { VariantType *x = (VariantType *)t.ptr(); out << x->variant->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case STATIC_TYPE : { StaticType *x = (StaticType *)t.ptr(); out << "Static["; printName(out, x->obj); out << "]"; break; } case ENUM_TYPE : { EnumType *x = (EnumType *)t.ptr(); out << x->enumeration->name->str; break; } case NEW_TYPE : { NewType *x = (NewType *)t.ptr(); out << x->newtype->name->str; break; } default : assert(false); } }
void typePrint(ostream &out, TypePtr t) { switch (t->typeKind) { case BOOL_TYPE : out << "Bool"; break; case INTEGER_TYPE : { IntegerType *x = (IntegerType *)t.ptr(); if (!x->isSigned) out << "U"; out << "Int" << x->bits; break; } case FLOAT_TYPE : { FloatType *x = (FloatType *)t.ptr(); out << "Float" << x->bits; break; } case POINTER_TYPE : { PointerType *x = (PointerType *)t.ptr(); out << "Pointer[" << x->pointeeType << "]"; break; } case CODE_POINTER_TYPE : { CodePointerType *x = (CodePointerType *)t.ptr(); out << "CodePointer["; if (x->argTypes.size() == 1) { out << x->argTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << ")"; } out << ", "; if (x->returnTypes.size() == 1) { if (x->returnIsRef[0]) out << "ByRef[" << x->returnTypes[0] << "]"; else out << x->returnTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->returnTypes.size(); ++i) { if (i != 0) out << ", "; if (x->returnIsRef[i]) out << "ByRef[" << x->returnTypes[i] << "]"; else out << x->returnTypes[i]; } out << ")"; } out << "]"; break; } case CCODE_POINTER_TYPE : { CCodePointerType *x = (CCodePointerType *)t.ptr(); switch (x->callingConv) { case CC_DEFAULT : if (x->hasVarArgs) out << "VarArgsCCodePointer"; else out << "CCodePointer"; break; case CC_STDCALL : out << "StdCallCodePointer"; break; case CC_FASTCALL : out << "FastCallCodePointer"; break; default : assert(false); } out << "["; if (x->argTypes.size() == 1) { out << x->argTypes[0]; } else { out << "("; for (unsigned i = 0; i < x->argTypes.size(); ++i) { if (i != 0) out << ", "; out << x->argTypes[i]; } out << ")"; } out << ", "; if (x->returnType.ptr()) out << x->returnType; else out << "()"; out << "]"; break; } case ARRAY_TYPE : { ArrayType *x = (ArrayType *)t.ptr(); out << "Array[" << x->elementType << ", " << x->size << "]"; break; } case VEC_TYPE : { VecType *x = (VecType *)t.ptr(); out << "Vec[" << x->elementType << ", " << x->size << "]"; break; } case TUPLE_TYPE : { TupleType *x = (TupleType *)t.ptr(); out << "Tuple" << x->elementTypes; break; } case UNION_TYPE : { UnionType *x = (UnionType *)t.ptr(); out << "Union" << x->memberTypes; break; } case RECORD_TYPE : { RecordType *x = (RecordType *)t.ptr(); out << x->record->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case VARIANT_TYPE : { VariantType *x = (VariantType *)t.ptr(); out << x->variant->name->str; if (!x->params.empty()) { out << "["; printNameList(out, x->params); out << "]"; } break; } case STATIC_TYPE : { StaticType *x = (StaticType *)t.ptr(); out << "Static["; printName(out, x->obj); out << "]"; break; } case ENUM_TYPE : { EnumType *x = (EnumType *)t.ptr(); out << x->enumeration->name->str; break; } default : assert(false); } }