Exemplo n.º 1
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VariableAnalysis::MarkAddressTaken(Instruction* instr) {
	if(auto loadInstr = instr->As<LoadInstr>()) {
		// Volatile loads should not be eliminated.
		if(loadInstr->IsVolatile()) {
			if(auto variableRef = loadInstr->SourceOp()->As<VariableReference>()) {
				auto localVar = variableRef->GetVariable();
				
                if(localVar == nullptr) {
                    return;
                }
                
                localVar->SetIsAddresTaken(true);
			}
		}

		return; // We're done with this instruction.
	}
	else if(auto storeInstr = instr->As<StoreInstr>()) {
		// Volatile stores should not be eliminated.
		if(storeInstr->IsVolatile()) {
			if(auto variableRef = storeInstr->DestinationOp()->As<VariableReference>()) {
				auto localVar = variableRef->GetVariable();
				
                if(localVar == nullptr) {
                    return;
                }

				localVar->SetIsAddresTaken(true);
			}
		}

		// If the stored operand is a local variable we can't eliminate it.
		if(storeInstr->SourceOp()->IsLocalVariableRef()) {
			auto variableRef = storeInstr->SourceOp()->As<VariableReference>();
            variableRef->GetVariable()->SetIsAddresTaken(true);
		}

		return; // We're done with this instruction.
	}

	// Any other instruction that has a variable reference as it's operand
	// is considered to take it's address.
	for(int i = 0; i < instr->SourceOpCount(); i++) {
		if(auto variableRef = instr->GetSourceOp(i)->As<VariableReference>()) {
			auto localVar = variableRef->GetVariable();

			if(localVar == nullptr) {
                continue;
            }

			// We don't set the flag for pointers, arrays and records because
			// we have a separate step that takes care of this.
			if((localVar->IsPointer() || 
                localVar->IsRecord()  ||
				localVar->IsArray()) == false) {
                localVar->SetIsAddresTaken(true);
			}
		}
	}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SimpleDeadCodeElimination::DetermineLiveStores(Variable* variable, 
                                                    StoreCollection& stores, 
                                                    Function* function) {
    // Any 'store' that might be live is removed from the list.
    // We need to check 'load' and 'call' instructions only.
    function->ForEachInstruction([&stores, variable, function, this]
                                (Instruction* instr) -> bool {
        if(auto loadInstr = instr->As<LoadInstr>()) {
            LoadStoreInfo info;
            info.Valid = false;
            info.HasVariableIndex = false;
            this->AddIndexes(loadInstr->SourceOp(), info, variable,
                             false /* isStore */);

            // Check if the 'load' is from our variable.
            if(info.Valid == false) {
                return true;
            }

            if(RemoveLiveStoresFromList(info, stores)) {
                // All stores are live, no reason to continue.
                return false;
            }
        }
        else if(auto callInstr = instr->As<CallInstr>()) {
            // Any local variable that appears as an argument is kept alive, 
            // because we don't know exactly if it's needed or not.
            for(int i = 0; i < callInstr->ArgumentCount(); i++) {
                auto argOp = callInstr->GetArgument(i);

                if(argOp->IsPointer()) {
                    LoadStoreInfo info;
                    info.Valid = true;
                    this->AddIndexes(argOp, info, variable, false /* isStore */);  
                    info.HasVariableIndex = true;

                    if(RemoveLiveStoresFromList(info, stores)) {
                        // All stores are live, no reason to continue.
                        return false;
                    }
                }
            }
        }
        else if(auto retInstr = instr->As<ReturnInstr>()) {
            if(retInstr->IsVoid() == false) {
                LoadStoreInfo info;
                info.Valid = false;
                info.HasVariableIndex = false;
                this->AddIndexes(retInstr->ReturnedOp(), info, variable, 
                                 false /* isStore */);  

                if(RemoveLiveStoresFromList(info, stores)) {
                    // All stores are live, no reason to continue.
                    return false;
                }
            }
        }
        return true;
    });
}
Exemplo n.º 3
0
void flext_base::cb_anything(flext_hdr *c,const t_symbol *s,int argc,t_atom *argv)
{
    Locker lock(c);
    if(UNLIKELY(!s)) {
        // apparently, this happens only in one case... object is a DSP object, but has no main DSP inlet...

        // interpret tag from args
        if(!argc)
            s = sym_bang;
        else if(argc == 1) {
            if(IsFloat(*argv))
                s = sym_float;
            else if(IsSymbol(*argv))
                s = sym_symbol;
            else if(IsPointer(*argv))
                s = sym_pointer;
            else
                FLEXT_ASSERT(false);
        }
        else
            s = sym_list;
    }

    thisObject(c)->CbMethodHandler(0,s,argc,argv);
}
Exemplo n.º 4
0
void wxsMenu::OnBuildCreatingCode()
{
    switch ( GetLanguage() )
    {
        case wxsCPP:
            AddHeader(_T("<wx/menu.h>"),GetInfo().ClassName,hfInPCH);
            if ( IsPointer() )
            {
                // There's no Create() method for wxMenu so we call ctor only when creating pointer
                Codef(_T("%C();\n"));
            }
            for ( int i=0; i<GetChildCount(); i++ )
            {
                GetChild(i)->BuildCode(GetCoderContext());
            }
            if ( GetParent() && GetParent()->GetClassName()==_T("wxMenuBar") )
            {
                Codef(_T("%MAppend(%O, %t);\n"),m_Label.wx_str());
            }
            BuildSetupWindowCode();
            break;

        case wxsUnknownLanguage: // fall-through
        default:
            wxsCodeMarks::Unknown(_T("wxsMenu::OnBuildCreatingCode"),GetLanguage());
    }
}
Exemplo n.º 5
0
OGLPLUS_LIB_FUNC
std::size_t BlendFileStructField::Size(void) const
{
	bool is_ptr = IsPointer() || IsPointerToFunc();

	if(IsArray())
	{
		std::size_t ec = ElementCount();
		if(is_ptr) return _sdna->_ptr_size * ec;
		else return BaseType().Size() * ec;
	}
	if(is_ptr) return _sdna->_ptr_size;
	return BaseType().Size();
}
Exemplo n.º 6
0
JString
JVMVarNode::GetPath()
	const
{
	JString str;
	if (IsRoot())
		{
		return str;
		}

	JBoolean isPointer = IsPointer();
	str  = GetFullName(&isPointer);
	str += isPointer ? "->" : ".";
	return str;
}
Exemplo n.º 7
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VariableAnalysis::InsertAggregateCandidates(OperandVariableDict& dict, 
                                                 const VariableList& varList) {
    auto unit = funct_->ParentUnit();

    for(int i = 0; i < varList.Count(); i++) {
        auto variable = varList[i];

        if((variable->IsArray()  || 
            variable->IsRecord() || 
            variable->IsPointer()) == false) {
            continue;
        }

        variable->SetIsAddresTaken(false); // Presume it's not.
        auto variableRefType = unit->Types().GetPointer(variable->GetType());
        auto variableRef = unit->References().GetVariableRef(variable, variableRefType);

        dict.Add(variableRef, OVPair(variableRef, variable));
    }
}
Exemplo n.º 8
0
    inline MsgBundle &Add(flext_base *th,int o,const t_atom &a) 
    { 
        const t_symbol *sym;
        if(IsSymbol(a))
            sym = sym_symbol;
        else if(IsFloat(a))
            sym = sym_float;
#if FLEXT_SYS == FLEXT_SYS_MAX
        else if(IsInt(a))
            sym = sym_int;
#endif
#if FLEXT_SYS == FLEXT_SYS_PD
        else if(IsPointer(a))
            sym = sym_pointer;
#endif
        else {
            error("atom type not supported");
            return *this;
        }
        return Add(th,o,sym,1,&a);
    }
Exemplo n.º 9
0
void flext_base::ToSysAtom(int n,const t_atom &at) const 
{ 
    outlet *o = GetOut(n); 
    if(LIKELY(o)) { 
        CRITON(); 
        if(IsSymbol(at))
            outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(GetSymbol(at))); 
        else if(IsFloat(at))
            outlet_float((t_outlet *)o,GetFloat(at)); 
#if FLEXT_SYS == FLEXT_SYS_MAX
        else if(IsInt(at))
            outlet_flint((t_outlet *)o,GetInt(at));
#endif
#if FLEXT_SYS == FLEXT_SYS_PD
        else if(IsPointer(at))
            outlet_pointer((t_outlet *)o,GetPointer(at)); 
#endif
        else
            error("Atom type not supported");
        CRITOFF(); 
    } 
}
Exemplo n.º 10
0
void
iregisterdllfun(void)
{
  int         i,
              index;
  ResType     argtypes[MAX_ARGS];  /* list of types of arguments */
  bool        vararg[MAX_ARGS];    /* is the argument a variable arg */
  bool        ispointer[MAX_ARGS]; /* is the argument a pointer */
  int         varargcount = 0;     /* number of variable args */
  int         ispointercount = 0;  /* number of pointer args */
  nialptr     z = apop();
  char       *nialname;            /* names used by calldllfun */
  char       *dllname;             /* the real name of the function */
                                   /* in the DLL file */
  char       *library;             /* name of the DLL file */
  ResType     resulttype;          /* the type of the result */
  nialptr     nargtypes;           /* the arg type array */
  int         argcount;
  int         j;
  int         sz;
  nialptr     current;       /* usually hold the current entry in the dlllist */
  int         is_register;

  /* if we have 5 args we are registering a function */

  if ((tally(z) == 5) && (kind(z) == atype))
    is_register = 1;         /* register mode */

  else 
  /* only one arg and it is a char or a phrase, we are deleting the fun */
  if ((kind(z) == chartype) || (kind(z) == phrasetype))
    is_register = 0;         /* delete mode */

  else {                     /* error mode */
    apush(makefault("?Incorrect number of arguments to registerdllfun"));
    freeup(z);
    return;
  }

  if (is_register) {
    /* The Nial level name for the DLL function */
    STRING_CHECK(z, 0)
      nialname = STRING_GET(z, 0);


    /* The internal DLL name for the function */
    STRING_CHECK(z, 1)
      dllname = STRING_GET(z, 1);

    /* The name of the library file */
    STRING_CHECK(z, 2)
      library = STRING_GET(z, 2);

    /* The name of the result type */
    STRING_CHECK(z, 3)
      resulttype = StringToTypeID(STRING_GET(z, 3));

    /* did we find an unrecognized result type? */
    if (resulttype < 0) {
      apush(makefault("?Return type not recognized"));
      freeup(z);
      return;
    }

    if (kind(fetch_array(z, 4)) != atype) {
      apush(makefault("?Argument must be a list of strings or phrases"));
      freeup(z);
      return;
    }

    nargtypes = fetch_array(z, 4);
    argcount = tally(nargtypes);

    /* Check each of the argument type */
    for (j = 0; j < argcount; j++)
      STRING_CHECK_FREEUP(nargtypes, j, z)
      /* create an integer list of argument types from the phrase/string list */
        for (i = 0; i < argcount; i++) {
        char       *tmp;

        tmp = pfirstchar(fetch_array(nargtypes, i));  /* safe: no allocation */
        argtypes[i] = StringToTypeID(tmp);

        /* the ith argument name was not recognized */
        if (argtypes[i] < 0) {
          char        stmp[256];

          wsprintf(stmp, "?Type \"%s\" for argument %d not recognized", tmp, i + 1);
          apush(makefault(stmp));
          freeup(z);
          return;
        }
        /* set the vararg and ispointer flags for this arg */
        vararg[i] = IsVarArg(tmp);
        ispointer[i] = IsPointer(tmp);
        /* keep count of these special args */
        if (vararg[i])
          varargcount++;
        if (ispointer[i])
          ispointercount++;
      }

    /* NEW workspace Version */

    /* If the list does not yet exist, then create a one element list here */
    if (tally(dlllist) == 0) {
      nialptr     tmp = create_new_dll_entry; /* build a empty entry */

      setup_dll_entry(tmp)   /* fill it with empty data */
        apush(tmp);
      isolitary();           /* make it a list */
      decrrefcnt(dlllist);
      freeup(dlllist);
      dlllist = apop();
      incrrefcnt(dlllist);
      index = 0;
    }
    else {
      int         pos;

      /* does the requested name already exist in out list? */
      if ((pos = inlist(nialname)) >= 0) {
        /* yes it's here already, so note its position, and free the old
         * entry */
        index = pos;
        freeEntry(index);
      }
      else {
        /* if we got here, then we need to create a new entry and add it to
         * and existing dlllist */
        nialptr     tmp = create_new_dll_entry;

        setup_dll_entry(tmp)
          decrrefcnt(dlllist);
        append(dlllist, tmp);
        dlllist = apop();
        incrrefcnt(dlllist);
        index = tally(dlllist) - 1; /* this is the location of the new entry */
      }
    }



    /* grab the entry to work on */
    current = fetch_array(dlllist, index);

    /* fill in data */
    set_handle(current, NULL);
    set_nialname(current, nialname);
    set_dllname(current, dllname);
    set_callingconvention(current, (dllname[0] == '_' ? C_CALL : PASCAL_CALL));
    set_library(current, library);
    set_isloaded(current, false);
    set_resulttype(current, resulttype);
    set_argcount(current, argcount);
    set_varargcount(current, varargcount);
    set_ispointercount(current, ispointercount);

    sz = argcount;
    replace_array(current, 10, (sz == 0 ? Null : new_create_array(inttype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_argtypes(current, j, argtypes[j]);

    replace_array(current, 11, (sz == 0 ? Null : new_create_array(booltype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_ispointer(current, j, ispointer[j]);

    replace_array(current, 14, (sz == 0 ? Null : new_create_array(booltype, 1, 0, &sz)));
    for (j = 0; j < sz; j++)
      set_vararg(current, j, vararg[j]);
  }
  else { /* delete entry code */
Exemplo n.º 11
0
void wxsMenuItem::OnBuildCreatingCode()
{
    switch ( GetLanguage() )
    {
        case wxsCPP:

            switch ( m_Type )
            {
                case Normal:
                {
                    if ( GetChildCount() )
                    {
                        // Creating new wxMenu
                        if ( IsPointer() )
                        {
                            Codef(_T("%C();\n"));
                        }
                        for ( int i=0; i<GetChildCount(); i++ )
                        {
                            GetChild(i)->BuildCode(GetCoderContext());
                        }
                        // Many parameters are passed in wxMenu::Append, so we call this function
                        // here, not in wxMenu
                        Codef(_T("%MAppend(%I, %t, %O, %t)%s;\n"),
                              m_Label.wx_str(),
                              m_Help.wx_str(),
                              m_Enabled?_T(""):_T("->Enable(false)"));
                        break;
                    }
                }
                // Fall through

             /* case Normal: */
                case Radio:
                case Check:
                {
                    wxString Text = m_Label;
                    if ( !m_Accelerator.IsEmpty() )
                    {
                        Text.Append(_T('\t'));
                        Text.Append(m_Accelerator);
                    }

                    const wxChar* ItemType;
                    switch ( m_Type )
                    {
                        case Normal: ItemType = _T("wxITEM_NORMAL"); break;
                        case Radio:  ItemType = _T("wxITEM_RADIO");  break;
                        default:     ItemType = _T("wxITEM_CHECK");  break;
                    }

                    Codef(_T("%C(%E, %I, %t, %t, %s);\n"),
                          Text.wx_str(),
                          m_Help.wx_str(),
                          ItemType);

                    if ( !m_Bitmap.IsEmpty() )
                    {
                        Codef(_T("%ASetBitmap(%i);\n"), &m_Bitmap, _T("wxART_OTHER"));
                    }

                    Codef(_T("%MAppend(%O);\n"));
                    if ( !m_Enabled )
                    {
                        Codef(_T("%AEnable(false);\n"));
                    }
                    if ( m_Checked && (m_Type==Check) )
                    {
                        Codef(_T("%ACheck(true);\n"));
                    }
                    break;
                }


                case Separator:
                {
                    Codef(_T("%MAppendSeparator();\n"));
                    break;
                }

                case Break:
                {
                    Codef(_T("%MBreak();\n"));
                    break;
                }

            }
            BuildSetupWindowCode();
            break;

        case wxsUnknownLanguage: // fall-through
        default:
            wxsCodeMarks::Unknown(_T("wxsMenuItem::OnBuildCreatingCode"),GetLanguage());
    }
}
Exemplo n.º 12
0
static void CompareParms( TYPEPTR *master, TREEPTR parm, source_loc *src_loc )
{
    TYPEPTR     typ;
    TYPEPTR     typ2;
    int         parm_num;
    cmp_type    cmp;

    typ = *master++;
    if( typ != NULL ) {                     /* 27-feb-90 */
        if( typ->decl_type == TYPE_VOID ) { /* type func(void); */
            typ = NULL;                     /* indicate no parms */
        }
    }
    parm_num = 1;
    while( ( typ != NULL ) && ( parm != NULL ) ) {
        SKIP_TYPEDEFS( typ );
        // TODO is crap needed or has it been done
        if( typ->decl_type == TYPE_FUNCTION ) {
            typ = PtrNode( typ, FLAG_NONE, SEG_CODE );
        } else if( typ->decl_type == TYPE_ARRAY ) {
            typ = PtrNode( typ->object, FLAG_WAS_ARRAY, SEG_DATA );
        }
        typ2 = parm->expr_type;
        // typ2 will be NULL if parm is OPR_ERROR in which case an error
        // has already been generated
        if( typ2 != NULL ) {
            /* check compatibility of parms */
            SetErrLoc( src_loc );
            SetDiagType2 ( typ2, typ );
            cmp = CompatibleType( typ, typ2, TRUE, IsNullConst( parm ) );
            switch( cmp ) {
            case NO:
            case PT:
            case PX:
            case AC:
                CErr2( ERR_PARM_TYPE_MISMATCH, parm_num );
                break;
            case PQ:
                if( !CompFlags.no_check_qualifiers ) { // else f**k em
                    CWarn2( WARN_QUALIFIER_MISMATCH,
                        ERR_PARM_QUALIFIER_MISMATCH, parm_num );
                }
                break;
            case PM:                                    /* 16-may-91 */
                CWarn2( WARN_POINTER_TYPE_MISMATCH,
                        ERR_PARM_POINTER_TYPE_MISMATCH, parm_num );
                break;
            case PS:
                CWarn2( WARN_SIGN_MISMATCH,
                        ERR_PARM_SIGN_MISMATCH, parm_num );
                break;
            case PW:
                CWarn2( WARN_PARM_INCONSISTENT_INDIRECTION_LEVEL,
                        ERR_PARM_INCONSISTENT_INDIRECTION_LEVEL, parm_num );
                break;
            case PC:  /* Allow only "void *p = int 0";  */
                if( IsPointer( typ ) && parm->right->op.opr == OPR_PUSHINT ) {
                    if( TypeSize(typ) != TypeSize(typ2) ) {
                        CErr2( ERR_PARM_TYPE_MISMATCH, parm_num );
                    } else if( parm->right->op.ulong_value != 0 ) {
                        CWarn1( WARN_NONPORTABLE_PTR_CONV,
                                ERR_NONPORTABLE_PTR_CONV );
                    }
                } else {
                    if( TypeSize(typ->object) == TypeSize(typ2->object) ) {
                        CWarn2( WARN_POINTER_TYPE_MISMATCH,
                             ERR_PARM_POINTER_TYPE_MISMATCH, parm_num );
                    } else {
                        CErr2( ERR_PARM_TYPE_MISMATCH, parm_num );
                    }
                }
                break;
            case OK:
                break;
            }
            SetDiagPop();
            InitErrLoc();
        }
        typ = *master++;
        if( typ != NULL && typ->decl_type == TYPE_DOT_DOT_DOT )
            return;
        parm = parm->left;
        ++parm_num;
    }
    if( typ != NULL || parm != NULL ) {     /* should both be NULL now */
        SetErrLoc( src_loc );
#if _CPU == 386
        /* can allow wrong number of parms with -3s option; 06-dec-91 */
        if( !CompFlags.register_conventions ) {
            CWarn1( WARN_PARM_COUNT_MISMATCH, ERR_PARM_COUNT_WARNING );
            return;
        }
#endif
        CErr1( ERR_PARM_COUNT_MISMATCH );           /* 18-feb-90 */
    }
}
Exemplo n.º 13
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AggregateCopyPropagation::MightWriteToOperand(Instruction* instr, Operand* op) {
    //! TODO: THIS SHOULD USE ALIAS INFO!
    // Only 'store' and 'call' instructions can write to memory.
    if(auto storeInstr = instr->As<StoreInstr>()) {
        // If we store into a local/global variable we can write
        // over the source or destination only if it's exactly
        // the same variable.
        auto destOp = storeInstr->DestinationOp();

        if(auto baseOp = GetBaseOperand(destOp)) {
            if(auto variableRef = baseOp->As<VariableReference>()) {
                return op->IsVariableReference() &&
                       (op == variableRef);
            }
        }

        // We presume it might write.
        return true;
    }
    else if(auto callInstr = instr->As<CallInstr>()) {
        // For most intrinsics we know the behavior.
        if(auto intrinsic = callInstr->GetIntrinsic()) {
            if(intrinsic->IsMathIntrinsic() ||
               intrinsic->IsBitwiseIntrinsic() ||
               intrinsic->IsStackIntrinsic()) {
               return false;
            }
        }

        // If the destination/source is a variable whose address
        // is not taken, and we have a 'call' that doesn't refer
        // to these operands then the callee can't write to them.
        auto baseOp = GetBaseOperand(op);

        if(baseOp == nullptr) {
            return true;
        }

        auto variableRef = baseOp->As<VariableReference>();

        if(variableRef == nullptr) {
            return true;
        }

        if(variableRef->IsGlobalVariableRef()) {
            if(auto function = callInstr->GetCalledFunction()) {
                return function->IsNoWrite() == false;
            }

            return true;
        }
        
        // Check each pointer argument.
        for(int i = 0; i < callInstr->ArgumentCount(); i++) {
            auto argument = WithoutPointerCasts(callInstr->GetArgument(i));

            if(argument->IsPointer()) {
                // If the parameter is marked as 'noescape' and 'nowrite'
                // we know the called function doesn't modify the argument.
                if(auto function = callInstr->GetCalledFunction()) {
                    auto parameter = function->GetParameter(i);

                    if(parameter->IsNoEscape() && parameter->IsNoWrite()) {
                        continue;
                    }
                }

                if(auto argVariableRef = argument->As<VariableReference>()) {
                    return argVariableRef == variableRef;
                }

                // If the address of the variable is taken
                // we need to presume it might be written here.
                if(variableRef->IsAddressTaken()) {
                    return true;
                }
            }
        }

        return false;
    }

    return false;
}