Ejemplo n.º 1
0
Node* DupExpr(Node* n)
{
  Node* p = NULL;
  if (n)
  {
    p = NewNode();
    *p = *n;
    p->child[2] = DupExpr(n->child[2]);
    p->child[0] = DupExpr(n->child[0]);
    p->child[1] = DupExpr(n->child[1]);
  }
  return p;
}
Ejemplo n.º 2
0
void GenTestCase(int no)
{
  Node *n1, *n2;
  unsigned v0;
  printf("void test%d(void)\n{\n", no);
  printf("  printf(\"-- Test %d (seed: %u) --\\n\");\n", no, mySeed);
  printf("  {\n");
  printf("    int failed = 0;\n");
  ReInit();
  n1 = GenCommaExpr();
  PrintDecls(n1);
  printf("    unsigned v0 = (");
  PrintExpr(n1);
  printf(");\n");
  n2 = DupExpr(n1);
  v0 = Eval(n2);
  CheckVars(n2);
  printf("    if (v0 != %uu) ", v0);
  printf("{ failed = 1; printf(\"v0 != %uu\\n\"); }\n", v0);
  printf("    if (failed)\n      printf(\"Test %d failed\\n\");\n", no);
  printf("    errors += failed;\n");
  printf("  }\n");
  printf("  printf(\"\\n\");\n");
  printf("}\n\n");
  DelNode(n1);
  DelNode(n2);
}
Ejemplo n.º 3
0
static Stmt *BuildProgramReturnAssignments( CgContext *cg, Stmt *fStmt, void *arg1, int arg2)
{
  struct BuildReturnAssignments *lstr;
  Symbol *program, *lSymb, *voutVar, *outSymb, *retSymb;
  Type *lType, *rettype;
  Expr *lExpr, *rexpr, *returnVar, *outputVar;
  Scope *lScope, *gScope, *voutScope;
  Stmt *lStmt, *stmtlist;
  int len;
	Atom lname;
  
  if (fStmt->kind == RETURN_STMT) {
    lstr = (struct BuildReturnAssignments *) arg1;
    gScope = lstr->globalScope;
    program = lstr->program;
    lType = program->type;
    rettype = static_cast< TypeFunction * >( lType )->rettype;
    TypeCategory category = rettype->category;
    if (IsVoid(rettype)) {
      fStmt = NULL;
    } else {
      if (category == TC_Struct) {
        stmtlist = NULL;
        voutVar = cg->theHal->varyingOut;
        voutScope = static_cast< TypeStruct * >( voutVar->type )->members;
        lScope = static_cast< TypeStruct * >( rettype )->members;
        lSymb = lScope->symbols;
        while (lSymb) {
          // Create an assignment statement of the bound variable to the $vout member:
          lname = lSymb->details.var.semantics.IsValid() ? lSymb->details.var.semantics : lSymb->name;
          outSymb = LookupLocalSymbol(cg, voutScope, lname);
          retSymb = LookupLocalSymbol(cg, lScope, lSymb->name);
          if (outSymb && retSymb) {
            // outSymb may not be in the symbol table if it's a "hidden" register.
            returnVar = DupExpr( cg, static_cast< ReturnStmt * >( fStmt )->expr);
            outputVar = (Expr *) NewSymbNode( cg, VARIABLE_OP, voutVar);
            lExpr = GenMemberReference( cg, outputVar, outSymb);
            rexpr = GenMemberReference( cg, returnVar, retSymb);
            if (IsScalar(lSymb->type) || IsVector(lSymb->type, &len)) {
              lStmt = NewSimpleAssignmentStmt( cg, &program->loc, lExpr, rexpr, 0);
              stmtlist = ConcatStmts(stmtlist, lStmt);
            } else {
              FatalError( cg, "Return of unsupported type");
              // xxx
            }
          }
          lSymb = lSymb->next;
        }
				delete fStmt;
        fStmt = stmtlist;
      } else {
        // Already reported:
        // SemanticError(&program->loc, ERROR_S_PROGRAM_MUST_RETURN_STRUCT,
        //               cg->GetString(program->name));
      }
    }
  }
  return fStmt;
} // BuildProgramReturnAssignments