<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: pe_class.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 18:23:07 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef ADC_CPP_PE_CLASS_HXX
#define ADC_CPP_PE_CLASS_HXX

// USED SERVICES
    // BASE CLASSES
#include "cpp_pe.hxx"
    // COMPONENTS
#include <semantic/callf.hxx>
#include <semantic/sub_peu.hxx>
#include <ary/cpp/c_etypes.hxx>
#include <ary/cpp/c_idlist.hxx>
    // PARAMETERS
#include "all_toks.hxx"

namespace ary
{
namespace cpp
{
    class Class;
}
}

namespace cpp
{

using ary::cpp::E_Protection;
using ary::cpp::E_Virtuality;

class PE_Base;
class PE_Enum;
class PE_Typedef;
class PE_VarFunc;
class PE_Ignore;

class PE_Class : public cpp::Cpp_PE
{
  public:
    enum E_State
    {
        start,              /// before class, struct or union
        expectName,         /// after class, struct or union
        gotName,            /// after name, before : or {
        bodyStd,            /// after {
        inProtection,       /// after public, protected or private and before ":"
        afterDecl,          /// after ending }
        size_of_states
    };

    enum E_KindOfResult
    {
        is_declaration,             // normal
        is_implicit_declaration,    // like in: class Abc { public int n; } aAbc;
        is_predeclaration,          // like:    class Abc;
        is_qualified_typename       // like in: class Abc * fx();

    };

                        PE_Class(
                            Cpp_PE *            i_pParent );
                        ~PE_Class();

    virtual void        Call_Handler(
                            const cpp::Token &  i_rTok );
    virtual Cpp_PE *    Handle_ChildFailure();

    E_KindOfResult      Result_KindOf() const;
    const udmstri &     Result_LocalName() const;
    const udmstri &     Result_FirstNameSegment() const;

  private:
    typedef SubPe< PE_Class, PE_Base >          SP_Base;
//  typedef SubPe< PE_Class, PE_Enum>           SP_Enum;
    typedef SubPe< PE_Class, PE_Typedef>        SP_Typedef;
    typedef SubPe< PE_Class, PE_VarFunc>        SP_VarFunc;
    typedef SubPe< PE_Class, PE_Ignore >        SP_Ignore;

    typedef SubPeUse< PE_Class, PE_Base>        SPU_Base;
//  typedef SubPeUse< PE_Class, PE_Enum>            SPU_Enum;
    typedef SubPeUse< PE_Class, PE_Typedef>     SPU_Typedef;
    typedef SubPeUse< PE_Class, PE_VarFunc>     SPU_VarFunc;
    typedef SubPeUse< PE_Class, PE_Ignore>      SPU_Ignore;

    typedef ary::cpp::List_Bases                BaseList;
    typedef ary::cpp::S_Classes_Base            Base;
    typedef ary::cpp::E_Protection              E_Protection;

    void                Setup_StatusFunctions();
    virtual void        InitData();
    virtual void        TransferData();
    void                Hdl_SyntaxError( const char *);
    void                Init_CurObject();

    void                SpReturn_Base();

    void                On_start_class( const char * );
    void                On_start_struct( const char * );
    void                On_start_union( const char * );

    void                On_expectName_Identifier( const char * );
    void                On_expectName_SwBracket_Left( const char * );
    void                On_expectName_Colon( const char * );

    void                On_gotName_SwBracket_Left( const char * );
    void                On_gotName_Semicolon( const char * );
    void                On_gotName_Colon( const char * );
    void                On_gotName_Return2Type( const char * );

    void                On_bodyStd_VarFunc( const char * );
    void                On_bodyStd_ClassKey( const char * );
    void                On_bodyStd_enum( const char * );
    void                On_bodyStd_typedef( const char * );
    void                On_bodyStd_public( const char * );
    void                On_bodyStd_protected( const char * );
    void                On_bodyStd_private( const char * );
    void                On_bodyStd_template( const char * );
    void                On_bodyStd_friend( const char * );
    void                On_bodyStd_using( const char * );
    void                On_bodyStd_SwBracket_Right( const char * );

    void                On_inProtection_Colon( const char * );

    void                On_afterDecl_Semicolon( const char * );
    void                On_afterDecl_Return2Type( const char * );

    // DATA
    Dyn< PeStatusArray<PE_Class> >
                        pStati;

    Dyn<SP_Base>        pSpBase;
//  Dyn<SP_Enum>        pSpEnum;
    Dyn<SP_Typedef>     pSpTypedef;
    Dyn<SP_VarFunc>     pSpVarFunc;
    Dyn<SP_Ignore>      pSpIgnore;

    Dyn<SPU_Base>       pSpuBase;
//  Dyn<SPU_Enum>       pSpuEnum;
    Dyn<SPU_Typedef>    pSpuTypedef;
    Dyn<SPU_VarFunc>    pSpuVarFunc;

    Dyn<SPU_Ignore>     pSpuTemplate;
    Dyn<SPU_Ignore>     pSpuUsing;
    Dyn<SPU_Ignore>     pSpuIgnoreFailure;

    udmstri             sLocalName;
    ary::cpp::E_ClassKey
                        eClassKey;
    ary::cpp::Class *   pCurObject;
    BaseList            aBases;

    E_KindOfResult      eResult_KindOf;
};

// IMPLEMENTATION

inline PE_Class::E_KindOfResult
PE_Class::Result_KindOf() const
{
    return eResult_KindOf;
}

inline const udmstri &
PE_Class::Result_LocalName() const
{
    return sLocalName;
}

inline const udmstri &
PE_Class::Result_FirstNameSegment() const
{
    return sLocalName;
}

}   // namespace cpp

#if 0   // Branches

class struct union
    -> Class
    -> Predeclaration

typedef
    -> Typedef

enum
    -> Enum

TypeDeclaration
    -> Function In Class
    -> Variable

public, protected, private
    -> Protection declaration

friend
    ->  Friend Class
    ->  Friend Function

virtual
    -> Function In Class

using
    -> Using Declaration

#endif // 0

#endif

<commit_msg>INTEGRATION: CWS adc18 (1.2.56); FILE MERGED 2007/10/19 10:37:30 np 1.2.56.2: #i81775# 2007/10/17 09:30:49 np 1.2.56.1: #i54779#<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: pe_class.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2007-11-02 16:53:05 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef ADC_CPP_PE_CLASS_HXX
#define ADC_CPP_PE_CLASS_HXX

// USED SERVICES
    // BASE CLASSES
#include "cpp_pe.hxx"
    // OTHER
#include <semantic/callf.hxx>
#include <semantic/sub_peu.hxx>
#include <ary/cpp/c_types4cpp.hxx>
#include <ary/cpp/c_slntry.hxx>
#include "all_toks.hxx"

namespace ary
{
namespace cpp
{
    class Class;
}
}

namespace cpp
{

using ary::cpp::E_Protection;
using ary::cpp::E_Virtuality;

class PE_Base;
class PE_Enum;
class PE_Typedef;
class PE_VarFunc;
class PE_Ignore;
class PE_Defines;

class PE_Class : public cpp::Cpp_PE
{
  public:
    enum E_State
    {
        start,              /// before class, struct or union
        expectName,         /// after class, struct or union
        gotName,            /// after name, before : or {
        bodyStd,            /// after {
        inProtection,       /// after public, protected or private and before ":"
        afterDecl,          /// after ending }
        size_of_states
    };

    enum E_KindOfResult
    {
        is_declaration,             // normal
        is_implicit_declaration,    // like in: class Abc { public int n; } aAbc;
        is_predeclaration,          // like:    class Abc;
        is_qualified_typename       // like in: class Abc * fx();

    };

                        PE_Class(
                            Cpp_PE *            i_pParent );
                        ~PE_Class();

    virtual void        Call_Handler(
                            const cpp::Token &  i_rTok );
    virtual Cpp_PE *    Handle_ChildFailure();

    E_KindOfResult      Result_KindOf() const;
    const String  &     Result_LocalName() const;
    const String  &     Result_FirstNameSegment() const;

  private:
    typedef SubPe< PE_Class, PE_Base >          SP_Base;
//  typedef SubPe< PE_Class, PE_Enum>           SP_Enum;
    typedef SubPe< PE_Class, PE_Typedef>        SP_Typedef;
    typedef SubPe< PE_Class, PE_VarFunc>        SP_VarFunc;
    typedef SubPe< PE_Class, PE_Ignore >        SP_Ignore;
    typedef SubPe< PE_Class, PE_Defines>        SP_Defines;

    typedef SubPeUse< PE_Class, PE_Base>        SPU_Base;
//  typedef SubPeUse< PE_Class, PE_Enum>            SPU_Enum;
    typedef SubPeUse< PE_Class, PE_Typedef>     SPU_Typedef;
    typedef SubPeUse< PE_Class, PE_VarFunc>     SPU_VarFunc;
    typedef SubPeUse< PE_Class, PE_Ignore>      SPU_Ignore;
    typedef SubPeUse< PE_Class, PE_Defines>     SPU_Defines;

    typedef ary::cpp::List_Bases                BaseList;
    typedef ary::cpp::S_Classes_Base            Base;
    typedef ary::cpp::E_Protection              E_Protection;

    void                Setup_StatusFunctions();
    virtual void        InitData();
    virtual void        TransferData();
    void                Hdl_SyntaxError( const char *);
    void                Init_CurObject();

    void                SpReturn_Base();

    void                On_start_class( const char * );
    void                On_start_struct( const char * );
    void                On_start_union( const char * );

    void                On_expectName_Identifier( const char * );
    void                On_expectName_SwBracket_Left( const char * );
    void                On_expectName_Colon( const char * );

    void                On_gotName_SwBracket_Left( const char * );
    void                On_gotName_Semicolon( const char * );
    void                On_gotName_Colon( const char * );
    void                On_gotName_Return2Type( const char * );

    void                On_bodyStd_VarFunc( const char * );
    void                On_bodyStd_ClassKey( const char * );
    void                On_bodyStd_enum( const char * );
    void                On_bodyStd_typedef( const char * );
    void                On_bodyStd_public( const char * );
    void                On_bodyStd_protected( const char * );
    void                On_bodyStd_private( const char * );
    void                On_bodyStd_template( const char * );
    void                On_bodyStd_friend( const char * );
    void                On_bodyStd_using( const char * );
    void                On_bodyStd_SwBracket_Right( const char * );
    void                On_bodyStd_DefineName(const char * );
    void                On_bodyStd_MacroName(const char * );

    void                On_inProtection_Colon( const char * );

    void                On_afterDecl_Semicolon( const char * );
    void                On_afterDecl_Return2Type( const char * );

    // DATA
    Dyn< PeStatusArray<PE_Class> >
                        pStati;

    Dyn<SP_Base>        pSpBase;
//  Dyn<SP_Enum>        pSpEnum;
    Dyn<SP_Typedef>     pSpTypedef;
    Dyn<SP_VarFunc>     pSpVarFunc;
    Dyn<SP_Ignore>      pSpIgnore;
    Dyn<SP_Defines>     pSpDefs;

    Dyn<SPU_Base>       pSpuBase;
//  Dyn<SPU_Enum>       pSpuEnum;
    Dyn<SPU_Typedef>    pSpuTypedef;
    Dyn<SPU_VarFunc>    pSpuVarFunc;

    Dyn<SPU_Ignore>     pSpuTemplate;
    Dyn<SPU_Ignore>     pSpuUsing;
    Dyn<SPU_Ignore>     pSpuIgnoreFailure;
    Dyn<SPU_Defines>    pSpuDefs;

    String              sLocalName;
    ary::cpp::E_ClassKey
                        eClassKey;
    ary::cpp::Class *   pCurObject;
    BaseList            aBases;

    E_KindOfResult      eResult_KindOf;
};

// IMPLEMENTATION

inline PE_Class::E_KindOfResult
PE_Class::Result_KindOf() const
{
    return eResult_KindOf;
}

inline const String  &
PE_Class::Result_LocalName() const
{
    return sLocalName;
}

inline const String  &
PE_Class::Result_FirstNameSegment() const
{
    return sLocalName;
}

}   // namespace cpp

#if 0   // Branches

class struct union
    -> Class
    -> Predeclaration

typedef
    -> Typedef

enum
    -> Enum

TypeDeclaration
    -> Function In Class
    -> Variable

public, protected, private
    -> Protection declaration

friend
    ->  Friend Class
    ->  Friend Function

virtual
    -> Function In Class

using
    -> Using Declaration

#endif // 0

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: pe_param.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2007-10-09 15:03:02 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <precomp.h>
#include "pe_param.hxx"

// NOT FULLY DEFINED SERVICES
#include <cosv/template/tpltools.hxx>
#include <ary/cpp/c_rwgate.hxx>
#include "pe_type.hxx"
#include "pe_vari.hxx"

namespace cpp {

//***********************       PE_Parameter        ***********************//

PE_Parameter::PE_Parameter( Cpp_PE * i_pParent )
    :   Cpp_PE(i_pParent),
        pStati( new PeStatusArray<PE_Parameter> )
        // pSpType,
        // pSpuType,
        // pSpVariable,
        // pSpuVariable,
        // aResultParamInfo
{
    Setup_StatusFunctions();

    pSpType         = new SP_Type(*this);
    pSpuType        = new SPU_Type(*pSpType, &PE_Parameter::SpInit_Type, &PE_Parameter::SpReturn_Type);
    pSpVariable     = new SP_Variable(*this);
    pSpuVariable    = new SPU_Variable(*pSpVariable, &PE_Parameter::SpInit_Variable, &PE_Parameter::SpReturn_Variable);
}

PE_Parameter::~PE_Parameter()
{
}

void
PE_Parameter::Call_Handler( const cpp::Token & i_rTok )
{
    pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
}

void
PE_Parameter::Setup_StatusFunctions()
{
    typedef CallFunction<PE_Parameter>::F_Tok   F_Tok;
    static F_Tok stateF_start[] =           { &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,

                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Bracket_Right,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Ellipse,

                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type };
    static INT16 stateT_start[] =           { Tid_Identifier,
                                              Tid_class,
                                              Tid_struct,
                                              Tid_union,
                                              Tid_enum,

                                              Tid_const,
                                              Tid_volatile,
                                              Tid_Bracket_Right,
                                              Tid_DoubleColon,
                                              Tid_Ellipse,

                                              Tid_typename,
                                              Tid_BuiltInType,
                                              Tid_TypeSpecializer };

    static F_Tok stateF_expectName[] =      { &PE_Parameter::On_expectName_Identifier,
                                              &PE_Parameter::On_expectName_ArrayBracket_Left,
                                              &PE_Parameter::On_expectName_Bracket_Right,
                                              &PE_Parameter::On_expectName_Comma,
                                              &PE_Parameter::On_afterName_Assign  };
    static INT16 stateT_expectName[] =      { Tid_Identifier,
                                              Tid_ArrayBracket_Left,
                                              Tid_Bracket_Right,
                                              Tid_Comma,
                                              Tid_Assign };
    static F_Tok stateF_afterName[] =       { &PE_Parameter::On_afterName_ArrayBracket_Left,
                                              &PE_Parameter::On_afterName_Bracket_Right,
                                              &PE_Parameter::On_afterName_Comma,
                                              &PE_Parameter::On_afterName_Assign };
    static INT16 stateT_afterName[] =       { Tid_ArrayBracket_Left,
                                              Tid_Bracket_Right,
                                              Tid_Comma,
                                              Tid_Assign };
    static F_Tok stateF_finished[] =        { &PE_Parameter::On_finished_Comma,
                                              &PE_Parameter::On_finished_Bracket_Right };
    static INT16 stateT_finished[] =        { Tid_Bracket_Right,
                                              Tid_Comma };

    SEMPARSE_CREATE_STATUS(PE_Parameter, start, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, expectName, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, afterName, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, finished, Hdl_SyntaxError);
}

void
PE_Parameter::InitData()
{
    pStati->SetCur(start);
    aResultParamInfo.Empty();
}

void
PE_Parameter::TransferData()
{
    pStati->SetCur(size_of_states);
}

void
PE_Parameter::Hdl_SyntaxError( const char * i_sText)
{
    StdHandlingOfSyntaxError(i_sText);
}

void
PE_Parameter::SpInit_Type()
{
    // Does nothing.
}

void
PE_Parameter::SpInit_Variable()
{
    // Does nothing.
}

void
PE_Parameter::SpReturn_Type()
{
    aResultParamInfo.nType = pSpuType->Child().Result_Type().Id();
    pStati->SetCur(expectName);
}

void
PE_Parameter::SpReturn_Variable()
{
    if (pSpuVariable->Child().Result_Pattern() > 0)
    {
        aResultParamInfo.sSizeExpression = pSpuVariable->Child().Result_SizeExpression();
        aResultParamInfo.sInitExpression = pSpuVariable->Child().Result_InitExpression();
    }
}

void
PE_Parameter::On_start_Type(const char *)
{
    pSpuType->Push(not_done);
}

void
PE_Parameter::On_start_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_start_Ellipse(const char *)
{
    SetTokenResult(done, pop_success);

    aResultParamInfo.nType = Env().AryGate().Tid_Ellipse();
}

void
PE_Parameter::On_expectName_Identifier(const char * i_sText)
{
    SetTokenResult(done, stay);
    pStati->SetCur(afterName);

    aResultParamInfo.sName = i_sText;
}

void
PE_Parameter::On_expectName_ArrayBracket_Left(const char * i_sText)
{
    On_afterName_ArrayBracket_Left(i_sText);
}

void
PE_Parameter::On_expectName_Bracket_Right(const char * i_sText)
{
    On_afterName_Bracket_Right(i_sText);
}

void
PE_Parameter::On_expectName_Comma(const char * i_sText)
{
    On_afterName_Comma(i_sText);
}

void
PE_Parameter::On_expectName_Assign(const char * i_sText)
{
    On_afterName_Assign(i_sText);
}

void
PE_Parameter::On_afterName_ArrayBracket_Left(const char *)
{
    pSpuVariable->Push(not_done);
}

void
PE_Parameter::On_afterName_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_afterName_Comma(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_afterName_Assign(const char *)
{
    pSpuVariable->Push(not_done);
}

void
PE_Parameter::On_finished_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_finished_Comma(const char *)
{
    SetTokenResult(not_done, pop_success);
}

}   // namespace cpp

<commit_msg>INTEGRATION: CWS adc18 (1.9.2); FILE MERGED 2007/10/18 15:23:18 np 1.9.2.1: #i81775#<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: pe_param.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2007-11-02 16:56:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <precomp.h>
#include "pe_param.hxx"

// NOT FULLY DEFINED SERVICES
#include <cosv/tpl/tpltools.hxx>
#include <ary/cpp/c_gate.hxx>
#include <ary/cpp/cp_type.hxx>
#include "pe_type.hxx"
#include "pe_vari.hxx"

namespace cpp {

//***********************       PE_Parameter        ***********************//

PE_Parameter::PE_Parameter( Cpp_PE * i_pParent )
    :   Cpp_PE(i_pParent),
        pStati( new PeStatusArray<PE_Parameter> )
        // pSpType,
        // pSpuType,
        // pSpVariable,
        // pSpuVariable,
        // aResultParamInfo
{
    Setup_StatusFunctions();

    pSpType         = new SP_Type(*this);
    pSpuType        = new SPU_Type(*pSpType, &PE_Parameter::SpInit_Type, &PE_Parameter::SpReturn_Type);
    pSpVariable     = new SP_Variable(*this);
    pSpuVariable    = new SPU_Variable(*pSpVariable, &PE_Parameter::SpInit_Variable, &PE_Parameter::SpReturn_Variable);
}

PE_Parameter::~PE_Parameter()
{
}

void
PE_Parameter::Call_Handler( const cpp::Token & i_rTok )
{
    pStati->Cur().Call_Handler(i_rTok.TypeId(), i_rTok.Text());
}

void
PE_Parameter::Setup_StatusFunctions()
{
    typedef CallFunction<PE_Parameter>::F_Tok   F_Tok;
    static F_Tok stateF_start[] =           { &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,

                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Bracket_Right,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Ellipse,

                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type,
                                              &PE_Parameter::On_start_Type };
    static INT16 stateT_start[] =           { Tid_Identifier,
                                              Tid_class,
                                              Tid_struct,
                                              Tid_union,
                                              Tid_enum,

                                              Tid_const,
                                              Tid_volatile,
                                              Tid_Bracket_Right,
                                              Tid_DoubleColon,
                                              Tid_Ellipse,

                                              Tid_typename,
                                              Tid_BuiltInType,
                                              Tid_TypeSpecializer };

    static F_Tok stateF_expectName[] =      { &PE_Parameter::On_expectName_Identifier,
                                              &PE_Parameter::On_expectName_ArrayBracket_Left,
                                              &PE_Parameter::On_expectName_Bracket_Right,
                                              &PE_Parameter::On_expectName_Comma,
                                              &PE_Parameter::On_afterName_Assign  };
    static INT16 stateT_expectName[] =      { Tid_Identifier,
                                              Tid_ArrayBracket_Left,
                                              Tid_Bracket_Right,
                                              Tid_Comma,
                                              Tid_Assign };
    static F_Tok stateF_afterName[] =       { &PE_Parameter::On_afterName_ArrayBracket_Left,
                                              &PE_Parameter::On_afterName_Bracket_Right,
                                              &PE_Parameter::On_afterName_Comma,
                                              &PE_Parameter::On_afterName_Assign };
    static INT16 stateT_afterName[] =       { Tid_ArrayBracket_Left,
                                              Tid_Bracket_Right,
                                              Tid_Comma,
                                              Tid_Assign };
    static F_Tok stateF_finished[] =        { &PE_Parameter::On_finished_Comma,
                                              &PE_Parameter::On_finished_Bracket_Right };
    static INT16 stateT_finished[] =        { Tid_Bracket_Right,
                                              Tid_Comma };

    SEMPARSE_CREATE_STATUS(PE_Parameter, start, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, expectName, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, afterName, Hdl_SyntaxError);
    SEMPARSE_CREATE_STATUS(PE_Parameter, finished, Hdl_SyntaxError);
}

void
PE_Parameter::InitData()
{
    pStati->SetCur(start);
    aResultParamInfo.Empty();
}

void
PE_Parameter::TransferData()
{
    pStati->SetCur(size_of_states);
}

void
PE_Parameter::Hdl_SyntaxError( const char * i_sText)
{
    StdHandlingOfSyntaxError(i_sText);
}

void
PE_Parameter::SpInit_Type()
{
    // Does nothing.
}

void
PE_Parameter::SpInit_Variable()
{
    // Does nothing.
}

void
PE_Parameter::SpReturn_Type()
{
    aResultParamInfo.nType = pSpuType->Child().Result_Type().Id();
    pStati->SetCur(expectName);
}

void
PE_Parameter::SpReturn_Variable()
{
    if (pSpuVariable->Child().Result_Pattern() > 0)
    {
        aResultParamInfo.sSizeExpression = pSpuVariable->Child().Result_SizeExpression();
        aResultParamInfo.sInitExpression = pSpuVariable->Child().Result_InitExpression();
    }
}

void
PE_Parameter::On_start_Type(const char *)
{
    pSpuType->Push(not_done);
}

void
PE_Parameter::On_start_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_start_Ellipse(const char *)
{
    SetTokenResult(done, pop_success);

    aResultParamInfo.nType = Env().AryGate().Types().Tid_Ellipse();
}

void
PE_Parameter::On_expectName_Identifier(const char * i_sText)
{
    SetTokenResult(done, stay);
    pStati->SetCur(afterName);

    aResultParamInfo.sName = i_sText;
}

void
PE_Parameter::On_expectName_ArrayBracket_Left(const char * i_sText)
{
    On_afterName_ArrayBracket_Left(i_sText);
}

void
PE_Parameter::On_expectName_Bracket_Right(const char * i_sText)
{
    On_afterName_Bracket_Right(i_sText);
}

void
PE_Parameter::On_expectName_Comma(const char * i_sText)
{
    On_afterName_Comma(i_sText);
}

void
PE_Parameter::On_expectName_Assign(const char * i_sText)
{
    On_afterName_Assign(i_sText);
}

void
PE_Parameter::On_afterName_ArrayBracket_Left(const char *)
{
    pSpuVariable->Push(not_done);
}

void
PE_Parameter::On_afterName_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_afterName_Comma(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_afterName_Assign(const char *)
{
    pSpuVariable->Push(not_done);
}

void
PE_Parameter::On_finished_Bracket_Right(const char *)
{
    SetTokenResult(not_done, pop_success);
}

void
PE_Parameter::On_finished_Comma(const char *)
{
    SetTokenResult(not_done, pop_success);
}

}   // namespace cpp

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cmdstrm.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 19:30:21 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _CMDSTRM_HXX
#define _CMDSTRM_HXX

#include <objtest.hxx>
#include <testapp.hxx>
#include "cmdbasestream.hxx"

class CmdStream : public CmdBaseStream
{
public:
    CmdStream();
    ~CmdStream();

    void WriteSortedParams( SbxArray* rPar, BOOL IsKeyString = FALSE );

    void GenCmdCommand( USHORT nNr, SbxArray* rPar );

    void GenCmdSlot( USHORT nNr, SbxArray* rPar );

    void GenCmdUNOSlot( const String &aURL );

    void GenCmdControl( ULONG nUId, USHORT nMethodId, SbxArray* rPar );
    void GenCmdControl( String aUId, USHORT nMethodId, SbxArray* rPar );

/*  void GenCmdControl (ULONG nUId, USHORT nMethodId = 0);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, String aString);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, String aString, USHORT nNr);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, String aString, BOOL bBool);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, USHORT nNr);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, USHORT nNr1, USHORT nNr2);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, USHORT nNr, BOOL bBool);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, ULONG nNr);
    void GenCmdControl (ULONG nUId, USHORT nMethodId, BOOL bBool);*/

    void GenCmdFlow( USHORT nArt );
    void GenCmdFlow( USHORT nArt, USHORT nNr1 );
    void GenCmdFlow( USHORT nArt, ULONG nNr1 );
    void GenCmdFlow( USHORT nArt, String aString1 );

    void Reset(ULONG nSequence);

    SvMemoryStream* GetStream();

    static CNames *pKeyCodes;           // Namen der Sondertasten  MOD1, F1, LEFT ...
    static ControlDefLoad __READONLY_DATA arKeyCodes [];

private:
    String WandleKeyEventString( String aKeys );    // Nutzt pKeyCodes.  <RETURN> <SHIFT LEFT LEFT>

//  CmdBaseStream::Write;
    void Write( comm_USHORT nNr ){CmdBaseStream::Write( nNr );}
    void Write( comm_ULONG nNr ){CmdBaseStream::Write( nNr );}
    void Write( const comm_UniChar* aString, comm_USHORT nLenInChars ){CmdBaseStream::Write( aString, nLenInChars );}
    void Write( comm_BOOL bBool ){CmdBaseStream::Write( bBool );}
//  new
    void Write( String aString, BOOL IsKeyString = FALSE );

    SvMemoryStream *pSammel;
};

#endif
<commit_msg>INTEGRATION: CWS sixtyfour05 (1.2.30); FILE MERGED 2006/04/13 10:31:54 cmc 1.2.30.1: #i63183# automation 64bit fixes<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cmdstrm.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2006-04-19 13:59:47 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _CMDSTRM_HXX
#define _CMDSTRM_HXX

#include <objtest.hxx>
#include <testapp.hxx>
#include "cmdbasestream.hxx"

class CmdStream : public CmdBaseStream
{
public:
    CmdStream();
    ~CmdStream();

    void WriteSortedParams( SbxArray* rPar, BOOL IsKeyString = FALSE );

    void GenCmdCommand( USHORT nNr, SbxArray* rPar );

    void GenCmdSlot( USHORT nNr, SbxArray* rPar );

    void GenCmdUNOSlot( const String &aURL );

    void GenCmdControl( comm_ULONG nUId, USHORT nMethodId, SbxArray* rPar );
    void GenCmdControl( String aUId, USHORT nMethodId, SbxArray* rPar );

    void GenCmdFlow( USHORT nArt );
    void GenCmdFlow( USHORT nArt, USHORT nNr1 );
    void GenCmdFlow( USHORT nArt, comm_ULONG nNr1 );
    void GenCmdFlow( USHORT nArt, String aString1 );

    void Reset(comm_ULONG nSequence);

    SvMemoryStream* GetStream();

    static CNames *pKeyCodes;           // Namen der Sondertasten  MOD1, F1, LEFT ...
    static ControlDefLoad __READONLY_DATA arKeyCodes [];

private:
    String WandleKeyEventString( String aKeys );    // Nutzt pKeyCodes.  <RETURN> <SHIFT LEFT LEFT>

//  CmdBaseStream::Write;
    void Write( comm_USHORT nNr ){CmdBaseStream::Write( nNr );}
    void Write( comm_ULONG nNr ){CmdBaseStream::Write( nNr );}
    void Write( const comm_UniChar* aString, comm_USHORT nLenInChars ){CmdBaseStream::Write( aString, nLenInChars );}
    void Write( comm_BOOL bBool ){CmdBaseStream::Write( bBool );}
//  new
    void Write( String aString, BOOL IsKeyString = FALSE );

    SvMemoryStream *pSammel;
};

#endif
<|endoftext|>


<commit_before><commit_msg>Windows compatibility<commit_after><|endoftext|>


<commit_before>
#include "Internal.hpp"
#include "ALAudioDevice.hpp"
#include "AudioNode.hpp"

#include "AudioDecoder.hpp"	// TODO: test
#include <Lumino/Engine/Diagnostics.hpp>	// TODO: test

namespace ln {
namespace detail {

	WaveDecoder wd;// TODO: test
	std::vector<float> tmpBuffer;

//==============================================================================
// ALAudioDevice

ALAudioDevice::ALAudioDevice()
{
}

void ALAudioDevice::initialize()
{
	m_alDevice = alcOpenDevice(nullptr);
	m_alContext = alcCreateContext(m_alDevice, nullptr);
	alcMakeContextCurrent(m_alContext);
	alGenSources(1, &m_masterSource);

	m_freeBuffers.resize(2);
	alGenBuffers(2, m_freeBuffers.data());

	m_masterSampleRate = 44100;	// TODO
	m_masterChannels = 2;

	//m_finalRenderdBuffer.resize(AudioNode::ProcessingSizeInFrames * m_masterChannels);
	m_finalRenderdBuffer.resize(m_masterSampleRate * m_masterChannels);

	// TODO: test
	auto diag = newObject<DiagnosticsManager>();
	wd.initialize(FileStream::create(u"D:\\tmp\\8_MapBGM2.wav"), diag);
	tmpBuffer.resize(AudioNode::ProcessingSizeInFrames * m_masterChannels);
}

void ALAudioDevice::dispose()
{
	if (m_alContext)
	{
		alcMakeContextCurrent(nullptr);
		alcDestroyContext(m_alContext);
		m_alContext = nullptr;
	}
	if (m_alDevice)
	{
		alcCloseDevice(m_alDevice);
		m_alDevice = nullptr;
	}
}

void ALAudioDevice::updateProcess()
{
	// remove the buffer that finished processing
	ALint processedCount;
	alGetSourcei(m_masterSource, AL_BUFFERS_PROCESSED, &processedCount);
	while (processedCount > 0)
	{
		ALuint buffer;
		alSourceUnqueueBuffers(m_masterSource, 1, &buffer);
		m_freeBuffers.push_back(buffer);
		--processedCount;
		printf("processed\n");
	}

	// render data and set buffer to source
	if (m_freeBuffers.size() > 0)
	{
		// TODO: test
		wd.read((float*)m_finalRenderdBuffer.data(), m_masterSampleRate);
		//wd.read(tmpBuffer.data(), tmpBuffer.size());
		//AudioDecoder::convertFromFloat32(m_finalRenderdBuffer.data(), tmpBuffer.data(), m_finalRenderdBuffer.size(), PCMFormat::S16L);

		alBufferData(m_freeBuffers.back(), AL_FORMAT_STEREO16, m_finalRenderdBuffer.data(), m_finalRenderdBuffer.size(), m_masterSampleRate);
		alSourceQueueBuffers(m_masterSource, 1, &m_freeBuffers.back());
		m_freeBuffers.pop_back();

		// play if needed
		ALint state;
		alGetSourcei(m_masterSource, AL_SOURCE_STATE, &state);
		if (state != AL_PLAYING)
		{
			alSourcePlay(m_masterSource);
		}
		printf("queue\n");
	}
}

} // namespace detail
} // namespace ln

<commit_msg>buffer resize<commit_after>
#include "Internal.hpp"
#include "ALAudioDevice.hpp"
#include "AudioNode.hpp"

#include "AudioDecoder.hpp"	// TODO: test
#include <Lumino/Engine/Diagnostics.hpp>	// TODO: test

namespace ln {
namespace detail {

	WaveDecoder wd;// TODO: test
	std::vector<float> tmpBuffer;

//==============================================================================
// ALAudioDevice

ALAudioDevice::ALAudioDevice()
{
}

void ALAudioDevice::initialize()
{
	m_alDevice = alcOpenDevice(nullptr);
	m_alContext = alcCreateContext(m_alDevice, nullptr);
	alcMakeContextCurrent(m_alContext);
	alGenSources(1, &m_masterSource);

	m_freeBuffers.resize(2);
	alGenBuffers(2, m_freeBuffers.data());

	m_masterSampleRate = 44100;	// TODO
	m_masterChannels = 2;

	m_finalRenderdBuffer.resize(AudioNode::ProcessingSizeInFrames * m_masterChannels);
	//m_finalRenderdBuffer.resize(m_masterSampleRate * m_masterChannels);

	// TODO: test
	auto diag = newObject<DiagnosticsManager>();
	wd.initialize(FileStream::create(u"D:\\tmp\\8_MapBGM2.wav"), diag);
	tmpBuffer.resize(AudioNode::ProcessingSizeInFrames * m_masterChannels);
}

void ALAudioDevice::dispose()
{
	if (m_alContext)
	{
		alcMakeContextCurrent(nullptr);
		alcDestroyContext(m_alContext);
		m_alContext = nullptr;
	}
	if (m_alDevice)
	{
		alcCloseDevice(m_alDevice);
		m_alDevice = nullptr;
	}
}

void ALAudioDevice::updateProcess()
{
	// remove the buffer that finished processing
	ALint processedCount;
	alGetSourcei(m_masterSource, AL_BUFFERS_PROCESSED, &processedCount);
	while (processedCount > 0)
	{
		ALuint buffer;
		alSourceUnqueueBuffers(m_masterSource, 1, &buffer);
		m_freeBuffers.push_back(buffer);
		--processedCount;
		printf("processed\n");
	}

	// render data and set buffer to source
	if (m_freeBuffers.size() > 0)
	{
		// TODO: test
		//wd.read((float*)m_finalRenderdBuffer.data(), m_masterSampleRate/* * m_masterChannels*/);
		wd.read((float*)m_finalRenderdBuffer.data(), m_finalRenderdBuffer.size());
		//wd.read(tmpBuffer.data(), tmpBuffer.size());
		//AudioDecoder::convertFromFloat32(m_finalRenderdBuffer.data(), tmpBuffer.data(), m_finalRenderdBuffer.size(), PCMFormat::S16L);

		alBufferData(m_freeBuffers.back(), AL_FORMAT_STEREO16, m_finalRenderdBuffer.data(), sizeof(int16_t) * m_finalRenderdBuffer.size(), m_masterSampleRate);
		alSourceQueueBuffers(m_masterSource, 1, &m_freeBuffers.back());
		m_freeBuffers.pop_back();

		// play if needed
		ALint state;
		alGetSourcei(m_masterSource, AL_SOURCE_STATE, &state);
		if (state != AL_PLAYING)
		{
			alSourcePlay(m_masterSource);
		}
		printf("queue\n");
	}
}

} // namespace detail
} // namespace ln

<|endoftext|>


<commit_before>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <chrono>

#include <bh_component.hpp>
#include <bh_extmethod.hpp>
#include <bh_util.hpp>
#include <bh_opcode.h>
#include <jitk/statistics.hpp>
#include <jitk/kernel.hpp>
#include <jitk/block.hpp>
#include <jitk/instruction.hpp>
#include <jitk/fuser.hpp>
#include <jitk/graph.hpp>
#include <jitk/transformer.hpp>
#include <jitk/fuser_cache.hpp>
#include <jitk/codegen_util.hpp>
#include <jitk/dtype.hpp>
#include <jitk/apply_fusion.hpp>

#include "engine_cuda.hpp"

using namespace bohrium;
using namespace jitk;
using namespace component;
using namespace std;

namespace {
class Impl : public ComponentImplWithChild {
  private:
    // Some statistics
    Statistics stat;
    // Fuse cache
    FuseCache fcache;
    // Known extension methods
    map<bh_opcode, extmethod::ExtmethodFace> extmethods;
    set<bh_opcode> child_extmethods;
    // The OpenCL engine
    EngineCUDA engine;
public:
    Impl(int stack_level) : ComponentImplWithChild(stack_level), stat(config.defaultGet("prof", false)),
                            fcache(stat), engine(config, stat) {}
    ~Impl();
    void execute(bh_ir *bhir);
    void extmethod(const string &name, bh_opcode opcode) {
        // ExtmethodFace does not have a default or copy constructor thus
        // we have to use its move constructor.
        try {
            extmethods.insert(make_pair(opcode, extmethod::ExtmethodFace(config, name)));
        } catch(extmethod::ExtmethodNotFound e) {
            // I don't know this function, lets try my child
            child.extmethod(name, opcode);
            child_extmethods.insert(opcode);
        }
    }

    // Write an OpenCL kernel
    void write_kernel(const Kernel &kernel, const SymbolTable &symbols, const ConfigParser &config,
                      const vector<const LoopB *> &threaded_blocks,
                      const vector<const bh_view*> &offset_strides, stringstream &ss);

    // Implement the handle of extension methods
    void handle_extmethod(bh_ir *bhir) {
        util_handle_extmethod(this, bhir, extmethods, child_extmethods, child, &engine);
    }

    // Returns the blocks that can be parallelized in 'kernel' (incl. sub-blocks)
    vector<const LoopB*> find_threaded_blocks(Kernel &kernel) {
        vector<const LoopB*> threaded_blocks;
        uint64_t total_threading;
        tie(threaded_blocks, total_threading) = util_find_threaded_blocks(kernel.block);
        if (total_threading < config.defaultGet<uint64_t>("parallel_threshold", 1000)) {
            for (const InstrPtr instr: kernel.getAllInstr()) {
                if (not bh_opcode_is_system(instr->opcode)) {
                    stat.threading_below_threshold += bh_nelements(instr->operand[0]);
                }
            }
        }
        return threaded_blocks;
    }
};
}

extern "C" ComponentImpl* create(int stack_level) {
    return new Impl(stack_level);
}
extern "C" void destroy(ComponentImpl* self) {
    delete self;
}

Impl::~Impl() {
    if (config.defaultGet<bool>("prof", false)) {
        stat.pprint("OpenCL", cout);
    }
}

// Writes the OpenCL specific for-loop header
void loop_head_writer(const SymbolTable &symbols, Scope &scope, const LoopB &block, const ConfigParser &config,
                      bool loop_is_peeled, const vector<const LoopB *> &threaded_blocks, stringstream &out) {
    // Write the for-loop header
    string itername;
    {stringstream t; t << "i" << block.rank; itername = t.str();}
    // Notice that we use find_if() with a lambda function since 'threaded_blocks' contains pointers not objects
    if (std::find_if(threaded_blocks.begin(), threaded_blocks.end(),
                     [&block](const LoopB* b){return *b == block;}) == threaded_blocks.end()) {
        out << "for(" << write_opencl_type(BH_UINT64) << " " << itername;
        if (block._sweeps.size() > 0 and loop_is_peeled) // If the for-loop has been peeled, we should start at 1
            out << "=1; ";
        else
            out << "=0; ";
        out << itername << " < " << block.size << "; ++" << itername << ") {\n";
    } else {
        assert(block._sweeps.size() == 0);
        out << "{ // Threaded block (ID " << itername << ")\n";
    }
}

const char *write_thread_id(unsigned int dim) {
    switch (dim) {
        case 0:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        case 1:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        case 2:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        default:
            throw runtime_error("CUDA only support 3 dimensions");
    }
}

void Impl::write_kernel(const Kernel &kernel, const SymbolTable &symbols, const ConfigParser &config,
                        const vector<const LoopB *> &threaded_blocks,
                        const vector<const bh_view*> &offset_strides, stringstream &ss) {

    // Write the need includes
    ss << "#include <kernel_dependencies/complex_cuda.h>\n";
    ss << "#include <kernel_dependencies/integer_operations.h>\n";
    if (kernel.useRandom()) { // Write the random function
        ss << "#include <kernel_dependencies/random123_cuda.h>\n";
    }
    ss << "\n";

    // Write the header of the execute function
    ss << "extern \"C\" __global__ void execute";
    write_kernel_function_arguments(kernel, symbols, offset_strides, write_cuda_type, ss, NULL, false);
    ss << "{\n";

    // Write the IDs of the threaded blocks
    if (threaded_blocks.size() > 0) {
        spaces(ss, 4);
        ss << "// The IDs of the threaded blocks: \n";
        for (unsigned int i=0; i < threaded_blocks.size(); ++i) {
            const LoopB *b = threaded_blocks[i];
            spaces(ss, 4);
            ss << "const size_t i" << b->rank << " = " << write_thread_id(i) << "; " \
               << "if (i" << b->rank << " >= " << b->size << ") {return;} // Prevent overflow\n";
        }
        ss << "\n";
    }

    // Write the block that makes up the body of 'execute()'
    write_loop_block(symbols, NULL, kernel.block, config, threaded_blocks, true, write_opencl_type, loop_head_writer, ss);

    ss << "}\n\n";
}

void Impl::execute(bh_ir *bhir) {
    // Let's handle extension methods
    util_handle_extmethod(this, bhir, extmethods, child_extmethods, child, &engine);

    // And then the regular instructions
    handle_execution(*this, bhir, engine, config, stat, fcache, &child);
}
<commit_msg>CUDA is CUDA<commit_after>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium
team <http://www.bh107.org>.

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/

#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <chrono>

#include <bh_component.hpp>
#include <bh_extmethod.hpp>
#include <bh_util.hpp>
#include <bh_opcode.h>
#include <jitk/statistics.hpp>
#include <jitk/kernel.hpp>
#include <jitk/block.hpp>
#include <jitk/instruction.hpp>
#include <jitk/fuser.hpp>
#include <jitk/graph.hpp>
#include <jitk/transformer.hpp>
#include <jitk/fuser_cache.hpp>
#include <jitk/codegen_util.hpp>
#include <jitk/dtype.hpp>
#include <jitk/apply_fusion.hpp>

#include "engine_cuda.hpp"

using namespace bohrium;
using namespace jitk;
using namespace component;
using namespace std;

namespace {
class Impl : public ComponentImplWithChild {
  private:
    // Some statistics
    Statistics stat;
    // Fuse cache
    FuseCache fcache;
    // Known extension methods
    map<bh_opcode, extmethod::ExtmethodFace> extmethods;
    set<bh_opcode> child_extmethods;
    // The OpenCL engine
    EngineCUDA engine;
public:
    Impl(int stack_level) : ComponentImplWithChild(stack_level), stat(config.defaultGet("prof", false)),
                            fcache(stat), engine(config, stat) {}
    ~Impl();
    void execute(bh_ir *bhir);
    void extmethod(const string &name, bh_opcode opcode) {
        // ExtmethodFace does not have a default or copy constructor thus
        // we have to use its move constructor.
        try {
            extmethods.insert(make_pair(opcode, extmethod::ExtmethodFace(config, name)));
        } catch(extmethod::ExtmethodNotFound e) {
            // I don't know this function, lets try my child
            child.extmethod(name, opcode);
            child_extmethods.insert(opcode);
        }
    }

    // Write an OpenCL kernel
    void write_kernel(const Kernel &kernel, const SymbolTable &symbols, const ConfigParser &config,
                      const vector<const LoopB *> &threaded_blocks,
                      const vector<const bh_view*> &offset_strides, stringstream &ss);

    // Implement the handle of extension methods
    void handle_extmethod(bh_ir *bhir) {
        util_handle_extmethod(this, bhir, extmethods, child_extmethods, child, &engine);
    }

    // Returns the blocks that can be parallelized in 'kernel' (incl. sub-blocks)
    vector<const LoopB*> find_threaded_blocks(Kernel &kernel) {
        vector<const LoopB*> threaded_blocks;
        uint64_t total_threading;
        tie(threaded_blocks, total_threading) = util_find_threaded_blocks(kernel.block);
        if (total_threading < config.defaultGet<uint64_t>("parallel_threshold", 1000)) {
            for (const InstrPtr instr: kernel.getAllInstr()) {
                if (not bh_opcode_is_system(instr->opcode)) {
                    stat.threading_below_threshold += bh_nelements(instr->operand[0]);
                }
            }
        }
        return threaded_blocks;
    }
};
}

extern "C" ComponentImpl* create(int stack_level) {
    return new Impl(stack_level);
}
extern "C" void destroy(ComponentImpl* self) {
    delete self;
}

Impl::~Impl() {
    if (config.defaultGet<bool>("prof", false)) {
        stat.pprint("CUDA", cout);
    }
}

// Writes the OpenCL specific for-loop header
void loop_head_writer(const SymbolTable &symbols, Scope &scope, const LoopB &block, const ConfigParser &config,
                      bool loop_is_peeled, const vector<const LoopB *> &threaded_blocks, stringstream &out) {
    // Write the for-loop header
    string itername;
    {stringstream t; t << "i" << block.rank; itername = t.str();}
    // Notice that we use find_if() with a lambda function since 'threaded_blocks' contains pointers not objects
    if (std::find_if(threaded_blocks.begin(), threaded_blocks.end(),
                     [&block](const LoopB* b){return *b == block;}) == threaded_blocks.end()) {
        out << "for(" << write_opencl_type(BH_UINT64) << " " << itername;
        if (block._sweeps.size() > 0 and loop_is_peeled) // If the for-loop has been peeled, we should start at 1
            out << "=1; ";
        else
            out << "=0; ";
        out << itername << " < " << block.size << "; ++" << itername << ") {\n";
    } else {
        assert(block._sweeps.size() == 0);
        out << "{ // Threaded block (ID " << itername << ")\n";
    }
}

const char *write_thread_id(unsigned int dim) {
    switch (dim) {
        case 0:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        case 1:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        case 2:
            return "blockIdx.x*blockDim.x+threadIdx.x";
        default:
            throw runtime_error("CUDA only support 3 dimensions");
    }
}

void Impl::write_kernel(const Kernel &kernel, const SymbolTable &symbols, const ConfigParser &config,
                        const vector<const LoopB *> &threaded_blocks,
                        const vector<const bh_view*> &offset_strides, stringstream &ss) {

    // Write the need includes
    ss << "#include <kernel_dependencies/complex_cuda.h>\n";
    ss << "#include <kernel_dependencies/integer_operations.h>\n";
    if (kernel.useRandom()) { // Write the random function
        ss << "#include <kernel_dependencies/random123_cuda.h>\n";
    }
    ss << "\n";

    // Write the header of the execute function
    ss << "extern \"C\" __global__ void execute";
    write_kernel_function_arguments(kernel, symbols, offset_strides, write_cuda_type, ss, NULL, false);
    ss << "{\n";

    // Write the IDs of the threaded blocks
    if (threaded_blocks.size() > 0) {
        spaces(ss, 4);
        ss << "// The IDs of the threaded blocks: \n";
        for (unsigned int i=0; i < threaded_blocks.size(); ++i) {
            const LoopB *b = threaded_blocks[i];
            spaces(ss, 4);
            ss << "const size_t i" << b->rank << " = " << write_thread_id(i) << "; " \
               << "if (i" << b->rank << " >= " << b->size << ") {return;} // Prevent overflow\n";
        }
        ss << "\n";
    }

    // Write the block that makes up the body of 'execute()'
    write_loop_block(symbols, NULL, kernel.block, config, threaded_blocks, true, write_opencl_type, loop_head_writer, ss);

    ss << "}\n\n";
}

void Impl::execute(bh_ir *bhir) {
    // Let's handle extension methods
    util_handle_extmethod(this, bhir, extmethods, child_extmethods, child, &engine);

    // And then the regular instructions
    handle_execution(*this, bhir, engine, config, stat, fcache, &child);
}
<|endoftext|>


<commit_before>/*
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "CUDA2HIP.h"

// Maps CUDA header names to HIP header names
const std::map<llvm::StringRef, hipCounter> CUDA_DEVICE_FUNC_MAP{
  // math functions
  {"umin",            {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"llmin",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"ullmin",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"umax",            {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"llmax",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"ullmax",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinff",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnanf",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finite",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finitef",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbit",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnan",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinf",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbitf",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbitl",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finitel",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinfl",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnanl",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_ldsign",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_fdsign",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_Pow_int",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // static math functions declared in device-functions.h
  {"mulhi",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"mul64hi",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float_as_int",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"int_as_float",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float_as_uint",   {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"uint_as_float",   {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"saturate",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"mul24",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"umul24",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float2int",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"int2float",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"uint2float",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // device functions
  {"__prof_trigger",  {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__trap",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__brkpt",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm0",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm1",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm2",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm3",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // SIMD functions
  {"__vabs2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vadd2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddus2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgs2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vhaddu2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpeq2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpges2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgeu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgtu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmples2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmplts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpltu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpne2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffu2",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxs2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmins2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vminu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vseteq2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetges2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgeu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetles2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetleu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetlts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetltu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetne2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsadu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsub2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubus2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vneg2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vnegss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffs2",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsads2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabs4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vadd4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddus4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgs4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vhaddu4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpeq4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpges4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgeu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgtu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmples4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpleu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmplts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpltu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpne4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffu4",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxs4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmins4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vminu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vseteq4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetles4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetleu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetlts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetltu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetges4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgeu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgtu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetne4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsadu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsub4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubus4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vneg4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vnegss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffs4",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsads4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
};
<commit_msg>[HIPIFY] Add unsupported fp16 functions<commit_after>/*
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "CUDA2HIP.h"

// Maps CUDA header names to HIP header names
const std::map<llvm::StringRef, hipCounter> CUDA_DEVICE_FUNC_MAP{
  // math functions
  {"umin",            {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"llmin",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"ullmin",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"umax",            {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"llmax",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"ullmax",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinff",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnanf",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finite",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finitef",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbit",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnan",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinf",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbitf",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__signbitl",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__finitel",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isinfl",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__isnanl",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_ldsign",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_fdsign",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"_Pow_int",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // static math functions declared in device-functions.h
  {"mulhi",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"mul64hi",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float_as_int",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"int_as_float",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float_as_uint",   {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"uint_as_float",   {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"saturate",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"mul24",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"umul24",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"float2int",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"int2float",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"uint2float",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // device functions
  {"__prof_trigger",  {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__trap",          {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__brkpt",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm0",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm1",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm2",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__pm3",           {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // SIMD functions
  {"__vabs2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vadd2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddus2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgs2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vhaddu2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpeq2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpges2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgeu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgtu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmples2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmplts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpltu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpne2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffu2",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxs2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmins2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vminu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vseteq2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetges2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgeu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetles2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetleu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetlts2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetltu2",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetne2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsadu2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsub2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubus2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vneg2",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vnegss2",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffs2",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsads2",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabs4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vadd4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vaddus4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgs4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vavgu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vhaddu4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpeq4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpges4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgeu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpgtu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmples4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpleu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmplts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpltu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vcmpne4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffu4",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxs4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmaxu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vmins4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vminu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vseteq4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetles4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetleu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetlts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetltu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetges4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgeu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgts4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetgtu4",      {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsetne4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsadu4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsub4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsubus4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vneg4",         {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vnegss4",       {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vabsdiffs4",    {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__vsads4",        {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  // fp16 functions
  {"__shfl_sync",     {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_up_sync",  {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_down_sync",{"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_xor_sync", {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_sync",     {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_up_sync",  {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_down_sync",{"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_xor_sync", {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
  {"__shfl_xor_sync", {"", "", CONV_DEVICE_FUNC, API_RUNTIME, UNSUPPORTED}},
};
<|endoftext|>


<commit_before>// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__
#define __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__

#include <map>
#include <string>
#include <stout/stringify.hpp>

namespace os {

inline std::map<std::string, std::string> environment()
{
  // NOTE: The `GetEnvironmentStrings` call returns a pointer to a
  // read-only block of memory with the following format (minus newlines):
  // Var1=Value1\0
  // Var2=Value2\0
  // Var3=Value3\0
  // ...
  // VarN=ValueN\0\0
  wchar_t* env = ::GetEnvironmentStringsW();
  std::map<std::string, std::string> result;

  for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';) {
    std::wstring entry(env + i);

    // Increment past the current environment string and null terminator.
    i = i + entry.size() + 1;

    size_t position = entry.find_first_of(L'=');
    if (position == std::string::npos) {
      continue; // Skip malformed environment entries.
    }

    result[stringify(entry.substr(0, position))] =
      stringify(entry.substr(position + 1));
  }

  return result;
}

} // namespace os {

#endif // __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__
<commit_msg>Windows: Fixed memory leak.<commit_after>// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__
#define __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__

#include <map>
#include <memory>
#include <string>
#include <stout/stringify.hpp>

namespace os {

inline std::map<std::string, std::string> environment()
{
  // NOTE: The `GetEnvironmentStrings` call returns a pointer to a
  // read-only block of memory with the following format (minus newlines):
  // Var1=Value1\0
  // Var2=Value2\0
  // Var3=Value3\0
  // ...
  // VarN=ValueN\0\0
  const std::unique_ptr<wchar_t[], decltype(&::FreeEnvironmentStringsW)> env(
      ::GetEnvironmentStringsW(), &::FreeEnvironmentStringsW);
  std::map<std::string, std::string> result;

  for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';
       /* incremented below */) {
    std::wstring entry(&env[i]);

    // Increment past the current environment string and null terminator.
    i = i + entry.size() + 1;

    size_t position = entry.find_first_of(L'=');
    if (position == std::string::npos) {
      continue; // Skip malformed environment entries.
    }

    result[stringify(entry.substr(0, position))] =
      stringify(entry.substr(position + 1));
  }

  return result;
}

} // namespace os {

#endif // __STOUT_OS_WINDOWS_ENVIRONMENT_HPP__
<|endoftext|>


<commit_before>#include "ATKUniversalVariableDelay.h"
#include "IPlug_include_in_plug_src.h"
#include "IControl.h"
#include "resource.h"

const int kNumPrograms = 1;

enum EParams
{
  kDelay = 0,
  kDepth,
  kMod,
  kBlend,
  kFeedforward,
  kFeedback,
  kNumParams
};

enum ELayout
{
  kWidth = GUI_WIDTH,
  kHeight = GUI_HEIGHT,

  kDelayX = 25,
  kDelayY = 32,
  kDepthX = 94,
  kDepthY = 32,
  kModX = 163,
  kModY = 32,
  kBlendX = 232,
  kBlendY = 32,
  kFeedforwardX = 301,
  kFeedforwardY = 32,
  kFeedbackX = 370,
  kFeedbackY = 32,
  kKnobFrames = 43
};

ATKUniversalVariableDelay::ATKUniversalVariableDelay(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), inFilter(nullptr, 1, 0, false), outFilter(nullptr, 1, 0, false), delayFilter(1000)
{
  TRACE;

  //arguments are: name, defaultVal, minVal, maxVal, step, label
  GetParam(kDelay)->InitDouble("Delay", 0.2, 0.2, 3.0, 0.1, "ms");
  GetParam(kDelay)->SetShape(2.);
  GetParam(kDepth)->InitDouble("Depth", 0.1, 0.1, 3.0, 0.1, "ms");
  GetParam(kDepth)->SetShape(2.);
  GetParam(kMod)->InitDouble("Modulation", 1, 0.1, 5.0, 0.1, "Hz");
  GetParam(kMod)->SetShape(1.);
  GetParam(kBlend)->InitDouble("Blend", 100, -100, 100, 0.01, "%");
  GetParam(kBlend)->SetShape(1.);
  GetParam(kFeedforward)->InitDouble("Feedforward", 50., -100, 100, 0.01, "%");
  GetParam(kFeedforward)->SetShape(1.);
  GetParam(kFeedback)->InitDouble("Feedback", 0., -90., 90., 0.01, "%");
  GetParam(kFeedback)->SetShape(1.);

  IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
  pGraphics->AttachBackground(UNIVERSALDELAY_ID, UNIVERSALDELAY_FN);

  IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
  IBitmap knob1 = pGraphics->LoadIBitmap(KNOB1_ID, KNOB1_FN, kKnobFrames);

  pGraphics->AttachControl(new IKnobMultiControl(this, kDelayX, kDelayY, kDelay, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kDepthX, kDepthY, kDepth, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kModX, kModY, kMod, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kBlendX, kBlendY, kBlend, &knob1));
  pGraphics->AttachControl(new IKnobMultiControl(this, kFeedforwardX, kFeedforwardY, kFeedforward, &knob1));
  pGraphics->AttachControl(new IKnobMultiControl(this, kFeedbackX, kFeedbackY, kFeedback, &knob1));

  AttachGraphics(pGraphics);

  MakePreset("Vibrato", 2, 1, 2, 0, 1, 0);
  MakePreset("Flanger", 2, 1, 2, 0.7, 0.7, 0.7);

  delayFilter.set_input_port(0, &inFilter, 0);
  delayFilter.set_input_port(1, &sinusGenerator, 0);
  outFilter.set_input_port(0, &delayFilter, 0);

  Reset();
}

ATKUniversalVariableDelay::~ATKUniversalVariableDelay() {}

void ATKUniversalVariableDelay::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  // Mutex is already locked for us.
  inFilter.set_pointer(inputs[0], nFrames);
  outFilter.set_pointer(outputs[0], nFrames);
  outFilter.process(nFrames);
}

void ATKUniversalVariableDelay::Reset()
{
  TRACE;
  IMutexLock lock(this);

  int sampling_rate = GetSampleRate();

  if (sampling_rate != outFilter.get_input_sampling_rate())
  {
    inFilter.set_input_sampling_rate(sampling_rate);
    inFilter.set_output_sampling_rate(sampling_rate);
    sinusGenerator.set_output_sampling_rate(sampling_rate);
    delayFilter.set_input_sampling_rate(sampling_rate);
    delayFilter.set_output_sampling_rate(sampling_rate);
    outFilter.set_input_sampling_rate(sampling_rate);
    outFilter.set_output_sampling_rate(sampling_rate);
  }
  sinusGenerator.full_setup();
}

void ATKUniversalVariableDelay::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);

  switch (paramIdx)
  {
  case kDelay:
    if (GetParam(kDepth)->Value() > GetParam(kDelay)->Value() - 0.1)
    {
      GetParam(kDelay)->Set(GetParam(kDepth)->Value() + 0.1);
    }
    sinusGenerator.set_offset(GetParam(kDelay)->Value() / 1000. * GetSampleRate());
    delayFilter.set_central_delay(GetParam(kDelay)->Value() / 1000. * GetSampleRate());
    break;
  case kDepth:
    if (GetParam(kDepth)->Value() > GetParam(kDelay)->Value() - 0.1)
    {
      GetParam(kDepth)->Set(GetParam(kDelay)->Value() - 0.1);
    }
    sinusGenerator.set_volume(GetParam(kDepth)->Value() / 1000. * GetSampleRate());
    break;
  case kMod:
    sinusGenerator.set_frequency(GetParam(kMod)->Value());
    break;
  case kBlend:
    delayFilter.set_blend((GetParam(kBlend)->Value()) / 100.);
    break;
  case kFeedforward:
    delayFilter.set_feedforward((GetParam(kFeedforward)->Value()) / 100.);
    break;
  case kFeedback:
    delayFilter.set_feedback((GetParam(kFeedback)->Value()) / 100.);
    break;

  default:
    break;
  }
}
<commit_msg>Flush the delay line and fix the max delay line size for 192kHz.<commit_after>#include "ATKUniversalVariableDelay.h"
#include "IPlug_include_in_plug_src.h"
#include "IControl.h"
#include "resource.h"

const int kNumPrograms = 1;

enum EParams
{
  kDelay = 0,
  kDepth,
  kMod,
  kBlend,
  kFeedforward,
  kFeedback,
  kNumParams
};

enum ELayout
{
  kWidth = GUI_WIDTH,
  kHeight = GUI_HEIGHT,

  kDelayX = 25,
  kDelayY = 32,
  kDepthX = 94,
  kDepthY = 32,
  kModX = 163,
  kModY = 32,
  kBlendX = 232,
  kBlendY = 32,
  kFeedforwardX = 301,
  kFeedforwardY = 32,
  kFeedbackX = 370,
  kFeedbackY = 32,
  kKnobFrames = 43
};

ATKUniversalVariableDelay::ATKUniversalVariableDelay(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), inFilter(nullptr, 1, 0, false), outFilter(nullptr, 1, 0, false), delayFilter(1152)
{
  TRACE;

  //arguments are: name, defaultVal, minVal, maxVal, step, label
  GetParam(kDelay)->InitDouble("Delay", 0.2, 0.2, 3.0, 0.1, "ms");
  GetParam(kDelay)->SetShape(2.);
  GetParam(kDepth)->InitDouble("Depth", 0.1, 0.1, 2.9, 0.1, "ms");
  GetParam(kDepth)->SetShape(2.);
  GetParam(kMod)->InitDouble("Modulation", 1, 0.1, 5.0, 0.1, "Hz");
  GetParam(kMod)->SetShape(1.);
  GetParam(kBlend)->InitDouble("Blend", 100, -100, 100, 0.01, "%");
  GetParam(kBlend)->SetShape(1.);
  GetParam(kFeedforward)->InitDouble("Feedforward", 50., -100, 100, 0.01, "%");
  GetParam(kFeedforward)->SetShape(1.);
  GetParam(kFeedback)->InitDouble("Feedback", 0., -90., 90., 0.01, "%");
  GetParam(kFeedback)->SetShape(1.);

  IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
  pGraphics->AttachBackground(UNIVERSALDELAY_ID, UNIVERSALDELAY_FN);

  IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
  IBitmap knob1 = pGraphics->LoadIBitmap(KNOB1_ID, KNOB1_FN, kKnobFrames);

  pGraphics->AttachControl(new IKnobMultiControl(this, kDelayX, kDelayY, kDelay, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kDepthX, kDepthY, kDepth, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kModX, kModY, kMod, &knob));
  pGraphics->AttachControl(new IKnobMultiControl(this, kBlendX, kBlendY, kBlend, &knob1));
  pGraphics->AttachControl(new IKnobMultiControl(this, kFeedforwardX, kFeedforwardY, kFeedforward, &knob1));
  pGraphics->AttachControl(new IKnobMultiControl(this, kFeedbackX, kFeedbackY, kFeedback, &knob1));

  AttachGraphics(pGraphics);

  MakePreset("Vibrato", 2, 1, 2, 0, 1, 0);
  MakePreset("Flanger", 2, 1, 2, 0.7, 0.7, 0.7);

  delayFilter.set_input_port(0, &inFilter, 0);
  delayFilter.set_input_port(1, &sinusGenerator, 0);
  outFilter.set_input_port(0, &delayFilter, 0);

  Reset();
}

ATKUniversalVariableDelay::~ATKUniversalVariableDelay() {}

void ATKUniversalVariableDelay::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  // Mutex is already locked for us.
  inFilter.set_pointer(inputs[0], nFrames);
  outFilter.set_pointer(outputs[0], nFrames);
  outFilter.process(nFrames);
}

void ATKUniversalVariableDelay::Reset()
{
  TRACE;
  IMutexLock lock(this);

  int sampling_rate = GetSampleRate();

  if (sampling_rate != outFilter.get_input_sampling_rate())
  {
    inFilter.set_input_sampling_rate(sampling_rate);
    inFilter.set_output_sampling_rate(sampling_rate);
    sinusGenerator.set_output_sampling_rate(sampling_rate);
    delayFilter.set_input_sampling_rate(sampling_rate);
    delayFilter.set_output_sampling_rate(sampling_rate);
    outFilter.set_input_sampling_rate(sampling_rate);
    outFilter.set_output_sampling_rate(sampling_rate);
  }
  sinusGenerator.full_setup();
  delayFilter.full_setup();
}

void ATKUniversalVariableDelay::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);

  switch (paramIdx)
  {
  case kDelay:
    if (GetParam(kDepth)->Value() > GetParam(kDelay)->Value() - 0.1)
    {
      GetParam(kDelay)->Set(GetParam(kDepth)->Value() + 0.1);
    }
    sinusGenerator.set_offset(GetParam(kDelay)->Value() / 1000. * GetSampleRate());
    delayFilter.set_central_delay(GetParam(kDelay)->Value() / 1000. * GetSampleRate());
    break;
  case kDepth:
    if (GetParam(kDepth)->Value() > GetParam(kDelay)->Value() - 0.1)
    {
      GetParam(kDepth)->Set(GetParam(kDelay)->Value() - 0.1);
    }
    sinusGenerator.set_volume(GetParam(kDepth)->Value() / 1000. * GetSampleRate());
    break;
  case kMod:
    sinusGenerator.set_frequency(GetParam(kMod)->Value());
    break;
  case kBlend:
    delayFilter.set_blend((GetParam(kBlend)->Value()) / 100.);
    break;
  case kFeedforward:
    delayFilter.set_feedforward((GetParam(kFeedforward)->Value()) / 100.);
    break;
  case kFeedback:
    delayFilter.set_feedback((GetParam(kFeedback)->Value()) / 100.);
    break;

  default:
    break;
  }
}
<|endoftext|>