Esempio n. 1
0
int nl_compare_internal(ImmT left, ImmT right) {
	if (_global_const_begin_ != NULL && left >= _global_const_begin_ && left < _global_const_end_ 
			&& right >= _global_const_begin_ && right < _global_const_end_) {
		return left == right;
	}
	if (((NlData *)left)->type != ((NlData *)right)->type) {
		if(IS_INT(left) && IS_STRING(right))
			return eq_int_string((NlInt *)left, (NlString *)right);
		if(IS_INT(right) && IS_STRING(left))
			return eq_int_string((NlInt *)right, (NlString *)left);
			
		if(IS_INT(right) && IS_FLOAT(left))
			return ((NlInt *)right)->i == ((NlFloat *)left)->f;
		if(IS_INT(left) && IS_FLOAT(right))
			return ((NlInt *)left)->i == ((NlFloat *)right)->f;
			
		if(IS_FLOAT(left) && IS_STRING(right))
			return eq_float_string((NlFloat *)left, (NlString *)right);
		if(IS_FLOAT(right) && IS_STRING(left))
			return eq_float_string((NlFloat *)right, (NlString *)left);
		return 0;
	}
	if (((NlData *)left)->type == ___TYPE_STRING) {
		return compare_strings((NlString *)left, (NlString *)right) == 0;
	} else if (((NlData *)left)->type == ___TYPE_INT) {
		return (((NlInt *)left)->i == ((NlInt *)right)->i);
	} else if (((NlData *)left)->type == ___TYPE_FLOAT) {
		return (((NlFloat *)left)->f == ((NlFloat *)right)->f);
	} else {
		return left == right;
	}
}
Esempio n. 2
0
char *
aopLiteralLong (value * val, int offset, int size)
{
	char *rs;
	union {
		float f;
		unsigned char c[4];
	}
	fl;

	if (!val) {
	  // assuming we have been warned before
	  val=constVal("0");
	}

	/* if it is a float then it gets tricky */
	/* otherwise it is fairly simple */
	if (!IS_FLOAT (val->type)) {
		unsigned long v = (unsigned long) floatFromVal (val);

		v >>= (offset * 8);
		switch (size) {
		case 1:
			tsprintf (buffer, "!immedbyte", (unsigned int) v & 0xff);
			break;
		case 2:
			tsprintf (buffer, "!immedword", (unsigned int) v & 0xffff);
			break;
		default:
			/* Hmm.  Too big for now. */
			assert (0);
		}
		rs = Safe_calloc (1, strlen (buffer) + 1);
		return strcpy (rs, buffer);
	}
Esempio n. 3
0
int realp(int x){
	if(IS_INTEGER(x) || (IS_FLOAT(x)) || IS_RATIONAL(x) || IS_BIGNUM(x))
    	return(1);
    else
    if(IS_COMPLEX(x) && (GET_IMAG_FLT(x) == 0))
    	return(1);
    else
    	return(0);
}
Esempio n. 4
0
/*-----------------------------------------------------------------*/
int pic14aopLiteral (value *val, int offset)
{
  union {
    float f;
    unsigned char c[4];
  } fl;

  /* if it is a float then it gets tricky */
  /* otherwise it is fairly simple */
  if (!IS_FLOAT(val->type)) {
    unsigned long v = (unsigned long) floatFromVal(val);

    //v >>= (offset * 8);
    return ( (v >> (offset * 8)) & 0xff);
    //sprintf(buffer,"0x%02x",((char) v) & 0xff);
    //_ALLOC_ATOMIC(rs,strlen(buffer)+1);
    //return strcpy (rs,buffer);
  }
Esempio n. 5
0
bool ffi_pointer_write(VMState *state, Object *type, void *ptr, Value val) {
  ValueCache *vcache = &state->shared->vcache;
  Object *string_base = vcache->string_base;
  FFIObject *ffi = (FFIObject*) vcache->ffi_obj;
  if (type == ffi->float_obj) {
    if (IS_FLOAT(val)) *(float*) ptr = AS_FLOAT(val);
    else if (IS_INT(val)) *(float*) ptr = AS_INT(val);
    else {
      VM_ASSERT(false, "invalid value for float type") false;
    }
    return true;
  } else {
    Object *c_type_obj = AS_OBJ(OBJECT_LOOKUP(type, c_type));
    StringObject *c_type = (StringObject*) obj_instance_of(c_type_obj, string_base);
    assert(c_type);
    VM_ASSERT(false, "unhandled pointer write type: %s", c_type->value) false;
  }
}
Esempio n. 6
0
/*
 * Parse the type and its initializer and emit it (recursively).
 */
static void
emitInitVal(struct dbuf_s *oBuf, symbol *topsym, sym_link *my_type, initList *list)
{
    symbol *sym;
    int size, i;
    long lit;
    unsigned char *str;

    size = getSize(my_type);

    if (IS_PTR(my_type)) {
        DEBUGprintf ("(pointer, %d byte) %p\n", size, list ? (void *)(long)list2int(list) : NULL);
        emitIvals(oBuf, topsym, list, 0, size);
        return;
    }

    if (IS_ARRAY(my_type) && topsym && topsym->isstrlit) {
        str = (unsigned char *)SPEC_CVAL(topsym->etype).v_char;
        emitIvalLabel(oBuf, topsym);
        do {
            dbuf_printf (oBuf, "\tretlw 0x%02x ; '%c'\n", str[0], (str[0] >= 0x20 && str[0] < 128) ? str[0] : '.');
        } while (*(str++));
        return;
    }

    if (IS_ARRAY(my_type) && list && list->type == INIT_NODE) {
        fprintf (stderr, "Unhandled initialized symbol: %s\n", topsym->name);
        assert ( !"Initialized char-arrays are not yet supported, assign at runtime instead." );
        return;
    }

    if (IS_ARRAY(my_type)) {
        DEBUGprintf ("(array, %d items, %d byte) below\n", DCL_ELEM(my_type), size);
        assert (!list || list->type == INIT_DEEP);
        if (list) list = list->init.deep;
        for (i = 0; i < DCL_ELEM(my_type); i++) {
            emitInitVal(oBuf, topsym, my_type->next, list);
            topsym = NULL;
            if (list) list = list->next;
        } // for i
        return;
    }

    if (IS_FLOAT(my_type)) {
        // float, 32 bit
        DEBUGprintf ("(float, %d byte) %lf\n", size, list ? list2int(list) : 0.0);
        emitIvals(oBuf, topsym, list, 0, size);
        return;
    }

    if (IS_CHAR(my_type) || IS_INT(my_type) || IS_LONG(my_type)) {
        // integral type, 8, 16, or 32 bit
        DEBUGprintf ("(integral, %d byte) 0x%lx/%ld\n", size, list ? (long)list2int(list) : 0, list ? (long)list2int(list) : 0);
        emitIvals(oBuf, topsym, list, 0, size);
        return;

    } else if (IS_STRUCT(my_type) && SPEC_STRUCT(my_type)->type == STRUCT) {
        // struct
        DEBUGprintf ("(struct, %d byte) handled below\n", size);
        assert (!list || (list->type == INIT_DEEP));

        // iterate over struct members and initList
        if (list) list = list->init.deep;
        sym = SPEC_STRUCT(my_type)->fields;
        while (sym) {
            long bitfield = 0;
            int len = 0;
            if (IS_BITFIELD(sym->type)) {
                while (sym && IS_BITFIELD(sym->type)) {
                    int bitoff = SPEC_BSTR(getSpec(sym->type)) + 8 * sym->offset;
                    assert (!list || ((list->type == INIT_NODE)
                                && IS_AST_LIT_VALUE(list->init.node)));
                    lit = (long) (list ? list2int(list) : 0);
                    DEBUGprintf ( "(bitfield member) %02lx (%d bit, starting at %d, bitfield %02lx)\n",
                            lit, SPEC_BLEN(getSpec(sym->type)),
                            bitoff, bitfield);
                    bitfield |= (lit & ((1ul << SPEC_BLEN(getSpec(sym->type))) - 1)) << bitoff;
                    len += SPEC_BLEN(getSpec(sym->type));

                    sym = sym->next;
                    if (list) list = list->next;
                } // while
                assert (len < sizeof (long) * 8); // did we overflow our initializer?!?
                len = (len + 7) & ~0x07; // round up to full bytes
                emitIvals(oBuf, topsym, NULL, bitfield, len / 8);
                topsym = NULL;
            } // if

            if (sym) {
                emitInitVal(oBuf, topsym, sym->type, list);
                topsym = NULL;
                sym = sym->next;
                if (list) list = list->next;
            } // if
        } // while
        if (list) {
            assert ( !"Excess initializers." );
        } // if
        return;

    } else if (IS_STRUCT(my_type) && SPEC_STRUCT(my_type)->type == UNION) {
        // union
        DEBUGprintf ("(union, %d byte) handled below\n", size);
        assert (list && list->type == INIT_DEEP);

        // iterate over union members and initList, try to map number and type of fields and initializers
        my_type = matchIvalToUnion(list, my_type, size);
        if (my_type) {
            emitInitVal(oBuf, topsym, my_type, list->init.deep);
            topsym = NULL;
            size -= getSize(my_type);
            if (size > 0) {
                // pad with (leading) zeros
                emitIvals(oBuf, NULL, NULL, 0, size);
            }
            return;
        } // if

        assert ( !"No UNION member matches the initializer structure.");
    } else if (IS_BITFIELD(my_type)) {
        assert ( !"bitfields should only occur in structs..." );

    } else {
        printf ("SPEC_NOUN: %d\n", SPEC_NOUN(my_type));
        assert( !"Unhandled initialized type.");
    }
}
Esempio n. 7
0
/*
 * For UNIONs, we first have to find the correct alternative to map the
 * initializer to. This function maps the structure of the initializer to
 * the UNION members recursively.
 * Returns the type of the first `fitting' member.
 */
static sym_link *
matchIvalToUnion (initList *list, sym_link *type, int size)
{
    symbol *sym;

    assert (type);

    if (IS_PTR(type) || IS_CHAR(type) || IS_INT(type) || IS_LONG(type)
            || IS_FLOAT(type))
    {
        if (!list || (list->type == INIT_NODE)) {
            DEBUGprintf ("OK, simple type\n");
            return (type);
        } else {
            DEBUGprintf ("ERROR, simple type\n");
            return (NULL);
        }
    } else if (IS_BITFIELD(type)) {
        if (!list || (list->type == INIT_NODE)) {
            DEBUGprintf ("OK, bitfield\n");
            return (type);
        } else {
            DEBUGprintf ("ERROR, bitfield\n");
            return (NULL);
        }
    } else if (IS_STRUCT(type) && SPEC_STRUCT(getSpec(type))->type == STRUCT) {
        if (!list || (list->type == INIT_DEEP)) {
            if (list) list = list->init.deep;
            sym = SPEC_STRUCT(type)->fields;
            while (sym) {
                DEBUGprintf ("Checking STRUCT member %s\n", sym->name);
                if (!matchIvalToUnion(list, sym->type, 0)) {
                    DEBUGprintf ("ERROR, STRUCT member %s\n", sym->name);
                    return (NULL);
                }
                if (list) list = list->next;
                sym = sym->next;
            } // while

            // excess initializers?
            if (list) {
                DEBUGprintf ("ERROR, excess initializers\n");
                return (NULL);
            }

            DEBUGprintf ("OK, struct\n");
            return (type);
        }
        return (NULL);
    } else if (IS_STRUCT(type) && SPEC_STRUCT(getSpec(type))->type == UNION) {
        if (!list || (list->type == INIT_DEEP)) {
            if (list) list = list->init.deep;
            sym = SPEC_STRUCT(type)->fields;
            while (sym) {
                DEBUGprintf ("Checking UNION member %s.\n", sym->name);
                if (((IS_STRUCT(sym->type) || getSize(sym->type) == size))
                        && matchIvalToUnion(list, sym->type, size))
                {
                    DEBUGprintf ("Matched UNION member %s.\n", sym->name);
                    return (sym->type);
                }
                sym = sym->next;
            } // while
        } // if
        // no match found
        DEBUGprintf ("ERROR, no match found.\n");
        return (NULL);
    } else {
        assert ( !"Unhandled type in UNION." );
    }

    assert ( !"No match found in UNION for the given initializer structure." );
    return (NULL);
}
Esempio n. 8
0
/*-----------------------------------------------------------------*/
static void 
convertToFcall (eBBlock ** ebbs, int count)
{
  int i;

  /* for all blocks do */
  for (i = 0; i < count; i++)
    {
      iCode *ic;

      /* for all instructions in the block do */
      for (ic = ebbs[i]->sch; ic; ic = ic->next)
	{

	  /* floating point operations are
	     converted to function calls */
	  if ((IS_CONDITIONAL (ic) ||
	       IS_ARITHMETIC_OP (ic)) &&
	      (IS_FLOAT (operandType (IC_RIGHT (ic)))))
	    {

	      cnvToFcall (ic, ebbs[i]);
	    }

	  /* casting is a little different */
	  if (ic->op == CAST)
	    {
	      if (IS_FLOAT (operandType (IC_RIGHT (ic))))
		cnvFromFloatCast (ic, ebbs[i]);
	      else if (IS_FLOAT (operandType (IC_LEFT (ic))))
		cnvToFloatCast (ic, ebbs[i]);
	    }

	  /* if long / int mult or divide or mod */
	  if (ic->op == '*' || ic->op == '/' || ic->op == '%')
	    {
	      sym_link *leftType = operandType (IC_LEFT (ic));

	      if (IS_INTEGRAL (leftType) && getSize (leftType) > port->support.muldiv)
                {
                  sym_link *rightType = operandType (IC_RIGHT (ic));

                  if (port->hasNativeMulFor != NULL &&
                      port->hasNativeMulFor (ic, leftType, rightType))
                    {
                      /* Leave as native */
                    }
                  else
                    {
                      convilong (ic, ebbs[i], leftType, ic->op);
                    }
                }
	    }
          
          if (ic->op == RRC || ic->op == RLC || ic->op == LEFT_OP || ic->op == RIGHT_OP)
            {
	      sym_link *type = operandType (IC_LEFT (ic));

	      if (IS_INTEGRAL (type) && getSize (type) > port->support.shift && port->support.shift >= 0)
                {
                  convilong (ic, ebbs[i], type, ic->op);
                }
            }
	}
    }
}
void FinalMachineCodeGen::convert_IC_MC(InterCode *interCode, ostream &os) {
    string  dst_regName ;
    string  src1_regName;
    string  src2_regName;
    ExprNode **opndsList = (ExprNode **)interCode->get3Operands();
    switch(interCode->getOPNType()) {
        case CALL   :   {
                            string func_name = ((InvocationNode*)opndsList[0])->symTabEntry()->name();
                            string retAddrReg;

                            if (int_reg_used_cnt || fl_reg_used_cnt) {
                                retAddrReg = LabelClass::assignLabel()->getLabel();
                            } else {
                                retAddrReg = opndsList[0]->next()->getLabel();
                            }

                            push_registers(retAddrReg, os); 
                            os << "JMP  " << func_name << endl;

                            if ((int_reg_used_cnt-1) || fl_reg_used_cnt || opndsList[1]) {
                                os << retAddrReg << ": ";
                                pop_registers(os);

                                if (opndsList[1]) {
                                    ExprNode *src1    = opndsList[1];
                                    string retValueReg = src1->getRegisterName();
                                    if(IS_FLOAT(src1->type()))
                                        os<<"MOVF "<<RRV_F<<" ";
                                    else
                                        os<<"MOVI "<<RRV_I<<" ";
                                    os<<retValueReg<<endl;
                                    //int_reg_used_cnt--; 
                                }
                            }
                            reg_list.resize(0);

                            break;
                        }
        case FPARAM:    {
                            ExprNode *src1       = opndsList[0];
                            dst_regName = src1->getRegisterName();

                            os << "ADD "<<RSP<<" 4 "<<RSP << endl;
                            if (IS_FLOAT(src1->type()))
                                os << "LDF "<<RSP<<" "<<dst_regName;
                            else 
                                os << "LDI "<<RSP<<" "<<dst_regName;
                            os << C_FPARAM << endl;
                            break; 
                        } 
        case APARAM:    {
                            ExprNode *param       = opndsList[0];
                            Type     *ret_type = (param) ? (param->coercedType() ? (Type*)param ->coercedType() : param->type()): NULL ;
                            string    str;
                            string regName;
                            if(param)
                            {
                                if(param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                {
                                    if(IS_FLOAT(ret_type))
                                     {
                                         regName = allocateNewRegName(true);
                                         str = "STF "+regName+" "+RSP;
                                         //fl_reg_used_cnt--;
                                     }
                                    else
                                        str = "STI "+param->getRefName()+" "+RSP;
                                }
                                else
                                {
                                    if(IS_FLOAT(ret_type))
                                       {
                                           string temp;
                                           regName = param->getRegisterName();
                                           if(regName.at(0) == 'R')
                                              {
                                                  temp =  convertToFloat(param, os);
                                                  str = "STF "+temp+" "+RSP;
                                              }
                                            else
                                                  str = "STF "+param->getRegisterName()+" "+RSP;
                                        }
                                    else
                                        str = "STI "+param->getRegisterName()+" "+RSP;

                                }
                                reg_list.push_back(str + C_APARAM);
                            }
                            break;
                        }
        case RETURN:    {
                            if (opndsList[0]) {
                                ExprNode *ret_val  = opndsList[0];
                                Type     *ret_type = (ret_val) ? (ret_val ->coercedType() ? (Type*)ret_val ->coercedType() : ret_val ->type()): NULL ;

                                if (IS_FLOAT(ret_type)) {
                                    dst_regName = ret_val->getRegisterName();
                                    os<<"MOVF "<<dst_regName<<" "<<RRV_F;
                                } else {
                                    dst_regName = ret_val->getRegisterName();
                                    os<<"MOVI "<<dst_regName<<" "<<RRV_I;
                                }
                                os<<endl;
                            }
                            os<<"ADD " << RSP << " 4 " << RSP << endl;
                            os<<"LDI " << RSP << " " << RRET_ADD << C_POP_RET << endl;
                            os << "JMPI " << RRET_ADD << endl;
                            break;
                        }
        case EXPR:      {
                            ExprNode *dst = opndsList[0];
                            Type   *type_dst  = dst ->coercedType() ? (Type*)dst ->coercedType() : dst ->type();
                            if (opndsList[0] && opndsList[1] && opndsList[2]) {
                                ExprNode *src1 = opndsList[1];
                                ExprNode *src2 = opndsList[2];

                                Type *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type();
                                Type *type_src2 = src2->coercedType() ? (Type*)src2->coercedType() : src2->type();
                                if (IS_FLOAT(type_dst)) {
                                    if (src1) {
                                        src1_regName = src1->getRegisterName();
                                        if (!IS_FLOAT(type_src1))
                                            src1_regName = convertToFloat(src1, os);
                                    }
                                    if (src2) {
                                        src2_regName = src2->getRegisterName();
                                        if(!IS_FLOAT(type_src2))
                                            src2_regName= convertToFloat(src2, os);
                                    }
                                    if (dst)
                                        dst_regName = dst->getRegisterName();

                                    switch(interCode->getsubCode()) {
                                        case OpNode::OpCode::PLUS  :   {   os<<"FADD ";    PRT_REG;    break; } 
                                        case OpNode::OpCode::MINUS :   {   os<<"FSUB ";    PRT_REG;    break; }
                                        case OpNode::OpCode::MULT  :   {   os<<"FMUL ";    PRT_REG;    break; }     
                                        case OpNode::OpCode::DIV   :   {   os<<"FDIV ";    PRT_REG;    break; }
                                        case OpNode::OpCode::GT    :   {   os<<"FGT " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::GE    :   {   os<<"FGE " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::LT    :   {   os<<"FLT " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::LE    :   {   os<<"FLE " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::EQ    :   {   os<<"FEQ " ;    PRT_REG;    break; }
                                        case OpNode::OpCode::NE    :   {   os<<"FEQ " ;    PRT_REG;    break; }
                                        default                    :                  break;    
                                    }
                                } else {
                                    if (src1) {
                                        src1_regName = src1->getRegisterName();
                                        if(IS_FLOAT(type_src1)) 
                                            src1_regName = convertToInt(src1, os);
                                    }
                                    if (src2) {
                                        src2_regName = src2->getRegisterName();
                                        if(IS_FLOAT(type_src2))
                                            src2_regName= convertToInt(src2, os);
                                    }
                                    if (dst)
                                        dst_regName = dst->getRegisterName();
                                    
                                    switch(interCode->getsubCode()) {
                                        case OpNode::OpCode::PLUS  :   {  os<<"ADD ";    PRT_REG;          break; }
                                        case OpNode::OpCode::MINUS :   {  os<<"SUB ";    PRT_REG;          break; }
                                        case OpNode::OpCode::MULT  :   {  os<<"MUL ";    PRT_REG;          break; }    
                                        case OpNode::OpCode::MOD   :   {  os<<"MOD ";    PRT_REG;          break; }    
                                        case OpNode::OpCode::DIV   :   {  os<<"DIV ";    PRT_REG;          break; }
                                        case OpNode::OpCode::BITAND:   {  os<<"AND ";    PRT_REG;          break; }
                                        case OpNode::OpCode::BITOR :   {  os<<"OR " ;    PRT_REG;          break; }
                                        case OpNode::OpCode::BITXOR:   {  os<<"XOR ";    PRT_REG;          break; }
                                        case OpNode::OpCode::GT    :   {  os<<"JMPC GT " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::GE    :   {  os<<"JMPC GE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::LT    :   {  os<<"JMPC LT " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::LE    :   {  os<<"JMPC LE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::EQ    :   {  os<<"JMPC EQ " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::NE    :   {  os<<"JMPC NE " <<src1_regName<<" "<<src2_regName<<" ";    relational( dst_regName, os);    break; }
                                        case OpNode::OpCode::SHL   :   {  ShiftLogic(true, src1_regName, src2_regName, dst_regName, os);    break; } 
                                        case OpNode::OpCode::SHR   :   {  ShiftLogic(false, src1_regName, src2_regName, dst_regName, os);           break; }
                                        case OpNode::OpCode::AND   :   {  ANDLogic  (src1_regName, src2_regName, dst_regName, os);    break; } 
                                        case OpNode::OpCode::OR    :   {  ORLogic   (src1_regName, src2_regName, dst_regName, os);           break; }
                                        default                    :                  break;    
                                    }
                                }
                            } else if(opndsList[0] && opndsList[1]) {
                                ExprNode *src1 = opndsList[1];
                                Type   *type_src1 = src1->coercedType() ? (Type*)src1->coercedType() : src1->type();
                                bool IsEndlNeeded = true;

                                src1_regName = src1->getRegisterName();
                                if(dst)
                                    dst_regName = dst->getRegisterName();

                                if (IS_FLOAT(type_dst)) {
                                    if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) {
                                        if (!IS_FLOAT(type_src1))
                                            src1_regName = convertToFloat(src1, os);
                                        os<<"MOVF "<<src1_regName<<" "<<dst_regName;

                                    } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) {
                                        if (!IS_FLOAT(type_src1)) 
                                            src1_regName = convertToFloat(src1, os);
                                        os<<"FNEG "<<src1_regName<<" "<<dst_regName;
                                    }
                                } else {
                                    if (interCode->getsubCode() == OpNode::OpCode::ASSIGN) {
                                        if (IS_STRING(type_src1)) {
                                            os<<"MOVS "<<src1_regName<<" "<<dst_regName;
                                        } else {
                                            if (IS_FLOAT(type_src1)) 
                                                src1_regName = convertToInt(src1, os);
                                            os<<"MOVI "<<src1_regName<<" "<<dst_regName;
                                        }
                                    } else if (interCode->getsubCode() == OpNode::OpCode::UMINUS) {
                                        if (IS_FLOAT(type_src1)) 
                                            src1_regName = convertToInt(src1, os);
                                        os<<"NEG "<<src1_regName<<" "<<dst_regName;
                                    } else if (interCode->getsubCode() ==  OpNode::OpCode::NOT) {
                                        NOTLogic(src1_regName, dst_regName, os);
                                        IsEndlNeeded = false;
                                    } else if (interCode->getsubCode() ==  OpNode::OpCode::BITNOT) {
                                        os << "BNOT " << src1_regName << " " << dst_regName;
                                    }

                                }
                                if (IsEndlNeeded) os<<endl;
                            }
                            break;
                        }
          case LABEL  : {
                            os<<interCode->getLabel()<<endl;
                            break; 
                        }
          case GOTO   : { 
                            InterCode* goto_lab = (InterCode*) opndsList[0];

                            os<<"JMP "<<goto_lab->getLabel() <<endl;
                            break; 
                        }
          case IFREL  : { 
                            ExprNode* cond        = (ExprNode*) opndsList[0];
                            InterCode* true_lab   = cond->OnTrue();
                            InterCode* false_lab  = cond->OnFalse();
                            ExprNode* expr1       = (ExprNode*) opndsList[1];
                            ExprNode* expr2       = (ExprNode*) opndsList[2];
                            bool if_cond_int      = false;

                            Type   *type_src1 = (expr1) ?  (expr1->coercedType() ? (Type*)expr1->coercedType() : expr1->type()): NULL ;
                            Type   *type_src2 = (expr2) ?  (expr2->coercedType() ? (Type*)expr2->coercedType() : expr2->type()): NULL ;

                            if (opndsList[2] && opndsList[1]) 
                            {

                                src1_regName = expr1->getRegisterName();
                                src2_regName = expr2->getRegisterName();

                                if(!IS_FLOAT(type_src1) && !IS_FLOAT(type_src2))
                                    if_cond_int  = true;
                                else
                                {
                                    if(!IS_FLOAT(type_src1)) 
                                        src1_regName = convertToFloat(expr1, os);
                                    if(!IS_FLOAT(type_src2))
                                        src2_regName= convertToFloat(expr2, os);
                                    if_cond_int = false;
                                }

                                os<<"JMPC ";
                                switch(interCode->getsubCode())
                                {
                                    case OpNode::OpCode::EQ   : (if_cond_int) ? os<<"EQ " : os<<"FEQ "; break; 
                                    case OpNode::OpCode::NE   : (if_cond_int) ? os<<"NE " : os<<"FNE "; break;
                                    case OpNode::OpCode::GT   : (if_cond_int) ? os<<"GT " : os<<"FGT "; break; 
                                    case OpNode::OpCode::GE   : (if_cond_int) ? os<<"GE " : os<<"FGE "; break;
                                    case OpNode::OpCode::LT   : (if_cond_int) ? os<<"LT " : os<<"FLT "; break; 
                                    case OpNode::OpCode::LE   : (if_cond_int) ? os<<"LE " : os<<"FLE "; break;
                                    default                   :  break ;    
                                }
                                os<<src1_regName<<" "<<src2_regName<<" "<<(true_lab->getLabel())<<endl;
                                if(false_lab)
                                    os<<"JMP "<<(false_lab->getLabel())<<endl;
                            }
                            else if(opndsList[1])
                            {
                                if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                        src1_regName = expr1->getRefName(); 
                                else
                                        src1_regName = expr1->getRegisterName();
                                
                                if(Type::isBool(type_src1->tag()))
                                {
                                    if(interCode->getsubCode() == OpNode::OpCode::NOT)
                                        os<<"JMPC EQ ";
                                    os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl;
                                    if(false_lab)
                                        os<<"JMP "<<(false_lab->getLabel())<<endl;
                                }
                            }
                            else
                            {
                                if(cond->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                        src1_regName = cond->getRefName(); 
                                else
                                        src1_regName = cond->getRegisterName();
                                os<<"JMPC NE ";
                                os<<src1_regName<<" 0 "<<(true_lab->getLabel())<<endl;
                                if(false_lab)
                                    os<<"JMP "<<(false_lab->getLabel())<<endl;
                            }
                            break;
                        }
         case ENTER  :  { 
                            IsLastBlockEmpty = true;
                            fl_reg_used_cnt  = 0 ;
                            int_reg_used_cnt = 0 ;
                            break;
                        }
         case LEAVE  :  { 
                            os<<"ADD "<<RSP<<" 4 "<<RSP << endl;
                            os<<"LDI "<<RSP <<" "<<RRET_ADD << C_POP_RET << endl;
                            os << "JMPI " << RRET_ADD << endl;
                            break;
                        }
         case PRINT  :  {
                            ExprNode *param        = opndsList[0];
                            Type   *type_dst     = (param ) ?  (param ->coercedType() ? (Type*)param ->coercedType() : param ->type()): NULL ;

                            if (IS_FLOAT(type_dst))         os<<"PRTF ";
                            else if (IS_STRING(type_dst))   os<<"PRTS ";
                            else                            os<<"PRTI ";

                            if (param->exprNodeType() == ExprNode::ExprNodeType::VALUE_NODE)
                                os << opndsList[0]->getRefName();
                            else 
                                os << opndsList[0]->getRegisterName();
                            os << endl;
                            break;
                        }
                     
         default:       {
                            assert(0 && "Invalid 3 address Opcode");
                        }
    }
}
Esempio n. 10
0
void DoArrayStore(short ptr, short id)
{
   short lreg, k, type;

   k = ptr-1;
   type = FLAG2TYPE(STflag[id-1]);
   #if IFKO_DEBUG_LEVEL > 1
      fprintf(stderr, "pnam=%s, pflag=%d, idname='%s', idflag=%d\n", 
              STname[SToff[k].sa[0]-1], STflag[SToff[k].sa[0]-1], 
              STname[id-1], STflag[id-1]);
   #endif
   lreg = LocalLoad(id);
/*
 * NOTE: we added vector store where the array type and variable type
 * may not exactly match. we may have DOUBLE pointer but the variable is 
 * T_VDOUBLE.
 */
#if 0   
   assert(FLAG2TYPE(STflag[SToff[k].sa[0]-1]) == type);
#else
   if (IS_VEC(STflag[id-1]))
   {
      if ( (IS_VDOUBLE(STflag[id-1]) && !IS_DOUBLE(STflag[SToff[ptr-1].sa[0]-1]))
        || (IS_VFLOAT(STflag[id-1]) && !IS_FLOAT(STflag[SToff[ptr-1].sa[0]-1])) )
         fko_error(__LINE__, "type mismatch for vector store!");
   }
   else
   {
      if (FLAG2TYPE(STflag[SToff[k].sa[0]-1]) != type)
         fko_error(__LINE__, "type mismatch for store!");
   }
#endif
   FixDeref(ptr);
   switch(type)
   {
   case T_INT:
      #ifdef X86_64
         assert(lreg < 8);
         InsNewInst(NULL, NULL, NULL, STS, ptr, -lreg, 0);
      #else
         InsNewInst(NULL, NULL, NULL, ST, ptr, -lreg, 0);
      #endif
      break;
   case T_FLOAT:
      InsNewInst(NULL, NULL, NULL, FST, ptr, -lreg, 0);
      break;
   case T_DOUBLE:
      InsNewInst(NULL, NULL, NULL, FSTD, ptr, -lreg, 0);
      break;
#if 1
   case T_VFLOAT:
      InsNewInst(NULL, NULL, NULL, VFST, ptr, -lreg, 0);
      break;
   case T_VDOUBLE:
      InsNewInst(NULL, NULL, NULL, VDST, ptr, -lreg, 0);
      break;
#endif
   default:
      fko_error(__LINE__, "Unknown type %d\n", type);
   }
   GetReg(-1);
}
Esempio n. 11
0
int numberp(int x){	
    if(IS_INTEGER(x) || (IS_FLOAT(x)) || IS_RATIONAL(x) || IS_BIGNUM(x) ||(IS_COMPLEX(x)))
    	return(1);
    else
    	return(0);
}
Esempio n. 12
0
int floatp(int x){
	if(IS_FLOAT(x))
    	return(1);
    else
    	return(0);
}