Exemple #1
0
bool checkTree(TreeP t)
{
	bool func = false;
	TreeP tmp = t;
	
	if(!isBinaryTree(t))
	{
		return false;
	}
	
	while(tmp->content.children[1]) {
		if(!isBinaryTree(t)) {
			return false;
		}
	
		tmp = tmp->content.children[1];
	}
	
	if(tmp->content.children[0]->op == YIELD_STRUCT)
	{
		func = true;
	}
	
	tmp = t;
	
	while(tmp->content.children[1]) {
		if(tmp->content.children[0]->type == RETURN) {
			if(!func && tmp->content.children[0]->nbChildren) {
				fprintf(stderr, "checkTree : return non vide dans un bloc procedural\n");
				return false;
			}
			else if(func && !checkInstruction(tmp->content.children[0])) {
				return false;
			}
		}
		else if(!checkInstruction(tmp->content.children[0])) {
			return false;
		}

		tmp = tmp->content.children[1];
	}

	return true;
}
void RegionDesc::Block::addInstruction() {
  if (m_length > 0) checkInstruction(last().op());
  assertx((m_last == kInvalidOffset) == (m_length == 0));

  ++m_length;
  if (m_length == 1) {
    m_last = m_start;
  } else {
    m_last = last().advanced().offset();
  }
}
Exemple #3
0
/* -------------------------------------------------------------------------------------- */
void checkBasicBlock(BasicBlock *p){
    ins *tmp;
    
    if(p == NULL) return;

    tmp = p->head;
    while (tmp != NULL){
	checkInstruction(tmp);
	tmp = tmp->next;
    }
}
/*
 * Check invariants about the bytecode instructions in this Block.
 *
 * 1. Single entry, single exit (aside from exceptions).  I.e. no
 *    non-fallthrough instructions mid-block and no control flow (not
 *    counting calls as control flow).
 *
 */
void RegionDesc::Block::checkInstructions() const {
  if (!debug || length() == 0) return;

  auto u = unit();
  auto sk = start();

  for (int i = 1; i < length(); ++i) {
    if (i != length() - 1) checkInstruction(sk.op());
    sk.advance(u);
  }
  assertx(sk.offset() == m_last);
}
CommandBase* ParserList::tryParse(string userCommand) {

    string instruction;
    string arguments;

    if (!getInstructionAndArguments(userCommand, instruction, arguments)) {
        return NULL;
    }

    if (!checkInstruction(instruction)) {
        return NULL;
    }

    return parseList(arguments);
}
Exemple #6
0
//Verifies all instructions and data on list and translate to binary
int verifyAndTranslate()
{
    struct command *com, *aux;
    char result[32];
    int currentAddress = 0;

    com = (struct command*)malloc(sizeof(struct command));
    com = first;
    while(com != NULL){
        //Directive
        if(getDirective(com->line) == 3){
            //printf("\n\nDado: (%s)",com->line);
            strcpy(com->line, checkData(com->line));
            if(strcmp(com->line, "0") == 0){
                printf("\n-> ERROR(6): INVALID VALUE - Line %d", com->lineNumber);
                return 0;
            }
            if(strcmp(com->line, "1") == 0){
                printf("\n-> ERROR(7): VALUE OVERFLOW - Line %d", com->lineNumber);
                return 0;
            }
            //printf("\n%s (%d bits)\n",com->line, strlen(com->line));
        }
        //Instruction
        else{
            //printf("\n\nInstrucao: (%s)",com->line);
            strcpy(com->line, checkInstruction(com->line, currentAddress));
            if(strcmp(com->line, "1") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(8): INVALID REGISTER - Line %d", com->lineNumber);
                return 0;
            }
            else if(strcmp(com->line, "2") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(9): INVALID LABEL - Line %d", com->lineNumber);
                return 0;
            }
            else if(strcmp(com->line, "3") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(10): INVALID CONSTANT - Line %d", com->lineNumber);
                return 0;
            }
            else if(strcmp(com->line, "4") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(11): INVALID MNEMONIC - Line %d", com->lineNumber);
                return 0;
            }

            else if(strcmp(com->line, "5") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(12): MISSING PARAMETERS - Line %d", com->lineNumber);
                return 0;
            }
            else if(strcmp(com->line, "6") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(13): CONSTANT OVERFLOW - Line %d", com->lineNumber);
                return 0;
            }
            else if(strcmp(com->line, "7") == 0){
                printf("\nPROGRAM NOT ASSEMBLED");
                printf("\n-> ERROR(14): ONLY UNSIGNED CONSTANT - Line %d", com->lineNumber);
                return 0;
            }

            //printf("\n%s (%d bits)\n",com->line, strlen(com->line));
        }
        com = com->next;
        currentAddress++;
    }
    return 1;
}
Exemple #7
0
bool checkInstruction(TreeP t) {
	switch(t->type) {
		//cas des operateurs binaires
		case OP:
			if(!isBinaryTree(t)) {
				return false;
			}
			if((!strcmp(evalType(getChild(t, 0))->nom, "integer")) && (!strcmp(evalType(getChild(t, 1))->nom, "integer"))) {
				fprintf(stderr, "checkInstruction : operation non conforme (type fils different de entier)\n");
				return false;
			}
			break;
		case CAT_STRUCT:
			if(!isBinaryTree(t)){
				return false;
			}
			if((!strcmp(evalType(getChild(t, 0))->nom, "string")) && (!strcmp(evalType(getChild(t, 1))->nom, "string"))) {
				fprintf(stderr, "checkInstruction : concatenation non conforme (type fils different de string)\n");
				return false;
			}
			break;
		case ASSIGN_STRUCT:
			if(!isBinaryTree(t)){
				return false;
			}
			//verifie que le type du sous-arbre gauche est du meme type que le type du sous-arbre droit
			if(strcmp(evalType(getChild(t, 0))->nom, evalType(getChild(t, 1))->nom)) {
				fprintf(stderr, "checkInstruction : affectation non conforme (type fils g & d differents)\n");
				return false;
			}
			break;

		//cas des opérateurs unaires
		case UNARY_STRUCT:
			if(t->nbChildren != 1) {
				return false;
			}
			if(strcmp(evalType(getChild(t, 0))->nom, "integer")) {
				fprintf(stderr, "checkInstruction : arbre unaire non conforme (type du fils non entier)\n");
				return false;
			}
			break;

		// cas de l'operateur '.'
		case DOT:
		case MTDCALL:
		/* Verifier que ce qu'il y a apres le "." fait bien partie de la classe de ce qu'il y a a gauche */
			if(!evalType(t))
			{
				fprintf(stderr, "checkInstruction : partie droite de l'expression avec operateur '.' non valide\n");
				return false;
			}
			break;


		//cas de l'operateur If Then Else
		case ITE:
			if(t->nbChildren != 3 || (strcmp(evalType(getChild(t, 0))->nom, "integer"))) {
				fprintf(stderr, "checkInstruction : If Then Else non valide\n");
				return false;
			}
			if(!checkInstruction(getChild(t, 1)) || !checkInstruction(t->content.children[2])) {
				return false;
			}
			break;

		case RETURN:
			if(!checkInstruction(getChild(t, 0))) {
				return false;
			}
			break;

		case YIELD_STRUCT:
			if(!checkInstruction(getChild(t, 0))) {
				return false;
			}
			break;


		default:
			fprintf(stderr, "Operateur non reconnu");
	}

	return true;
}
Exemple #8
0
//fonction qui verifie le type de l'arbre
ClasseP evalType(TreeP t)
{
	TreeP tmp = NULL;

	if(t->type == INTEGER)
	{
		return getClasse("integer");
	}
	if(t->type == STRING)
	{
		return getClasse("string");
	}
	
	checkInstruction(t);
	
	switch(t->type) {
		case OP:
			if((!strcmp(evalType(getChild(t, 0))->nom, "integer")) && (!strcmp(evalType(getChild(t, 1))->nom, "integer")))
				return getClasse("integer");
			else
				return NULL;
			break;
		case CAT_STRUCT:
			if((!strcmp(evalType(getChild(t, 0))->nom, "string")) && (!strcmp(evalType(getChild(t, 1))->nom, "string")))
				return getClasse("string");
			else
				return NULL;
			break;
		case UNARY_STRUCT:
			if((!strcmp(evalType(getChild(t, 0))->nom, "integer")))
				return getClasse("integer");
			else
				return NULL;
			break;

		case DOT:
			if(getChild(t, 1)->nbChildren > 1) {
				tmp = getChild(getChild(t, 1), 0);
				if(tmp->type != VAR_STRUCT)
					return NULL;

				if(getAttribut(evalType(getChild(t, 0)), tmp->content.var->nom))
					return getClasse(tmp->content.var->type);
				else
					return NULL;
			}
			else {
				if(getChild(t, 1)->type != VAR_STRUCT)
					return NULL;
				if(getAttribut(evalType(getChild(t, 0)), getChild(t, 1)->content.var->nom))
					return getClasse(getChild(t, 1)->content.var->type);
				else
					return NULL;
			}
		case MTDCALL:
			if(getChild(t, 1)->nbChildren > 1) {
				tmp = getChild(getChild(t, 1), 0);
				if(tmp->type != MTD)
					return NULL;

				if(getMethode(evalType(getChild(t, 0)), tmp->content.meth->nom))
					return getClasse(tmp->content.meth->type);
				else
					return NULL;
			}
			else {
				if(getChild(t, 1)->type != MTD)
					return NULL;
				if(getMethode(evalType(getChild(t, 0)), getChild(t, 1)->content.meth->nom))
					return getClasse(getChild(t, 1)->content.meth->type);
				else
					return NULL;
			}
			break;
		default:
			return NULL;
	}
	
	return 0;
}