예제 #1
0
 void visitCallIndirect(CallIndirect* curr) {
   if (isDead(curr->target)) {
     replaceCurrent(curr->target);
     return;
   }
   handleCall(curr, curr->target);
 }
예제 #2
0
void Client::handleReceive()
{
	boost::asio::async_read(
		socket_,
		boost::asio::buffer(receive_.getBody(), receive_.getLength()),
		[this](boost::system::error_code ec, std::size_t)
		{
			if ( ! ec)
			{
				
				switch (receive_.getType())
				{
					case PacketType::STATE:
						std::cout << "Received state packet" << std::endl;
					break;
					case PacketType::CALL:
						handleCall();
					break;
					default:
						std::cout << "Received unhandeled packet with type:" << receive_.getType() << std::endl;
					break;
				}

				// Keep waiting for new stuff
				doReceive();
			}
			else
			{
				socket_.close();
			}
		}
	);
}
예제 #3
0
RemoteReceiver::RemoteReceiver(QObject *parent)
    : QObject(parent)
    , m_server(new IpcServer(this))
    , m_node(0)
    , m_connectionAcknowledged(false)
    , m_socket(0)
    , m_client(0)
{
    connect(m_server, SIGNAL(received(QString,QByteArray)), this, SLOT(handleCall(QString,QByteArray)));
    connect(m_server, SIGNAL(clientConnected(QTcpSocket*)), this, SLOT(onClientConnected(QTcpSocket*)));
    connect(m_server, SIGNAL(clientConnected(QHostAddress)), this, SIGNAL(clientConnected(QHostAddress)));
    connect(m_server, SIGNAL(clientDisconnected(QHostAddress)), this, SIGNAL(clientDisconnected(QHostAddress)));
}
void Interpreter::command(const QString &command)
{
    QMutexLocker locker(&m_mutexInput);

    if (m_localProgramRunning)
        return;

    QStringList words = command.split(QRegExp("[\\s(),\\t]"), QString::SkipEmptyParts);

    if (m_waiting)
    {
        m_command = command;
        m_command.remove(QRegExp("[(),\\t]"));
        m_key = (Qt::Key)0;
        m_selection = RectA(0, 0, 0, 0);
        m_waitInput.wakeAll();
        goto end;
    }

    if (words.size()==0)
        goto end;

    if (words[0]=="do")
    {
        clearLocalProgram();
        beginLocalProgram();
    }
    else if (words[0]=="done")
    {
        endLocalProgram();
        locker.unlock();
        runOrStopProgram(true);
        locker.relock();
    }
    else if (words[0]=="list")
        listProgram();
    else if (words[0].left(4)=="cont")
    {
        locker.unlock();
        runOrStopProgram(true);
        locker.relock();
    }
    else if (words[0]=="close")
        queueCommand(CLOSE);
    else
        handleCall(words);
end:
    prompt();
}
예제 #5
0
void Interpreter::command(const QString &command)
{
    QMutexLocker locker(&m_mutexInput);

    if (m_localProgramRunning)
        return;

    if (m_waiting)
    {
        m_command = command;
        m_command.remove(QRegExp("[(),\\t]"));
        m_key = (Qt::Key)0;
        m_waitInput.wakeAll();
        return;
    }

    QStringList words = command.split(QRegExp("[\\s(),\\t]"), QString::SkipEmptyParts);

    if (words.size()==0)
        goto end;

    if (words[0]=="do")
    {
        clearLocalProgram();
        beginLocalProgram();
    }
    else if (words[0]=="done")
    {
        endLocalProgram();
        runLocalProgram();
        return;
    }
    else if (words[0]=="list")
        listProgram();
    else if (words[0].left(4)=="cont")
    {
        if (runLocalProgram()>=0)
            return;
    }
    else if (words[0]=="rendermode")
    {
        if (words.size()>1)
            m_renderer->setMode(words[1].toInt());
        else
            emit textOut("Missing mode parameter.\n");
    }
    else if (words[0]=="region")
    {
        emit videoInput(VideoWidget::REGION);
        m_argvHost = words;
    }
#if 0
    else if (words[0]=="set")
    {
        if (words.size()==3)
        {
            words[1].remove(QRegExp("[\\s\\D]+"));
            m_renderer->m_blobs.setLabel(words[1], words[2]);
        }
    }
#endif
    else
    {
        handleCall(words);
        return; // don't print prompt
    }

end:
    prompt();
}
// MAIN FUNCTION -----------------------------------------------------------
int main(int argc, char *argv[])
{
    pthread_t worker;
    pthread_attr_t attr;
    setup(&attr);
    struct logInformation logInfo;
    struct threadArguments taTemp;
    
	parseCommandLineArguments(argc, argv);
    printf("New logging session started on port %i on %s", portNumber, ctime(&timeServerStarted));
    int sockid = makeServerSocket();
    
    // daemonize the process if debuggin mode is not set
    if (commandLineOptions.debuggingMode == FALSE)
    {
        if (daemon_init() != 0)
        {
            printf("Error: unable to daemonize process\n");
            exit(-1);
        }   
    }
    
    while (TRUE)
    {
        // allow an incoming call
        int success = listen(sockid, 1);
        if (success == -1)
        {
            printf("Error: unable to listen on socket\n");
            exit(1);
        }
        
        // wait for an incoming call
        struct sockaddr_in saddr;
        saddr.sin_family = AF_INET;
        socklen_t c_len = sizeof(saddr);
        int fd = accept(sockid, (struct sockaddr *)&saddr, &c_len);
        if (success == -1)
        {
            printf("Error: unable to accept connection on socket\n");
            exit(1);
        }
        //printf("address: %s\n", (char *)inet_ntoa(saddr.sin_addr));
        logInfo.IPaddress = malloc(sizeof((char *)inet_ntoa(saddr.sin_addr)));
        strcpy((logInfo.IPaddress), (char *)inet_ntoa(saddr.sin_addr));
        //printf("We got a call! Yay!\n");
        updateNumberServerRequests(); // update the number of server requests
        
        // get the current time and store it in the log structure
        time_t currentTime = time(0);
        char *timeString = asctime(gmtime(&currentTime)); // get the Greenwich Mean Time
        char *timeStringPointer = timeString;
        // step through the time string until we find the newline character and 
        // change it to a null character to remove it
        while (*timeStringPointer != '\n')
        {
            timeStringPointer++;
        }
        *timeStringPointer = '\0';
        logInfo.timeRequestReceived = timeString;        
        //printf("time request received %s\n", logInfo.timeRequestReceived);

        //int *fdPointer = malloc(sizeof(int));
        //*fdPointer = fd;
        // copy file descriptor for the socket and logInfo structure so we can pass it to a thread
        struct threadArguments *ta = malloc(sizeof(struct threadArguments));
        taTemp.fd = fd;
        taTemp.logInfo = logInfo;
        *ta = taTemp;

        if (commandLineOptions.debuggingMode == TRUE)
        {
            handleCall(ta); // only accept one request at a time
        }
        else
        {
            // create a new thread to handle the request
            pthread_create(&worker, &attr, handleCall, ta);
        }
    }
    
	return 0;
}
예제 #7
0
void ShmemServer::handle_conn()
{
#ifndef NDEBUG
    std::cout << "DEBUG" << ": got IR" << std::endl;
#endif
    // initialize backend with received IR
    auto backend = parseIRtoBackend((char *) shmemptr);
    *(long *)shmemptr = TimeDiffOpt.count();
    *(((long *)shmemptr) + 1) = TimeDiffInit.count();
    // signal to client: got IR, ready to get calls, time measures in shmem
    sem_post(shmem_sem);

    while (1) {
        sem_wait(shmem_force_order_sem);
        // wait for call
        sem_wait(shmem_sem);
        sem_post(shmem_force_order_sem);
#ifndef NDEBUG
        std::cout << "DEBUG" << ": got call \n";
#endif
        // check for exit symbol
        if (((char *)shmemptr)[0] == ';') {
#ifndef NDEBUG
            std::cout << "DEBUG" << ": found exit symbol \n";
#endif
            break;
        }

        llvm::Function* calledFunction = nullptr;
        std::vector<llvm::GenericValue> args;
        std::list<std::vector<llvm::GenericValue>::size_type> indexesOfPointersInArgs;
        llvm::GenericValue result = handleCall(backend.get(), (char *) shmemptr, calledFunction, args, indexesOfPointersInArgs);

        auto shmempos = shmemptr;
        // write measured time to memory
        *(long *)shmempos = TimeDiffLastExecution.count();
        shmempos = (long *)shmempos + 1;

        // write changes to args and result back to shared memory
        for (const auto& indexOfPtr : indexesOfPointersInArgs) {
            auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr);
            while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID)
                paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType();

            if (paramType->getTypeID() == llvm::Type::IntegerTyID) {
                ShmemHelperFunctions::marshallArrayOfSizeAndTypeIntoMemory(args[indexOfPtr].PointerVal, args[indexOfPtr+1].IntVal.getSExtValue(), std::pair<llvm::Type::TypeID, unsigned>(paramType->getTypeID(), ((llvm::IntegerType*)paramType)->getBitWidth()), shmempos);
            } else
                ShmemHelperFunctions::marshallArrayOfSizeAndTypeIntoMemory(args[indexOfPtr].PointerVal, args[indexOfPtr+1].IntVal.getSExtValue(), std::pair<llvm::Type::TypeID, unsigned>(paramType->getTypeID(), 0U), shmempos);

            free(args[indexOfPtr].PointerVal);
        }

        switch (calledFunction->getReturnType()->getTypeID()) {
            case llvm::Type::VoidTyID:
                // void return
                break;
            case llvm::Type::FloatTyID:
                *(float *)shmempos  = result.FloatVal;
                break;
            case llvm::Type::DoubleTyID:
                *(double *)shmempos = result.DoubleVal;
                break;
            case llvm::Type::X86_FP80TyID: {
                char tmpHexString[64];
                llvm::APFloat(llvm::APFloat::x87DoubleExtended, result.IntVal).convertToHexString(tmpHexString, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven);
                *(long double *)shmempos = strtold(tmpHexString, nullptr);
                break;
            }
            case llvm::Type::FP128TyID: {
                char tmpHexString[64];
                llvm::APFloat(llvm::APFloat::IEEEquad, result.IntVal).convertToHexString(tmpHexString, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven);
                *(long double *)shmempos = strtold(tmpHexString, nullptr);
                break;
             }
            case llvm::Type::IntegerTyID: // Note: LLVM does not differentiate between signed/unsiged int types
                switch (result.IntVal.getBitWidth()) {
                    case 8:
                        *(uint8_t *)shmempos = (uint8_t) result.IntVal.getZExtValue();
                        break;
                    case 16:
                        *(uint16_t *)shmempos = (uint16_t) result.IntVal.getZExtValue();
                        break;
                    case 32:
                        *(uint32_t *)shmempos = (uint32_t) result.IntVal.getZExtValue();
                        break;
                    case 64:
                        *(uint64_t *)shmempos = (uint64_t) result.IntVal.getZExtValue();
                        break;
                    default:
                        error(std::string("ERROR, integer bitwidth of " + std::to_string(result.IntVal.getBitWidth()) + " not supported").c_str());
                 }
                break;
            default:
            error(std::string("ERROR, LLVM TypeID " + std::to_string(calledFunction->getReturnType()->getTypeID()) + " of result of function \"" + calledFunction->getName().str() + "\" is not supported").c_str());
        }

#ifndef NDEBUG
        std::cout << "DEBUG" << ": signaling 'result is ready' to client \n";
#endif

        sem_post(shmem_sem);
    }
}
예제 #8
0
void SocketServer::handle_conn(int sockfd)
{
    //MPI_CONNECTION_INIT
    // TODO: check this! 
    int argc = 0;
    
    #ifndef NDEBUG
        std::cout << "INFO" << ": trying MPI_Init " << std::endl;
    #endif
    MPI_Init( &argc, NULL );
    #ifndef NDEBUG
        std::cout << "INFO" << ": ... done " << std::endl;
    #endif
    
    // Create MPI Structure
    int sizeOfData;
    MPI_Type_size( MPI_INT,&sizeOfData );
    int array_of_block_lengths[2] = {1, 1};
    MPI_Aint array_of_displacements[2] = {0, sizeOfData};
    MPI_Datatype array_of_types[2] = { MPI_INT, MPI_INT };

    MPI_Type_create_struct(2, array_of_block_lengths, array_of_displacements, array_of_types, &ArgListType);
    MPI_Type_commit(&ArgListType);
    // End of MPI struct
    
    client = MPI_COMM_WORLD;

    #ifndef NDEBUG
        std::cout << "DEBUG: Waiting for IR\n" << std::endl;
    #endif
    
    MPI_Status status;
    int mpi_server_tag = MPI_SERVER_TAG;
    int myrank;
    MPI_Comm_rank(client, &myrank);
    int mpi_server_rank =0;
    
    // TODO: check this! 
    if(myrank==0)
          mpi_server_rank = 1;
    
    int incomingMessageSize=0;    
    MPI_Probe(MPI_ANY_SOURCE, mpi_server_tag, client, &status);
    MPI_Get_count(&status,MPI_CHAR,&incomingMessageSize);    
    char *module_ir_buffer = (char *) calloc(incomingMessageSize + 1 , sizeof(char));    
    MPI_Recv(module_ir_buffer, incomingMessageSize + 1, MPI_CHAR, MPI_ANY_SOURCE, mpi_server_tag, client, &status);
    
    #ifndef NDEBUG
        std::cout << "DEBUG: Recieved IR\n" << std::endl;
    #endif
  
    auto backend = parseIRtoBackend(module_ir_buffer);
    // notify client that calls can be accepted now by sending time taken for optimizing module and initialising backend
    const std::string readyStr(std::to_string(TimeDiffOpt.count()) + ":" + std::to_string(TimeDiffInit.count()));
    MPI_Send((void *)readyStr.c_str(), readyStr.size() , MPI_CHAR, mpi_server_rank, mpi_server_tag, client);
    free(module_ir_buffer);

    // initialise msg_buffer
    std::shared_ptr<char> msg_buffer((char*)calloc(MSG_BUFFER_SIZE, sizeof(char)), &free);
    while (1) {
        bzero(msg_buffer.get(), MSG_BUFFER_SIZE);
        // first acquire message length
        unsigned msg_length;
        auto UINT_MAX_str_len = std::to_string(UINT_MAX).length();
        int num_chars = recv(sockfd, msg_buffer.get(), UINT_MAX_str_len + 1, 0);
    
        if (num_chars == 0) {
            std::cout << "Client assigned to process " << getpid() << " has closed its socket 3 \n";
            exit(0);
        }

        if (num_chars < 0)
            error("ERROR, could not read from socket");

        #ifndef NDEBUG
            //std::cout << getpid() << ": got message \"" << msg_buffer << "\"\n"; // TODO command line argument to print messages
            std::cout << getpid() << ": got message \n";
        #endif

        llvm::Function* calledFunction = nullptr;
        std::vector<llvm::GenericValue> args;
        std::list<std::vector<llvm::GenericValue>::size_type> indexesOfPointersInArgs;
        llvm::GenericValue result = handleCall(backend.get(), msg_buffer.get(), calledFunction, args, indexesOfPointersInArgs);

        // reset buffer and write time taken to buffer
        bzero(msg_buffer.get(), MSG_BUFFER_SIZE);
        sprintf(msg_buffer.get(), ";%ld", (long)TimeDiffLastExecution.count());

        //MPI_DATA_MOVEMENT
        //Send data back to the client
        //Create the MPI data structure
        //allocate memory for struct    
        #ifndef TIMING 
            auto StartTime = std::chrono::high_resolution_clock::now();
        #endif  
    
        struct ArgumentList argList[MAX_NUMBER_OF_ARGUMENTS];
        MPI_Status status;

        //Create the structure
        int structSize=0;
    
        for (const auto& indexOfPtr : indexesOfPointersInArgs) {
            auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr);
            while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID)
            paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType();

            if (paramType->getTypeID() == llvm::Type::IntegerTyID) {
                argList[structSize].typeofArg = ENUM_MPI_INT;
            } else {
                argList[structSize].typeofArg = ENUM_MPI_DOUBLE;
            }
            argList[structSize].sizeOfArg =argumentList[indexOfPtr].sizeOfArg;
            structSize++;
        }

        #ifndef NDEBUG
            std::cout << "\nMPI SERVER: Sending message back from server to client";
            std::cout.flush();
        #endif


        #ifndef NDEBUG
            std::cout << "\nMPI SERVER: Sending MPI Header";
            std::cout.flush();

            for (int i=0; i<structSize; i++) {
                std::cout <<  "\n MPI Sent DS : Size : " << argList[i].sizeOfArg << "  Type" << argList[i].typeofArg ;
                std::cout.flush();
            }
        #endif
        MPI_Send(argList, structSize, ArgListType, mpi_server_rank, mpi_server_tag, client);

        #ifndef NDEBUG
            std::cout << "\nMPI SERVER: Sent MPI Header";
            std::cout.flush();

            std::cout << "\nMPI SERVER: Sending data";
            std::cout.flush();
        #endif

        //Start sending individual arrrays
        for (const auto& indexOfPtr : indexesOfPointersInArgs) {
            auto paramType = calledFunction->getFunctionType()->getParamType(indexOfPtr);
            while (paramType->getTypeID() == llvm::Type::ArrayTyID || paramType->getTypeID() == llvm::Type::PointerTyID)
            paramType = llvm::cast<llvm::SequentialType>(paramType)->getElementType();

            if (paramType->getTypeID() == llvm::Type::IntegerTyID) {
            MPI_Send(args[indexOfPtr].PointerVal,argList[indexOfPtr].sizeOfArg, MPI_INT, mpi_server_rank, mpi_server_tag, client);
            } else {
            MPI_Send(args[indexOfPtr].PointerVal, argList[indexOfPtr].sizeOfArg, MPI_DOUBLE, mpi_server_rank, mpi_server_tag, client);
            }
            free(args[indexOfPtr].PointerVal);
        }

        #ifndef TIMING 
            auto EndTime = std::chrono::high_resolution_clock::now();
            std::cout << "\n SERVR: MPI_DATA_TRANSFER S->C = " <<    std::chrono::duration_cast<std::chrono::microseconds>(EndTime - StartTime).count() << "\n";
        #endif
    
        #ifndef NDEBUG
            std::cout << "\nMPI SERVER: Data sent";
            std::cout.flush();

            std::cout << "\nMPI SERVER: Return Messages sent";
            std::cout.flush();
        #endif
        
        char returnValStr[MAX_VAL_SIZE];
        switch (calledFunction->getReturnType()->getTypeID()) {
            case llvm::Type::VoidTyID:
                sprintf(returnValStr, ":");
                break;
            case llvm::Type::FloatTyID:
                sprintf(returnValStr, ":%a", result.FloatVal);
                break;
            case llvm::Type::DoubleTyID:
                sprintf(returnValStr, ":%la", result.DoubleVal);
                break;
            case llvm::Type::X86_FP80TyID:
                returnValStr[0]=':';
                llvm::APFloat(llvm::APFloat::x87DoubleExtended, result.IntVal).convertToHexString(returnValStr+1, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven);
                break;
            case llvm::Type::FP128TyID:
                returnValStr[0]=':';
                llvm::APFloat(llvm::APFloat::IEEEquad, result.IntVal).convertToHexString(returnValStr+1, 0U, false, llvm::APFloat::roundingMode::rmNearestTiesToEven);
                break;
            case llvm::Type::IntegerTyID: // Note: LLVM does not differentiate between signed/unsiged int types
                sprintf(returnValStr, ":%s", result.IntVal.toString(16,false).c_str());
                break;
            default:
                error(std::string("ERROR, LLVM TypeID " + std::to_string(calledFunction->getReturnType()->getTypeID()) + " of result of function \"" + calledFunction->getName().str() + "\" is not supported").c_str());
        }
        strcat(msg_buffer.get(), returnValStr);

        //Send the message
        MPI_Send(msg_buffer.get(), strlen(msg_buffer.get()), MPI_CHAR, mpi_server_rank, mpi_server_tag, client);
    
        MPI_Type_free(&ArgListType);
    
        // TODO: check this!
        MPI_Finalize();
    }
}
예제 #9
0
 void visitCallIndirect(CallIndirect* curr) {
   auto* outer = optimize(curr, curr->target);
   if (EffectAnalyzer(curr->target).hasSideEffects()) return;
   handleCall(curr, outer);
 }
예제 #10
0
 void visitCallImport(CallImport* curr) {
   handleCall(curr);
 }
예제 #11
0
 void visitCall(Call* curr) {
   handleCall(curr);
 }
예제 #12
0
 void visitCall(Call* curr) {
   handleCall(curr, nullptr);
 }
void BinaryRelationEngine::run() {	
	// handle call differently

	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	

	vector<string> first;

	if (astParam1->getParameterType() == VT_CONSTANTSTRING 
		||astParam1->getParameterType() == VT_CONSTANTINTEGER) {
			first.push_back(astParam1->getVariableName());
	} else if (myQM->getVariableType(astParam1->getVariableName()).compare("integer") == 0) {
		CommonUtility::convertIntVectorToString(myQM->getValueListInteger (astParam1->getVariableName()), first);
	} else {
		first = myQM->getValueList(astParam1->getVariableName());
	}

	vector<string> second;

	if (astParam2->getParameterType() == VT_CONSTANTSTRING 
		||astParam2->getParameterType() == VT_CONSTANTINTEGER) {
			second.push_back(astParam2->getVariableName());
	} else if (myQM->getVariableType(astParam2->getVariableName()).compare("integer") == 0){
		CommonUtility::convertIntVectorToString(myQM->getValueListInteger (astParam2->getVariableName()), second);
	} else {
		second= myQM->getValueList(astParam2->getVariableName());
	}

	if (astParam1->getParameterType() == VT_CALL ||
		astParam2->getParameterType() == VT_CALL) {
			handleCall(first, second);
			return;
	}


	FastSearchString secondList;
	FastSearchString firstList;




	vector<pair<string, string>> relationship;

	bool keepRelation = keepRelationship();
	bool exist;

	if (first.size() < second.size()) {
		vector<string>::iterator iterFirst;

		FastSearchString secondFast;
		CommonUtility::convertToMap(second, secondFast);

		for (iterFirst = first.begin(); iterFirst != first.end(); iterFirst++){
			exist = false;
			if (secondFast.find(*iterFirst) != secondFast.end() ) {
				exist = true;

				if (keepRelation) 
					relationship.push_back(VectorRelation(*iterFirst, *iterFirst));		// they are the same. make no mistake here
				else if (astParam2->updateAble()) 
					secondList[*iterFirst] = true;
				else if (!astParam1->updateAble()) 
					return; // we have got what we come for. 
			}

			if (exist && !keepRelation && astParam1->updateAble()) 
				firstList[*iterFirst] = true;
		}
	} else {
		vector<string>::iterator iterSecond;

		FastSearchString firstFast;
		CommonUtility::convertToMap(first, firstFast);

		for (iterSecond = second.begin(); iterSecond != second.end(); iterSecond++){
			exist = false;
			if (firstFast.find(*iterSecond) != firstFast.end() ) {
				exist = true;

				if (keepRelation) 
					relationship.push_back(VectorRelation(*iterSecond, *iterSecond));		// they are the same. make no mistake here
				else if (astParam1->updateAble()) 
					firstList[*iterSecond] = true;
				else if (!astParam1->updateAble()) 
					return; // we have got what we come for. 
			}

			if (exist && !keepRelation && astParam2->updateAble()) 
				secondList[*iterSecond] = true;
		}
	}

	updateVariable( relationship, firstList, secondList, keepRelation);

	failed = (firstList.size() == 0 && secondList.size() == 0 && relationship.size() == 0);



}