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 230

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

powered by: WebSVN 2.1.0

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