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.tab.c] - Blame information for rev 216

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 216 diegovalve
 
2
/* A Bison parser, made by GNU Bison 2.4.1.  */
3
 
4
/* Skeleton implementation for Bison LALR(1) parsers in C++
5
 
6
      Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
7
   Foundation, Inc.
8
 
9
   This program is free software: you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation, either version 3 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
 
22
/* As a special exception, you may create a larger work that contains
23
   part or all of the Bison parser skeleton and distribute that work
24
   under terms of your choice, so long as that work isn't itself a
25
   parser generator using the skeleton or a modified version thereof
26
   as a parser skeleton.  Alternatively, if you modify or redistribute
27
   the parser skeleton itself, you may (at your option) remove this
28
   special exception, which will cause the skeleton and the resulting
29
   Bison output files to be licensed under the GNU General Public
30
   License without this special exception.
31
 
32
   This special exception was added by the Free Software Foundation in
33
   version 2.2 of Bison.  */
34
 
35
 
36
/* First part of user declarations.  */
37
 
38
 
39
/* Line 311 of lalr1.cc  */
40
#line 41 "parser.tab.c"
41
 
42
 
43
#include "parser.tab.h"
44
 
45
/* User implementation prologue.  */
46
 
47
 
48
/* Line 317 of lalr1.cc  */
49
#line 50 "parser.tab.c"
50
/* Unqualified %code blocks.  */
51
 
52
/* Line 318 of lalr1.cc  */
53
#line 68 "parser.y"
54
 
55
        #include "Instruction.h"
56
        #include <vector>
57
        Instruction I,tmpI;
58
 
59
        std::vector< unsigned int > gBranchStack;
60
        static int gInsertedInstructions = 0;
61
        static int gWhileLoopAddress = 0;
62
#define FUNCTION_PARAM_START_REGION 4
63
#define FUNCTION_PARAM_LAST_REGION  10
64
        std::map<std::string, unsigned int> gFunctionParameters;
65
        std::map<std::string, unsigned int> gAutoVarMap;
66
        std::map<std::string, unsigned int> gThreadMap; //Key: Symbol, value: start code addr
67
        bool gThreadScope = false;
68
#define AUTOVAR_START_REGION 9
69
#define THREAD_OFFSET 128
70
unsigned int gExtraDestModifications = 0;
71
unsigned int gAutoVarIndex = AUTOVAR_START_REGION;
72
unsigned int gThreadAutoVarIndex = THREAD_OFFSET;
73
unsigned int gFunctionParameterIndex = FUNCTION_PARAM_START_REGION;
74
//----------------------------------------------------------
75
unsigned int GetNextFunctionParamRegister()
76
{
77
        unsigned Ret = gFunctionParameterIndex++;
78
        return Ret;
79
}
80
 
81
//----------------------------------------------------------
82
void AddFunctionParameter( std::string aVar, Theia::Parser::location_type  yylloc)
83
{
84
        ////std::cout << "Adding " << aVar << "\n";
85
        if (gFunctionParameterIndex+1 > FUNCTION_PARAM_LAST_REGION)
86
        {
87
                        std::ostringstream ret;
88
                        ret << "Cannot allocate more parameters '" << aVar << "' at line " << yylloc << " \n";
89
                        throw ret.str();
90
        }
91
        if (gFunctionParameters.find(aVar) != gFunctionParameters.end())
92
        {
93
                        std::ostringstream ret;
94
                        ret << "Parameter '" << aVar << "' at line " << yylloc << " is already defined\n";
95
                        throw ret.str();
96
        }
97
 
98
        gFunctionParameters[ aVar ] = gFunctionParameterIndex++;
99
 
100
}
101
//----------------------------------------------------------
102
std::string  GetRegisterFromFunctionParameter( std::string aVar )
103
{
104
        ////std::cout << "Looking for " << aVar << "\n";
105
        if (gFunctionParameters.find(aVar) == gFunctionParameters.end())
106
                return "NULL";
107
 
108
        std::ostringstream ss;
109
        ss << gFunctionParameters[ aVar ];
110
        return  ("R" + ss.str());
111
}
112
//----------------------------------------------------------
113
unsigned int GetCurretAutoVarFrameSize()
114
{
115
 
116
        return gAutoVarMap.size();
117
 
118
}
119
//----------------------------------------------------------
120
std::string GetRegisterFromAutoVar( std::string aVar, Theia::Parser::location_type  yylloc )
121
{
122
        if (gAutoVarMap.find(aVar) == gAutoVarMap.end())
123
        {
124
                        std::ostringstream ret;
125
                        ret << "Undefined variable '" << aVar << "' at line " << yylloc << " \n";
126
                        throw ret.str();
127
        }
128
 
129
                std::ostringstream ss;
130
                ss << gAutoVarMap[ aVar ];
131
                return  ("R" + ss.str());
132
}
133
//----------------------------------------------------------
134
int GetCurrentLineNumber( const Theia::Parser::location_type &loc )
135
{
136
                int ret = -1;
137
                std::stringstream ss2;
138
                std::string where;
139
                ss2 << loc;
140
                ss2 >> where;
141
                where.erase(where.find_first_of("."));
142
                std::stringstream ss3;
143
                ss3 << where;
144
                ss3 >> ret;
145
                return ret;
146
}
147
//----------------------------------------------------------
148
unsigned int AllocAutoVar( unsigned int aSize = 1)
149
{
150
 
151
        if (!gThreadScope)
152
        {
153
                gAutoVarIndex += aSize;
154
                return gAutoVarIndex - (aSize-1);
155
        }else{
156
                gThreadAutoVarIndex += aSize;
157
                return (gThreadAutoVarIndex - (aSize-1));
158
        }
159
}
160
//----------------------------------------------------------
161
void ClearFunctionParameterMap()
162
{
163
        gFunctionParameters.clear();
164
        gFunctionParameterIndex = FUNCTION_PARAM_START_REGION;
165
}
166
//----------------------------------------------------------
167
void ClearAutoVarMap()
168
{
169
        gAutoVarMap.clear();
170
        gAutoVarIndex = AUTOVAR_START_REGION;
171
}
172
//----------------------------------------------------------
173
unsigned int gTempRegisterIndex = 1;
174
unsigned int GetFreeTempRegister( )
175
{
176
        if (!gThreadScope)
177
                return gAutoVarIndex + (gTempRegisterIndex++);
178
        else
179
                return gThreadAutoVarIndex + (gTempRegisterIndex++);
180
 
181
}
182
//----------------------------------------------------------                    
183
void ResetTempRegisterIndex( void )
184
{
185
 
186
        gTempRegisterIndex = 1;
187
}
188
//----------------------------------------------------------
189
bool IsSwizzled( std::string aSource)
190
{
191
        if (aSource.find(".") != std::string::npos)
192
                return true;
193
        else
194
                return false;
195
}
196
 
197
//----------------------------------------------------------
198
void SetSwizzleAndSign( unsigned int aSourceIndex, std::string aSwizzle, Instruction & I )
199
{
200
        std::string Reg,X,Y,Z, junk;
201
        std::stringstream ss( aSwizzle );
202
        ss >> Reg >> junk >> X >> Y >> Z;
203
 
204
 
205
        if (aSourceIndex == 1)
206
        {
207
                if (X == "X") { I.SetSrc1SwizzleX(SWX_X);       }
208
                if (X == "Y") { I.SetSrc1SwizzleX(SWX_Y);       }
209
                if (X == "Z") { I.SetSrc1SwizzleX(SWX_Z);       }
210
                if (X == "-X") { I.SetSrc1SignX( true ); I.SetSrc1SwizzleX(SWX_X);      }
211
                if (X == "-Y") { I.SetSrc1SignX( true ); I.SetSrc1SwizzleX(SWX_Y);      }
212
                if (X == "-Z") { I.SetSrc1SignX( true ); I.SetSrc1SwizzleX(SWX_Z);      }
213
 
214
                if (Y == "X") { I.SetSrc1SwizzleY(SWY_X);       }
215
                if (Y == "Y") { I.SetSrc1SwizzleY(SWY_Y);       }
216
                if (Y == "Z") { I.SetSrc1SwizzleY(SWY_Z);       }
217
                if (Y == "-X") { I.SetSrc1SignY( true ); I.SetSrc1SwizzleY(SWY_X);      }
218
                if (Y == "-Y") { I.SetSrc1SignY( true ); I.SetSrc1SwizzleY(SWY_Y);      }
219
                if (Y == "-Z") { I.SetSrc1SignY( true ); I.SetSrc1SwizzleY(SWY_Z);      }
220
 
221
                if (Z == "X") { I.SetSrc1SwizzleZ(SWZ_X);       }
222
                if (Z == "Y") { I.SetSrc1SwizzleZ(SWZ_Y);       }
223
                if (Z == "Z") { I.SetSrc1SwizzleZ(SWZ_Z);       }
224
                if (Z == "-X") { I.SetSrc1SignZ( true ); I.SetSrc1SwizzleZ(SWZ_X);      }
225
                if (Z == "-Y") { I.SetSrc1SignZ( true ); I.SetSrc1SwizzleZ(SWZ_Y);      }
226
                if (Z == "-Z") { I.SetSrc1SignZ( true ); I.SetSrc1SwizzleZ(SWZ_Z);      }
227
        } else {
228
                if (X == "X") { I.SetSrc0SwizzleX(SWX_X);       }
229
                if (X == "Y") { I.SetSrc0SwizzleX(SWX_Y);       }
230
                if (X == "Z") { I.SetSrc0SwizzleX(SWX_Z);       }
231
                if (X == "-X") { I.SetSrc0SignX( true ); I.SetSrc0SwizzleX(SWX_X);      }
232
                if (X == "-Y") { I.SetSrc0SignX( true ); I.SetSrc0SwizzleX(SWX_Y);      }
233
                if (X == "-Z") { I.SetSrc0SignX( true ); I.SetSrc0SwizzleX(SWX_Z);      }
234
 
235
                if (Y == "X") { I.SetSrc0SwizzleY(SWY_X);       }
236
                if (Y == "Y") { I.SetSrc0SwizzleY(SWY_Y);       }
237
                if (Y == "Z") { I.SetSrc0SwizzleY(SWY_Z);       }
238
                if (Y == "-X") { I.SetSrc0SignY( true ); I.SetSrc0SwizzleY(SWY_X);      }
239
                if (Y == "-Y") { I.SetSrc0SignY( true ); I.SetSrc0SwizzleY(SWY_Y);      }
240
                if (Y == "-Z") { I.SetSrc0SignY( true ); I.SetSrc0SwizzleY(SWY_Z);      }
241
 
242
                if (Z == "X") { I.SetSrc0SwizzleZ(SWZ_X);       }
243
                if (Z == "Y") { I.SetSrc0SwizzleZ(SWZ_Y);       }
244
                if (Z == "Z") { I.SetSrc0SwizzleZ(SWZ_Z);       }
245
                if (Z == "-X") { I.SetSrc0SignZ( true ); I.SetSrc0SwizzleZ(SWZ_X);      }
246
                if (Z == "-Y") { I.SetSrc0SignZ( true ); I.SetSrc0SwizzleZ(SWZ_Y);      }
247
                if (Z == "-Z") { I.SetSrc0SignZ( true ); I.SetSrc0SwizzleZ(SWZ_Z);      }
248
        }
249
}
250
//----------------------------------------------------------
251
void StoreReturnAddress( std::vector<Instruction> & aInstructions, Theia::Parser::location_type & yylloc )
252
{
253
                I.SetCode( EOPERATION_ADD );
254
                I.mComment = "store return address**";
255
                I.SetImm( aInstructions.size()+4 );
256
                I.SetWriteChannel(ECHANNEL_X);
257
                I.SetDestinationAddress( RETURN_ADDRESS_REGISTER );
258
                I.SetDestZero( true );
259
                I.mSourceLine = GetCurrentLineNumber( yylloc );
260
                aInstructions.push_back( I );
261
                I.Clear();
262
}
263
//----------------------------------------------------------
264
void SavePreviousFramePointer( std::vector<Instruction> & aInstructions )
265
{
266
                I.SetCode( EOPERATION_ADD );
267
                I.mComment = "store current frame offset";
268
                I.SetWriteChannel(ECHANNEL_Y);
269
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
270
                I.SetSrc1Address(SPR_CONTROL_REGISTER);
271
                I.SetSrc1SwizzleX(SWX_X);
272
                I.SetSrc1SwizzleY(SWY_X);
273
                I.SetSrc1SwizzleZ(SWZ_X);
274
                I.SetSrc0Address(0);
275
                I.SetSrc0SwizzleX(SWX_X);
276
                I.SetSrc0SwizzleY(SWY_X);
277
                I.SetSrc0SwizzleZ(SWZ_X);
278
                aInstructions.push_back( I );
279
                I.Clear();
280
}
281
//----------------------------------------------------------
282
void SetIndexRegister( unsigned int aIndex, std::vector<Instruction> & aInstructions  )
283
{
284
                Instruction Tmp;
285
                Tmp.SetCode( EOPERATION_ADD );
286
                Tmp.mComment = "store array index register";
287
                Tmp.SetWriteChannel(ECHANNEL_Z);
288
                Tmp.SetDestinationAddress( SPR_CONTROL_REGISTER );
289
                Tmp.SetSrc1Address( aIndex );
290
                Tmp.SetSrc1Displace( true );
291
                Tmp.SetSrc1SwizzleX(SWX_X);
292
                Tmp.SetSrc1SwizzleY(SWY_X);
293
                Tmp.SetSrc1SwizzleZ(SWZ_X);
294
                Tmp.SetSrc0Address(0);
295
                Tmp.SetSrc0SwizzleX(SWX_X);
296
                Tmp.SetSrc0SwizzleY(SWY_X);
297
                Tmp.SetSrc0SwizzleZ(SWZ_X);
298
                //Tmp.SetImm( aIndex );
299
                //Tmp.SetDestZero( true );
300
                aInstructions.push_back( Tmp );
301
 
302
}
303
//----------------------------------------------------------
304
void UpdateFramePointer( std::vector<Instruction> & aInstructions )
305
{
306
                I.SetCode( EOPERATION_ADD );
307
                I.mComment = "displace next frame offset by the number of auto variables in current frame";
308
                I.SetWriteChannel(ECHANNEL_X);
309
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
310
                I.SetImm( GetCurretAutoVarFrameSize() );
311
                I.SetDestZero( false );
312
                aInstructions.push_back( I );
313
                I.Clear();
314
}
315
//----------------------------------------------------------
316
void CallFunction( std::string aFunctionName,  std::vector<Instruction> & aInstructions, std::map<std::string,unsigned int>  &  aSymbolMap)
317
{
318
                I.SetCode( EOPERATION_ADD );
319
                I.mComment = "call the function";
320
                I.SetBranchFlag( true );
321
                I.SetBranchType( EBRANCH_ALWAYS );
322
                //Now do the branch
323
                if (aSymbolMap.find(aFunctionName) == aSymbolMap.end())
324
                        I.SetDestinationSymbol( "@"+aFunctionName );
325
                else
326
                        I.SetDestinationAddress( aSymbolMap[ aFunctionName ] );
327
 
328
                aInstructions.push_back( I );
329
                I.Clear();
330
}
331
//----------------------------------------------------------
332
void SetDestinationFromRegister( std::string aDestination, Instruction & aInst, bool Imm  )
333
{
334
                //Look for displament addressing mode
335
 
336
                if (aDestination.find("OFFSET") != std::string::npos)
337
                {
338
                        aDestination.erase(aDestination.find("OFFSET"));
339
                        ////std::cout << "^_^ left_hand_side " << Destination << "\n";
340
                        if (Imm == true)
341
                                aInst.SetSrc0Displace( true ); //When Imm == 0, then setting this makes offset
342
                        else
343
                                aInst.SetDestZero( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
344
                }
345
                if (aDestination.find(".") != std::string::npos)
346
                {
347
                        aInst.ClearWriteChannel();
348
                        if (aDestination.find("x") != std::string::npos)
349
                                aInst.SetWriteChannel(ECHANNEL_X);
350
                        if (aDestination.find("y") != std::string::npos)
351
                                aInst.SetWriteChannel(ECHANNEL_Y);
352
                        if (aDestination.find("z") != std::string::npos)
353
                                aInst.SetWriteChannel(ECHANNEL_Z);
354
 
355
                        aDestination.erase(aDestination.find("."));
356
 
357
                }
358
                aInst.SetDestinationAddress( atoi(aDestination.c_str()+1) );
359
}
360
//----------------------------------------------------------
361
void PopulateSourceRegisters( std::string a1, std::string a2, Instruction & I, std::vector<Instruction> & aInstructions )
362
{
363
 
364
 
365
                        if ( a1.find("R") == std::string::npos )
366
                        {
367
                                //This is for constants
368
                                unsigned int ImmediateValue;
369
                                std::string StringHex = a1;
370
                                std::stringstream ss;
371
                                ss << std::hex << StringHex;
372
                                ss >> ImmediateValue;
373
                                I.SetImm( ImmediateValue );
374
                        } else {
375
 
376
 
377
 
378
                                if (a1.find("array_element") != std::string::npos)
379
                                {
380
 
381
 
382
                                        std::string Index = a1.substr(a1.find("array_element"));
383
                                        ////std::cout << "XXXXX " << Index << "\n\n\n";
384
                                        Index = Index.substr(Index.find_first_not_of("array_element R"));
385
                                        ////std::cout << "XXXXX " << Index << "\n\n\n";
386
                                        SetIndexRegister( atoi(Index.c_str()), aInstructions );
387
                                        a1.erase(a1.find("array_element"));
388
                                        I.SetSrc0Displace( true );
389
                                        I.SetSrc1Displace( true );
390
                                        I.SetImmBit( true );
391
                                }
392
                                        //Look for displament addressing mode
393
                                else if (a1.find("OFFSET") != std::string::npos)
394
                                {
395
                                        a1.erase(a1.find("OFFSET"));
396
                                        ////std::cout << "^_^ a1" << a1 << "\n";
397
                                        I.SetSrc1Displace( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
398
                                }
399
 
400
                                std::string Src1 = a1;
401
                                if (IsSwizzled( Src1 ))
402
                                {
403
                                        SetSwizzleAndSign( 1, Src1,  I );
404
                                        Src1.erase(Src1.find("."));
405
                                }
406
                                I.SetSrc1Address( atoi( Src1.c_str()+1 ) );
407
                        }
408
 
409
                        if ( a2.find("R") == std::string::npos)
410
                        {
411
                        } else {
412
 
413
 
414
 
415
                                //Look for displament addressing mode
416
                                if (a2.find("OFFSET") != std::string::npos)
417
                                {
418
                                        a2.erase(a2.find("OFFSET"));
419
                                        ////std::cout << "^_^ a2 " << a2 << "\n";
420
                                        I.SetSrc0Displace( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
421
                                }
422
 
423
                                std::string Src0 = a2;
424
                                if (IsSwizzled( Src0 ))
425
                                {
426
                                        SetSwizzleAndSign( 0, Src0,  I );
427
                                        Src0.erase(Src0.find("."));
428
                                }
429
                                I.SetSrc0Address( atoi( Src0.c_str()+1 ) );
430
                        }
431
}
432
//----------------------------------------------------------
433
void ClearNextFunctionParamRegister()
434
{
435
        gFunctionParameterIndex = FUNCTION_PARAM_START_REGION;
436
}
437
//----------------------------------------------------------
438
void AddFunctionInputList( std::string aVar, std::vector<Instruction> & aInstructions,Theia::Parser::location_type  yylloc)
439
{
440
        //Get the value from the variable
441
 
442
        //Copy the value into function parameter register
443
        unsigned FunctionParamReg = GetNextFunctionParamRegister();
444
        I.Clear();
445
        I.SetCode( EOPERATION_ADD );
446
        I.mComment = "copy the value into function parameter register";
447
        I.SetWriteChannel(ECHANNEL_XYZ);
448
        //I.SetDestZero( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
449
        I.SetDestinationAddress( FunctionParamReg );
450
 
451
        if (aVar.find("R") != std::string::npos)
452
        {
453
                if (aVar.find("OFFSET") != std::string::npos)
454
                {
455
                        I.SetSrc1Displace( true );
456
                        aVar.erase(aVar.find("OFFSET"));
457
                }
458
                I.SetSrc1Address(atoi(aVar.c_str()+1));
459
                return;
460
        }
461
        std::string Reg = GetRegisterFromFunctionParameter( aVar );
462
        if (Reg == "NULL")
463
        {
464
                Reg = GetRegisterFromAutoVar( aVar, yylloc );
465
                I.SetSrc1Address(atoi(Reg.c_str()+1));
466
                I.SetSrc1Displace( true );
467
        } else {
468
                I.SetSrc1Address(atoi(Reg.c_str()+1));
469
                I.SetSrc1Displace( false );
470
        }
471
 
472
 
473
 
474
        I.SetSrc1SwizzleX(SWX_X);
475
        I.SetSrc1SwizzleY(SWY_Y);
476
        I.SetSrc1SwizzleZ(SWZ_Z);
477
        I.SetSrc0Address(0);
478
        I.SetSrc0SwizzleX(SWX_X);
479
        I.SetSrc0SwizzleY(SWY_X);
480
        I.SetSrc0SwizzleZ(SWZ_X);
481
        aInstructions.push_back( I );
482
        I.Clear();
483
}
484
//----------------------------------------------------------
485
void SetExpressionDestination( std::string aStringDestination, Instruction & I )
486
{
487
                std::string Destination = aStringDestination;
488
 
489
                //Look for indirect addressing
490
                if (Destination.find("INDEX") != std::string::npos)
491
                {
492
 
493
                        std::string IndexRegister = Destination.substr(Destination.find("INDEX")+5);
494
                        Destination.erase(Destination.find("INDEX"));
495
                        I.SetImm( 0 );
496
                        I.SetCode( EOPERATION_ADD );
497
 
498
                        if (Destination.find(".") != std::string::npos)
499
                        {
500
                                I.ClearWriteChannel();
501
                                if (Destination.find("x") != std::string::npos)
502
                                        I.SetWriteChannel(ECHANNEL_X);
503
                                if (Destination.find("y") != std::string::npos)
504
                                        I.SetWriteChannel(ECHANNEL_Y);
505
                                if (Destination.find("z") != std::string::npos)
506
                                        I.SetWriteChannel(ECHANNEL_Z);
507
                                Destination.erase(Destination.find("."));
508
 
509
                        }
510
 
511
                        I.SetDestinationAddress( atoi(Destination.c_str()+1) );
512
 
513
                } else {
514
 
515
                        //Look for displament addressing mode
516
                        if (Destination.find("OFFSET") != std::string::npos)
517
                        {
518
                                Destination.erase(Destination.find("OFFSET"));
519
                                I.SetDestZero( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
520
                        }
521
                        if (Destination.find(".") != std::string::npos)
522
                        {
523
                                I.ClearWriteChannel();
524
                                if (Destination.find("x") != std::string::npos)
525
                                        I.SetWriteChannel(ECHANNEL_X);
526
                                if (Destination.find("y") != std::string::npos)
527
                                        I.SetWriteChannel(ECHANNEL_Y);
528
                                if (Destination.find("z") != std::string::npos)
529
                                        I.SetWriteChannel(ECHANNEL_Z);
530
 
531
                                Destination.erase(Destination.find("."));
532
 
533
                        }
534
                        I.SetDestinationAddress( atoi(Destination.c_str()+1) );
535
 
536
 
537
 
538
                }
539
}
540
 
541
//----------------------------------------------------------
542
bool SourceNull( std::string aSource )
543
{
544
        if (aSource == "NULL")
545
                return true;
546
 
547
        return false;
548
}
549
//----------------------------------------------------------
550
 
551
void PopulateInstruction( std::string aDestination, std::string aSource1, std::string aSource0, Instruction & I, Theia::Parser::location_type  yylloc, bool aHasLiteral = false, unsigned int aLiteral = 0)
552
{
553
 
554
 
555
        bool DestinationHasOffset  = false;
556
        bool DetinationHasIndex    = false;
557
        bool Source0HasOffset      = false;
558
        bool Source1HasOffset      = false;
559
        bool Source1HasIndex       = false;
560
        bool Source0HasIndex       = false;
561
 
562
 
563
        if (aDestination.find("INDEX") != std::string::npos)
564
        {
565
                std::string ArrayIndex = aDestination.substr(aDestination.find("INDEX")+5);
566
                aSource1 = ArrayIndex;
567
                DetinationHasIndex      = true;
568
 
569
        }
570
 
571
        if (aSource1.find("INDEX") != std::string::npos)
572
                Source1HasIndex = true;
573
 
574
        if (aSource0.find("INDEX") != std::string::npos)
575
                Source0HasIndex = true;
576
 
577
        if (aDestination.find("OFFSET") != std::string::npos)
578
                DestinationHasOffset = true;
579
 
580
        if      (aSource0.find("OFFSET") != std::string::npos)
581
                Source0HasOffset = true;
582
 
583
        if      (aSource1.find("OFFSET") != std::string::npos)
584
                Source1HasOffset = true;
585
 
586
        if (IsSwizzled( aSource1 ))
587
                SetSwizzleAndSign( 1, aSource1,  I );
588
        I.SetSrc1Address( atoi( aSource1.c_str()+1 ) );
589
 
590
        if (IsSwizzled( aSource0 ))
591
                SetSwizzleAndSign( 0, aSource0,  I );
592
        I.SetSrc0Address( atoi( aSource0.c_str()+1 ) );
593
 
594
 
595
 
596
        //Fisrt take care of the destination write channel
597
        if (aDestination.find(".") != std::string::npos)
598
                {
599
                        I.ClearWriteChannel();
600
                        if (aDestination.find("x") != std::string::npos)
601
                                I.SetWriteChannel(ECHANNEL_X);
602
                        if (aDestination.find("y") != std::string::npos)
603
                                I.SetWriteChannel(ECHANNEL_Y);
604
                        if (aDestination.find("z") != std::string::npos)
605
                                I.SetWriteChannel(ECHANNEL_Z);
606
                        aDestination.erase(aDestination.find("."));
607
        } else {
608
                I.SetWriteChannel(ECHANNEL_XYZ);
609
        }
610
        //Now set the destination Index
611
        I.SetDestinationAddress( atoi(aDestination.c_str()+1) );
612
 
613
 
614
        //Now determine the addressing mode
615
        //Simple addressing modes
616
        if (!aHasLiteral &&     !DetinationHasIndex && !Source0HasIndex && !Source1HasIndex)
617
        {
618
 
619
                I.SetAddressingMode( DestinationHasOffset,Source1HasOffset,Source0HasOffset);
620
                return;
621
        }
622
 
623
 
624
        I.SetImmBit( true ); //This is to set the IMM bit = 1, may be overwritten latter
625
        //Complex addressing modes
626
        if
627
        (
628
        aHasLiteral &&
629
        !SourceNull( aSource0 ) &&
630
        !Source0HasOffset &&
631
        !Source1HasOffset &&
632
        !DestinationHasOffset
633
        )
634
        {
635
                I.SetAddressingMode( false,false,false);
636
                I.SetImm( aLiteral );
637
 
638
        }
639
        else
640
        if
641
        (
642
        aHasLiteral &&
643
        !SourceNull( aSource0 ) &&
644
        Source0HasOffset &&
645
        !Source0HasIndex &&
646
        DestinationHasOffset
647
 
648
        )
649
        {
650
 
651
                I.SetAddressingMode( false,false,true);
652
                I.SetImm( aLiteral );
653
 
654
 
655
        }
656
        else
657
        if
658
        (
659
        !aHasLiteral &&
660
        !SourceNull( aSource1 ) &&
661
        !Source1HasOffset &&
662
        !SourceNull( aSource0 ) &&
663
        Source0HasOffset &&
664
        Source0HasIndex &&
665
        DestinationHasOffset
666
 
667
        )
668
        {
669
                I.SetAddressingMode( false,true,false);
670
 
671
        }
672
        else
673
        if
674
        (
675
        !aHasLiteral &&
676
        !Source1HasOffset &&
677
        !SourceNull( aSource0 ) &&
678
        Source0HasOffset &&
679
        !Source0HasIndex &&
680
        DestinationHasOffset &&
681
        DetinationHasIndex
682
 
683
        )
684
        {
685
                I.SetAddressingMode( false,true,true);
686
 
687
        }
688
        else
689
        if
690
        (
691
        aHasLiteral &&
692
        SourceNull( aSource0 ) &&
693
        !DestinationHasOffset &&
694
        !DetinationHasIndex
695
 
696
        )
697
        {
698
 
699
 
700
                I.SetAddressingMode( true,false,false);
701
                I.SetImm( aLiteral );
702
        }
703
        else
704
        if
705
        (
706
        aHasLiteral &&
707
        SourceNull( aSource0 ) &&
708
        DestinationHasOffset &&
709
        !DetinationHasIndex
710
 
711
        )
712
        {
713
 
714
                I.SetAddressingMode( true,false,true);
715
                I.SetImm( aLiteral );
716
        }
717
        else
718
        if
719
        (
720
        !aHasLiteral &&
721
        Source1HasOffset &&
722
        Source1HasIndex &&
723
        SourceNull( aSource0 ) &&
724
        DestinationHasOffset &&
725
        !DetinationHasIndex
726
 
727
        )
728
        {
729
 
730
                I.SetAddressingMode( true,true,false);
731
        }
732
        else
733
        if
734
        (
735
        !aHasLiteral &&
736
        Source1HasOffset &&
737
        Source1HasIndex &&
738
        Source0HasOffset &&
739
        !Source0HasIndex &&
740
        DestinationHasOffset &&
741
        !DetinationHasIndex
742
 
743
        )
744
        {
745
 
746
                I.SetAddressingMode( true,true,true);
747
        } else {
748
                        std::ostringstream ret;
749
                        ret << "Could not determine addressing mode  at line " << yylloc << " \n";
750
                        throw ret.str();
751
        }
752
 
753
 
754
}
755
 
756
//-------------------------------------------------------------
757
void PopulateBoolean(EBRANCHTYPE aBranchType, std::string Source1, std::string Source0, Instruction & I, std::vector<Instruction> & aInstructions, Theia::Parser::location_type & yylloc )
758
{
759
 
760
                                        if (Source0.find("R") == std::string::npos)
761
                                        {
762
                                                I.mSourceLine = GetCurrentLineNumber( yylloc );
763
                                                I.SetCode( EOPERATION_ADD );
764
                                                unsigned int TempRegIndex  = GetFreeTempRegister();
765
                                                I.SetDestinationAddress( TempRegIndex );
766
                                                unsigned int ImmediateValue;
767
                                                std::string StringHex = Source0;
768
                                                std::stringstream ss;
769
                                                ss << std::hex << StringHex;
770
                                                ss >> ImmediateValue;
771
                                                I.SetImm( ImmediateValue );
772
                                                I.SetDestZero( true );
773
                                                I.SetSrc0Displace( true );
774
                                                I.SetWriteChannel(ECHANNEL_X);
775
                                                I.SetWriteChannel(ECHANNEL_Y);
776
                                                I.SetWriteChannel(ECHANNEL_Z);
777
                                                aInstructions.push_back(I);
778
                                                I.Clear();
779
 
780
                                                std::stringstream ss2;
781
                                                ss2 << "R" << TempRegIndex;
782
                                                ss2 >> Source0;
783
                                                Source0 += " OFFSET ";
784
 
785
                                        }
786
                                        else
787
                                                I.mSourceLine = GetCurrentLineNumber( yylloc );
788
 
789
                                        I.SetCode( EOPERATION_ADD );
790
                                        I.SetSrc0SignX( true );
791
                                        I.SetSrc0SignY( true );
792
                                        I.SetSrc0SignZ( true );
793
                                        I.SetBranchFlag( true );
794
                                        I.ClearWriteChannel();
795
                                        I.SetBranchType( aBranchType );
796
 
797
                                        PopulateSourceRegisters( Source1, Source0, I, aInstructions);
798
                                        aInstructions.push_back(I);
799
                                        I.Clear();
800
                                        ////std::cout << "pushing code at position " << (mInstructions.size() - 1) << "\n";
801
                                        gBranchStack.push_back(aInstructions.size() - 1);
802
                                        ResetTempRegisterIndex();
803
}
804
 
805
//-------------------------------------------------------------
806
        // Prototype for the yylex function
807
        static int yylex(Theia::Parser::semantic_type * yylval,
808
                         Theia::Parser::location_type * yylloc,
809
                         Theia::Scanner &scanner);
810
 
811
 
812
 
813
/* Line 318 of lalr1.cc  */
814
#line 815 "parser.tab.c"
815
 
816
#ifndef YY_
817
# if YYENABLE_NLS
818
#  if ENABLE_NLS
819
#   include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
820
#   define YY_(msgid) dgettext ("bison-runtime", msgid)
821
#  endif
822
# endif
823
# ifndef YY_
824
#  define YY_(msgid) msgid
825
# endif
826
#endif
827
 
828
/* Suppress unused-variable warnings by "using" E.  */
829
#define YYUSE(e) ((void) (e))
830
 
831
/* Enable debugging if requested.  */
832
#if YYDEBUG
833
 
834
/* A pseudo ostream that takes yydebug_ into account.  */
835
# define YYCDEBUG if (yydebug_) (*yycdebug_)
836
 
837
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)  \
838
do {                                                    \
839
  if (yydebug_)                                         \
840
    {                                                   \
841
      *yycdebug_ << Title << ' ';                       \
842
      yy_symbol_print_ ((Type), (Value), (Location));   \
843
      *yycdebug_ << std::endl;                          \
844
    }                                                   \
845
} while (false)
846
 
847
# define YY_REDUCE_PRINT(Rule)          \
848
do {                                    \
849
  if (yydebug_)                         \
850
    yy_reduce_print_ (Rule);            \
851
} while (false)
852
 
853
# define YY_STACK_PRINT()               \
854
do {                                    \
855
  if (yydebug_)                         \
856
    yystack_print_ ();                  \
857
} while (false)
858
 
859
#else /* !YYDEBUG */
860
 
861
# define YYCDEBUG if (false) std::cerr
862
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
863
# define YY_REDUCE_PRINT(Rule)
864
# define YY_STACK_PRINT()
865
 
866
#endif /* !YYDEBUG */
867
 
868
#define yyerrok         (yyerrstatus_ = 0)
869
#define yyclearin       (yychar = yyempty_)
870
 
871
#define YYACCEPT        goto yyacceptlab
872
#define YYABORT         goto yyabortlab
873
#define YYERROR         goto yyerrorlab
874
#define YYRECOVERING()  (!!yyerrstatus_)
875
 
876
 
877
/* Line 380 of lalr1.cc  */
878
#line 28 "parser.y"
879
namespace Theia {
880
 
881
/* Line 380 of lalr1.cc  */
882
#line 883 "parser.tab.c"
883
#if YYERROR_VERBOSE
884
 
885
  /* Return YYSTR after stripping away unnecessary quotes and
886
     backslashes, so that it's suitable for yyerror.  The heuristic is
887
     that double-quoting is unnecessary unless the string contains an
888
     apostrophe, a comma, or backslash (other than backslash-backslash).
889
     YYSTR is taken from yytname.  */
890
  std::string
891
  Parser::yytnamerr_ (const char *yystr)
892
  {
893
    if (*yystr == '"')
894
      {
895
        std::string yyr = "";
896
        char const *yyp = yystr;
897
 
898
        for (;;)
899
          switch (*++yyp)
900
            {
901
            case '\'':
902
            case ',':
903
              goto do_not_strip_quotes;
904
 
905
            case '\\':
906
              if (*++yyp != '\\')
907
                goto do_not_strip_quotes;
908
              /* Fall through.  */
909
            default:
910
              yyr += *yyp;
911
              break;
912
 
913
            case '"':
914
              return yyr;
915
            }
916
      do_not_strip_quotes: ;
917
      }
918
 
919
    return yystr;
920
  }
921
 
922
#endif
923
 
924
  /// Build a parser object.
925
  Parser::Parser (Theia::Scanner &scanner_yyarg, std::map<std::string,unsigned int>  & mSymbolMap_yyarg, std::vector< Instruction > &mInstructions_yyarg, bool &mGenerateFixedPointArithmetic_yyarg)
926
    :
927
#if YYDEBUG
928
      yydebug_ (false),
929
      yycdebug_ (&std::cerr),
930
#endif
931
      scanner (scanner_yyarg),
932
      mSymbolMap (mSymbolMap_yyarg),
933
      mInstructions (mInstructions_yyarg),
934
      mGenerateFixedPointArithmetic (mGenerateFixedPointArithmetic_yyarg)
935
  {
936
  }
937
 
938
  Parser::~Parser ()
939
  {
940
  }
941
 
942
#if YYDEBUG
943
  /*--------------------------------.
944
  | Print this symbol on YYOUTPUT.  |
945
  `--------------------------------*/
946
 
947
  inline void
948
  Parser::yy_symbol_value_print_ (int yytype,
949
                           const semantic_type* yyvaluep, const location_type* yylocationp)
950
  {
951
    YYUSE (yylocationp);
952
    YYUSE (yyvaluep);
953
    switch (yytype)
954
      {
955
         default:
956
          break;
957
      }
958
  }
959
 
960
 
961
  void
962
  Parser::yy_symbol_print_ (int yytype,
963
                           const semantic_type* yyvaluep, const location_type* yylocationp)
964
  {
965
    *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
966
               << ' ' << yytname_[yytype] << " ("
967
               << *yylocationp << ": ";
968
    yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
969
    *yycdebug_ << ')';
970
  }
971
#endif
972
 
973
  void
974
  Parser::yydestruct_ (const char* yymsg,
975
                           int yytype, semantic_type* yyvaluep, location_type* yylocationp)
976
  {
977
    YYUSE (yylocationp);
978
    YYUSE (yymsg);
979
    YYUSE (yyvaluep);
980
 
981
    YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
982
 
983
    switch (yytype)
984
      {
985
 
986
        default:
987
          break;
988
      }
989
  }
990
 
991
  void
992
  Parser::yypop_ (unsigned int n)
993
  {
994
    yystate_stack_.pop (n);
995
    yysemantic_stack_.pop (n);
996
    yylocation_stack_.pop (n);
997
  }
998
 
999
#if YYDEBUG
1000
  std::ostream&
1001
  Parser::debug_stream () const
1002
  {
1003
    return *yycdebug_;
1004
  }
1005
 
1006
  void
1007
  Parser::set_debug_stream (std::ostream& o)
1008
  {
1009
    yycdebug_ = &o;
1010
  }
1011
 
1012
 
1013
  Parser::debug_level_type
1014
  Parser::debug_level () const
1015
  {
1016
    return yydebug_;
1017
  }
1018
 
1019
  void
1020
  Parser::set_debug_level (debug_level_type l)
1021
  {
1022
    yydebug_ = l;
1023
  }
1024
#endif
1025
 
1026
  int
1027
  Parser::parse ()
1028
  {
1029
    /// Lookahead and lookahead in internal form.
1030
    int yychar = yyempty_;
1031
    int yytoken = 0;
1032
 
1033
    /* State.  */
1034
    int yyn;
1035
    int yylen = 0;
1036
    int yystate = 0;
1037
 
1038
    /* Error handling.  */
1039
    int yynerrs_ = 0;
1040
    int yyerrstatus_ = 0;
1041
 
1042
    /// Semantic value of the lookahead.
1043
    semantic_type yylval;
1044
    /// Location of the lookahead.
1045
    location_type yylloc;
1046
    /// The locations where the error started and ended.
1047
    location_type yyerror_range[2];
1048
 
1049
    /// $$.
1050
    semantic_type yyval;
1051
    /// @$.
1052
    location_type yyloc;
1053
 
1054
    int yyresult;
1055
 
1056
    YYCDEBUG << "Starting parse" << std::endl;
1057
 
1058
 
1059
    /* Initialize the stacks.  The initial state will be pushed in
1060
       yynewstate, since the latter expects the semantical and the
1061
       location values to have been already stored, initialize these
1062
       stacks with a primary value.  */
1063
    yystate_stack_ = state_stack_type (0);
1064
    yysemantic_stack_ = semantic_stack_type (0);
1065
    yylocation_stack_ = location_stack_type (0);
1066
    yysemantic_stack_.push (yylval);
1067
    yylocation_stack_.push (yylloc);
1068
 
1069
    /* New state.  */
1070
  yynewstate:
1071
    yystate_stack_.push (yystate);
1072
    YYCDEBUG << "Entering state " << yystate << std::endl;
1073
 
1074
    /* Accept?  */
1075
    if (yystate == yyfinal_)
1076
      goto yyacceptlab;
1077
 
1078
    goto yybackup;
1079
 
1080
    /* Backup.  */
1081
  yybackup:
1082
 
1083
    /* Try to take a decision without lookahead.  */
1084
    yyn = yypact_[yystate];
1085
    if (yyn == yypact_ninf_)
1086
      goto yydefault;
1087
 
1088
    /* Read a lookahead token.  */
1089
    if (yychar == yyempty_)
1090
      {
1091
        YYCDEBUG << "Reading a token: ";
1092
        yychar = yylex (&yylval, &yylloc, scanner);
1093
      }
1094
 
1095
 
1096
    /* Convert token to internal form.  */
1097
    if (yychar <= yyeof_)
1098
      {
1099
        yychar = yytoken = yyeof_;
1100
        YYCDEBUG << "Now at end of input." << std::endl;
1101
      }
1102
    else
1103
      {
1104
        yytoken = yytranslate_ (yychar);
1105
        YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1106
      }
1107
 
1108
    /* If the proper action on seeing token YYTOKEN is to reduce or to
1109
       detect an error, take that action.  */
1110
    yyn += yytoken;
1111
    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
1112
      goto yydefault;
1113
 
1114
    /* Reduce or error.  */
1115
    yyn = yytable_[yyn];
1116
    if (yyn <= 0)
1117
      {
1118
        if (yyn == 0 || yyn == yytable_ninf_)
1119
        goto yyerrlab;
1120
        yyn = -yyn;
1121
        goto yyreduce;
1122
      }
1123
 
1124
    /* Shift the lookahead token.  */
1125
    YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1126
 
1127
    /* Discard the token being shifted.  */
1128
    yychar = yyempty_;
1129
 
1130
    yysemantic_stack_.push (yylval);
1131
    yylocation_stack_.push (yylloc);
1132
 
1133
    /* Count tokens shifted since error; after three, turn off error
1134
       status.  */
1135
    if (yyerrstatus_)
1136
      --yyerrstatus_;
1137
 
1138
    yystate = yyn;
1139
    goto yynewstate;
1140
 
1141
  /*-----------------------------------------------------------.
1142
  | yydefault -- do the default action for the current state.  |
1143
  `-----------------------------------------------------------*/
1144
  yydefault:
1145
    yyn = yydefact_[yystate];
1146
    if (yyn == 0)
1147
      goto yyerrlab;
1148
    goto yyreduce;
1149
 
1150
  /*-----------------------------.
1151
  | yyreduce -- Do a reduction.  |
1152
  `-----------------------------*/
1153
  yyreduce:
1154
    yylen = yyr2_[yyn];
1155
    /* If YYLEN is nonzero, implement the default value of the action:
1156
       `$$ = $1'.  Otherwise, use the top of the stack.
1157
 
1158
       Otherwise, the following line sets YYVAL to garbage.
1159
       This behavior is undocumented and Bison
1160
       users should not rely upon it.  */
1161
    if (yylen)
1162
      yyval = yysemantic_stack_[yylen - 1];
1163
    else
1164
      yyval = yysemantic_stack_[0];
1165
 
1166
    {
1167
      slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
1168
      YYLLOC_DEFAULT (yyloc, slice, yylen);
1169
    }
1170
    YY_REDUCE_PRINT (yyn);
1171
    switch (yyn)
1172
      {
1173
          case 6:
1174
 
1175
/* Line 678 of lalr1.cc  */
1176
#line 842 "parser.y"
1177
    {
1178
                mGenerateFixedPointArithmetic = true;
1179
        }
1180
    break;
1181
 
1182
  case 7:
1183
 
1184
/* Line 678 of lalr1.cc  */
1185
#line 847 "parser.y"
1186
    {
1187
                //Insert a stupid NOP before the exit... is a bug but easier to just patch like this...
1188
 
1189
                I.Clear();
1190
                I.mComment = "NOP";
1191
                I.SetCode( EOPERATION_NOP );
1192
                mInstructions.push_back(I);
1193
                I.Clear();
1194
 
1195
                I.SetEofFlag(true);
1196
                I.mComment = "Set the Exit bit";
1197
                I.SetCode( EOPERATION_ADD );
1198
                mInstructions.push_back(I);
1199
                I.Clear();
1200
        }
1201
    break;
1202
 
1203
  case 8:
1204
 
1205
/* Line 678 of lalr1.cc  */
1206
#line 864 "parser.y"
1207
    {
1208
 
1209
                //////////////////////////////////////////////////////////////////////////////
1210
                // This means this that the expression was just a constant.
1211
                // No operations were inserted
1212
                //////////////////////////////////////////////////////////////////////////////
1213
                if (gInsertedInstructions == 0)
1214
                {
1215
                        I.Clear();
1216
                        I.SetCode(EOPERATION_ADD);
1217
                        I.mComment ="Set the return value";
1218
                        if ((yysemantic_stack_[(3) - (3)]).find("R") != std::string::npos)
1219
                        {
1220
                                PopulateInstruction( "R1", (yysemantic_stack_[(3) - (2)]),"R0 . X X X",I,yylloc);
1221
                        }
1222
                        else
1223
                        {
1224
                                unsigned int ImmediateValue = 0;
1225
                                std::string StringHex = (yysemantic_stack_[(3) - (3)]);
1226
                                std::stringstream ss;
1227
                                ss << std::hex << StringHex;
1228
                                ss >> ImmediateValue;
1229
                                PopulateInstruction( "R1", (yysemantic_stack_[(3) - (3)]),"NULL",I, yylloc, true, ImmediateValue);
1230
                        }
1231
                        mInstructions.push_back(I);
1232
                        I.Clear();
1233
                } else {
1234
 
1235
                        mInstructions[ mInstructions.size() - gInsertedInstructions].mSourceLine = GetCurrentLineNumber(yylloc);
1236
                        gInsertedInstructions = 0;
1237
                        mInstructions.back().mComment ="Assigning return value";
1238
                        mInstructions.back().SetDestinationAddress( RETURN_VALUE_REGISTER );
1239
 
1240
                }
1241
                ResetTempRegisterIndex();
1242
 
1243
                I.SetCode( EOPERATION_ADD );
1244
                I.mComment = "Restore previous function frame offset";
1245
                I.ClearWriteChannel();
1246
                I.SetWriteChannel(ECHANNEL_X);
1247
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
1248
                I.SetSrc1Address(SPR_CONTROL_REGISTER);
1249
                I.SetSrc1SwizzleX(SWX_Y);
1250
                I.SetSrc1SwizzleY(SWY_Y);
1251
                I.SetSrc1SwizzleZ(SWZ_Y);
1252
                I.SetSrc0Address(0);
1253
                I.SetSrc0SwizzleX(SWX_X);
1254
                I.SetSrc0SwizzleY(SWY_X);
1255
                I.SetSrc0SwizzleZ(SWZ_X);
1256
                mInstructions.push_back( I );
1257
                I.Clear();
1258
 
1259
                //Now return
1260
                I.SetImm( 0 );
1261
                I.SetCode( EOPERATION_ADD );
1262
                I.mComment = "return from function";
1263
                I.SetBranchFlag( true );
1264
                I.SetBranchType( EBRANCH_ALWAYS );
1265
                I.SetDestinationAddress( RETURN_ADDRESS_REGISTER );
1266
                mInstructions.push_back(I);
1267
                I.Clear();
1268
 
1269
 
1270
 
1271
        }
1272
    break;
1273
 
1274
  case 9:
1275
 
1276
/* Line 678 of lalr1.cc  */
1277
#line 931 "parser.y"
1278
    {
1279
                I.SetCode( EOPERATION_ADD );
1280
                I.mComment = "Restore previous function frame offset";
1281
                I.SetWriteChannel(ECHANNEL_X);
1282
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
1283
                I.SetSrc1Address(SPR_CONTROL_REGISTER);
1284
                I.SetSrc1SwizzleX(SWX_Y);
1285
                I.SetSrc1SwizzleY(SWY_Y);
1286
                I.SetSrc1SwizzleZ(SWZ_Y);
1287
                I.SetSrc0Address(0);
1288
                I.SetSrc0SwizzleX(SWX_X);
1289
                I.SetSrc0SwizzleY(SWY_X);
1290
                I.SetSrc0SwizzleZ(SWZ_X);
1291
                mInstructions.push_back( I );
1292
                I.Clear();
1293
 
1294
                I.SetImm( 0 );
1295
                I.SetCode( EOPERATION_ADD );
1296
                I.mComment = "return from function";
1297
                I.SetBranchFlag( true );
1298
                I.SetBranchType( EBRANCH_ALWAYS );
1299
                I.SetDestinationAddress( RETURN_ADDRESS_REGISTER );
1300
                mInstructions.push_back(I);
1301
                I.Clear();
1302
        }
1303
    break;
1304
 
1305
  case 10:
1306
 
1307
/* Line 678 of lalr1.cc  */
1308
#line 959 "parser.y"
1309
    {
1310
 
1311
                 I.mSourceLine = GetCurrentLineNumber( yylloc );
1312
                 I.SetCode( EOPERATION_ADD );
1313
                 SetDestinationFromRegister( (yysemantic_stack_[(4) - (1)]), I , true);
1314
                 unsigned int ImmediateValue;
1315
                 std::string StringHex = (yysemantic_stack_[(4) - (3)]);
1316
                 std::stringstream ss;
1317
                 ss << std::hex << StringHex;
1318
                 ss >> ImmediateValue;
1319
                 I.SetImm( ImmediateValue );
1320
                 I.SetDestZero( false );
1321
 
1322
                 mInstructions.push_back( I );
1323
                 I.Clear();
1324
         }
1325
    break;
1326
 
1327
  case 11:
1328
 
1329
/* Line 678 of lalr1.cc  */
1330
#line 977 "parser.y"
1331
    {
1332
 
1333
                I.mSourceLine = GetCurrentLineNumber( yylloc );
1334
                I.SetCode( EOPERATION_ADD );
1335
                SetDestinationFromRegister( (yysemantic_stack_[(4) - (1)]), I, false );
1336
                I.SetSrc0SignX( true );
1337
                I.SetSrc0SignY( true );
1338
                I.SetSrc0SignZ( true );
1339
                std::string Destination = (yysemantic_stack_[(4) - (1)]);
1340
                if (Destination.find("OFFSET") != std::string::npos)
1341
                {
1342
                        I.SetSrc1Displace( true );
1343
                        Destination.erase(Destination.find("OFFSET"));
1344
                }
1345
 
1346
                if (Destination.find(".") != std::string::npos)
1347
                        Destination.erase(Destination.find("."));
1348
 
1349
 
1350
                I.SetSrc1Address(atoi(Destination.c_str()+1));
1351
                I.SetSrc0Address(0);
1352
                I.SetSrc0SwizzleX(SWX_Y);
1353
                I.SetSrc0SwizzleY(SWY_Y);
1354
                I.SetSrc0SwizzleZ(SWZ_Y);
1355
                mInstructions.push_back( I );
1356
                I.Clear();
1357
         }
1358
    break;
1359
 
1360
  case 12:
1361
 
1362
/* Line 678 of lalr1.cc  */
1363
#line 1006 "parser.y"
1364
    {
1365
 
1366
                I.mSourceLine = GetCurrentLineNumber( yylloc );
1367
                I.SetCode( EOPERATION_ADD );
1368
                SetDestinationFromRegister( (yysemantic_stack_[(4) - (1)]), I, false );
1369
                std::string Destination = (yysemantic_stack_[(4) - (1)]);
1370
                if (Destination.find("OFFSET") != std::string::npos)
1371
                {
1372
                        I.SetSrc1Displace( true );
1373
                        Destination.erase(Destination.find("OFFSET"));
1374
                }
1375
 
1376
                if (Destination.find(".") != std::string::npos)
1377
                        Destination.erase(Destination.find("."));
1378
 
1379
                I.SetSrc1Address(atoi(Destination.c_str()+1));
1380
                I.SetSrc0Address(0);
1381
                I.SetSrc0SwizzleX(SWX_Y);
1382
                I.SetSrc0SwizzleY(SWY_Y);
1383
                I.SetSrc0SwizzleZ(SWZ_Y);
1384
                mInstructions.push_back( I );
1385
                I.Clear();
1386
         }
1387
    break;
1388
 
1389
  case 13:
1390
 
1391
/* Line 678 of lalr1.cc  */
1392
#line 1031 "parser.y"
1393
    {
1394
 
1395
                //////////////////////////////////////////////////////////////////////////////
1396
                // This means this that the expression will write into the output memory
1397
                // constant index
1398
                //////////////////////////////////////////////////////////////////////////////
1399
 
1400
                if ((yysemantic_stack_[(4) - (1)]).find("OUT") != std::string::npos && (yysemantic_stack_[(4) - (1)]).find("INDEX") == std::string::npos )
1401
                {
1402
                        //PopulateInstruction( "R0", "R0 . X X X",$3,I,yylloc);
1403
 
1404
                        I.SetCode(EOPERATION_OUT);
1405
                        (yysemantic_stack_[(4) - (1)]).erase((yysemantic_stack_[(4) - (1)]).find("OUT"),3);
1406
 
1407
                        unsigned int ImmediateValue;
1408
                        std::stringstream ss;
1409
                        ss << std::hex << (yysemantic_stack_[(4) - (1)]);
1410
                        ss >> ImmediateValue;
1411
                        PopulateInstruction( (yysemantic_stack_[(4) - (3)]), "R0 OFFSET", "R0 OFFSET", I, yylloc, true, ImmediateValue );
1412
                        #ifdef DEBUG
1413
                        I.PrintFields();
1414
                        #endif
1415
                        mInstructions.push_back(I);
1416
                        I.Clear();
1417
                        ResetTempRegisterIndex();
1418
                        goto LABEL_EXPRESSION_DONE;
1419
                }
1420
                //////////////////////////////////////////////////////////////////////////////
1421
                // This means this that the expression will write into the output memory
1422
                // variable index
1423
                //////////////////////////////////////////////////////////////////////////////
1424
 
1425
                if ((yysemantic_stack_[(4) - (1)]).find("OUT") != std::string::npos && (yysemantic_stack_[(4) - (1)]).find("INDEX") != std::string::npos )
1426
                {
1427
                        std::string Destination = (yysemantic_stack_[(4) - (1)]);
1428
                        DCOUT << "!!!!!!!!!!!!!!!!!Destination " << Destination << "\n";
1429
                        std::string IndexRegister = Destination.substr(Destination.find("INDEX")+5);
1430
                        Destination.erase(Destination.find("INDEX"));
1431
 
1432
 
1433
                        I.SetDestZero( true ); //Use indexing for DST
1434
                        I.SetWriteChannel(ECHANNEL_XYZ);
1435
 
1436
                        PopulateSourceRegisters( IndexRegister + " OFFSET ", (yysemantic_stack_[(4) - (3)]), I, mInstructions );
1437
 
1438
 
1439
                        //I.SetImm( 0 );
1440
                        I.SetCode( EOPERATION_OUT );
1441
                        std::string Source0 = (yysemantic_stack_[(4) - (3)]);
1442
                        DCOUT << "!!!!!!!!!!!!!!!!!Source0 '" << Source0 << "'\n";
1443
                /*      if (Source0.find("OFFSET") != std::string::npos)
1444
                        {
1445
                                        Source0.erase(Source0.find("OFFSET"));
1446
                                        I.SetSrc0Displace(1);
1447
                        }
1448
                        I.SetSrc1Address(atoi(IndexRegister.c_str()+1));
1449
                        I.SetSrc0Address(atoi(Source0.c_str()+1));*/
1450
 
1451
                /*      if (Destination.find(".") != std::string::npos)
1452
                        {
1453
                                I.ClearWriteChannel();
1454
                                if (Destination.find("x") != std::string::npos)
1455
                                        I.SetWriteChannel(ECHANNEL_X);
1456
                                if (Destination.find("y") != std::string::npos)
1457
                                        I.SetWriteChannel(ECHANNEL_Y);
1458
                                if (Destination.find("z") != std::string::npos)
1459
                                        I.SetWriteChannel(ECHANNEL_Z);
1460
 
1461
                                Destination.erase(Destination.find("."));
1462
 
1463
                        }
1464
 
1465
                        std::string Source0 = $3;
1466
                        if (Source0.find("OFFSET") != std::string::npos)
1467
                        {
1468
                                        Source0.erase(Source0.find("OFFSET"));
1469
                                        I.SetSrc0Displace(1);
1470
                        }
1471
                        I.SetSrc1Address(atoi(IndexRegister.c_str()+1));
1472
                        I.SetSrc0Address(atoi(Source0.c_str()+1));
1473
 
1474
 
1475
                                //      I.SetSrc0Address(mInstructions.back().GetDestinationAddress());
1476
                        I.SetDestZero(0);
1477
                        I.SetSrc1Displace(1);
1478
                        I.SetSrc0Displace(1);
1479
                        I.SetDestinationAddress( atoi(Destination.c_str()+1) );*/
1480
                        mInstructions.push_back( I );
1481
                        I.Clear();
1482
                        ResetTempRegisterIndex();
1483
                        goto LABEL_EXPRESSION_DONE;
1484
                }
1485
                //////////////////////////////////////////////////////////////////////////////
1486
                // This means this that the expression was just a constant.
1487
                // No operations were inserted
1488
                //////////////////////////////////////////////////////////////////////////////
1489
                if (gInsertedInstructions == 0)
1490
                {
1491
 
1492
                        I.Clear();
1493
 
1494
                        I.SetCode(EOPERATION_ADD);
1495
                        I.mSourceLine = GetCurrentLineNumber(yylloc);
1496
                        if ((yysemantic_stack_[(4) - (3)]).find("R") != std::string::npos)
1497
                        {
1498
                        // case 1:
1499
                        // foo = 0;        //$$ = R0 . X X X
1500
                        /*      SetDestinationFromRegister( $1, I, false );
1501
                                PopulateSourceRegisters( $3, "R0 . X X X", I, mInstructions);*/
1502
 
1503
                                PopulateInstruction( (yysemantic_stack_[(4) - (1)]), "R0 . X X X",(yysemantic_stack_[(4) - (3)]),I,yylloc);
1504
 
1505
                        } else {
1506
                        // case 2:
1507
                        // foo = 0xcafe;  //$$ = 0xcafe
1508
                                SetDestinationFromRegister( (yysemantic_stack_[(4) - (1)]), I, true );
1509
                                unsigned int ImmediateValue = 0;
1510
                                std::string StringHex = (yysemantic_stack_[(4) - (3)]);
1511
                                std::stringstream ss;
1512
                                ss << std::hex << StringHex;
1513
                                ss >> ImmediateValue;
1514
 
1515
                                PopulateInstruction( (yysemantic_stack_[(4) - (1)]), (yysemantic_stack_[(4) - (3)]),"NULL",I, yylloc, true, ImmediateValue);
1516
                        }
1517
                        std::string strConstant = (yysemantic_stack_[(4) - (3)]);
1518
 
1519
                        mInstructions.push_back(I);
1520
                        I.Clear();
1521
                        ResetTempRegisterIndex();
1522
                        goto LABEL_EXPRESSION_DONE;
1523
                }
1524
 
1525
                //////////////////////////////////////////////////////////////////////////////
1526
                // This means that the last instruction which was inserted was a tripple 
1527
                // constant assignement, like foo = (1,2,3)
1528
                //////////////////////////////////////////////////////////////////////////////
1529
                if (mInstructions.back().mBisonFlagTrippleConstAssign)
1530
                {
1531
                        unsigned int LastIndex = mInstructions.size() - 1;
1532
                        mInstructions[LastIndex].SetDestinationAddress(atoi((yysemantic_stack_[(4) - (1)]).c_str()+1));
1533
                        mInstructions[LastIndex-1].SetDestinationAddress(atoi((yysemantic_stack_[(4) - (1)]).c_str()+1));
1534
                        mInstructions[LastIndex-2].SetDestinationAddress(atoi((yysemantic_stack_[(4) - (1)]).c_str()+1));
1535
                        mInstructions[LastIndex-2].mSourceLine = GetCurrentLineNumber( yylloc );
1536
                        if((yysemantic_stack_[(4) - (1)]).find("OFFSET") == std::string::npos)
1537
                        {
1538
                                mInstructions[LastIndex].SetAddressingMode(true,false,false);
1539
                                mInstructions[LastIndex-1].SetAddressingMode(true,false,false);
1540
                                mInstructions[LastIndex-2].SetAddressingMode(true,false,false);
1541
                        }
1542
 
1543
                        ResetTempRegisterIndex();
1544
                        goto LABEL_EXPRESSION_DONE;
1545
                }
1546
                //////////////////////////////////////////////////////////////////////////////
1547
                // Handle the case where the destination is an array of vector
1548
                // ej: R = v1[ i ]  + V2
1549
                //////////////////////////////////////////////////////////////////////////////
1550
                if (I.GetOperation() == 0 && (yysemantic_stack_[(4) - (3)]).find("array_element") != std::string::npos)
1551
                {
1552
                        //No operation meaning the the expression only has a single variable
1553
                        //See if the expression returned is an array_element 
1554
                        if ((yysemantic_stack_[(4) - (3)]).find("array_element") != std::string::npos)
1555
                        {
1556
                                ////std::cout << "expression is an array element\n\n";
1557
                                std::string Index = (yysemantic_stack_[(4) - (3)]).substr((yysemantic_stack_[(4) - (3)]).find("array_element"));
1558
                                Index = Index.substr(Index.find_first_not_of("array_element R"));
1559
                                SetIndexRegister( atoi(Index.c_str()), mInstructions );
1560
                                (yysemantic_stack_[(4) - (3)]).erase((yysemantic_stack_[(4) - (3)]).find("array_element"));
1561
                                SetExpressionDestination( (yysemantic_stack_[(4) - (1)]), I );
1562
                                I.SetCode(EOPERATION_ADD);
1563
                                I.SetImmBit( true );
1564
                                I.SetDestZero( true );
1565
                                I.SetSrc1Displace( true );
1566
                                I.SetSrc0Displace( false );
1567
                                I.mSourceLine = GetCurrentLineNumber(yylloc);
1568
 
1569
                                if ((yysemantic_stack_[(4) - (3)]).find("OFFSET") != std::string::npos)
1570
                                        (yysemantic_stack_[(4) - (3)]).erase((yysemantic_stack_[(4) - (3)]).find("OFFSET"));
1571
 
1572
                                I.SetSrc1Address(atoi((yysemantic_stack_[(4) - (3)]).c_str()+1));
1573
                                I.SetSrc0Address(0);
1574
                                mInstructions.push_back(I);
1575
                                I.Clear();
1576
                        }
1577
                }
1578
                else
1579
                {
1580
 
1581
                                mInstructions[ mInstructions.size() - gInsertedInstructions].mSourceLine = GetCurrentLineNumber(yylloc);
1582
                                gInsertedInstructions = 0;
1583
                                std::string Destination = (yysemantic_stack_[(4) - (1)]);
1584
                                //std::cout << "DST " << Destination << " \n";
1585
                                //Look for indirect addressing
1586
                                if (Destination.find("INDEX") != std::string::npos)
1587
                                {
1588
 
1589
                                        std::string IndexRegister = Destination.substr(Destination.find("INDEX")+5);
1590
 
1591
                                        Destination.erase(Destination.find("INDEX"));
1592
 
1593
                                        I.SetImm( 0 );
1594
                                        I.SetCode( EOPERATION_ADD );
1595
 
1596
                                        if (Destination.find(".") != std::string::npos)
1597
                                        {
1598
                                                I.ClearWriteChannel();
1599
                                                if (Destination.find("x") != std::string::npos)
1600
                                                        I.SetWriteChannel(ECHANNEL_X);
1601
                                                if (Destination.find("y") != std::string::npos)
1602
                                                        I.SetWriteChannel(ECHANNEL_Y);
1603
                                                if (Destination.find("z") != std::string::npos)
1604
                                                        I.SetWriteChannel(ECHANNEL_Z);
1605
 
1606
                                                Destination.erase(Destination.find("."));
1607
 
1608
                                        }
1609
 
1610
                                        std::string Source0 = (yysemantic_stack_[(4) - (3)]);
1611
                                        if (Source0.find("OFFSET") != std::string::npos)
1612
                                        {
1613
                                                Source0.erase(Source0.find("OFFSET"));
1614
                                                I.SetSrc0Displace(1);
1615
                                        }
1616
                                        I.SetSrc1Address(atoi(IndexRegister.c_str()+1));
1617
                                        I.SetSrc0Address(atoi(Source0.c_str()+1));
1618
 
1619
 
1620
                                //      I.SetSrc0Address(mInstructions.back().GetDestinationAddress());
1621
                                        I.SetDestZero(0);
1622
                                        I.SetSrc1Displace(1);
1623
                                        I.SetSrc0Displace(1);
1624
                                        I.SetDestinationAddress( atoi(Destination.c_str()+1) );
1625
                                        mInstructions.push_back( I );
1626
                                        I.Clear();
1627
                                } else {
1628
 
1629
                                        if (mInstructions.back().GetImm())
1630
                                        {
1631
                                                //Look for displament addressing mode
1632
                                                unsigned int AddressingMode = mInstructions.back().GetAddressingMode();
1633
                                                if (Destination.find("OFFSET") != std::string::npos)
1634
                                                {
1635
                                                        //This means AddressMode is '101', so leave the way it is
1636
                                                        mInstructions.back().ClearWriteChannel();
1637
                                                        mInstructions.back().SetWriteChannel(ECHANNEL_Z);
1638
                                                        Destination.erase(Destination.find("OFFSET"));
1639
                                                } else {
1640
                                                        //This is not supposed to have index, so change addressing mode to '100'
1641
 
1642
                                                        mInstructions.back().SetDestZero( true );
1643
                                                        mInstructions.back().SetSrc1Displace( false );
1644
                                                        mInstructions.back().SetSrc0Displace( false );
1645
                                                        mInstructions.back().ClearWriteChannel();
1646
                                                        mInstructions.back().SetWriteChannel(ECHANNEL_Z);
1647
                                                }
1648
 
1649
                                        } else {
1650
                                                mInstructions.back().SetDestZero( false ); //First assume no offset was used
1651
 
1652
 
1653
 
1654
                                                //Look for displament addressing mode
1655
                                                if (Destination.find("OFFSET") != std::string::npos)
1656
                                                {
1657
                                                        Destination.erase(Destination.find("OFFSET"));
1658
                                                        mInstructions.back().SetDestZero( true ); //When Imm != 0, DestZero means DST = DSTINDEX + offset
1659
                                                }
1660
                                        }
1661
                                                if (Destination.find(".") != std::string::npos)
1662
                                                {
1663
                                                        mInstructions.back().ClearWriteChannel();
1664
                                                        if (Destination.find("x") != std::string::npos)
1665
                                                                mInstructions.back().SetWriteChannel(ECHANNEL_X);
1666
                                                        if (Destination.find("y") != std::string::npos)
1667
                                                                mInstructions.back().SetWriteChannel(ECHANNEL_Y);
1668
                                                        if (Destination.find("z") != std::string::npos)
1669
                                                                mInstructions.back().SetWriteChannel(ECHANNEL_Z);
1670
 
1671
                                                        Destination.erase(Destination.find("."));
1672
 
1673
                                                }
1674
                                                mInstructions.back().SetDestinationAddress( atoi((yysemantic_stack_[(4) - (1)]).c_str()+1) );
1675
                                                for (int i = 1; i <= gExtraDestModifications; i++ )
1676
                                                {
1677
                                                        int idx = (mInstructions.size()-1)-i;
1678
                                                        mInstructions[idx].SetDestinationAddress( atoi((yysemantic_stack_[(4) - (1)]).c_str()+1) );
1679
                                                        if (mInstructions[idx].GetImm())
1680
                                                        {
1681
 
1682
                                                                //This is not supposed to have index, so change addressing mode to '100'
1683
                                                                mInstructions[idx].SetDestZero( true );
1684
                                                                mInstructions[idx].SetSrc1Displace( false );
1685
                                                                mInstructions[idx].SetSrc0Displace( false );
1686
 
1687
 
1688
                                                        }
1689
 
1690
                                                }
1691
                                                gExtraDestModifications = 0;
1692
 
1693
 
1694
 
1695
                                }
1696
                                ResetTempRegisterIndex();
1697
                }
1698
 
1699
                LABEL_EXPRESSION_DONE:
1700
                gInsertedInstructions = 0;
1701
                while(0);
1702
 
1703
        }
1704
    break;
1705
 
1706
  case 14:
1707
 
1708
/* Line 678 of lalr1.cc  */
1709
#line 1343 "parser.y"
1710
    { /*Middle rule here, get me the loop address*/ ;gWhileLoopAddress = (mInstructions.size());}
1711
    break;
1712
 
1713
  case 15:
1714
 
1715
/* Line 678 of lalr1.cc  */
1716
#line 1344 "parser.y"
1717
    {
1718
                mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size()+1);
1719
                gBranchStack.pop_back();
1720
                //Now I need to put a GOTO so that the while gets evaluated again...
1721
                //jump out of the if
1722
           I.Clear();
1723
           I.SetCode( EOPERATION_ADD );
1724
           I.mComment = "while loop goto re-eval boolean";
1725
           I.SetDestinationAddress( gWhileLoopAddress );
1726
           I.SetBranchFlag( true );
1727
           I.SetBranchType( EBRANCH_ALWAYS );
1728
           mInstructions.push_back(I);
1729
           I.Clear();
1730
 
1731
        }
1732
    break;
1733
 
1734
  case 16:
1735
 
1736
/* Line 678 of lalr1.cc  */
1737
#line 1363 "parser.y"
1738
    {
1739
 
1740
           //jump out of the if
1741
           I.Clear();
1742
           I.SetCode( EOPERATION_ADD );
1743
           I.SetBranchFlag( true );
1744
           I.SetBranchType( EBRANCH_ALWAYS );
1745
           mInstructions.push_back(I);
1746
           I.Clear();
1747
           //Take care of the destination addr of the if statement.
1748
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
1749
          gBranchStack.pop_back();
1750
          //push the inconditional jump into the stack
1751
          gBranchStack.push_back(mInstructions.size() - 1);
1752
          ////std::cout << "else\n";
1753
 
1754
        }
1755
    break;
1756
 
1757
  case 17:
1758
 
1759
/* Line 678 of lalr1.cc  */
1760
#line 1381 "parser.y"
1761
    {
1762
 
1763
           mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
1764
           gBranchStack.pop_back();
1765
           //Now push the JMP
1766
 
1767
                ////std::cout << "END elseif\n";
1768
        }
1769
    break;
1770
 
1771
  case 18:
1772
 
1773
/* Line 678 of lalr1.cc  */
1774
#line 1392 "parser.y"
1775
    {
1776
                mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size());
1777
                //mInstructions[gBranchStack.back()].mSourceLine = GetCurrentLineNumber(yylloc);
1778
 
1779
                gBranchStack.pop_back();
1780
                ////std::cout << "if closing at " << mInstructions.size() << "\n";
1781
 
1782
        }
1783
    break;
1784
 
1785
  case 19:
1786
 
1787
/* Line 678 of lalr1.cc  */
1788
#line 1402 "parser.y"
1789
    {
1790
          ////std::cout << "Function declaration for " << $2 << " at " << mInstructions.size() << "\n" ;
1791
          mSymbolMap[ (yysemantic_stack_[(5) - (2)]) ] = mInstructions.size();
1792
        }
1793
    break;
1794
 
1795
  case 20:
1796
 
1797
/* Line 678 of lalr1.cc  */
1798
#line 1406 "parser.y"
1799
    {
1800
                //Clear the auto var index now that we leave the function scope
1801
                ClearAutoVarMap();
1802
                ClearFunctionParameterMap();
1803
 
1804
                //Now uddate the current SPR_CONTROL_REGISTER.x = SPR_CONTROL_REGISTER.y
1805
                I.SetCode( EOPERATION_ADD );
1806
                I.mComment = "Restore previous function frame offset";
1807
                I.SetWriteChannel(ECHANNEL_X);
1808
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
1809
                I.SetSrc1Address(SPR_CONTROL_REGISTER);
1810
                I.SetSrc1SwizzleX(SWX_Y);
1811
                I.SetSrc1SwizzleY(SWY_Y);
1812
                I.SetSrc1SwizzleZ(SWZ_Y);
1813
                I.SetSrc0Address(0);
1814
                I.SetSrc0SwizzleX(SWX_X);
1815
                I.SetSrc0SwizzleY(SWY_X);
1816
                I.SetSrc0SwizzleZ(SWZ_X);
1817
 
1818
                mInstructions.push_back( I );
1819
                I.Clear();
1820
        }
1821
    break;
1822
 
1823
  case 21:
1824
 
1825
/* Line 678 of lalr1.cc  */
1826
#line 1431 "parser.y"
1827
    {
1828
                gThreadMap[ (yysemantic_stack_[(4) - (2)]) ] = mInstructions.size();
1829
                gThreadScope = true;
1830
        }
1831
    break;
1832
 
1833
  case 22:
1834
 
1835
/* Line 678 of lalr1.cc  */
1836
#line 1436 "parser.y"
1837
    {
1838
                ////std::cout << "Defining thread" << "\n";
1839
                gThreadScope = false;
1840
                ClearAutoVarMap();
1841
                //Since the thread is done, then disable threading
1842
                I.SetCode( EOPERATION_ADD );
1843
                I.mComment = "Disable multi-threading";
1844
                I.SetDestinationAddress( SPR_CONTROL_REGISTER0 );
1845
                unsigned int Value = 0;
1846
                I.SetImm( Value );
1847
                I.SetDestZero( true );
1848
                I.SetWriteChannel(ECHANNEL_Z);
1849
                mInstructions.push_back( I );
1850
                I.Clear();
1851
 
1852
        }
1853
    break;
1854
 
1855
  case 23:
1856
 
1857
/* Line 678 of lalr1.cc  */
1858
#line 1454 "parser.y"
1859
    {
1860
                unsigned int ThreadCodeOffset = 0;
1861
                ////std::cout << "Starting thread" << "\n";
1862
                if (gThreadMap.find((yysemantic_stack_[(5) - (2)])) == gThreadMap.end())
1863
                {
1864
 
1865
                        std::ostringstream ret;
1866
                        ret << "Undefined thread '" << (yysemantic_stack_[(5) - (2)]) << "' at line " << yylloc << " \n";
1867
                        ret << "Current version of the compiler needs thread defintion prior of thread instantiation\n";
1868
                        throw ret.str();
1869
                } else {
1870
                        ThreadCodeOffset = gThreadMap[(yysemantic_stack_[(5) - (2)])];
1871
                        //Now enable the multithreading and set instruction offset
1872
                        I.SetCode( EOPERATION_ADD );
1873
                        std::ostringstream ss;
1874
                        ss << "Set thread instruction offset to 8'd" << ThreadCodeOffset;
1875
                        I.mComment = ss.str();
1876
                        I.SetDestinationAddress( SPR_CONTROL_REGISTER0 );
1877
                        unsigned int Value = (ThreadCodeOffset << 1);
1878
                        I.SetImm( Value );
1879
                        I.SetDestZero( true );
1880
                        I.SetWriteChannel(ECHANNEL_Z);
1881
                        mInstructions.push_back( I );
1882
                        I.Clear();
1883
 
1884
 
1885
                        I.SetCode( EOPERATION_ADD );
1886
                        I.mComment = "Enable multi-threading";
1887
                        I.SetDestinationAddress( SPR_CONTROL_REGISTER0 );
1888
                        Value = (ThreadCodeOffset << 1 | 1);
1889
                        I.SetImm( Value );
1890
                        I.SetDestZero( true );
1891
                        I.SetWriteChannel(ECHANNEL_Z);
1892
                        mInstructions.push_back( I );
1893
                        I.Clear();
1894
 
1895
                }
1896
 
1897
        }
1898
    break;
1899
 
1900
  case 24:
1901
 
1902
/* Line 678 of lalr1.cc  */
1903
#line 1495 "parser.y"
1904
    {
1905
                ////std::cout << "Function call returning to var\n";
1906
                StoreReturnAddress( mInstructions, yylloc );
1907
                SavePreviousFramePointer( mInstructions );
1908
                UpdateFramePointer( mInstructions );
1909
                CallFunction( (yysemantic_stack_[(7) - (3)]), mInstructions, mSymbolMap );
1910
 
1911
 
1912
                //Return value comes in R1, so let's store this in our variable
1913
                I.SetCode( EOPERATION_ADD );
1914
                SetDestinationFromRegister( (yysemantic_stack_[(7) - (1)]), I, false );
1915
                I.mComment = "grab the return value from the function";
1916
                I.SetSrc1Address( RETURN_VALUE_REGISTER);
1917
                I.SetSrc0Address(0);
1918
                I.SetSrc0SwizzleX(SWX_X);
1919
                I.SetSrc0SwizzleY(SWY_X);
1920
                I.SetSrc0SwizzleZ(SWZ_X);
1921
                mInstructions.push_back( I );
1922
                I.Clear();
1923
                ClearNextFunctionParamRegister();
1924
        }
1925
    break;
1926
 
1927
  case 25:
1928
 
1929
/* Line 678 of lalr1.cc  */
1930
#line 1519 "parser.y"
1931
    {
1932
 
1933
                //Store the return address      
1934
                StoreReturnAddress( mInstructions, yylloc );
1935
 
1936
 
1937
                //Store the current SPR_CONTROL_REGISTER.x into the previous SPR_CONTROL_REGISTER.y
1938
                //SPR_CONTROL_REGISTER.y = SPR_CONTROL_REGISTER.xxx + 0;
1939
                I.SetCode( EOPERATION_ADD );
1940
                I.mComment = "store current frame offset";
1941
                I.SetWriteChannel(ECHANNEL_Y);
1942
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
1943
                I.SetSrc1Address(SPR_CONTROL_REGISTER);
1944
                I.SetSrc1SwizzleX(SWX_X);
1945
                I.SetSrc1SwizzleY(SWY_X);
1946
                I.SetSrc1SwizzleZ(SWZ_X);
1947
                I.SetSrc0Address(0);
1948
                I.SetSrc0SwizzleX(SWX_X);
1949
                I.SetSrc0SwizzleY(SWY_X);
1950
                I.SetSrc0SwizzleZ(SWZ_X);
1951
                mInstructions.push_back( I );
1952
                I.Clear();
1953
                //Now uddate the current SPR_CONTROL_REGISTER.x += number of auto variables
1954
                I.SetCode( EOPERATION_ADD );
1955
                I.mComment = "displace next frame offset by the number of auto variables in current frame";
1956
                I.SetWriteChannel(ECHANNEL_X);
1957
                I.SetDestinationAddress( SPR_CONTROL_REGISTER );
1958
                I.SetImm( GetCurretAutoVarFrameSize() );
1959
                I.SetDestZero( false );
1960
                mInstructions.push_back( I );
1961
                I.Clear();
1962
                //Call the function with a JMP
1963
                I.SetCode( EOPERATION_ADD );
1964
                I.mComment = "call the function";
1965
                I.SetBranchFlag( true );
1966
                I.SetBranchType( EBRANCH_ALWAYS );
1967
                //Now do the branch
1968
                if (mSymbolMap.find((yysemantic_stack_[(5) - (1)])) == mSymbolMap.end())
1969
                {
1970
                //      ////std::cout << "Error in line : " << $1 <<" undelcared IDENTIFIER\n";
1971
                        I.SetDestinationSymbol( "@"+(yysemantic_stack_[(5) - (1)]) );
1972
                //      exit(1);
1973
                } else {
1974
                        I.SetDestinationAddress( mSymbolMap[ (yysemantic_stack_[(5) - (1)]) ] );
1975
                }
1976
 
1977
 
1978
                mInstructions.push_back( I );
1979
                I.Clear();
1980
 
1981
        }
1982
    break;
1983
 
1984
  case 27:
1985
 
1986
/* Line 678 of lalr1.cc  */
1987
#line 1578 "parser.y"
1988
    {
1989
                                                AddFunctionInputList( (yysemantic_stack_[(3) - (1)]), mInstructions,yylloc );
1990
                                          }
1991
    break;
1992
 
1993
  case 28:
1994
 
1995
/* Line 678 of lalr1.cc  */
1996
#line 1583 "parser.y"
1997
    {
1998
                                                AddFunctionInputList( (yysemantic_stack_[(1) - (1)]),mInstructions, yylloc );
1999
                                          }
2000
    break;
2001
 
2002
  case 30:
2003
 
2004
/* Line 678 of lalr1.cc  */
2005
#line 1592 "parser.y"
2006
    {
2007
                                                        AddFunctionParameter( (yysemantic_stack_[(3) - (1)]), yylloc );
2008
                                                }
2009
    break;
2010
 
2011
  case 31:
2012
 
2013
/* Line 678 of lalr1.cc  */
2014
#line 1597 "parser.y"
2015
    {
2016
                                                        AddFunctionParameter( (yysemantic_stack_[(1) - (1)]), yylloc );
2017
                                                }
2018
    break;
2019
 
2020
  case 32:
2021
 
2022
/* Line 678 of lalr1.cc  */
2023
#line 1618 "parser.y"
2024
    {
2025
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2026
                        gExtraDestModifications = 0;
2027
 
2028
                        I.SetCode( EOPERATION_ADD );
2029
                        I.SetDestinationAddress( TempRegIndex );
2030
                        I.SetDestZero( true ); //Use indexing for DST
2031
                        I.SetWriteChannel(ECHANNEL_XYZ);
2032
 
2033
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions );
2034
                        mInstructions.push_back(I);
2035
                        gInsertedInstructions++;
2036
                        I.Clear();
2037
 
2038
                        std::stringstream ss;
2039
                        ss << "R" << TempRegIndex << " OFFSET ";
2040
                        (yyval) = ss.str();
2041
 
2042
                }
2043
    break;
2044
 
2045
  case 33:
2046
 
2047
/* Line 678 of lalr1.cc  */
2048
#line 1639 "parser.y"
2049
    {
2050
                        gExtraDestModifications = 0;
2051
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2052
                        I.SetCode( EOPERATION_ADD );
2053
                        I.SetDestinationAddress( TempRegIndex );
2054
                        I.SetDestZero( true ); //Use indexing for DST
2055
                        I.SetWriteChannel(ECHANNEL_XYZ);
2056
                        I.SetSrc0SignX( true );
2057
                        I.SetSrc0SignY( true );
2058
                        I.SetSrc0SignZ( true );
2059
 
2060
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions);
2061
                        mInstructions.push_back(I);
2062
                        gInsertedInstructions++;
2063
                        I.Clear();
2064
 
2065
                        std::stringstream ss;
2066
                        ss << "R" << TempRegIndex << " OFFSET ";
2067
                        (yyval) = ss.str();
2068
                }
2069
    break;
2070
 
2071
  case 34:
2072
 
2073
/* Line 678 of lalr1.cc  */
2074
#line 1661 "parser.y"
2075
    {
2076
                        gExtraDestModifications = 0;
2077
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2078
                        I.SetDestinationAddress( TempRegIndex );
2079
                        I.SetDestZero( true ); //Use indexing for DST
2080
                        I.SetWriteChannel(ECHANNEL_XYZ);
2081
                        I.SetCode( EOPERATION_LOGIC );
2082
                        I.SetLogicOperation( ELOGIC_OR );
2083
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions);
2084
 
2085
 
2086
                        mInstructions.push_back(I);
2087
                        gInsertedInstructions++;
2088
                        I.Clear();
2089
 
2090
                        std::stringstream ss;
2091
                        ss << "R" << TempRegIndex << " OFFSET ";
2092
                        (yyval) = ss.str();
2093
                }
2094
    break;
2095
 
2096
  case 35:
2097
 
2098
/* Line 678 of lalr1.cc  */
2099
#line 1682 "parser.y"
2100
    {
2101
                        (yyval) = (yysemantic_stack_[(1) - (1)]);
2102
                }
2103
    break;
2104
 
2105
  case 36:
2106
 
2107
/* Line 678 of lalr1.cc  */
2108
#line 1690 "parser.y"
2109
    {
2110
                        gExtraDestModifications = 0;
2111
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2112
                        I.SetDestinationAddress( TempRegIndex );
2113
                        I.SetDestZero( true ); //Use indexing for DST
2114
                        I.SetWriteChannel(ECHANNEL_XYZ);
2115
                        I.SetCode( EOPERATION_MUL );
2116
 
2117
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions);
2118
 
2119
                        //If we are using fixed point aritmethic then we need to apply the scale
2120
                        //R = A * ( B >> SCALE)
2121
                        if (mGenerateFixedPointArithmetic)
2122
                                I.SetSrc0Rotation( EROT_RESULT_RIGHT );
2123
 
2124
                        mInstructions.push_back(I);
2125
                        gInsertedInstructions++;
2126
                        I.Clear();
2127
 
2128
                        std::stringstream ss;
2129
                        ss << "R" << TempRegIndex << " OFFSET ";
2130
                        (yyval) = ss.str();
2131
                }
2132
    break;
2133
 
2134
  case 37:
2135
 
2136
/* Line 678 of lalr1.cc  */
2137
#line 1715 "parser.y"
2138
    {
2139
                        gExtraDestModifications = 0;
2140
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2141
                        I.SetDestinationAddress( TempRegIndex );
2142
                        I.SetDestZero( true ); //Use indexing for DST
2143
                        I.SetWriteChannel(ECHANNEL_XYZ);
2144
                        I.SetCode( EOPERATION_DIV );
2145
 
2146
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions);
2147
 
2148
                        //If we are using fixed point aritmethic then we need to apply the scale
2149
                        // R = (A << N) / B
2150
                        if (mGenerateFixedPointArithmetic)
2151
                                I.SetSrc1Rotation( EROT_SRC1_LEFT );
2152
 
2153
                        mInstructions.push_back(I);
2154
                        gInsertedInstructions++;
2155
                        I.Clear();
2156
 
2157
                        std::stringstream ss;
2158
                        ss << "R" << TempRegIndex << " OFFSET ";
2159
                        (yyval) = ss.str();
2160
                }
2161
    break;
2162
 
2163
  case 38:
2164
 
2165
/* Line 678 of lalr1.cc  */
2166
#line 1740 "parser.y"
2167
    {
2168
                        gExtraDestModifications = 0;
2169
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2170
                        I.SetDestinationAddress( TempRegIndex );
2171
                        I.SetDestZero( true ); //Use indexing for DST
2172
                        I.SetWriteChannel(ECHANNEL_XYZ);
2173
                        I.SetCode( EOPERATION_LOGIC );
2174
                        I.SetLogicOperation( ELOGIC_AND );
2175
                        PopulateSourceRegisters( (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions);
2176
 
2177
 
2178
                        mInstructions.push_back(I);
2179
                        gInsertedInstructions++;
2180
                        I.Clear();
2181
 
2182
                        std::stringstream ss;
2183
                        ss << "R" << TempRegIndex << " OFFSET ";
2184
                        (yyval) = ss.str();
2185
                }
2186
    break;
2187
 
2188
  case 39:
2189
 
2190
/* Line 678 of lalr1.cc  */
2191
#line 1761 "parser.y"
2192
    {
2193
                        (yyval) = (yysemantic_stack_[(1) - (1)]);
2194
                }
2195
    break;
2196
 
2197
  case 40:
2198
 
2199
/* Line 678 of lalr1.cc  */
2200
#line 1769 "parser.y"
2201
    {
2202
                        (yyval) = (yysemantic_stack_[(1) - (1)]);
2203
                }
2204
    break;
2205
 
2206
  case 41:
2207
 
2208
/* Line 678 of lalr1.cc  */
2209
#line 1774 "parser.y"
2210
    {
2211
                        gExtraDestModifications = 0;
2212
                        unsigned int TempRegIndex  = GetFreeTempRegister();
2213
                        I.SetDestinationAddress( TempRegIndex );
2214
                        I.SetDestZero( true ); //Use indexing for DST
2215
                        I.SetWriteChannel(ECHANNEL_XYZ);
2216
                        I.SetCode( EOPERATION_SQRT );
2217
                        I.SetSrc0Address( 0 );
2218
                        PopulateSourceRegisters( (yysemantic_stack_[(4) - (3)]) ,"R0 . X X X", I, mInstructions);
2219
                        mInstructions.push_back(I);
2220
                        gInsertedInstructions++;
2221
                        I.Clear();
2222
 
2223
                        std::stringstream ss;
2224
                        ss << "R" << TempRegIndex << " OFFSET ";
2225
                        (yyval) = ss.str();
2226
                }
2227
    break;
2228
 
2229
  case 42:
2230
 
2231
/* Line 678 of lalr1.cc  */
2232
#line 1793 "parser.y"
2233
    {
2234
                        (yyval) = (yysemantic_stack_[(3) - (2)]);
2235
                }
2236
    break;
2237
 
2238
  case 43:
2239
 
2240
/* Line 678 of lalr1.cc  */
2241
#line 1803 "parser.y"
2242
    {
2243
 
2244
                unsigned int ImmediateValue;
2245
                std::string StringHex = (yysemantic_stack_[(1) - (1)]);
2246
                std::stringstream ss;
2247
                ss << std::hex << StringHex;
2248
                ss >> ImmediateValue;
2249
 
2250
                switch (ImmediateValue)
2251
                {
2252
                case 0:
2253
                        (yyval) = "R0 . X X X";
2254
                break;
2255
                case 1:
2256
                        (yyval) = "R0 . Y Y Y";
2257
                break;
2258
                case 2:
2259
                        (yyval) = "R0 . Z Z Z";
2260
                break;
2261
                default:
2262
                        std::string StringHex = (yysemantic_stack_[(1) - (1)]);
2263
                        std::stringstream ss;
2264
                        ss << std::hex << StringHex;
2265
                        ss >> ImmediateValue;
2266
                        (yyval) = ss.str();
2267
                        break;
2268
                }
2269
        }
2270
    break;
2271
 
2272
  case 44:
2273
 
2274
/* Line 678 of lalr1.cc  */
2275
#line 1833 "parser.y"
2276
    {
2277
                unsigned int TempRegIndex  = GetFreeTempRegister();
2278
                unsigned int ImmediateValue;
2279
 
2280
                {
2281
 
2282
                std::string StringHex = (yysemantic_stack_[(7) - (2)]);
2283
                std::stringstream ss;
2284
                ss << std::hex << StringHex;
2285
                ss >> ImmediateValue;
2286
 
2287
 
2288
                I.SetDestinationAddress( TempRegIndex );
2289
                I.SetImm( ImmediateValue );
2290
                I.SetDestZero(true);
2291
                I.SetSrc0Displace(true);
2292
                I.SetWriteChannel(ECHANNEL_X);
2293
                I.SetCode( EOPERATION_ADD );
2294
                mInstructions.push_back(I);
2295
                gInsertedInstructions++;
2296
                I.Clear();
2297
                }
2298
 
2299
                {
2300
                std::string StringHex = (yysemantic_stack_[(7) - (4)]);
2301
                std::stringstream ss;
2302
                ss << std::hex << StringHex;
2303
                ss >> ImmediateValue;
2304
 
2305
                I.SetDestinationAddress( TempRegIndex );
2306
                I.SetImm( ImmediateValue );
2307
                I.SetDestZero(true);
2308
                I.SetSrc0Displace(true);
2309
                I.SetWriteChannel(ECHANNEL_Y);
2310
                I.SetCode( EOPERATION_ADD );
2311
                mInstructions.push_back(I);
2312
                gInsertedInstructions++;
2313
                I.Clear();
2314
                }
2315
 
2316
                {
2317
                std::string StringHex = (yysemantic_stack_[(7) - (6)]);
2318
                std::stringstream ss;
2319
                ss << std::hex << StringHex;
2320
                ss >> ImmediateValue;
2321
 
2322
                I.SetDestinationAddress( TempRegIndex );
2323
                I.SetImm( ImmediateValue );
2324
                I.SetDestZero(true);
2325
                I.SetSrc0Displace(true);
2326
                I.SetWriteChannel(ECHANNEL_Z);
2327
                I.SetCode( EOPERATION_ADD );
2328
                I.mBisonFlagTrippleConstAssign = true;
2329
                mInstructions.push_back(I);
2330
                gInsertedInstructions++;
2331
                I.Clear();
2332
                }
2333
 
2334
                gExtraDestModifications = 2;
2335
                std::stringstream ss2;
2336
                ss2 << "R" << TempRegIndex << " OFFSET ";
2337
                (yyval) = ss2.str();
2338
        }
2339
    break;
2340
 
2341
  case 45:
2342
 
2343
/* Line 678 of lalr1.cc  */
2344
#line 1898 "parser.y"
2345
    {
2346
 
2347
 
2348
                std::string Register;
2349
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(2) - (1)]))) != "NULL")
2350
                        (yyval) = Register;
2351
                 else
2352
                        (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(2) - (1)]), yylloc) + " OFFSET ";
2353
 
2354
                if ((yysemantic_stack_[(2) - (2)]) != "NULL")
2355
                {
2356
 
2357
                        (yyval) += " array_element " + (yysemantic_stack_[(2) - (2)]);
2358
 
2359
                }
2360
        }
2361
    break;
2362
 
2363
  case 46:
2364
 
2365
/* Line 678 of lalr1.cc  */
2366
#line 1916 "parser.y"
2367
    {
2368
 
2369
                std::string X = (yysemantic_stack_[(5) - (3)]),Y = (yysemantic_stack_[(5) - (4)]),Z = (yysemantic_stack_[(5) - (5)]);
2370
                std::string Register;
2371
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(5) - (1)]))) != "NULL")
2372
                        (yyval) = (Register + " . " + " " + X + " " + Y  + " " + Z + " OFFSET ");
2373
                else
2374
                        (yyval) = (GetRegisterFromAutoVar( (yysemantic_stack_[(5) - (1)]), yylloc) + " . " + " " + X + " " + Y  + " " + Z + " OFFSET ");
2375
        }
2376
    break;
2377
 
2378
  case 47:
2379
 
2380
/* Line 678 of lalr1.cc  */
2381
#line 1927 "parser.y"
2382
    {
2383
 
2384
                std::string R = (yysemantic_stack_[(1) - (1)]);
2385
                R.erase(0,1);
2386
                (yyval) = "R" + R;
2387
 
2388
        }
2389
    break;
2390
 
2391
  case 48:
2392
 
2393
/* Line 678 of lalr1.cc  */
2394
#line 1936 "parser.y"
2395
    {
2396
 
2397
                std::string R = (yysemantic_stack_[(4) - (1)]);
2398
                R.erase(0,1);
2399
                (yyval) = "<<R" + R;
2400
        }
2401
    break;
2402
 
2403
  case 49:
2404
 
2405
/* Line 678 of lalr1.cc  */
2406
#line 1944 "parser.y"
2407
    {
2408
 
2409
                std::string R = (yysemantic_stack_[(4) - (1)]);
2410
                R.erase(0,1);
2411
                (yyval) = ">>R" + R;
2412
        }
2413
    break;
2414
 
2415
  case 50:
2416
 
2417
/* Line 678 of lalr1.cc  */
2418
#line 1952 "parser.y"
2419
    {
2420
                std::string R = (yysemantic_stack_[(5) - (1)]);
2421
                std::string X = (yysemantic_stack_[(5) - (3)]),Y = (yysemantic_stack_[(5) - (4)]),Z = (yysemantic_stack_[(5) - (5)]);
2422
                R.erase(0,1);
2423
                (yyval) = "R" + R + " . " + " " + X + " " + Y  + " " + Z;
2424
 
2425
        }
2426
    break;
2427
 
2428
  case 51:
2429
 
2430
/* Line 678 of lalr1.cc  */
2431
#line 1965 "parser.y"
2432
    {
2433
                (yyval) = "X";
2434
        }
2435
    break;
2436
 
2437
  case 52:
2438
 
2439
/* Line 678 of lalr1.cc  */
2440
#line 1970 "parser.y"
2441
    {
2442
                (yyval) = "-X";
2443
        }
2444
    break;
2445
 
2446
  case 53:
2447
 
2448
/* Line 678 of lalr1.cc  */
2449
#line 1975 "parser.y"
2450
    {
2451
                (yyval) = "Y";
2452
        }
2453
    break;
2454
 
2455
  case 54:
2456
 
2457
/* Line 678 of lalr1.cc  */
2458
#line 1980 "parser.y"
2459
    {
2460
                (yyval) = "-Y";
2461
        }
2462
    break;
2463
 
2464
  case 55:
2465
 
2466
/* Line 678 of lalr1.cc  */
2467
#line 1985 "parser.y"
2468
    {
2469
                (yyval) = "Z";
2470
        }
2471
    break;
2472
 
2473
  case 56:
2474
 
2475
/* Line 678 of lalr1.cc  */
2476
#line 1990 "parser.y"
2477
    {
2478
                (yyval) = "-Z";
2479
        }
2480
    break;
2481
 
2482
  case 57:
2483
 
2484
/* Line 678 of lalr1.cc  */
2485
#line 1998 "parser.y"
2486
    {
2487
                (yyval) = "NULL";
2488
        }
2489
    break;
2490
 
2491
  case 58:
2492
 
2493
/* Line 678 of lalr1.cc  */
2494
#line 2003 "parser.y"
2495
    {
2496
                /*std::string Register;
2497
                if ((Register = GetRegisterFromFunctionParameter($2)) != "NULL")
2498
                        $$ = Register;
2499
                else*/
2500
                //Indexes into arrays can only be auto variables!
2501
                (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(3) - (2)]), yylloc );
2502
        }
2503
    break;
2504
 
2505
  case 59:
2506
 
2507
/* Line 678 of lalr1.cc  */
2508
#line 2016 "parser.y"
2509
    {
2510
 
2511
                (yyval) = "OUT " + (yysemantic_stack_[(4) - (3)]);
2512
        }
2513
    break;
2514
 
2515
  case 60:
2516
 
2517
/* Line 678 of lalr1.cc  */
2518
#line 2022 "parser.y"
2519
    {
2520
                std::string Register;
2521
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(4) - (3)]))) == "NULL")
2522
                        Register = GetRegisterFromAutoVar( (yysemantic_stack_[(4) - (3)]), yylloc );
2523
 
2524
                (yyval) = "OUT INDEX" + Register;
2525
        }
2526
    break;
2527
 
2528
  case 61:
2529
 
2530
/* Line 678 of lalr1.cc  */
2531
#line 2031 "parser.y"
2532
    {
2533
 
2534
                std::string Register;
2535
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(2) - (1)]))) != "NULL")
2536
                        (yyval) = Register + ".xyz";
2537
                else
2538
                        (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(2) - (1)]), yylloc ) + ".xyz" + " OFFSET " + (((yysemantic_stack_[(2) - (2)]) != "NULL")?" INDEX"+(yysemantic_stack_[(2) - (2)]):"");
2539
 
2540
        }
2541
    break;
2542
 
2543
  case 62:
2544
 
2545
/* Line 678 of lalr1.cc  */
2546
#line 2042 "parser.y"
2547
    {
2548
                std::string Register;
2549
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(3) - (1)]))) != "NULL")
2550
                        (yyval) = Register + ".x";
2551
                else
2552
                (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(3) - (1)]), yylloc ) + ".x" + " OFFSET ";
2553
        }
2554
    break;
2555
 
2556
  case 63:
2557
 
2558
/* Line 678 of lalr1.cc  */
2559
#line 2051 "parser.y"
2560
    {
2561
                std::string Register;
2562
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(3) - (1)]))) != "NULL")
2563
                        (yyval) = Register + ".y";
2564
                else
2565
                        (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(3) - (1)]), yylloc ) + ".y" + " OFFSET ";
2566
        }
2567
    break;
2568
 
2569
  case 64:
2570
 
2571
/* Line 678 of lalr1.cc  */
2572
#line 2060 "parser.y"
2573
    {
2574
                std::string Register;
2575
                if ((Register = GetRegisterFromFunctionParameter((yysemantic_stack_[(3) - (1)]))) != "NULL")
2576
                        (yyval) = Register + ".z";
2577
                else
2578
                        (yyval) = GetRegisterFromAutoVar( (yysemantic_stack_[(3) - (1)]), yylloc ) + ".z" + " OFFSET ";
2579
        }
2580
    break;
2581
 
2582
  case 65:
2583
 
2584
/* Line 678 of lalr1.cc  */
2585
#line 2069 "parser.y"
2586
    {
2587
                std::string R = (yysemantic_stack_[(1) - (1)]);
2588
                R.erase(0,1);
2589
                (yyval) = "R" + R + ".xyz";
2590
        }
2591
    break;
2592
 
2593
  case 66:
2594
 
2595
/* Line 678 of lalr1.cc  */
2596
#line 2076 "parser.y"
2597
    {
2598
                std::string R = (yysemantic_stack_[(3) - (1)]);
2599
                R.erase(0,1);
2600
                (yyval) = "R" + R + ".x";
2601
        }
2602
    break;
2603
 
2604
  case 67:
2605
 
2606
/* Line 678 of lalr1.cc  */
2607
#line 2083 "parser.y"
2608
    {
2609
                std::string R = (yysemantic_stack_[(3) - (1)]);
2610
                R.erase(0,1);
2611
                (yyval) = "R" + R + ".y";
2612
        }
2613
    break;
2614
 
2615
  case 68:
2616
 
2617
/* Line 678 of lalr1.cc  */
2618
#line 2090 "parser.y"
2619
    {
2620
 
2621
                std::string R = (yysemantic_stack_[(3) - (1)]);
2622
                R.erase(0,1);
2623
                (yyval) = "R" + R + ".z";
2624
        }
2625
    break;
2626
 
2627
  case 69:
2628
 
2629
/* Line 678 of lalr1.cc  */
2630
#line 2098 "parser.y"
2631
    {
2632
                std::string R = (yysemantic_stack_[(5) - (1)]);
2633
                R.erase(0,1);
2634
                (yyval) = "R" + R + ".xy";
2635
        }
2636
    break;
2637
 
2638
  case 70:
2639
 
2640
/* Line 678 of lalr1.cc  */
2641
#line 2105 "parser.y"
2642
    {
2643
                std::string R = (yysemantic_stack_[(5) - (1)]);
2644
                R.erase(0,1);
2645
                (yyval) = "R" + R + ".xz";
2646
        }
2647
    break;
2648
 
2649
  case 71:
2650
 
2651
/* Line 678 of lalr1.cc  */
2652
#line 2112 "parser.y"
2653
    {
2654
                std::string R = (yysemantic_stack_[(5) - (1)]);
2655
                R.erase(0,1);
2656
                (yyval) = "R" + R + ".yz";
2657
        }
2658
    break;
2659
 
2660
  case 72:
2661
 
2662
/* Line 678 of lalr1.cc  */
2663
#line 2123 "parser.y"
2664
    {
2665
                                        PopulateBoolean(EBRANCH_IF_ZERO, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2666
 
2667
                                }
2668
    break;
2669
 
2670
  case 73:
2671
 
2672
/* Line 678 of lalr1.cc  */
2673
#line 2129 "parser.y"
2674
    {
2675
                                        PopulateBoolean(EBRANCH_IF_NOT_ZERO, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2676
 
2677
                                }
2678
    break;
2679
 
2680
  case 74:
2681
 
2682
/* Line 678 of lalr1.cc  */
2683
#line 2135 "parser.y"
2684
    {
2685
                                        PopulateBoolean(EBRANCH_IF_ZERO_OR_SIGN, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2686
 
2687
                                }
2688
    break;
2689
 
2690
  case 75:
2691
 
2692
/* Line 678 of lalr1.cc  */
2693
#line 2142 "parser.y"
2694
    {
2695
                                        PopulateBoolean(EBRANCH_IF_ZERO_OR_NOT_SIGN, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2696
 
2697
                                }
2698
    break;
2699
 
2700
  case 76:
2701
 
2702
/* Line 678 of lalr1.cc  */
2703
#line 2148 "parser.y"
2704
    {
2705
                                        PopulateBoolean(EBRANCH_IF_NOT_SIGN, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2706
 
2707
                                }
2708
    break;
2709
 
2710
  case 77:
2711
 
2712
/* Line 678 of lalr1.cc  */
2713
#line 2154 "parser.y"
2714
    {
2715
                                        PopulateBoolean(EBRANCH_IF_SIGN, (yysemantic_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (3)]), I, mInstructions, yylloc );
2716
 
2717
                                }
2718
    break;
2719
 
2720
  case 78:
2721
 
2722
/* Line 678 of lalr1.cc  */
2723
#line 2163 "parser.y"
2724
    {
2725
                        // Transform to HEX string
2726
                        unsigned int Val;
2727
                        std::string StringDec = (yysemantic_stack_[(1) - (1)]);
2728
                        std::stringstream ss;
2729
                        ss << StringDec;
2730
                        ss >> Val;
2731
                        std::stringstream ss2;
2732
                        ss2 << std::hex << Val;
2733
                        (yyval) = ss2.str();
2734
                }
2735
    break;
2736
 
2737
  case 79:
2738
 
2739
/* Line 678 of lalr1.cc  */
2740
#line 2176 "parser.y"
2741
    {
2742
                        std::string StringHex = (yysemantic_stack_[(1) - (1)]);
2743
                        // Get rid of the 0x
2744
                        StringHex.erase(StringHex.begin(),StringHex.begin()+2);
2745
                        std::stringstream ss;
2746
                        ss << std::hex << StringHex;
2747
 
2748
                        (yyval) = ss.str();
2749
                }
2750
    break;
2751
 
2752
  case 80:
2753
 
2754
/* Line 678 of lalr1.cc  */
2755
#line 2187 "parser.y"
2756
    {
2757
                        // Transform to HEX string
2758
                        std::string StringBin = (yysemantic_stack_[(1) - (1)]);
2759
                        // Get rid of the 0b
2760
                        StringBin.erase(StringBin.begin(),StringBin.begin()+2);
2761
                        std::bitset<32> Bitset( StringBin );
2762
                        std::stringstream ss2;
2763
                        ss2 << std::hex <<  Bitset.to_ulong();
2764
                        (yyval) = ss2.str();
2765
                }
2766
    break;
2767
 
2768
  case 81:
2769
 
2770
/* Line 678 of lalr1.cc  */
2771
#line 2201 "parser.y"
2772
    {
2773
                                if (gAutoVarMap.find((yysemantic_stack_[(4) - (1)])) != gAutoVarMap.end())
2774
                                {
2775
                                        std::ostringstream ret;
2776
                                        ret << "Duplicated symbol '" << (yysemantic_stack_[(4) - (1)]) << "'\n";
2777
                                        throw ret.str();
2778
                                }
2779
 
2780
                                std::stringstream ss;
2781
                                ss << (yysemantic_stack_[(4) - (2)]);
2782
                                unsigned int Size;
2783
                                ss >> Size;
2784
                                gAutoVarMap[ (yysemantic_stack_[(4) - (1)]) ] = AllocAutoVar(Size);
2785
                        }
2786
    break;
2787
 
2788
  case 82:
2789
 
2790
/* Line 678 of lalr1.cc  */
2791
#line 2217 "parser.y"
2792
    {
2793
                                if (gAutoVarMap.find((yysemantic_stack_[(11) - (1)])) != gAutoVarMap.end())
2794
                                {
2795
                                std::ostringstream ret;
2796
                                ret << "Duplicated symbol " << (yysemantic_stack_[(11) - (1)]) << "'\n";
2797
                                throw ret.str();
2798
                                }
2799
                                gAutoVarMap[ (yysemantic_stack_[(11) - (1)]) ] = AllocAutoVar();
2800
 
2801
                                unsigned int Destination = gAutoVarMap[ (yysemantic_stack_[(11) - (1)]) ];
2802
 
2803
 
2804
 
2805
                                I.ClearWriteChannel();
2806
                                unsigned int ImmediateValue;
2807
                                {
2808
                                I.SetDestinationAddress( Destination );
2809
                                I.SetWriteChannel(ECHANNEL_X);
2810
                                std::string StringHex = (yysemantic_stack_[(11) - (4)]);
2811
                                std::stringstream ss;
2812
                                ss << std::hex << StringHex;
2813
                                ss >> ImmediateValue;
2814
                                I.SetImm( ImmediateValue );
2815
                                I.SetDestZero( true );
2816
                                I.SetSrc1Displace( false );
2817
                                I.SetSrc0Displace( true );
2818
                                I.SetCode( EOPERATION_ADD );
2819
                                I.mSourceLine = GetCurrentLineNumber( yylloc );
2820
                                mInstructions.push_back(I);
2821
                                I.Clear();
2822
                                }
2823
                                {
2824
                                I.SetDestinationAddress( Destination );
2825
                                I.SetWriteChannel(ECHANNEL_Y);
2826
                                std::string StringHex = (yysemantic_stack_[(11) - (6)]);
2827
                                std::stringstream ss;
2828
                                ss << std::hex << StringHex;
2829
                                ss >> ImmediateValue;
2830
                                I.SetImm( ImmediateValue );
2831
                                I.SetDestZero( true );
2832
                                I.SetSrc1Displace( false );
2833
                                I.SetSrc0Displace( true );
2834
                                I.SetCode( EOPERATION_ADD );
2835
                                mInstructions.push_back(I);
2836
                                I.Clear();
2837
                                }
2838
                                {
2839
                                I.SetDestinationAddress( Destination );
2840
                                I.SetWriteChannel(ECHANNEL_Z);
2841
                                std::string StringHex = (yysemantic_stack_[(11) - (8)]);
2842
                                std::stringstream ss;
2843
                                ss << std::hex << StringHex;
2844
                                ss >> ImmediateValue;
2845
                                I.SetImm( ImmediateValue );
2846
                                I.SetDestZero( true );
2847
                                I.SetSrc1Displace( false );
2848
                                I.SetSrc0Displace( true );
2849
                                I.SetCode( EOPERATION_ADD );
2850
                                mInstructions.push_back(I);
2851
                                I.Clear();
2852
                                }
2853
                        }
2854
    break;
2855
 
2856
  case 83:
2857
 
2858
/* Line 678 of lalr1.cc  */
2859
#line 2281 "parser.y"
2860
    {
2861
                                if (gAutoVarMap.find((yysemantic_stack_[(9) - (1)])) != gAutoVarMap.end())
2862
                                {
2863
                                std::ostringstream ret;
2864
                                ret << "Duplicated symbol " << (yysemantic_stack_[(9) - (1)]) << "'\n";
2865
                                throw ret.str();
2866
                                }
2867
                                gAutoVarMap[ (yysemantic_stack_[(9) - (1)]) ] = AllocAutoVar();
2868
 
2869
                                unsigned int Destination = gAutoVarMap[ (yysemantic_stack_[(9) - (1)]) ];
2870
 
2871
 
2872
                                I.SetDestZero( true );
2873
                                I.SetSrc1Displace( false );
2874
                                I.SetSrc0Displace( true );
2875
 
2876
 
2877
                                I.ClearWriteChannel();
2878
                                unsigned int ImmediateValue;
2879
                                {
2880
                                I.SetDestinationAddress( Destination );
2881
                                I.SetWriteChannel(ECHANNEL_X);
2882
                                std::string StringHex = (yysemantic_stack_[(9) - (4)]);
2883
                                std::stringstream ss;
2884
                                ss << std::hex << StringHex;
2885
                                ss >> ImmediateValue;
2886
                                I.SetImm( ImmediateValue );
2887
                                I.SetDestZero( true );
2888
                                I.SetSrc1Displace( false );
2889
                                I.SetSrc0Displace( true );
2890
                                I.SetCode( EOPERATION_ADD );
2891
                                I.mSourceLine = GetCurrentLineNumber( yylloc );
2892
                                mInstructions.push_back(I);
2893
                                I.Clear();
2894
                                }
2895
                                {
2896
                                I.SetDestinationAddress( Destination );
2897
                                I.SetWriteChannel(ECHANNEL_Y);
2898
                                std::string StringHex = (yysemantic_stack_[(9) - (6)]);
2899
                                std::stringstream ss;
2900
                                ss << std::hex << StringHex;
2901
                                ss >> ImmediateValue;
2902
                                I.SetImm( ImmediateValue );
2903
                                I.SetDestZero( true );
2904
                                I.SetSrc1Displace( false );
2905
                                I.SetSrc0Displace( true );
2906
                                I.SetCode( EOPERATION_ADD );
2907
                                mInstructions.push_back(I);
2908
                                I.Clear();
2909
                                }
2910
                                {
2911
                                I.SetDestinationAddress( Destination );
2912
                                I.SetWriteChannel(ECHANNEL_Z);
2913
                                std::string StringHex = (yysemantic_stack_[(9) - (8)]);
2914
                                std::stringstream ss;
2915
                                ss << std::hex << StringHex;
2916
                                ss >> ImmediateValue;
2917
                                I.SetImm( ImmediateValue );
2918
                                I.SetDestZero( true );
2919
                                I.SetSrc1Displace( false );
2920
                                I.SetSrc0Displace( true );
2921
                                I.SetCode( EOPERATION_ADD );
2922
                                mInstructions.push_back(I);
2923
                                I.Clear();
2924
                                }
2925
                        }
2926
    break;
2927
 
2928
  case 84:
2929
 
2930
/* Line 678 of lalr1.cc  */
2931
#line 2349 "parser.y"
2932
    {
2933
 
2934
                                if (gAutoVarMap.find((yysemantic_stack_[(2) - (1)])) != gAutoVarMap.end())
2935
                                {
2936
                                        std::ostringstream ret;
2937
                                        ret << "Duplicated symbol " << (yysemantic_stack_[(2) - (1)]) << "'\n";
2938
                                        throw ret.str();
2939
                                }
2940
                                std::stringstream ss;
2941
                                ss << std::hex << (yysemantic_stack_[(2) - (2)]);
2942
                                unsigned int Size;
2943
                                ss >> Size;
2944
                                ////std::cout  << "Array Size is " << Size << " " << $2 << "\n";
2945
                                gAutoVarMap[ (yysemantic_stack_[(2) - (1)]) ] = AllocAutoVar(Size);
2946
                        }
2947
    break;
2948
 
2949
  case 85:
2950
 
2951
/* Line 678 of lalr1.cc  */
2952
#line 2368 "parser.y"
2953
    {
2954
                 (yyval) = "1";
2955
                 }
2956
    break;
2957
 
2958
  case 86:
2959
 
2960
/* Line 678 of lalr1.cc  */
2961
#line 2373 "parser.y"
2962
    {
2963
 
2964
                 (yyval) = (yysemantic_stack_[(3) - (2)]);
2965
                 }
2966
    break;
2967
 
2968
 
2969
 
2970
/* Line 678 of lalr1.cc  */
2971
#line 2972 "parser.tab.c"
2972
        default:
2973
          break;
2974
      }
2975
    YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
2976
 
2977
    yypop_ (yylen);
2978
    yylen = 0;
2979
    YY_STACK_PRINT ();
2980
 
2981
    yysemantic_stack_.push (yyval);
2982
    yylocation_stack_.push (yyloc);
2983
 
2984
    /* Shift the result of the reduction.  */
2985
    yyn = yyr1_[yyn];
2986
    yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
2987
    if (0 <= yystate && yystate <= yylast_
2988
        && yycheck_[yystate] == yystate_stack_[0])
2989
      yystate = yytable_[yystate];
2990
    else
2991
      yystate = yydefgoto_[yyn - yyntokens_];
2992
    goto yynewstate;
2993
 
2994
  /*------------------------------------.
2995
  | yyerrlab -- here on detecting error |
2996
  `------------------------------------*/
2997
  yyerrlab:
2998
    /* If not already recovering from an error, report this error.  */
2999
    if (!yyerrstatus_)
3000
      {
3001
        ++yynerrs_;
3002
        error (yylloc, yysyntax_error_ (yystate, yytoken));
3003
      }
3004
 
3005
    yyerror_range[0] = yylloc;
3006
    if (yyerrstatus_ == 3)
3007
      {
3008
        /* If just tried and failed to reuse lookahead token after an
3009
         error, discard it.  */
3010
 
3011
        if (yychar <= yyeof_)
3012
          {
3013
          /* Return failure if at end of input.  */
3014
          if (yychar == yyeof_)
3015
            YYABORT;
3016
          }
3017
        else
3018
          {
3019
            yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
3020
            yychar = yyempty_;
3021
          }
3022
      }
3023
 
3024
    /* Else will try to reuse lookahead token after shifting the error
3025
       token.  */
3026
    goto yyerrlab1;
3027
 
3028
 
3029
  /*---------------------------------------------------.
3030
  | yyerrorlab -- error raised explicitly by YYERROR.  |
3031
  `---------------------------------------------------*/
3032
  yyerrorlab:
3033
 
3034
    /* Pacify compilers like GCC when the user code never invokes
3035
       YYERROR and the label yyerrorlab therefore never appears in user
3036
       code.  */
3037
    if (false)
3038
      goto yyerrorlab;
3039
 
3040
    yyerror_range[0] = yylocation_stack_[yylen - 1];
3041
    /* Do not reclaim the symbols of the rule which action triggered
3042
       this YYERROR.  */
3043
    yypop_ (yylen);
3044
    yylen = 0;
3045
    yystate = yystate_stack_[0];
3046
    goto yyerrlab1;
3047
 
3048
  /*-------------------------------------------------------------.
3049
  | yyerrlab1 -- common code for both syntax error and YYERROR.  |
3050
  `-------------------------------------------------------------*/
3051
  yyerrlab1:
3052
    yyerrstatus_ = 3;   /* Each real token shifted decrements this.  */
3053
 
3054
    for (;;)
3055
      {
3056
        yyn = yypact_[yystate];
3057
        if (yyn != yypact_ninf_)
3058
        {
3059
          yyn += yyterror_;
3060
          if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
3061
            {
3062
              yyn = yytable_[yyn];
3063
              if (0 < yyn)
3064
                break;
3065
            }
3066
        }
3067
 
3068
        /* Pop the current state because it cannot handle the error token.  */
3069
        if (yystate_stack_.height () == 1)
3070
        YYABORT;
3071
 
3072
        yyerror_range[0] = yylocation_stack_[0];
3073
        yydestruct_ ("Error: popping",
3074
                     yystos_[yystate],
3075
                     &yysemantic_stack_[0], &yylocation_stack_[0]);
3076
        yypop_ ();
3077
        yystate = yystate_stack_[0];
3078
        YY_STACK_PRINT ();
3079
      }
3080
 
3081
    yyerror_range[1] = yylloc;
3082
    // Using YYLLOC is tempting, but would change the location of
3083
    // the lookahead.  YYLOC is available though.
3084
    YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
3085
    yysemantic_stack_.push (yylval);
3086
    yylocation_stack_.push (yyloc);
3087
 
3088
    /* Shift the error token.  */
3089
    YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
3090
                     &yysemantic_stack_[0], &yylocation_stack_[0]);
3091
 
3092
    yystate = yyn;
3093
    goto yynewstate;
3094
 
3095
    /* Accept.  */
3096
  yyacceptlab:
3097
    yyresult = 0;
3098
    goto yyreturn;
3099
 
3100
    /* Abort.  */
3101
  yyabortlab:
3102
    yyresult = 1;
3103
    goto yyreturn;
3104
 
3105
  yyreturn:
3106
    if (yychar != yyempty_)
3107
      yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
3108
 
3109
    /* Do not reclaim the symbols of the rule which action triggered
3110
       this YYABORT or YYACCEPT.  */
3111
    yypop_ (yylen);
3112
    while (yystate_stack_.height () != 1)
3113
      {
3114
        yydestruct_ ("Cleanup: popping",
3115
                   yystos_[yystate_stack_[0]],
3116
                   &yysemantic_stack_[0],
3117
                   &yylocation_stack_[0]);
3118
        yypop_ ();
3119
      }
3120
 
3121
    return yyresult;
3122
  }
3123
 
3124
  // Generate an error message.
3125
  std::string
3126
  Parser::yysyntax_error_ (int yystate, int tok)
3127
  {
3128
    std::string res;
3129
    YYUSE (yystate);
3130
#if YYERROR_VERBOSE
3131
    int yyn = yypact_[yystate];
3132
    if (yypact_ninf_ < yyn && yyn <= yylast_)
3133
      {
3134
        /* Start YYX at -YYN if negative to avoid negative indexes in
3135
           YYCHECK.  */
3136
        int yyxbegin = yyn < 0 ? -yyn : 0;
3137
 
3138
        /* Stay within bounds of both yycheck and yytname.  */
3139
        int yychecklim = yylast_ - yyn + 1;
3140
        int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
3141
        int count = 0;
3142
        for (int x = yyxbegin; x < yyxend; ++x)
3143
          if (yycheck_[x + yyn] == x && x != yyterror_)
3144
            ++count;
3145
 
3146
        // FIXME: This method of building the message is not compatible
3147
        // with internationalization.  It should work like yacc.c does it.
3148
        // That is, first build a string that looks like this:
3149
        // "syntax error, unexpected %s or %s or %s"
3150
        // Then, invoke YY_ on this string.
3151
        // Finally, use the string as a format to output
3152
        // yytname_[tok], etc.
3153
        // Until this gets fixed, this message appears in English only.
3154
        res = "syntax error, unexpected ";
3155
        res += yytnamerr_ (yytname_[tok]);
3156
        if (count < 5)
3157
          {
3158
            count = 0;
3159
            for (int x = yyxbegin; x < yyxend; ++x)
3160
              if (yycheck_[x + yyn] == x && x != yyterror_)
3161
                {
3162
                  res += (!count++) ? ", expecting " : " or ";
3163
                  res += yytnamerr_ (yytname_[x]);
3164
                }
3165
          }
3166
      }
3167
    else
3168
#endif
3169
      res = YY_("syntax error");
3170
    return res;
3171
  }
3172
 
3173
 
3174
  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
3175
     STATE-NUM.  */
3176
  const signed char Parser::yypact_ninf_ = -121;
3177
  const short int
3178
  Parser::yypact_[] =
3179
  {
3180
       216,   -26,   243,   -19,   -14,     3,    19,   -11,    27,  -121,
3181
      20,    33,    29,     7,  -121,    50,    68,    45,   248,  -121,
3182
    -121,  -121,  -121,    48,   -22,    59,    71,    75,    54,     8,
3183
    -121,  -121,  -121,   108,  -121,   248,   184,   248,   153,    81,
3184
    -121,   104,   117,   122,   126,   134,  -121,  -121,   271,   121,
3185
     123,   173,   135,   173,   114,  -121,    15,   115,   195,   195,
3186
    -121,   248,   127,   133,   248,  -121,   248,   248,   248,   248,
3187
     248,   138,    14,   157,   103,  -121,  -121,   148,   164,   100,
3188
    -121,  -121,  -121,   145,  -121,   248,   174,   175,   151,   158,
3189
      24,    57,   182,   183,   185,   173,   179,   -26,  -121,   173,
3190
     205,  -121,  -121,  -121,   195,   195,    16,   211,   212,     8,
3191
       8,     8,  -121,  -121,  -121,   190,   215,   248,   248,   248,
3192
     248,   248,   248,   224,   214,   220,   221,   217,   248,  -121,
3193
     231,  -121,   227,  -121,  -121,   248,  -121,  -121,  -121,  -121,
3194
     230,  -121,  -121,   234,  -121,  -121,  -121,   195,   195,  -121,
3195
    -121,  -121,   138,  -121,    86,    86,    86,    86,    86,    86,
3196
     216,  -121,  -121,  -121,  -121,  -121,   238,   239,  -121,   241,
3197
     173,   173,  -121,  -121,  -121,   247,    55,   216,   216,   249,
3198
     250,   244,   216,   273,    93,   143,  -121,   173,  -121,   161,
3199
    -121,  -121,  -121,   272,  -121,   274,   252,   216,   -26,   199,
3200
    -121,  -121
3201
  };
3202
 
3203
  /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
3204
     doesn't specify something else to do.  Zero means the default is an
3205
     error.  */
3206
  const unsigned char
3207
  Parser::yydefact_[] =
3208
  {
3209
         2,     0,     0,     0,     0,     0,    65,    57,     0,    14,
3210
       0,     0,     0,     0,     4,     0,    85,     0,     0,    78,
3211
      79,    80,     9,    47,    57,     0,     0,     0,     0,    35,
3212
      39,    40,    43,     0,     7,     0,     0,    26,     0,     0,
3213
      61,     0,     0,     0,     0,     0,     1,     3,     0,     0,
3214
       0,     0,     0,     0,    84,     5,     0,    43,     0,     0,
3215
      45,     0,     0,     0,     0,     8,     0,     0,     0,     0,
3216
       0,    29,     0,     0,    66,    67,    68,     0,     0,    28,
3217
      62,    63,    64,     0,     6,     0,     0,     0,     0,     0,
3218
      57,     0,     0,     0,     0,     0,     0,     0,    42,     0,
3219
       0,    51,    53,    55,     0,     0,     0,     0,     0,    32,
3220
      33,    34,    37,    36,    38,    31,     0,     0,     0,     0,
3221
       0,     0,     0,     0,     0,     0,     0,     0,    26,    58,
3222
       0,    21,     0,    60,    59,    26,    13,    12,    11,    10,
3223
       0,    86,    81,     0,    52,    54,    56,     0,     0,    41,
3224
      48,    49,    29,    19,    73,    72,    74,    75,    76,    77,
3225
       2,    69,    70,    71,    25,    27,     0,     0,    23,     0,
3226
       0,     0,    50,    46,    30,     0,     0,     2,     2,     0,
3227
       0,     0,     2,    18,     0,     0,    24,     0,    44,     0,
3228
      16,    15,    22,     0,    20,     0,    83,     2,     0,     0,
3229
      82,    17
3230
  };
3231
 
3232
  /* YYPGOTO[NTERM-NUM].  */
3233
  const short int
3234
  Parser::yypgoto_[] =
3235
  {
3236
      -121,   -52,   -13,  -121,  -121,  -121,  -121,  -120,   142,     0,
3237
      47,   171,  -121,   -55,   283,  -121,   213,   -17,   -94,  -121
3238
  };
3239
 
3240
  /* YYDEFGOTO[NTERM-NUM].  */
3241
  const short int
3242
  Parser::yydefgoto_[] =
3243
  {
3244
        -1,    13,    14,    42,   195,   175,   167,    78,   116,    79,
3245
      29,    30,    31,   104,    60,    15,    73,    32,    17,    54
3246
  };
3247
 
3248
  /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
3249
     positive, shift that token.  If negative, reduce the rule which
3250
     number is the opposite.  If zero, do what YYDEFACT says.  */
3251
  const signed char Parser::yytable_ninf_ = -1;
3252
  const unsigned char
3253
  Parser::yytable_[] =
3254
  {
3255
        47,    57,    28,   142,   105,    37,    59,    46,   165,    16,
3256
       1,     2,     3,    34,     4,   169,    33,    38,    56,    35,
3257
      39,     5,   117,   118,   119,   120,   121,   122,    89,    68,
3258
      69,    39,    98,   149,    94,    72,    96,    64,    64,    64,
3259
     135,     6,     7,    66,    66,    66,     8,    36,    91,   147,
3260
     148,     9,    59,    10,    11,    43,    70,    12,     1,     2,
3261
       3,   106,     4,    67,    67,    67,    39,    41,    44,     5,
3262
      48,    45,    55,    49,   183,    61,    58,    64,   140,    50,
3263
      64,    65,   143,    66,   136,    72,    66,    62,    52,     6,
3264
       7,    63,   172,   173,     8,    51,     1,     2,     3,     9,
3265
       4,    10,    11,    67,   200,    12,    67,     5,   176,    64,
3266
      53,   109,   191,   110,   111,    66,    83,   154,   155,   156,
3267
     157,   158,   159,    64,    71,   184,   185,     6,     7,    66,
3268
     189,    84,     8,    85,   124,    67,   125,     9,    86,    10,
3269
      11,   128,    87,    12,    92,   199,     1,     2,     3,    67,
3270
       4,    95,    93,   180,   181,    97,    99,     5,    19,    20,
3271
      21,   107,   192,    47,     1,     2,     3,   108,     4,    88,
3272
     193,    47,    47,   115,   123,     5,    47,     6,     7,   126,
3273
     194,   127,     8,    80,    81,    82,    47,     9,   129,    10,
3274
      11,   131,   132,    12,   133,     6,     7,    19,    20,    21,
3275
       8,   134,     1,     2,     3,     9,     4,    10,    11,   137,
3276
     138,    12,   139,     5,    74,    75,    76,    77,   201,     1,
3277
       2,     3,   141,     4,   100,   101,   102,   103,   150,   151,
3278
       5,   152,   153,     6,     7,   144,   145,   146,     8,   112,
3279
     113,   114,   160,     9,   164,    10,    11,   161,   166,    12,
3280
       6,     7,   162,   163,   168,     8,   177,   178,   179,    18,
3281
       9,   188,    10,    11,    18,   182,    12,    19,    20,    21,
3282
      22,   170,    19,    20,    21,   171,   186,    23,    24,    25,
3283
      26,    27,    23,    24,    25,    26,    27,    18,   190,   196,
3284
      40,   187,   197,   198,   174,    19,    20,    21,   130,     0,
3285
       0,     0,     0,     0,     0,    23,    90,    25,    26,    27
3286
  };
3287
 
3288
  /* YYCHECK.  */
3289
  const short int
3290
  Parser::yycheck_[] =
3291
  {
3292
        13,    18,     2,    97,    59,    16,    28,     0,   128,    35,
3293
       3,     4,     5,    27,     7,   135,    35,    28,    18,    16,
3294
      42,    14,     8,     9,    10,    11,    12,    13,    45,    21,
3295
      22,    42,    17,    17,    51,    35,    53,    23,    23,    23,
3296
      16,    34,    35,    29,    29,    29,    39,    28,    48,   104,
3297
     105,    44,    28,    46,    47,    35,    48,    50,     3,     4,
3298
       5,    61,     7,    49,    49,    49,    42,    40,    35,    14,
3299
      20,    42,    27,    23,    19,    16,    28,    23,    95,    29,
3300
      23,    27,    99,    29,    27,    85,    29,    16,    20,    34,
3301
      35,    16,   147,   148,    39,    45,     3,     4,     5,    44,
3302
       7,    46,    47,    49,   198,    50,    49,    14,   160,    23,
3303
      42,    64,    19,    66,    67,    29,    35,   117,   118,   119,
3304
     120,   121,   122,    23,    16,   177,   178,    34,    35,    29,
3305
     182,    27,    39,    16,    31,    49,    33,    44,    16,    46,
3306
      47,    41,    16,    50,    23,   197,     3,     4,     5,    49,
3307
       7,    16,    29,   170,   171,    41,    41,    14,    24,    25,
3308
      26,    34,    19,   176,     3,     4,     5,    34,     7,    35,
3309
     187,   184,   185,    35,    17,    14,   189,    34,    35,    31,
3310
      19,    17,    39,    30,    31,    32,   199,    44,    43,    46,
3311
      47,    17,    17,    50,    43,    34,    35,    24,    25,    26,
3312
      39,    43,     3,     4,     5,    44,     7,    46,    47,    27,
3313
      27,    50,    27,    14,    30,    31,    32,    33,    19,     3,
3314
       4,     5,    43,     7,    29,    30,    31,    32,    17,    17,
3315
      14,    41,    17,    34,    35,    30,    31,    32,    39,    68,
3316
      69,    70,    18,    44,    27,    46,    47,    33,    17,    50,
3317
      34,    35,    32,    32,    27,    39,    18,    18,    17,    16,
3318
      44,    17,    46,    47,    16,    18,    50,    24,    25,    26,
3319
      27,    41,    24,    25,    26,    41,    27,    34,    35,    36,
3320
      37,    38,    34,    35,    36,    37,    38,    16,    15,    17,
3321
       7,    41,    18,    41,   152,    24,    25,    26,    85,    -1,
3322
      -1,    -1,    -1,    -1,    -1,    34,    35,    36,    37,    38
3323
  };
3324
 
3325
  /* STOS_[STATE-NUM] -- The (internal number of the) accessing
3326
     symbol of state STATE-NUM.  */
3327
  const unsigned char
3328
  Parser::yystos_[] =
3329
  {
3330
         0,     3,     4,     5,     7,    14,    34,    35,    39,    44,
3331
      46,    47,    50,    52,    53,    66,    35,    69,    16,    24,
3332
      25,    26,    27,    34,    35,    36,    37,    38,    60,    61,
3333
      62,    63,    68,    35,    27,    16,    28,    16,    28,    42,
3334
      65,    40,    54,    35,    35,    42,     0,    53,    20,    23,
3335
      29,    45,    20,    42,    70,    27,    60,    68,    28,    28,
3336
      65,    16,    16,    16,    23,    27,    29,    49,    21,    22,
3337
      48,    16,    60,    67,    30,    31,    32,    33,    58,    60,
3338
      30,    31,    32,    35,    27,    16,    16,    16,    35,    68,
3339
      35,    60,    23,    29,    68,    16,    68,    41,    17,    41,
3340
      29,    30,    31,    32,    64,    64,    60,    34,    34,    61,
3341
      61,    61,    62,    62,    62,    35,    59,     8,     9,    10,
3342
      11,    12,    13,    17,    31,    33,    31,    17,    41,    43,
3343
      67,    17,    17,    43,    43,    16,    27,    27,    27,    27,
3344
      68,    43,    69,    68,    30,    31,    32,    64,    64,    17,
3345
      17,    17,    41,    17,    60,    60,    60,    60,    60,    60,
3346
      18,    33,    32,    32,    27,    58,    17,    57,    27,    58,
3347
      41,    41,    64,    64,    59,    56,    52,    18,    18,    17,
3348
      68,    68,    18,    19,    52,    52,    27,    41,    17,    52,
3349
      15,    19,    19,    68,    19,    55,    17,    18,    41,    52,
3350
      69,    19
3351
  };
3352
 
3353
#if YYDEBUG
3354
  /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
3355
     to YYLEX-NUM.  */
3356
  const unsigned short int
3357
  Parser::yytoken_number_[] =
3358
  {
3359
         0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
3360
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
3361
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
3362
     285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
3363
     295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
3364
     305
3365
  };
3366
#endif
3367
 
3368
  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
3369
  const unsigned char
3370
  Parser::yyr1_[] =
3371
  {
3372
         0,    51,    52,    52,    52,    53,    53,    53,    53,    53,
3373
      53,    53,    53,    53,    54,    53,    55,    53,    53,    56,
3374
      53,    57,    53,    53,    53,    53,    58,    58,    58,    59,
3375
      59,    59,    60,    60,    60,    60,    61,    61,    61,    61,
3376
      62,    62,    62,    63,    63,    63,    63,    63,    63,    63,
3377
      63,    64,    64,    64,    64,    64,    64,    65,    65,    66,
3378
      66,    66,    66,    66,    66,    66,    66,    66,    66,    66,
3379
      66,    66,    67,    67,    67,    67,    67,    67,    68,    68,
3380
      68,    69,    69,    69,    69,    70,    70
3381
  };
3382
 
3383
  /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
3384
  const unsigned char
3385
  Parser::yyr2_[] =
3386
  {
3387
         0,     2,     0,     2,     1,     3,     3,     2,     3,     2,
3388
       4,     4,     4,     4,     0,     8,     0,    12,     7,     0,
3389
       9,     0,     8,     5,     7,     5,     0,     3,     1,     0,
3390
       3,     1,     3,     3,     3,     1,     3,     3,     3,     1,
3391
       1,     4,     3,     1,     7,     2,     5,     1,     4,     4,
3392
       5,     1,     2,     1,     2,     1,     2,     0,     3,     4,
3393
       4,     2,     3,     3,     3,     1,     3,     3,     3,     5,
3394
       5,     5,     3,     3,     3,     3,     3,     3,     1,     1,
3395
       1,     4,    11,     9,     2,     0,     3
3396
  };
3397
 
3398
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
3399
  /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
3400
     First, the terminals, then, starting at \a yyntokens_, nonterminals.  */
3401
  const char*
3402
  const Parser::yytname_[] =
3403
  {
3404
    "$end", "error", "$undefined", "AUTO", "RETURN", "FUNCTION", "JMP",
3405
  "EXIT", "EQUAL", "NOT_EQUAL", "GREATER_THAN", "LESS_THAN",
3406
  "LESS_OR_EQUAL_THAN", "GREATER_OR_EQUAL_THAN", "IF", "ELSE",
3407
  "OPEN_ROUND_BRACE", "CLOSE_ROUND_BRACE", "OPEN_BRACE", "CLOSE_BRACE",
3408
  "ASSIGN", "DIV", "MUL", "ADD", "DECCONST", "HEXCONST", "BINCONST", "EOS",
3409
  "DOT", "MINUS", "TK_X", "TK_Y", "TK_Z", "TK_N", "REG", "IDENTIFIER",
3410
  "SQRT", "SCALE", "UNSCALE", "USING", "FIXED_POINT", "COMMA",
3411
  "OPEN_SQUARE_BRACE", "CLOSE_SQUARE_BRACE", "WHILE", "ADD_EQ", "THREAD",
3412
  "START", "BITWISE_AND", "BITWISE_OR", "OUT", "$accept", "statement_list",
3413
  "statement", "$@1", "$@2", "$@3", "$@4", "function_input_list",
3414
  "function_argument_list", "expression", "term", "factor", "source",
3415
  "coordinate", "array_index", "left_hand_side", "boolean_expression",
3416
  "constant", "auto_var_list", "array_size", 0
3417
  };
3418
#endif
3419
 
3420
#if YYDEBUG
3421
  /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
3422
  const Parser::rhs_number_type
3423
  Parser::yyrhs_[] =
3424
  {
3425
        52,     0,    -1,    -1,    52,    53,    -1,    53,    -1,     3,
3426
      69,    27,    -1,    39,    40,    27,    -1,     7,    27,    -1,
3427
       4,    60,    27,    -1,     4,    27,    -1,    66,    45,    68,
3428
      27,    -1,    66,    29,    29,    27,    -1,    66,    23,    23,
3429
      27,    -1,    66,    20,    60,    27,    -1,    -1,    44,    54,
3430
      16,    67,    17,    18,    52,    19,    -1,    -1,    14,    16,
3431
      67,    17,    18,    52,    19,    15,    55,    18,    52,    19,
3432
      -1,    14,    16,    67,    17,    18,    52,    19,    -1,    -1,
3433
       5,    35,    16,    59,    17,    56,    18,    52,    19,    -1,
3434
      -1,    46,    35,    16,    17,    57,    18,    52,    19,    -1,
3435
      47,    35,    16,    17,    27,    -1,    66,    20,    35,    16,
3436
      58,    17,    27,    -1,    35,    16,    58,    17,    27,    -1,
3437
      -1,    60,    41,    58,    -1,    60,    -1,    -1,    35,    41,
3438
      59,    -1,    35,    -1,    60,    23,    61,    -1,    60,    29,
3439
      61,    -1,    60,    49,    61,    -1,    61,    -1,    61,    22,
3440
      62,    -1,    61,    21,    62,    -1,    61,    48,    62,    -1,
3441
      62,    -1,    63,    -1,    36,    16,    60,    17,    -1,    16,
3442
      60,    17,    -1,    68,    -1,    16,    68,    41,    68,    41,
3443
      68,    17,    -1,    35,    65,    -1,    35,    28,    64,    64,
3444
      64,    -1,    34,    -1,    37,    16,    34,    17,    -1,    38,
3445
      16,    34,    17,    -1,    34,    28,    64,    64,    64,    -1,
3446
      30,    -1,    29,    30,    -1,    31,    -1,    29,    31,    -1,
3447
      32,    -1,    29,    32,    -1,    -1,    42,    35,    43,    -1,
3448
      50,    42,    68,    43,    -1,    50,    42,    35,    43,    -1,
3449
      35,    65,    -1,    35,    28,    30,    -1,    35,    28,    31,
3450
      -1,    35,    28,    32,    -1,    34,    -1,    34,    28,    30,
3451
      -1,    34,    28,    31,    -1,    34,    28,    32,    -1,    34,
3452
      28,    30,    31,    33,    -1,    34,    28,    30,    33,    32,
3453
      -1,    34,    28,    33,    31,    32,    -1,    60,     9,    60,
3454
      -1,    60,     8,    60,    -1,    60,    10,    60,    -1,    60,
3455
      11,    60,    -1,    60,    12,    60,    -1,    60,    13,    60,
3456
      -1,    24,    -1,    25,    -1,    26,    -1,    35,    70,    41,
3457
      69,    -1,    35,    20,    16,    68,    41,    68,    41,    68,
3458
      17,    41,    69,    -1,    35,    20,    16,    68,    41,    68,
3459
      41,    68,    17,    -1,    35,    70,    -1,    -1,    42,    68,
3460
      43,    -1
3461
  };
3462
 
3463
  /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
3464
     YYRHS.  */
3465
  const unsigned short int
3466
  Parser::yyprhs_[] =
3467
  {
3468
         0,     0,     3,     4,     7,     9,    13,    17,    20,    24,
3469
      27,    32,    37,    42,    47,    48,    57,    58,    71,    79,
3470
      80,    90,    91,   100,   106,   114,   120,   121,   125,   127,
3471
     128,   132,   134,   138,   142,   146,   148,   152,   156,   160,
3472
     162,   164,   169,   173,   175,   183,   186,   192,   194,   199,
3473
     204,   210,   212,   215,   217,   220,   222,   225,   226,   230,
3474
     235,   240,   243,   247,   251,   255,   257,   261,   265,   269,
3475
     275,   281,   287,   291,   295,   299,   303,   307,   311,   313,
3476
     315,   317,   322,   334,   344,   347,   348
3477
  };
3478
 
3479
  /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
3480
  const unsigned short int
3481
  Parser::yyrline_[] =
3482
  {
3483
         0,   830,   830,   832,   834,   839,   841,   846,   863,   930,
3484
     958,   976,  1005,  1030,  1343,  1343,  1363,  1359,  1391,  1402,
3485
    1401,  1431,  1430,  1453,  1494,  1518,  1574,  1577,  1582,  1588,
3486
    1591,  1596,  1617,  1638,  1660,  1681,  1689,  1714,  1739,  1760,
3487
    1768,  1773,  1792,  1802,  1832,  1897,  1915,  1926,  1935,  1943,
3488
    1951,  1964,  1969,  1974,  1979,  1984,  1989,  1998,  2002,  2015,
3489
    2021,  2030,  2041,  2050,  2059,  2068,  2075,  2082,  2089,  2097,
3490
    2104,  2111,  2122,  2128,  2134,  2141,  2147,  2153,  2162,  2175,
3491
    2186,  2200,  2216,  2280,  2348,  2368,  2372
3492
  };
3493
 
3494
  // Print the state stack on the debug stream.
3495
  void
3496
  Parser::yystack_print_ ()
3497
  {
3498
    *yycdebug_ << "Stack now";
3499
    for (state_stack_type::const_iterator i = yystate_stack_.begin ();
3500
         i != yystate_stack_.end (); ++i)
3501
      *yycdebug_ << ' ' << *i;
3502
    *yycdebug_ << std::endl;
3503
  }
3504
 
3505
  // Report on the debug stream that the rule \a yyrule is going to be reduced.
3506
  void
3507
  Parser::yy_reduce_print_ (int yyrule)
3508
  {
3509
    unsigned int yylno = yyrline_[yyrule];
3510
    int yynrhs = yyr2_[yyrule];
3511
    /* Print the symbols being reduced, and their result.  */
3512
    *yycdebug_ << "Reducing stack by rule " << yyrule - 1
3513
               << " (line " << yylno << "):" << std::endl;
3514
    /* The symbols being reduced.  */
3515
    for (int yyi = 0; yyi < yynrhs; yyi++)
3516
      YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
3517
                       yyrhs_[yyprhs_[yyrule] + yyi],
3518
                       &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
3519
                       &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
3520
  }
3521
#endif // YYDEBUG
3522
 
3523
  /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
3524
  Parser::token_number_type
3525
  Parser::yytranslate_ (int t)
3526
  {
3527
    static
3528
    const token_number_type
3529
    translate_table[] =
3530
    {
3531
           0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3532
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3533
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3534
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3535
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3536
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3537
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3538
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3539
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3540
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3541
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3542
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3543
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3544
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3545
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3546
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3547
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3548
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3549
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3550
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3551
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3552
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3553
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3554
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3555
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
3556
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
3557
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
3558
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
3559
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
3560
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
3561
      45,    46,    47,    48,    49,    50
3562
    };
3563
    if ((unsigned int) t <= yyuser_token_number_max_)
3564
      return translate_table[t];
3565
    else
3566
      return yyundef_token_;
3567
  }
3568
 
3569
  const int Parser::yyeof_ = 0;
3570
  const int Parser::yylast_ = 309;
3571
  const int Parser::yynnts_ = 20;
3572
  const int Parser::yyempty_ = -2;
3573
  const int Parser::yyfinal_ = 46;
3574
  const int Parser::yyterror_ = 1;
3575
  const int Parser::yyerrcode_ = 256;
3576
  const int Parser::yyntokens_ = 51;
3577
 
3578
  const unsigned int Parser::yyuser_token_number_max_ = 305;
3579
  const Parser::token_number_type Parser::yyundef_token_ = 2;
3580
 
3581
 
3582
/* Line 1054 of lalr1.cc  */
3583
#line 28 "parser.y"
3584
} // Theia
3585
 
3586
/* Line 1054 of lalr1.cc  */
3587
#line 3588 "parser.tab.c"
3588
 
3589
 
3590
/* Line 1056 of lalr1.cc  */
3591
#line 2378 "parser.y"
3592
 
3593
 
3594
 
3595
 
3596
// Error function throws an exception (std::string) with the location and error message
3597
void Theia::Parser::error(const Theia::Parser::location_type &loc,
3598
                                          const std::string &msg) {
3599
        std::ostringstream ret;
3600
        ret << "Parser Error at " << loc << ": "  << msg;
3601
        throw ret.str();
3602
}
3603
 
3604
// Now that we have the Parser declared, we can declare the Scanner and implement
3605
// the yylex function
3606
#include "Scanner.h"
3607
static int yylex(Theia::Parser::semantic_type * yylval,
3608
                 Theia::Parser::location_type * yylloc,
3609
                 Theia::Scanner &scanner) {
3610
        return scanner.yylex(yylval, yylloc);
3611
}
3612
 
3613
 

powered by: WebSVN 2.1.0

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