int main(int argc, char **argv) {
    char *filename;
    
    char source[255];
    char listing[255];
    char assembly[255];
    
    
    
    if(argc == 2) {
        filename = argv[1];
        
        strcpy(source, "io/input/");
        strcpy(listing, "io/output/");
        strcpy(assembly, "io/output/");
        
        strcat(source, filename);
        strcat(listing, filename);
        strcat(assembly, filename);
        
        strcat(source, ".src");
        strcat(listing, ".lst");
        strcat(assembly, ".asm");
        
        if(!OpenFiles(source, listing)) {
            printf("SOMETHING F****D UP\n");
        }
        
        InitCodeGen(assembly);
        InitSemantics();
        
        switch(yyparse()) {
            case 0:
                PostMessage(GetCurrentColumn(), "COMPILATION SUCSESSFUL");
                break;
            case 1:
                PostMessage(GetCurrentColumn(), "COMPILATION FAILED - BAD INPUT");
                printf("COMPILATION FAILED - BAD INPUT\n");
                break;
            case 2:
                PostMessage(GetCurrentColumn(), "COMPILATION FAILED - OUT OF MEMORY");
                printf("COMPILATION FAILED - OUT OF MEMORY\n");
                break;
            default:
                PostMessage(GetCurrentColumn(), "SOMETHING UNEXPECTED HAPPENED");
                printf("SOMETHING UNEXPECTED HAPPENED\n");
                break;
        }
        UpdateListingFile();
    } else {
        printf("Useage: Q <SourceName>");
    }
    
    exit(0);
}
Example #2
0
struct ExprRes *  doRval(char * name)  { 
   struct ExprRes *res;
   struct SymEntry * e;
   if( global ){
       e = FindName(locTable, name);
       if( !e) {
           e = FindName(table, name);
       }
   }
   else {
       e = FindName(table, name);
               }
   if (!e) {
		WriteIndicator(GetCurrentColumn());
		WriteMessage("Undeclared variable");
        exit(1); //doing something stupid like "print ln;" will cause me to segfault if we don't quit
   }
  struct Vtype * vtype = ((struct Vtype *)e->Attributes);



  res = (struct ExprRes *) malloc(sizeof(struct ExprRes));
  res->Reg = AvailTmpReg();
  
  if ( vtype->Local == 0 ){
         res->Instrs = GenInstr(NULL,"lw",TmpRegName(res->Reg),name,NULL); 
  }
  else {
      res->Instrs = GenInstr(NULL, "lw", TmpRegName(res->Reg), RegOff(vtype->StackIndex, "$sp"), NULL);
  }
  
  res->Type = vtype->Type;
  return res;
}
Example #3
0
struct InstrSeq * doArrayAssign( char * name, struct ExprRes * index, struct ExprRes * val){
    struct SymEntry *e;
    if( global ){
        e = FindName(locTable, name);
        if( !e){
            e = FindName(table, name);
        }
    }
    else{
        e = FindName(table, name);
    }
    struct Vtype * vtype = ((struct Vtype *)e->Attributes);
    struct InstrSeq * code;
    int reg = AvailTmpReg();
    char * buffer;
    if (!e){
        WriteIndicator(GetCurrentColumn());
        WriteMessage("Undeclared variable");
    }
    if(index->Type != TYPE_INT){
        TypeError();
    }
    else if( val->Type != -1 && ((vtype->Type ==  TYPE_BOOLARR &&  val->Type != TYPE_BOOL) || (vtype->Type == TYPE_INTARR && val->Type != TYPE_INT ))){
        TypeError();
    }
    buffer = RegOff(0, TmpRegName(reg));
    code = val->Instrs;
    AppendSeq(code, index->Instrs);
    // change for locality later
    if (! vtype->Local){
        AppendSeq( code, GenInstr( NULL, "la", TmpRegName(reg), name, NULL));
         
    }
    else {
        AppendSeq(code, GenInstr(NULL, "addi", TmpRegName(reg), "$sp", Imm(vtype->StackIndex)));
    }
    
    
    
    AppendSeq( code, GenInstr( NULL, "mul", TmpRegName(index->Reg), TmpRegName(index->Reg), "4"));
    AppendSeq( code, GenInstr(NULL, "add", TmpRegName(reg), TmpRegName(reg), TmpRegName(index->Reg)));
    AppendSeq( code, GenInstr(NULL, "sw", TmpRegName(val->Reg), buffer, NULL));
    ReleaseTmpReg(val->Reg);
    ReleaseTmpReg(index->Reg);
    ReleaseTmpReg(reg);
    free(val);
    free(index);

    return code;
    
}
Example #4
0
bool CGUIPanelContainer::GetCondition(int condition, int data) const
{
  int row = GetCurrentRow();
  int col = GetCurrentColumn();

  if (m_orientation == HORIZONTAL)
    std::swap(row, col);

  switch (condition)
  {
  case CONTAINER_ROW:
    return (row == data);
  case CONTAINER_COLUMN:
    return (col == data);
  default:
    return CGUIBaseContainer::GetCondition(condition, data);
  }
}
Example #5
0
std::string CGUIPanelContainer::GetLabel(int info) const
{
  int row = GetCurrentRow();
  int col = GetCurrentColumn();

  if (m_orientation == HORIZONTAL)
    std::swap(row, col);

  switch (info)
  {
  case CONTAINER_ROW:
    return StringUtils::Format("%i", row);
  case CONTAINER_COLUMN:
    return StringUtils::Format("%i", col);
  default:
    return CGUIBaseContainer::GetLabel(info);
  }
  return StringUtils::Empty;
}
Example #6
0
extern struct ExprRes *doFuncCall(char *name)
{
   char nname[100];
   snprintf(nname, 100, "_%s", name);
   struct SymEntry *e;
   e = FindName(ProcSymTab, name);
   if(!e)
   {
        WriteIndicator(GetCurrentColumn());
        WriteMessage("Function Not Declared");
        exit(1);
   }
   struct ExprRes *res = malloc(sizeof(struct ExprRes));
   res->Reg = AvailTmpReg();
   res->Type = TYPE_INT;
   res->Instrs = SaveSeq();
   AppendSeq(res->Instrs, GenInstr(NULL, "jal", nname, NULL, NULL));
   AppendSeq(res->Instrs, RestoreSeq());
   AppendSeq(res->Instrs, GenInstr(NULL, "move", TmpRegName(res->Reg), "$v0", NULL));
   return res;
}
Example #7
0
struct ExprRes * doArrayRval(char * name, struct  ExprRes * index){
    int reg = AvailTmpReg();
    struct SymEntry * e = FindName(table, name);
    if( !e ){
        WriteIndicator(GetCurrentColumn());
        WriteMessage("Undeclared variable");
        exit(1);
    }

    if(index->Type != TYPE_INT){
        TypeError();
    }
    char * buffer = RegOff(0, TmpRegName(reg));
    struct Vtype * vtype = ((struct Vtype *)e->Attributes);


    //change later for variable locality
    
    if( vtype->Local) {
        AppendSeq(index->Instrs, GenInstr(NULL, "addi", TmpRegName(reg), "$sp", Imm(vtype->StackIndex)));

    }
    else{
        AppendSeq(index->Instrs, GenInstr( NULL, "la", TmpRegName(reg), name, NULL));
    }
    AppendSeq(index->Instrs, GenInstr(NULL, "mul", TmpRegName(index->Reg), TmpRegName(index->Reg), "4"));
    AppendSeq(index->Instrs, GenInstr(NULL, "add", TmpRegName(reg), TmpRegName(reg), TmpRegName(index->Reg)));
    AppendSeq(index->Instrs, GenInstr(NULL , "lw", TmpRegName(index->Reg), buffer, NULL));

    if( vtype->Type == TYPE_INTARR){
        index->Type = TYPE_INT;
    }
    else {
        index->Type = TYPE_BOOL;
    }
    ReleaseTmpReg(reg);
    return index;

}
Example #8
0
struct InstrSeq * doAssign(char *name, struct ExprRes * Expr) { 
    struct SymEntry *e;
  struct InstrSeq *code;
   
  if (global){
       e = FindName(locTable, name);
       if(!e){
           e = FindName(table, name);
       }
   }
   else{
        e = FindName(table,name);
   }
   if (!e) {
		WriteIndicator(GetCurrentColumn());
		WriteMessage("Undeclared variable");
   }
   struct Vtype * vtype = ((struct Vtype *)e->Attributes);
   if(  Expr->Type != -1 &&  vtype->Type != Expr->Type){
       TypeError();
   }
  
   code = Expr->Instrs;
  
   if( vtype->Local == 0 ) {
        AppendSeq(code, GenInstr(NULL, "sw", TmpRegName(Expr->Reg), name, NULL));
   }
   else {
        AppendSeq(code, GenInstr(NULL, "sw", TmpRegName(Expr->Reg), RegOff(vtype->StackIndex, "$sp"), NULL));
   }

  
   ReleaseTmpReg(Expr->Reg);
   free(Expr);
  
   return code;
}
Example #9
0
void TypeError(){
    WriteIndicator(GetCurrentColumn());
    WriteMessage("Conflicting Types");
    exit(1);
}
Example #10
0
void PadToTab(int tabPos)
{
  int currentCol = GetCurrentColumn();
  for (int i = currentCol; i < tabPos; i++)
    TexOutput(_T(" "), true);
}