Esempio n. 1
0
  void visitSelfCall(SelfCall *p) {
    fprintf( m_outputfile, "#### SELF CALL\n");
    int args;
    Symbol * symbP;
    SymScope * sync;
    MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
    char * funcName = strdup(MethIdP->m_symname->spelling());
    sync = m_symboltable->get_current_scope();
    symbP = sync->lookup((const char *)"xxx");


    p->visit_children(this);
    args = p->m_expression_list->size();
    args = args * wordsize;
// cout<<"the number of params: "<<args<<endl;
    char * className = strdup(symbP->classType.classID);
    strcat(className,"_");
    strcat(className,funcName);

    fprintf( m_outputfile, "call %s\n",className);
    fprintf( m_outputfile, "addl $%d , %%esp\n",args);

         // WRITEME

  }
Esempio n. 2
0
  void visitMethodImpl(MethodImpl *p) {
    fprintf( m_outputfile, "#### METHOD IMPLEMENTATION\n");
    int localSpace, args, mem;
    int j=0;
    int methMem = 0;
    CompoundType info;
    currMethodOffset = new OffsetTable();
// cout<<"before my childen"<<endl;

//this is to make the label name
    Symbol * symbP;
    SymScope * sync;
    MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
    char * funcName = strdup(MethIdP->m_symname->spelling());
    sync = m_symboltable->get_current_scope();
    symbP = sync->lookup((const char *)"xxx");
    char * classMethName = strdup(symbP->classType.classID);
    strcat(classMethName,"_");
    strcat(classMethName,funcName);
    fprintf( m_outputfile, "_%s:\n",classMethName);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fprintf( m_outputfile, " pushl %%ebp\n");
    fprintf( m_outputfile, " movl %%esp , %%ebp\n");
    MethodBodyImpl * MethBodP = dynamic_cast<MethodBodyImpl*>(p->m_methodbody);
    localSpace = (p->m_parameter_list->size() + MethBodP->m_declaration_list->size());

    localSpace = localSpace * wordsize;
    // currMethodOffset->insert(classMethName, localSpace, 4,symbP->classType);
    currMethodOffset->setTotalSize(localSpace);
    currMethodOffset->setParamSize(p->m_parameter_list->size() * wordsize);

//### inserting paramaters into the offset table ###########
    for (std::list<Parameter_ptr>::iterator it = p->m_parameter_list->begin() ; it != p->m_parameter_list->end(); ++it){
    ParameterImpl * param = dynamic_cast<ParameterImpl*>(*it);
      VariableIDImpl * VarId = dynamic_cast<VariableIDImpl*>(param->m_variableid);

      info.baseType = param->m_type->m_attribute.m_type.baseType; 
      if(info.baseType == 8){ 
        info.classID = param->m_type->m_attribute.m_type.classType.classID;
        }
      else{
        info.classID = "NO CLASS";
        }
        methMem -= 4;
// cout<<"Offset-> symname: "<<VarId->m_symname->spelling()<<" offset: "<<methMem<<" class type: " <<info.baseType<<endl;
      currMethodOffset->insert(VarId->m_symname->spelling(), methMem, 4,info);
      
    }
//################################  

      

//<><>Diving into Declaration <><><><>><><><><><><><><><><><>><><><><><><
       typename std::list<Declaration_ptr>::iterator it = MethBodP->m_declaration_list->begin();
       for( ; it != MethBodP->m_declaration_list->end(); ++it) {
          DeclarationImpl * DeclaP = dynamic_cast<DeclarationImpl *> (*it);
          typename std::list<VariableID_ptr>::iterator it = DeclaP->m_variableid_list->begin();
          for( ; it != DeclaP->m_variableid_list->end(); ++it) {
            methMem -= 4; // need to move to the next offset
            VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(*it);
            char * var = strdup(VarIdP->m_symname->spelling());
 // cout<<"Offset-> symname: "<<var<<" Offset: "<<methMem<<" Class type: " <<endl;
            info.baseType = DeclaP->m_type->m_attribute.m_type.baseType; 
            if(info.baseType == 8){ 
              info.classID = DeclaP->m_type->m_attribute.m_type.classType.classID;
              }
            else{
              info.classID = "NO CLASS";
              }
            currMethodOffset->insert(var, methMem, 4,info);

           }

        }
//<><><><><><><><><><><><><><><><><>><><><><><><
//~~~~ allocating space on the stack and  moves parameters into local ~~~~~~   

// cout<<"param size: "<<currMethodOffset->getParamSize()<<endl;
// cout<<" LocalSpace: "<< -(methMem)<<endl;

  fprintf( m_outputfile, " subl $%d, %%esp\n",-(methMem));
   mem = -4;
   for(int i = currMethodOffset->getParamSize() + 4; i>= 8; i = i-4){
     
      fprintf( m_outputfile, " movl %d(%%ebp) , %%eax\n",i);
      fprintf( m_outputfile, " movl %%eax , %d(%%ebp)\n",mem);
      mem -= 4;
      // symbP->methodType.argsType[j].baseType;
     }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


     p->visit_children(this);
// cout<<"after the children"<<endl;
    fprintf( m_outputfile, " leave\n");
    fprintf( m_outputfile, " ret\n");  
         // WRITEME
  }