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 227 and 230

Show entire file | Details | Blame | View Log

Rev 227 Rev 230
Line 831... Line 831...
                         Theia::Parser::location_type * yylloc,
                         Theia::Parser::location_type * yylloc,
                         Theia::Scanner &scanner);
                         Theia::Scanner &scanner);
}
}
 
 
%token AUTO RETURN FUNCTION JMP EXIT EQUAL NOT_EQUAL GREATER_THAN LESS_THAN LESS_OR_EQUAL_THAN GREATER_OR_EQUAL_THAN IF ELSE OPEN_ROUND_BRACE CLOSE_ROUND_BRACE OPEN_BRACE CLOSE_BRACE ASSIGN DIV MUL ADD DECCONST HEXCONST BINCONST EOS DOT MINUS TK_X TK_Y TK_Z TK_N REG
%token AUTO RETURN FUNCTION JMP EXIT EQUAL NOT_EQUAL GREATER_THAN LESS_THAN LESS_OR_EQUAL_THAN GREATER_OR_EQUAL_THAN IF ELSE OPEN_ROUND_BRACE CLOSE_ROUND_BRACE OPEN_BRACE CLOSE_BRACE ASSIGN DIV MUL ADD DECCONST HEXCONST BINCONST EOS DOT MINUS TK_X TK_Y TK_Z TK_N REG
%token IDENTIFIER SQRT SCALE UNSCALE USING FIXED_POINT COMMA OPEN_SQUARE_BRACE CLOSE_SQUARE_BRACE WHILE ADD_EQ THREAD START BITWISE_AND BITWISE_OR OUT
%token IDENTIFIER SQRT SCALE UNSCALE USING FIXED_POINT COMMA OPEN_SQUARE_BRACE CLOSE_SQUARE_BRACE WHILE ADD_EQ THREAD START BITWISE_AND BITWISE_OR OUT IN
%%
%%
 
 
statement_list: //empty
statement_list: //empty
        |
        |
        statement_list statement
        statement_list statement
Line 1038... Line 1038...
         |
         |
         left_hand_side ASSIGN expression  EOS
         left_hand_side ASSIGN expression  EOS
        {
        {
 
 
                //////////////////////////////////////////////////////////////////////////////
                //////////////////////////////////////////////////////////////////////////////
 
                // This means this that the expression will read from the T memory
 
                // variable index
 
                // For example:
 
                //          vector MyAddress,MyReadValue;
 
                //          MyReadValue = in [ MyAddress ];
 
                //
 
                //////////////////////////////////////////////////////////////////////////////
 
 
 
                DCOUT << $3 << " YYY \n";
 
                if ($3.find("IN") != std::string::npos )
 
                {
 
 
 
                        std::string ReadAddress = $3;
 
 
 
                        std::string SourceAddrRegister = ReadAddress.substr(ReadAddress.find("INDEX")+5);
 
                        DCOUT << "!!!!!!!!!!!!!!!!!   " << ReadAddress << "\n";
 
                        ReadAddress.erase(0,ReadAddress.find("IN")+3);
 
                        DCOUT << "!!!!!!!!!!!!!!!!!   " << ReadAddress << "\n";
 
 
 
                        I.SetDestZero( true ); //Use indexing for DST
 
                        I.SetWriteChannel(ECHANNEL_XYZ);
 
 
 
 
 
                        PopulateSourceRegisters( ReadAddress, "R0", I, mInstructions );
 
 
 
                        SetDestinationFromRegister( $1, I, false );
 
                        I.mSourceLine = GetCurrentLineNumber(yylloc);
 
                        I.SetCode( EOPERATION_IO );
 
                        I.SetIOOperation( EIO_TMREAD );
 
 
 
 
 
                        mInstructions.push_back( I );
 
                        I.Clear();
 
                        ResetTempRegisterIndex();
 
                        goto LABEL_EXPRESSION_DONE;
 
                }
 
                //////////////////////////////////////////////////////////////////////////////
                // This means this that the expression will write into the output memory
                // This means this that the expression will write into the output memory
                // constant index
                // constant index
                //////////////////////////////////////////////////////////////////////////////
                //////////////////////////////////////////////////////////////////////////////
 
 
                if ($1.find("OUT") != std::string::npos && $1.find("INDEX") == std::string::npos )
                if ($1.find("OUT") != std::string::npos && $1.find("INDEX") == std::string::npos )
                {
                {
                        //PopulateInstruction( "R0", "R0 . X X X",$3,I,yylloc);
                        //PopulateInstruction( "R0", "R0 . X X X",$3,I,yylloc);
 
 
                        I.SetCode(EOPERATION_OUT);
                        I.SetCode(EOPERATION_IO);
 
                        I.SetIOOperation( EIO_OMWRITE );
 
 
                        $1.erase($1.find("OUT"),3);
                        $1.erase($1.find("OUT"),3);
 
 
                        unsigned int ImmediateValue;
                        unsigned int ImmediateValue;
                        std::stringstream ss;
                        std::stringstream ss;
                        ss << std::hex << $1;
                        ss << std::hex << $1;
Line 1083... Line 1122...
                //      PopulateSourceRegisters( IndexRegister + " OFFSET ", $3, I, mInstructions );
                //      PopulateSourceRegisters( IndexRegister + " OFFSET ", $3, I, mInstructions );
                        PopulateSourceRegisters( IndexRegister, $3, I, mInstructions );
                        PopulateSourceRegisters( IndexRegister, $3, I, mInstructions );
 
 
 
 
                        //I.SetImm( 0 );
                        //I.SetImm( 0 );
                        I.SetCode( EOPERATION_OUT );
                        I.SetCode( EOPERATION_IO );
                        std::string Source0 = $3;
                        I.SetIOOperation( EIO_OMWRITE );
                        DCOUT << "!!!!!!!!!!!!!!!!!Source0 '" << Source0 << "'\n";
 
                /*      if (Source0.find("OFFSET") != std::string::npos)
 
                        {
 
                                        Source0.erase(Source0.find("OFFSET"));
 
                                        I.SetSrc0Displace(1);
 
                        }
 
                        I.SetSrc1Address(atoi(IndexRegister.c_str()+1));
 
                        I.SetSrc0Address(atoi(Source0.c_str()+1));*/
 
 
 
                /*      if (Destination.find(".") != std::string::npos)
 
                        {
 
                                I.ClearWriteChannel();
 
                                if (Destination.find("x") != std::string::npos)
 
                                        I.SetWriteChannel(ECHANNEL_X);
 
                                if (Destination.find("y") != std::string::npos)
 
                                        I.SetWriteChannel(ECHANNEL_Y);
 
                                if (Destination.find("z") != std::string::npos)
 
                                        I.SetWriteChannel(ECHANNEL_Z);
 
 
 
                                Destination.erase(Destination.find("."));
 
 
 
                        }
 
 
 
                        std::string Source0 = $3;
                        std::string Source0 = $3;
                        if (Source0.find("OFFSET") != std::string::npos)
                        DCOUT << "!!!!!!!!!!!!!!!!!Source0 '" << Source0 << "'\n";
                        {
 
                                        Source0.erase(Source0.find("OFFSET"));
 
                                        I.SetSrc0Displace(1);
 
                        }
 
                        I.SetSrc1Address(atoi(IndexRegister.c_str()+1));
 
                        I.SetSrc0Address(atoi(Source0.c_str()+1));
 
 
 
 
 
                                //      I.SetSrc0Address(mInstructions.back().GetDestinationAddress());
 
                        I.SetDestZero(0);
 
                        I.SetSrc1Displace(1);
 
                        I.SetSrc0Displace(1);
 
                        I.SetDestinationAddress( atoi(Destination.c_str()+1) );*/
 
                        mInstructions.push_back( I );
                        mInstructions.push_back( I );
                        I.Clear();
                        I.Clear();
                        ResetTempRegisterIndex();
                        ResetTempRegisterIndex();
                        goto LABEL_EXPRESSION_DONE;
                        goto LABEL_EXPRESSION_DONE;
                }
                }
Line 1364... Line 1369...
           I.SetBranchType( EBRANCH_ALWAYS );
           I.SetBranchType( EBRANCH_ALWAYS );
           mInstructions.push_back(I);
           mInstructions.push_back(I);
           I.Clear();
           I.Clear();
 
 
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   If-else                                                                                                                                                                                   /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   if ()                                                                                                                             /////
 
        /////   {                                                                                                                                                                                                         /////
 
        /////                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   } else {                                                                                                                                                                                          /////
 
        /////                                                                                                                                                                             /////
 
        /////   }                                                                                                                                                                                                         /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        | IF
        | IF
          OPEN_ROUND_BRACE boolean_expression CLOSE_ROUND_BRACE
          OPEN_ROUND_BRACE boolean_expression CLOSE_ROUND_BRACE
          OPEN_BRACE statement_list CLOSE_BRACE
          OPEN_BRACE statement_list CLOSE_BRACE
      ELSE
      ELSE
        {
        { //Start of middle rule
 
 
           //jump out of the if
           //jump out of the if
           I.Clear();
           I.Clear();
           I.SetCode( EOPERATION_ADD );
           I.SetCode( EOPERATION_ADD );
           I.SetBranchFlag( true );
           I.SetBranchFlag( true );
Line 1382... Line 1399...
           //Take care of the destination addr of the if statement.
           //Take care of the destination addr of the if statement.
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
          gBranchStack.pop_back();
          gBranchStack.pop_back();
          //push the inconditional jump into the stack
          //push the inconditional jump into the stack
          gBranchStack.push_back(mInstructions.size() - 1);
          gBranchStack.push_back(mInstructions.size() - 1);
          ////std::cout << "else\n";
 
 
 
        }
 
 
        } //End of middle rule
          OPEN_BRACE  statement_list CLOSE_BRACE
          OPEN_BRACE  statement_list CLOSE_BRACE
        {
        {
 
 
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
           gBranchStack.pop_back();
           gBranchStack.pop_back();
           //Now push the JMP
 
 
 
                ////std::cout << "END elseif\n";
 
        }
        }
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
        /////                                                                                                                                                                                                             /////
 
        /////   If statement                                                                                                                                                                      /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   if ()                                                                                                                             /////
 
        /////   {                                                                                                                                                                                                         /////
 
        /////                                                                                                                                                                             /////
 
        /////                                                                                                                                                                                                             /////
 
        /////   }                                                                                                                                                                                                         /////
 
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        |
        |
        //NOW the if statement
 
        IF OPEN_ROUND_BRACE boolean_expression CLOSE_ROUND_BRACE OPEN_BRACE statement_list CLOSE_BRACE
        IF OPEN_ROUND_BRACE boolean_expression CLOSE_ROUND_BRACE OPEN_BRACE statement_list CLOSE_BRACE
        {
        {
                mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
                mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
                //mInstructions[gBranchStack.back()].mSourceLine = GetCurrentLineNumber(yylloc);
                //mInstructions[gBranchStack.back()].mSourceLine = GetCurrentLineNumber(yylloc);
 
 
Line 1654... Line 1678...
                                                {
                                                {
                                                        AddFunctionParameter( $1, yylloc );
                                                        AddFunctionParameter( $1, yylloc );
                                                }
                                                }
                                                ;
                                                ;
 
 
//  ::=  +  |
 
          //  -  |
 
          // 
 
 
 
//  ::=  *  |
 
           //  /  |
 
           // 
 
 
 
//  ::= x | y | ... |
 
             // (  ) |
 
             // -  |
 
             // 
 
 
 
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
/////                                                                                                                                                                                                             /////
 
/////   Expression declaration.                                                                                                                                           /////
 
/////                                                                                                                                                                                                             /////
 
/////   This is the definition for the expressions which make the Right Hand values                                                       /////
 
/////   The expressions follow the general shape of Expression made of "Terms" which in turn are made our of  /////                                                                                                                                                                                               /////
 
/////   "factors". This so the order operations is taken into cosiderations and subexpressions can be grouped /////
 
/////   using parenthesis. The expressions follow th BNF format as described next                             /////
 
/////                                                                                                                                                                                                         /////
 
/////  ::=  +  |                                                                              /////
 
/////           -   |                                                                              /////
 
/////                                                                                                   /////
 
/////                                                                                                         /////
 
/////  ::=  *  |                                                                          /////
 
/////             /  |                                                                          /////
 
/////                                                                                                 /////
 
/////                                                                                                         /////
 
/////  ::=    |                                                                               /////
 
/////              (  )  |                                                                               /////
 
/////              -  |                                                                               /////
 
/////                                                                                                 /////
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
expression
expression
                :
                :
                expression ADD term
                expression ADD term
                {
                {
                        unsigned int TempRegIndex  = GetFreeTempRegister();
                        unsigned int TempRegIndex  = GetFreeTempRegister();
Line 1732... Line 1766...
 
 
                        std::stringstream ss;
                        std::stringstream ss;
                        ss << "R" << TempRegIndex << " OFFSET ";
                        ss << "R" << TempRegIndex << " OFFSET ";
                        $$ = ss.str();
                        $$ = ss.str();
                }
                }
 
                //////////////////////////////////////////////////////////////////////////////
 
                //  This is the "in" operator used as the RHV
 
                //  Example:
 
                //   MyValue = in[ MyAddress ]
 
                //
 
                //  Note that this RHV cannot be combined with other RHV expressions, in other
 
                //  words you can not do thing like this: RHV = in[ addr ] + SomeOtherVariable
 
                //
 
                //////////////////////////////////////////////////////////////////////////////
 
                |
 
                IN OPEN_SQUARE_BRACE IDENTIFIER CLOSE_SQUARE_BRACE
 
                {
 
                        std::string Register;
 
                        if ((Register = GetRegisterFromFunctionParameter($3)) != "NULL")
 
                                $$ = "IN " + Register;
 
                        else
 
                                $$ = "IN " + GetRegisterFromAutoVar( $3, yylloc ) + " OFFSET ";
 
                }
                |
                |
                term
                term
                {
                {
                        $$ = $1;
                        $$ = $1;
                }
                }
Line 1824... Line 1876...
                :
                :
                source
                source
                {
                {
                        $$ = $1;
                        $$ = $1;
                }
                }
 
                //////////////////////////////////////////////////////////////////////////////
 
                // this is the square root used as part of RHS
 
                // Example:
 
                //   RHS = sqrt(  )
 
                //////////////////////////////////////////////////////////////////////////////
                |
                |
                SQRT OPEN_ROUND_BRACE expression CLOSE_ROUND_BRACE
                SQRT OPEN_ROUND_BRACE expression CLOSE_ROUND_BRACE
                {
                {
                        gExtraDestModifications = 0;
                        gExtraDestModifications = 0;
                        unsigned int TempRegIndex  = GetFreeTempRegister();
                        unsigned int TempRegIndex  = GetFreeTempRegister();
Line 2075... Line 2132...
                $$ = "OUT " + $3;
                $$ = "OUT " + $3;
        }
        }
        |
        |
        OUT OPEN_SQUARE_BRACE IDENTIFIER CLOSE_SQUARE_BRACE
        OUT OPEN_SQUARE_BRACE IDENTIFIER CLOSE_SQUARE_BRACE
        {
        {
        /*
 
                std::string Register;
 
                if ((Register = GetRegisterFromFunctionParameter($3)) == "NULL")
 
                        Register = GetRegisterFromAutoVar( $3, yylloc );
 
 
 
                $$ = "OUT INDEX" + Register;
 
                */
 
                std::string Register;
                std::string Register;
                if ((Register = GetRegisterFromFunctionParameter($3)) != "NULL")
                if ((Register = GetRegisterFromFunctionParameter($3)) != "NULL")
                        $$ = "OUT INDEX" + Register;
                        $$ = "OUT INDEX" + Register;
                else
                else
                        $$ = "OUT INDEX" + GetRegisterFromAutoVar( $3, yylloc ) + " OFFSET ";
                        $$ = "OUT INDEX" + GetRegisterFromAutoVar( $3, yylloc ) + " OFFSET ";

powered by: WebSVN 2.1.0

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