SgType * TypeTable::createType(const std::string & name) { if(boost::starts_with(name, "complex ")) { std::string subtype = name.substr(8, std::string::npos); return SageBuilder::buildComplexType(createType(nameToType(subtype))); } return createType(nameToType(name)); }
static LLVMValueRef translateNilExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) { if (!Node->Value) exit(1); Type *RecordType = createType(IdTy, ((Type*)Node->Value)->Val); LLVMTypeRef Record = getLLVMTypeFromType(TyTable, RecordType); return LLVMConstPointerNull(LLVMPointerType(Record, 0)); }
static LLVMValueRef translateRecordExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) { PtrVector *V = &(Node->Child); ASTNode *FieldNode = (ASTNode*) ptrVectorGet(V, 0); Type *ThisType = createType(IdTy, Node->Value); LLVMTypeRef RecordType = getLLVMTypeFromType(TyTable, ThisType); LLVMValueRef RecordVal = LLVMBuildMalloc(Builder, RecordType, ""); unsigned FieldNumber = LLVMCountStructElementTypes(RecordType), I; for (I = 0; I < FieldNumber; ++I) { LLVMValueRef ElemIdx[] = { getSConstInt(0), getSConstInt(I) }; LLVMValueRef ElemI = LLVMBuildInBoundsGEP(Builder, RecordVal, ElemIdx, 2, ""); LLVMValueRef FieldPtr = translateExpr(TyTable, ValTable, ptrVectorGet(&(FieldNode->Child), I)); LLVMValueRef ValueFrom = NULL; switch (LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(FieldPtr)))) { case LLVMIntegerTypeKind: case LLVMFloatTypeKind: ValueFrom = LLVMBuildLoad(Builder, FieldPtr, ""); break; case LLVMPointerTypeKind: ValueFrom = toDynamicMemory(FieldPtr); break; default: ValueFrom = FieldPtr; } LLVMBuildStore(Builder, ValueFrom, ElemI); } return RecordVal; }
//Laadt de map in de huidige objectmanager. bool MapLoader::load(std::string fileName){ float locationX; float locationY; float locationWidth; float locationHeight; int type=0; float parameter = 0; reader.read(fileName); manager->loadBackground( reader.getParameterValue("header", "background") ); for (int i=0; i<reader.elements.key.size(); i++){ if (reader.elements.key.at(i) == "objects"){ for(int j=0;j<reader.elements.value.at(i).key.size();j++){ if (reader.elements.value.at(i).key.at(j) == "location"){ locationX = std::stof( reader.commaExtract( reader.elements.value.at(i).value.at(j) ,0) ); locationY = std::stof( reader.commaExtract( reader.elements.value.at(i).value.at(j) ,1) ); locationWidth = std::stof( reader.commaExtract( reader.elements.value.at(i).value.at(j) ,2) ); locationHeight = std::stof( reader.commaExtract( reader.elements.value.at(i).value.at(j) ,3) ); }//if else if (reader.elements.value.at(i).key.at(j) == "type"){ type = std::stoi(reader.elements.value.at(i).value.at(j)); }else if (reader.elements.value.at(i).key.at(j) == "parameter"){ parameter = std::stof(reader.elements.value.at(i).value.at(j)); }//if }//for createType(manager, type,locationX + locationWidth/2,locationY + locationHeight/2, locationWidth, locationHeight, parameter ); }//if }//for return 1; }//load
TypePtr makeStringType (long length) { TypePtr stringTypePtr = createType(); if (!stringTypePtr) ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc stringType "); stringTypePtr->form = FRM_ARRAY; stringTypePtr->size = length; stringTypePtr->typeIdPtr = NULL; stringTypePtr->info.array.indexTypePtr = IntegerTypePtr; stringTypePtr->info.array.elementTypePtr = CharTypePtr; stringTypePtr->info.array.elementCount = length + 1; return(stringTypePtr); }
static LLVMValueRef translateArrayExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) { PtrVector *V = &(Node->Child); ASTNode *SizeNode = (ASTNode*) ptrVectorGet(V, 0), *InitNode = (ASTNode*) ptrVectorGet(V, 1); Type *ThisType = createType(IdTy, Node->Value); LLVMTypeRef ArrayType = getLLVMTypeFromType(TyTable, ThisType); LLVMValueRef SizeVal = translateExpr(TyTable, ValTable, SizeNode), InitVal = translateExpr(TyTable, ValTable, InitNode); LLVMValueRef ArrayVal = LLVMBuildArrayMalloc(Builder, ArrayType, SizeVal, ""); // This BasicBlock and ThisFunction LLVMBasicBlockRef ThisBB = LLVMGetInsertBlock(Builder); LLVMValueRef ThisFn = LLVMGetBasicBlockParent(ThisBB); LLVMValueRef Counter = LLVMBuildAlloca(Builder, LLVMInt32Type(), ""); LLVMBuildStore(Builder, LLVMConstInt(LLVMInt32Type(), 0, 1), Counter); LLVMTargetDataRef DataRef = LLVMCreateTargetData(LLVMGetDataLayout(Module)); unsigned long long Size = LLVMStoreSizeOfType(DataRef, ArrayType); LLVMBasicBlockRef InitBB, MidBB, EndBB; InitBB = LLVMAppendBasicBlock(ThisFn, "for.init"); EndBB = LLVMAppendBasicBlock(ThisFn, "for.end"); MidBB = LLVMAppendBasicBlock(ThisFn, "for.mid"); LLVMBuildBr(Builder, InitBB); LLVMPositionBuilderAtEnd(Builder, InitBB); LLVMValueRef CurrentCounter = LLVMBuildLoad(Builder, Counter, ""); LLVMValueRef Comparation = LLVMBuildICmp(Builder, LLVMIntSLT, CurrentCounter, SizeVal, ""); LLVMBuildCondBr(Builder, Comparation, MidBB, EndBB); LLVMPositionBuilderAtEnd(Builder, MidBB); CurrentCounter = LLVMBuildLoad(Builder, Counter, ""); LLVMValueRef TheValue = LLVMBuildLoad(Builder, InitVal, ""); LLVMValueRef ElemIdx[] = { LLVMConstInt(LLVMInt32Type(), 0, 1), CurrentCounter }; LLVMValueRef Elem = LLVMBuildInBoundsGEP(Builder, ArrayVal, ElemIdx, 2, ""); copyMemory(Elem, TheValue, getSConstInt(Size)); LLVMBuildBr(Builder, InitBB); LLVMPositionBuilderAtEnd(Builder, EndBB); return ArrayVal; }
// ------------------------------------------------------- QString LibComp::vhdlCode(int) { QString s = " " + Name + ": entity Sub_" + createType() + " port map ("; // output all node names QListIterator<Port *> iport(Ports); Port *pp = iport.next(); if(pp) s += pp->Connection->Name; while (iport.hasNext()) { pp = iport.next(); s += ", "+pp->Connection->Name; // node names } s += ");\n"; return s; }
// ------------------------------------------------------- QString LibComp::netlist() { QString s = "Sub:"+Name; // output as subcircuit // output all node names foreach(Port *p1, Ports) s += " "+p1->Connection->Name; // node names // output property s += " Type=\""+createType()+"\""; // type for subcircuit // output user defined parameters for(Property *pp = Props.at(2); pp != 0; pp = Props.next()) s += " "+pp->Name+"=\""+pp->Value+"\""; return s + '\n'; }
TypePtr enumerationType (void) { SymTableNodePtr constantIdPtr = NULL; SymTableNodePtr lastIdPtr = NULL; TypePtr typePtr = createType(); if (!typePtr) ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc enumeration type "); long constantValue = -1; typePtr->form = FRM_ENUM; typePtr->size = sizeof(long); typePtr->typeIdPtr = NULL; getToken(); //------------------------------------------------------------ // Process list of identifiers in this new enumeration type... while (curToken == TKN_IDENTIFIER) { searchAndEnterLocalSymTable(constantIdPtr); constantIdPtr->defn.key = DFN_CONST; constantIdPtr->defn.info.constant.value.integer = ++constantValue; constantIdPtr->typePtr = typePtr; constantIdPtr->library = CurLibrary; if (lastIdPtr == NULL) typePtr->info.enumeration.constIdPtr = lastIdPtr = constantIdPtr; else { lastIdPtr->next = constantIdPtr; lastIdPtr = constantIdPtr; } getToken(); ifTokenGet(TKN_COMMA); } ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN); typePtr->info.enumeration.max = constantValue; return(typePtr); }
STDMETHODIMP CMethod::raw_getReturnType(IType** ppType) { *ppType = createType(m_pParent, m_pDesc->elemdescFunc.tdesc); return S_OK; }
LinkEvaluatorBase* LinkEvaluatorFactory::createEvaluator(const std::string& typeString) { return dynamic_cast<LinkEvaluatorBase*>(createType(typeString)); }
TypePtr doType (void) { switch (curToken) { case TKN_IDENTIFIER: { SymTableNodePtr idPtr; searchAllSymTables(idPtr); if (!idPtr) { syntaxError(ABL_ERR_SYNTAX_UNDEFINED_IDENTIFIER); return(NULL); } else if (idPtr->defn.key == DFN_TYPE) { //---------------------------------------------------------- // NOTE: Array types should be parsed in this case if a left // bracket follows the type identifier. TypePtr elementType = setType(identifierType(idPtr)); if (curToken == TKN_LBRACKET) { //-------------- // Array type... TypePtr typePtr = createType(); if (!typePtr) ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc array type "); TypePtr elementTypePtr = typePtr; do { getToken(); if (tokenIn(indexTypeStartList)) { elementTypePtr->form = FRM_ARRAY; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; //---------------------------------------------- // All array indices must be integer, for now... elementTypePtr->info.array.indexTypePtr = setType(IntegerTypePtr); //------------------------ // Read the index count... switch (curToken) { case TKN_NUMBER: if (curLiteral.type == LIT_INTEGER) elementTypePtr->info.array.elementCount = curLiteral.value.integer; else { elementTypePtr->form = FRM_NONE; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; elementTypePtr->info.array.indexTypePtr = NULL; syntaxError(ABL_ERR_SYNTAX_INVALID_INDEX_TYPE); } getToken(); break; case TKN_IDENTIFIER: { SymTableNodePtr idPtr; searchAllSymTables(idPtr); if (idPtr == NULL) syntaxError(ABL_ERR_SYNTAX_UNDEFINED_IDENTIFIER); else if (idPtr->defn.key == DFN_CONST) { if (idPtr->typePtr == IntegerTypePtr) elementTypePtr->info.array.elementCount = idPtr->defn.info.constant.value.integer; else { elementTypePtr->form = FRM_NONE; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; elementTypePtr->info.array.indexTypePtr = NULL; syntaxError(ABL_ERR_SYNTAX_INVALID_INDEX_TYPE); } } else { elementTypePtr->form = FRM_NONE; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; elementTypePtr->info.array.indexTypePtr = NULL; syntaxError(ABL_ERR_SYNTAX_INVALID_INDEX_TYPE); } getToken(); } break; default: elementTypePtr->form = FRM_NONE; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; elementTypePtr->info.array.indexTypePtr = NULL; syntaxError(ABL_ERR_SYNTAX_INVALID_INDEX_TYPE); getToken(); } } else { elementTypePtr->form = FRM_NONE; elementTypePtr->size = 0; elementTypePtr->typeIdPtr = NULL; elementTypePtr->info.array.indexTypePtr = NULL; syntaxError(ABL_ERR_SYNTAX_INVALID_INDEX_TYPE); getToken(); } synchronize(followDimensionList, NULL, NULL); //-------------------------------- // Create an array element type... if (curToken == TKN_COMMA) { elementTypePtr = elementTypePtr->info.array.elementTypePtr = createType(); if (!elementTypePtr) ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc array element Type "); } } while (curToken == TKN_COMMA); ifTokenGetElseError(TKN_RBRACKET, ABL_ERR_SYNTAX_MISSING_RBRACKET); elementTypePtr->info.array.elementTypePtr = elementType; typePtr->size = arraySize(typePtr); elementType = typePtr; } return(elementType); } else { syntaxError(ABL_ERR_SYNTAX_NOT_A_TYPE_IDENTIFIER); return(NULL); } } break; case TKN_LPAREN: return(enumerationType()); default: syntaxError(ABL_ERR_SYNTAX_INVALID_TYPE); return(NULL); } }
void initSymTable (void) { //--------------------------------- // Init the level-0 symbol table... SymTableDisplay[0] = NULL; //---------------------------------------------------------------------- // Set up the basic variable types as identifiers in the symbol table... SymTableNodePtr integerIdPtr; enterNameLocalSymTable(integerIdPtr, "integer"); SymTableNodePtr charIdPtr; enterNameLocalSymTable(charIdPtr, "char"); SymTableNodePtr realIdPtr; enterNameLocalSymTable(realIdPtr, "real"); SymTableNodePtr booleanIdPtr; enterNameLocalSymTable(booleanIdPtr, "boolean"); SymTableNodePtr falseIdPtr; enterNameLocalSymTable(falseIdPtr, "false"); SymTableNodePtr trueIdPtr; enterNameLocalSymTable(trueIdPtr, "true"); //------------------------------------------------------------------ // Now, create the basic variable TYPEs, and point their identifiers // to their proper type definition... IntegerTypePtr = createType(); if (!IntegerTypePtr) ABL_Fatal(0, " ABL: Unable to AblSymTableHeap->malloc Integer Type "); CharTypePtr = createType(); if (!CharTypePtr) ABL_Fatal(0, " ABL: Unable to AblSymTableHeap->malloc Char Type "); RealTypePtr = createType(); if (!RealTypePtr) ABL_Fatal(0, " ABL: Unable to AblSymTableHeap->malloc Real Type "); BooleanTypePtr = createType(); if (!BooleanTypePtr) ABL_Fatal(0, " ABL: Unable to AblSymTableHeap->malloc Boolean Type "); integerIdPtr->defn.key = DFN_TYPE; integerIdPtr->typePtr = IntegerTypePtr; IntegerTypePtr->form = FRM_SCALAR; IntegerTypePtr->size = sizeof(long); IntegerTypePtr->typeIdPtr = integerIdPtr; charIdPtr->defn.key = DFN_TYPE; charIdPtr->typePtr = CharTypePtr; CharTypePtr->form = FRM_SCALAR; CharTypePtr->size = sizeof(char); CharTypePtr->typeIdPtr = charIdPtr; realIdPtr->defn.key = DFN_TYPE; realIdPtr->typePtr = RealTypePtr; RealTypePtr->form = FRM_SCALAR; RealTypePtr->size = sizeof(float); RealTypePtr->typeIdPtr = realIdPtr; booleanIdPtr->defn.key = DFN_TYPE; booleanIdPtr->typePtr = BooleanTypePtr; BooleanTypePtr->form = FRM_ENUM; BooleanTypePtr->size = sizeof(long); BooleanTypePtr->typeIdPtr = booleanIdPtr; //---------------------------------------------------- // Set up the FALSE identifier for the boolean type... BooleanTypePtr->info.enumeration.max = 1; ((TypePtr)(booleanIdPtr->typePtr))->info.enumeration.constIdPtr = falseIdPtr; falseIdPtr->defn.key = DFN_CONST; falseIdPtr->defn.info.constant.value.integer = 0; falseIdPtr->typePtr = BooleanTypePtr; //---------------------------------------------------- // Set up the TRUE identifier for the boolean type... falseIdPtr->next = trueIdPtr; trueIdPtr->defn.key = DFN_CONST; trueIdPtr->defn.info.constant.value.integer = 1; trueIdPtr->typePtr = BooleanTypePtr; //------------------------------------------- // Set up the standard, built-in functions... //(char* name, long routineKey, bool isOrder, char* paramList, char* returnType, void* callback); enterStandardRoutine("return", RTN_RETURN, false, NULL, NULL, NULL); enterStandardRoutine("print", RTN_PRINT, false, NULL, NULL, NULL); enterStandardRoutine("concat", RTN_CONCAT, false, NULL, NULL, NULL); enterStandardRoutine("getstatehandle", RTN_GET_STATE_HANDLE, false, NULL, NULL, NULL); //----------------------------------- // Honor Bound-specific extensions... //----------------------------------- initStandardRoutines(); }