OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [compiler/] [src/] [vp_compiler/] [parser.y] - Diff between revs 216 and 227

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 216 Rev 227
Line 450... Line 450...
}
}
//----------------------------------------------------------
//----------------------------------------------------------
void AddFunctionInputList( std::string aVar, std::vector & aInstructions,Theia::Parser::location_type  yylloc)
void AddFunctionInputList( std::string aVar, std::vector & aInstructions,Theia::Parser::location_type  yylloc)
{
{
        //Get the value from the variable
        //Get the value from the variable
 
        DCOUT << "Calling AddFunctionInputList input arg: " << aVar << " \n";
        //Copy the value into function parameter register
        //Copy the value into function parameter register
        unsigned FunctionParamReg = GetNextFunctionParamRegister();
        unsigned FunctionParamReg = GetNextFunctionParamRegister();
        I.Clear();
        I.Clear();
        I.SetCode( EOPERATION_ADD );
        I.SetCode( EOPERATION_ADD );
        I.mComment = "copy the value into function parameter register";
        I.mComment = "copy the value into function parameter register";
Line 468... Line 468...
                {
                {
                        I.SetSrc1Displace( true );
                        I.SetSrc1Displace( true );
                        aVar.erase(aVar.find("OFFSET"));
                        aVar.erase(aVar.find("OFFSET"));
                }
                }
                I.SetSrc1Address(atoi(aVar.c_str()+1));
                I.SetSrc1Address(atoi(aVar.c_str()+1));
 
                I.SetSrc1SwizzleX(SWX_X);
 
                I.SetSrc1SwizzleY(SWY_Y);
 
                I.SetSrc1SwizzleZ(SWZ_Z);
 
                I.SetSrc0Address(0);
 
                I.SetSrc0SwizzleX(SWX_X);
 
                I.SetSrc0SwizzleY(SWY_X);
 
                I.SetSrc0SwizzleZ(SWZ_X);
 
                aInstructions.push_back( I );
 
                I.Clear();
                return;
                return;
        }
        }
        std::string Reg = GetRegisterFromFunctionParameter( aVar );
        std::string Reg = GetRegisterFromFunctionParameter( aVar );
        if (Reg == "NULL")
        if (Reg == "NULL")
        {
        {
Line 1069... Line 1078...
 
 
 
 
                        I.SetDestZero( true ); //Use indexing for DST
                        I.SetDestZero( true ); //Use indexing for DST
                        I.SetWriteChannel(ECHANNEL_XYZ);
                        I.SetWriteChannel(ECHANNEL_XYZ);
 
 
                        PopulateSourceRegisters( IndexRegister + " OFFSET ", $3, I, mInstructions );
                //      PopulateSourceRegisters( IndexRegister + " OFFSET ", $3, I, mInstructions );
 
                        PopulateSourceRegisters( IndexRegister, $3, I, mInstructions );
 
 
 
 
                        //I.SetImm( 0 );
                        //I.SetImm( 0 );
                        I.SetCode( EOPERATION_OUT );
                        I.SetCode( EOPERATION_OUT );
                        std::string Source0 = $3;
                        std::string Source0 = $3;
Line 1395... Line 1405...
 
 
                gBranchStack.pop_back();
                gBranchStack.pop_back();
                ////std::cout << "if closing at " << mInstructions.size() << "\n";
                ////std::cout << "if closing at " << mInstructions.size() << "\n";
 
 
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   Function declaration                                                                                                                                                              /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   function  ( [ , ... , ])                                                                                                          /////
 
        /////   {                                                                                                                                                                                                         /////
 
        /////                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   }                                                                                                                                                                                                         /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        |
        |
        FUNCTION IDENTIFIER OPEN_ROUND_BRACE function_argument_list CLOSE_ROUND_BRACE
        FUNCTION IDENTIFIER OPEN_ROUND_BRACE function_argument_list CLOSE_ROUND_BRACE
        {
        {
          ////std::cout << "Function declaration for " << $2 << " at " << mInstructions.size() << "\n" ;
          DCOUT << "Function declaration for " << $2 << " at " << mInstructions.size() << "\n" ;
          mSymbolMap[ $2 ] = mInstructions.size();
          mSymbolMap[ $2 ] = mInstructions.size();
        } OPEN_BRACE statement_list CLOSE_BRACE
        } OPEN_BRACE statement_list CLOSE_BRACE
        {
        {
                //Clear the auto var index now that we leave the function scope
                //Clear the auto var index now that we leave the function scope
                ClearAutoVarMap();
                ClearAutoVarMap();
Line 1423... Line 1443...
                I.SetSrc0SwizzleZ(SWZ_X);
                I.SetSrc0SwizzleZ(SWZ_X);
 
 
                mInstructions.push_back( I );
                mInstructions.push_back( I );
                I.Clear();
                I.Clear();
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   Thread declaration                                                                                                                                                                        /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   thread  ( )                                                                                                                                                       /////
 
        /////   {                                                                                                                                                                                                         /////
 
        /////                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   }                                                                                                                                                                                                         /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        |
        |
        //Thread declaration
        //Thread declaration
        THREAD IDENTIFIER OPEN_ROUND_BRACE CLOSE_ROUND_BRACE
        THREAD IDENTIFIER OPEN_ROUND_BRACE CLOSE_ROUND_BRACE
        {
        {
                gThreadMap[ $2 ] = mInstructions.size();
                gThreadMap[ $2 ] = mInstructions.size();
Line 1447... Line 1477...
                I.SetWriteChannel(ECHANNEL_Z);
                I.SetWriteChannel(ECHANNEL_Z);
                mInstructions.push_back( I );
                mInstructions.push_back( I );
                I.Clear();
                I.Clear();
 
 
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   Start thread                                                                                                                                                                              /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   start  ( );                                                                                                                                                       /////
 
        /////                                                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        |
        |
        START IDENTIFIER OPEN_ROUND_BRACE CLOSE_ROUND_BRACE EOS
        START IDENTIFIER OPEN_ROUND_BRACE CLOSE_ROUND_BRACE EOS
        {
        {
                unsigned int ThreadCodeOffset = 0;
                unsigned int ThreadCodeOffset = 0;
                ////std::cout << "Starting thread" << "\n";
                ////std::cout << "Starting thread" << "\n";
Line 1488... Line 1526...
                        I.Clear();
                        I.Clear();
 
 
                }
                }
 
 
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   Function call and assign return value to variable                                                                                                         /////
 
        /////                                                                                                                                                                                                             /////
 
        /////    =  ( [ , ... , ]);                                                                                       /////
 
        /////                                                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        |
        |
        left_hand_side ASSIGN IDENTIFIER OPEN_ROUND_BRACE function_input_list CLOSE_ROUND_BRACE EOS
        left_hand_side ASSIGN IDENTIFIER OPEN_ROUND_BRACE function_input_list CLOSE_ROUND_BRACE EOS
        {
        {
                ////std::cout << "Function call returning to var\n";
                ////std::cout << "Function call returning to var\n";
                StoreReturnAddress( mInstructions, yylloc );
                StoreReturnAddress( mInstructions, yylloc );
Line 1512... Line 1558...
                mInstructions.push_back( I );
                mInstructions.push_back( I );
                I.Clear();
                I.Clear();
                ClearNextFunctionParamRegister();
                ClearNextFunctionParamRegister();
        }
        }
        |
        |
        //Function call
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   Function call (return value is ignored)                                                                                                                           /////
 
        /////                                                                                                                                                                                                             /////
 
        /////    ( [ , ... , ]);                                                                                                                          /////
 
        /////                                                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        IDENTIFIER  OPEN_ROUND_BRACE function_input_list CLOSE_ROUND_BRACE EOS
        IDENTIFIER  OPEN_ROUND_BRACE function_input_list CLOSE_ROUND_BRACE EOS
        {
        {
 
 
                //Store the return address
                //Store the return address
                StoreReturnAddress( mInstructions, yylloc );
                StoreReturnAddress( mInstructions, yylloc );
Line 1550... Line 1603...
                //Call the function with a JMP
                //Call the function with a JMP
                I.SetCode( EOPERATION_ADD );
                I.SetCode( EOPERATION_ADD );
                I.mComment = "call the function";
                I.mComment = "call the function";
                I.SetBranchFlag( true );
                I.SetBranchFlag( true );
                I.SetBranchType( EBRANCH_ALWAYS );
                I.SetBranchType( EBRANCH_ALWAYS );
                //Now do the branch
 
 
                //Now assign the destination of the branch (our function virtual address)
                if (mSymbolMap.find($1) == mSymbolMap.end())
                if (mSymbolMap.find($1) == mSymbolMap.end())
                {
                {
                //      ////std::cout << "Error in line : " << $1 <<" undelcared IDENTIFIER\n";
                        //The destination is not yet declared
 
                        //so leave it as a symbol so that it can latter
 
                        //resolved by the linker
                        I.SetDestinationSymbol( "@"+$1 );
                        I.SetDestinationSymbol( "@"+$1 );
                //      exit(1);
 
                } else {
                } else {
 
                        //The destination symbol has already been declared
 
                        //so assign it right away
                        I.SetDestinationAddress( mSymbolMap[ $1 ] );
                        I.SetDestinationAddress( mSymbolMap[ $1 ] );
                }
                }
 
 
 
                //Push the last instruction in the sequence and clean up
                mInstructions.push_back( I );
                mInstructions.push_back( I );
                I.Clear();
                I.Clear();
 
 
        }
        }
        ;
        ;
Line 1916... Line 1973...
        {
        {
 
 
                std::string X = $3,Y = $4,Z = $5;
                std::string X = $3,Y = $4,Z = $5;
                std::string Register;
                std::string Register;
                if ((Register = GetRegisterFromFunctionParameter($1)) != "NULL")
                if ((Register = GetRegisterFromFunctionParameter($1)) != "NULL")
                        $$ = (Register + " . " + " " + X + " " + Y  + " " + Z + " OFFSET ");
                        $$ = (Register + " . " + " " + X + " " + Y  + " " + Z/* + " OFFSET "*/);
                else
                else
                        $$ = (GetRegisterFromAutoVar( $1, yylloc) + " . " + " " + X + " " + Y  + " " + Z + " OFFSET ");
                        $$ = (GetRegisterFromAutoVar( $1, yylloc) + " . " + " " + X + " " + Y  + " " + Z + " OFFSET ");
        }
        }
        |
        |
        REG
        REG
Line 2018... Line 2075...
                $$ = "OUT " + $3;
                $$ = "OUT " + $3;
        }
        }
        |
        |
        OUT OPEN_SQUARE_BRACE IDENTIFIER CLOSE_SQUARE_BRACE
        OUT OPEN_SQUARE_BRACE IDENTIFIER CLOSE_SQUARE_BRACE
        {
        {
 
        /*
                std::string Register;
                std::string Register;
                if ((Register = GetRegisterFromFunctionParameter($3)) == "NULL")
                if ((Register = GetRegisterFromFunctionParameter($3)) == "NULL")
                        Register = GetRegisterFromAutoVar( $3, yylloc );
                        Register = GetRegisterFromAutoVar( $3, yylloc );
 
 
                $$ = "OUT INDEX" + Register;
                $$ = "OUT INDEX" + Register;
 
                */
 
                std::string Register;
 
                if ((Register = GetRegisterFromFunctionParameter($3)) != "NULL")
 
                        $$ = "OUT INDEX" + Register;
 
                else
 
                        $$ = "OUT INDEX" + GetRegisterFromAutoVar( $3, yylloc ) + " OFFSET ";
 
 
 
 
 
 
        }
        }
        |
        |
        IDENTIFIER array_index
        IDENTIFIER array_index
        {
        {
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.