int main(int argc, char *argv[])
{
    if(argc<2)
    {
        printf("Please select an input file\n");
        exit(0);
    }
    FILE *fp=fopen(argv[1],"r");
    if(!fp)
    {
        printf("couldn't open file for reading\n");
        exit(0);
    }

    char funcName[100];
    StmtRepresentation* result = NULL;

    yyin=fp;

    typeTable = CreateTypeNameTable();
    program = CreateProgramNode();
    yyparse();
    DebugProgramNode(program);

    printf("Enter a function name to be traced: ");
    scanf("%s", funcName);
    opTrace = NULL;
    symTable = CreateSymTable();
    g_operation_id = 0;
    lastIssueOP = NULL;

    result = TraceFuncNode(program, funcName, NULL);
    DeleteStmtRepresentation(result);
    ShowOPTrace(opTrace);
    CalculateCriticalPath(opTrace);

    /* Delete Symbol Table */
    DeleteSymbolTable(symTable);
    DeleteOPTrace(opTrace);
    DeleteTypeNameTable(typeTable);
    DeleteProgramNode(program);
    fclose(fp);
}
Esempio n. 2
0
/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
*/
static void yy_reduce(
  yyParser *yypParser,         /* The parser */
  unsigned int yyruleno        /* Number of the rule by which to reduce */
){
  int yygoto;                     /* The next state */
  int yyact;                      /* The next action */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  Parser_v0_1_ARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    yysize = yyRuleInfo[yyruleno].nrhs;
    fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
      yyRuleName[yyruleno], yymsp[-yysize].stateno);
  }
#endif /* NDEBUG */

  /* Check that the stack is large enough to grow by a single entry
  ** if the RHS of the rule is empty.  This ensures that there is room
  ** enough on the stack to push the LHS value */
  if( yyRuleInfo[yyruleno].nrhs==0 ){
#ifdef YYTRACKMAXSTACKDEPTH
    if( yypParser->yyidx>yypParser->yyidxMax ){
      yypParser->yyidxMax = yypParser->yyidx;
    }
#endif
#if YYSTACKDEPTH>0 
    if( yypParser->yyidx>=YYSTACKDEPTH-1 ){
      yyStackOverflow(yypParser);
      return;
    }
#else
    if( yypParser->yyidx>=yypParser->yystksz-1 ){
      yyGrowStack(yypParser);
      if( yypParser->yyidx>=yypParser->yystksz-1 ){
        yyStackOverflow(yypParser);
        return;
      }
    }
#endif
  }

  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
/********** Begin reduce actions **********************************************/
        YYMINORTYPE yylhsminor;
      case 0: /* program ::= IDENTIFIER NUMBER types */
{ *arg = yymsp[0].minor.yy11; }
        break;
      case 1: /* types ::= types type */
{ yylhsminor.yy11 = yymsp[-1].minor.yy11; Add(yylhsminor.yy11, yymsp[0].minor.yy33); }
  yymsp[-1].minor.yy11 = yylhsminor.yy11;
        break;
      case 2: /* types ::= type */
{ yylhsminor.yy11 = CreateProgramNode(); Add(yylhsminor.yy11, yymsp[0].minor.yy33); }
  yymsp[0].minor.yy11 = yylhsminor.yy11;
        break;
      case 3: /* type ::= IDENTIFIER LBRACE values RBRACE SEMICOLON */
{ yylhsminor.yy33 = yymsp[-2].minor.yy33; SetIden(yylhsminor.yy33, yymsp[-4].minor.yy0); }
  yymsp[-4].minor.yy33 = yylhsminor.yy33;
        break;
      case 4: /* values ::= values value */
{ yylhsminor.yy33 = yymsp[-1].minor.yy33; Add(yylhsminor.yy33, yymsp[0].minor.yy30); }
  yymsp[-1].minor.yy33 = yylhsminor.yy33;
        break;
      case 5: /* values ::= value */
{ yylhsminor.yy33 = CreateTypeNode(); Add(yylhsminor.yy33, yymsp[0].minor.yy30); }
  yymsp[0].minor.yy33 = yylhsminor.yy33;
        break;
      case 6: /* value ::= IDENTIFIER COLON expression SEMICOLON */
{ yylhsminor.yy30 = CreateAssignNode(yymsp[-3].minor.yy0, yymsp[-1].minor.yy37); }
  yymsp[-3].minor.yy30 = yylhsminor.yy30;
        break;
      case 7: /* expression ::= number */
{ yylhsminor.yy37 = CreateExpressionNode(yymsp[0].minor.yy10); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 8: /* expression ::= IDENTIFIER */
{ yylhsminor.yy37 = CreateExpressionNode(yymsp[0].minor.yy0); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 9: /* expression ::= IDENTIFIER vector */
{ yylhsminor.yy37 = CreateColourNode(yymsp[-1].minor.yy0, yymsp[0].minor.yy6); }
  yymsp[-1].minor.yy37 = yylhsminor.yy37;
        break;
      case 10: /* expression ::= number IDENTIFIER */
{ yylhsminor.yy37 = CreateUnitValueNode(yymsp[-1].minor.yy10, yymsp[0].minor.yy0); }
  yymsp[-1].minor.yy37 = yylhsminor.yy37;
        break;
      case 11: /* expression ::= vector */
{ yylhsminor.yy37 = CreateVecExprNode(yymsp[0].minor.yy6); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 12: /* vector ::= LESSER vector_vals GREATER */
{ yymsp[-2].minor.yy6 = yymsp[-1].minor.yy6; }
        break;
      case 13: /* vector_vals ::= vector_vals COMMA number */
{ yylhsminor.yy6 = yymsp[-2].minor.yy6; Add(yylhsminor.yy6, CreateExpressionNode(yymsp[0].minor.yy10)); }
  yymsp[-2].minor.yy6 = yylhsminor.yy6;
        break;
      case 14: /* vector_vals ::= number */
{ yylhsminor.yy6 = CreateVectorNode(); Add(yylhsminor.yy6, CreateExpressionNode(yymsp[0].minor.yy10)); }
  yymsp[0].minor.yy6 = yylhsminor.yy6;
        break;
      case 15: /* number ::= HEXVAL */
      case 16: /* number ::= NUMBER */ yytestcase(yyruleno==16);
{ yylhsminor.yy10 = yymsp[0].minor.yy0; }
  yymsp[0].minor.yy10 = yylhsminor.yy10;
        break;
      default:
        break;
/********** End reduce actions ************************************************/
  };
  assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact <= YY_MAX_SHIFTREDUCE ){
    if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
    yypParser->yyidx -= yysize - 1;
    yymsp -= yysize-1;
    yymsp->stateno = (YYACTIONTYPE)yyact;
    yymsp->major = (YYCODETYPE)yygoto;
    yyTraceShift(yypParser, yyact);
  }else{
    assert( yyact == YY_ACCEPT_ACTION );
    yypParser->yyidx -= yysize;
    yy_accept(yypParser);
  }
}