String BrazilianStemmer::stem(const String& term)
    {
        // creates CT
        createCT(term);

        if (!isIndexable(CT))
            return L"";
        if (!isStemmable(CT))
            return CT;

        R1 = getR1(CT);
        R2 = getR1(R1);
        RV = getRV(CT);
        TERM = term + L";" + CT;

        bool altered = step1();
        if (!altered)
            altered = step2();

        if (altered)
            step3();
        else
            step4();

        step5();

        return CT;
    }
Esempio n. 2
0
int checkItypeInstructionIsValid(uint32_t ins) {
  uint8_t r1 = getR1(ins);
  uint8_t r2 = getR2(ins);
  if (r1<0 || r2<0 || r1>=NUMBER_OF_REGISTERS || r2>=NUMBER_OF_REGISTERS) {
    printSegmentationFaultMessage();
    return 0;
  }
  return 1;
}
Esempio n. 3
0
int checkIfLoadAndStoreAreValid(uint32_t ins) {
  uint8_t r1 = getR1(ins);
  uint8_t r2 = getR2(ins);
  int16_t iVal = getImmediateValue(ins);
  if (r1<0 || r2<0 || r1>=NUMBER_OF_REGISTERS || r2>=NUMBER_OF_REGISTERS 
                                        || r2+iVal<0 || r2+iVal>=MEMORY_SIZE) {
    printSegmentationFaultMessage();
    return 0;
  }
  return 1;
}
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: getBitPlane((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: getDisplayOption((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: getEdgeFilter((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: getImpulseNoise((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 4: getKLTQuality((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 5: getKLTMinDist((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 6: getKLTWindowSize((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 7: getKLTNumLevels((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 8: getLogarithmConstant((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 9: getOFAlgorithm((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 10: getPowerLawConstant((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 11: getPowerLawGamma((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 12: getR1((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 13: getK((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 14: getMinSize((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 15: getSharpeningAlgorithm((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 16: getSigma((*reinterpret_cast< double(*)>(_a[1]))); break;
        case 17: getSmoothingFilter((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 18: getSmoothingMask((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 19: exitApplication(); break;
        case 20: openImageDirectory(); break;
        case 21: toggleAddGaussianNoise(); break;
        case 22: toggleAddGammaNoise(); break;
        case 23: toggleAddImpulseNoise(); break;
        case 24: toggleBitPlaneSlicing(); break;
        case 25: toggleContrastStretching(); break;
        case 26: toggleFilter(); break;
        case 27: toggleFitToWindow(); break;
        case 28: toggleHistogramEqualization(); break;
        case 29: toggleLogarithm(); break;
        case 30: toggleNegative(); break;
        case 31: toggleOpticalFlow(); break;
        case 32: togglePowerLaw(); break;
        case 33: toggleSegmentation(); break;
        case 34: toggleSharpeningAlgorithm(); break;
        case 35: toggleSmoothing(); break;
        case 36: toggleSwapRedBlue(); break;
        case 37: updateImageNumber((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 38: timerEvent((*reinterpret_cast< QTimerEvent*(*)>(_a[1]))); break;
        case 39: on_pushButtonTrack_clicked(); break;
        default: ;
        }
        _id -= 40;
    }
    return _id;
}
Esempio n. 5
0
int checkBrachInstructionIsValid(uint32_t ins, struct Processor *proc) {
  uint8_t r1 = getR1(ins);
  uint8_t r2 = getR2(ins);
  int16_t iVal = getImmediateValue(ins);
  uint32_t pc = proc->pc;
  if (r1<0 || r2<0 || r1>=NUMBER_OF_REGISTERS || r2>=NUMBER_OF_REGISTERS 
                                || pc+(iVal*4)<0 || pc+(iVal*4)>=MEMORY_SIZE) {
    printSegmentationFaultMessage();
    return 0;
  }
  return 1;
}
Esempio n. 6
0
int carryOutInstruction(struct Processor *processor) {
  uint32_t instruction = getInstructionAtPC(processor);
  uint8_t opcode = getOpcode(instruction);
  uint32_t backupPC = processor->pc;
  int32_t temp;
  div_t division;

  switch (opcode)  {
    case HALT : return 0;
    case ADD  : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) + 
                  getRegisterValue(processor, getR3(instruction));
                break;
                
    case ADDI : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) + 
                  getImmediateValue(instruction);
                break;
               
    case SUB  : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) - 
                  getRegisterValue(processor, getR3(instruction));
                break;
                
    case SUBI : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) - 
                   getImmediateValue(instruction);
                 break;
                  
    case MUL  : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) * 
                  getRegisterValue(processor, getR3(instruction));
                break;
                  
    case MULI : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction)) * 
                  getImmediateValue(instruction);
                break;
                
    case LW   : processor->gpr[getR1(instruction)] = 
                getMemory(processor, 
                          getRegisterValue(processor, getR2(instruction)) + 
                                            getImmediateValue(instruction));
                break;
                  
    case SW   : setMemory(processor, getRegisterValue
                  (processor, getR2(instruction)) + 
                  getImmediateValue(instruction), 
                  getRegisterValue(processor, getR1(instruction)));
                break;
                
    case BEQ  : if (processor->gpr[getR1(instruction)] == 
                    processor->gpr[getR2(instruction)]) 
                  { processor->pc += getImmediateValue(instruction) * 4;};
                break;
                  
      case BNE  : if (processor->gpr[getR1(instruction)] != 
                      processor->gpr[getR2(instruction)]) 
                    { processor->pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BLT  : if (processor->gpr[getR1(instruction)] <
                      processor->gpr[getR2(instruction)])
                    { processor->pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BGT  : if (processor->gpr[getR1(instruction)] >
                     processor->gpr[getR2(instruction)]) 
                   { processor->pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BLE  : if (processor->gpr[getR1(instruction)] <= 
                      processor->gpr[getR2(instruction)]) 
                  { processor->pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BGE  : if (processor->gpr[getR1(instruction)] >= 
                      processor->gpr[getR2(instruction)]) 
                    { processor->pc += (getImmediateValue(instruction) * 4);};
                  break;
                  
      case JMP  : processor->pc = getAddress(instruction);
                  break;
                  
      case JR   : processor->pc = getRegisterValue
                    (processor, getR1(instruction));
                  break;
                  
      case JAL  : processor->gpr[31] = processor->pc + sizeof(uint32_t); 
                  processor->pc = getAddress(instruction);
                  break;
                  
      case OUT  : printf("%c", (char)getRegisterValue
                    (processor, getR1(instruction)));
                  break;
                  
      case DIV  : division = div(getRegisterValue(processor,getR2(instruction))
                              ,getRegisterValue(processor,getR3(instruction)));
                  processor->gpr[getR1(instruction)] = division.quot;
      
      case DIVI : division = div(getRegisterValue(processor,getR2(instruction))
                              ,getImmediateValue(instruction));
                  processor->gpr[getR1(instruction)] = division.quot;
      
      case MOD  : division = div(getRegisterValue(processor,getR2(instruction))
                              ,getRegisterValue(processor,getR3(instruction)));
                  processor->gpr[getR1(instruction)] = division.rem;
      
      case MODI : division = div(getRegisterValue(processor,getR2(instruction))
                              ,getImmediateValue(instruction));
                  processor->gpr[getR1(instruction)] = division.rem;
      
      case FACT : processor->gpr[getR1(instruction)] = 
                  getRegisterValue(processor, getR2(instruction));
                  for(int i = 1; i<processor->gpr[getR2(instruction)] ; i++) {
                    processor->gpr[getR1(instruction)] = 
                      (getRegisterValue(processor, getR1(instruction)))*
                      (getRegisterValue(processor, getR2(instruction))-i);};
                  break;
      
      case FACTI: processor->gpr[getR1(instruction)] = 
                  getImmediateValue(instruction);
                  for(int i = 1; i<getImmediateValue(instruction) ; i++) {
                    processor->gpr[getR1(instruction)] = 
                      (getRegisterValue(processor, getR1(instruction)))*
                      (getImmediateValue(instruction)-i);};
                  break;
      
      case SWAP : temp = 
                    getRegisterValue(processor, getR1(instruction));
                  processor->gpr[getR1(instruction)] = 
                    getRegisterValue(processor, getR2(instruction));
                  processor->gpr[getR2(instruction)] = temp;
                  break;
                  
      default   : printf("invalid opcode\n");
                  break;
    }
    
    if(processor->pc == backupPC)  processor->pc += sizeof(uint32_t);
    return 1;
}
Esempio n. 7
0
/*
  This method carries out the execution of the binary code in the file specified
  by the arguments at run time. The file is loaded into the memory of the
  structure processor and then the execution is carried out in the while loop.
  The execution of terminates when an instruction with opcode HALT is reached.
  @param argv : this specifies the arguements which were given through the
                terminal when the program was run.
  @param argc : this specifes the number of arguments provided
  @return     : the method returns 0 when the method executes without any errors
*/
int main(int argc, char **argv) {
  assert("There are wrong number of arguents given" && argc==2);
  struct Processor processor;
  char *filepath = argv[1];

  memset(&processor, 0, sizeof(struct Processor));

  binaryFileLoader(filepath, &processor);
    
  while (getInstructionAtPC(&processor)) {
    uint32_t instruction = getInstructionAtPC(&processor);
    uint8_t opcode = getOpcode(instruction);
    uint32_t backupPC = processor.pc;
    int32_t temp;
    div_t division;

    switch (opcode)  {
      case ADD  : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) + 
                    getRegisterValue(&processor, getR3(instruction));
                  break;
                  
      case ADDI : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) + 
                    getImmediateValue(instruction);
                  break;
                 
      case SUB  : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) - 
                    getRegisterValue(&processor, getR3(instruction));
                  break;
                  
      case SUBI : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) - 
                    getImmediateValue(instruction);
                  break;
                  
      case MUL  : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) * 
                    getRegisterValue(&processor, getR3(instruction));
                  break;
                  
      case MULI : processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction)) * 
                    getImmediateValue(instruction);
                  break;
                  
      case LW   : processor.gpr[getR1(instruction)] = 
                  getMemory(&processor, 
                            getRegisterValue(&processor, getR2(instruction)) + 
                                              getImmediateValue(instruction));
                  break;
                  
      case SW   : setMemory(&processor, getRegisterValue
                    (&processor, getR2(instruction)) + 
                    getImmediateValue(instruction), 
                    getRegisterValue(&processor, getR1(instruction)));
                  break;
                  
      case BEQ  : if (processor.gpr[getR1(instruction)] == 
                      processor.gpr[getR2(instruction)]) 
                    { processor.pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BNE  : if (processor.gpr[getR1(instruction)] != 
                      processor.gpr[getR2(instruction)]) 
                    { processor.pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BLT  : if (processor.gpr[getR1(instruction)] <
                      processor.gpr[getR2(instruction)])
                    { processor.pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BGT  : if (processor.gpr[getR1(instruction)] >
                     processor.gpr[getR2(instruction)]) 
                   { processor.pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BLE  : if (processor.gpr[getR1(instruction)] <= 
                      processor.gpr[getR2(instruction)]) 
                  { processor.pc += getImmediateValue(instruction) * 4;};
                  break;
                  
      case BGE  : if (processor.gpr[getR1(instruction)] >= 
                      processor.gpr[getR2(instruction)]) 
                    { processor.pc += (getImmediateValue(instruction) * 4);};
                  break;
                  
      case JMP  : processor.pc = getAddress(instruction);
                  break;
                  
      case JR   : processor.pc = getRegisterValue
                    (&processor, getR1(instruction));
                  break;
                  
      case JAL  : processor.gpr[31] = processor.pc + sizeof(uint32_t); 
                  processor.pc = getAddress(instruction);
                  break;
                  
      case OUT  : printf("%c", (char)getRegisterValue
                    (&processor, getR1(instruction)));
                  break;
                  
      case DIV  : division = div(getRegisterValue(&processor,getR2(instruction))
                              ,getRegisterValue(&processor,getR3(instruction)));
                  processor.gpr[getR1(instruction)] = division.quot;
      
      case DIVI : division = div(getRegisterValue(&processor,getR2(instruction))
                              ,getImmediateValue(instruction));
                  processor.gpr[getR1(instruction)] = division.quot;
      
      case MOD  : division = div(getRegisterValue(&processor,getR2(instruction))
                              ,getRegisterValue(&processor,getR3(instruction)));
                  processor.gpr[getR1(instruction)] = division.rem;
      
      case MODI : division = div(getRegisterValue(&processor,getR2(instruction))
                              ,getImmediateValue(instruction));
                  processor.gpr[getR1(instruction)] = division.rem;
      
      case FACT : processor.gpr[getR1(instruction)] = 
                  getRegisterValue(&processor, getR2(instruction));
                  for(int i = 1; i<processor.gpr[getR2(instruction)] ; i++) {
                    processor.gpr[getR1(instruction)] = 
                      (getRegisterValue(&processor, getR1(instruction)))*
                      (getRegisterValue(&processor, getR2(instruction))-i);};
                  break;
      
      case FACTI: processor.gpr[getR1(instruction)] = 
                  getImmediateValue(instruction);
                  for(int i = 1; i<getImmediateValue(instruction) ; i++) {
                    processor.gpr[getR1(instruction)] = 
                      (getRegisterValue(&processor, getR1(instruction)))*
                      (getImmediateValue(instruction)-i);};
                  break;
      
      case SWAP : temp = 
                    getRegisterValue(&processor, getR1(instruction));
                  processor.gpr[getR1(instruction)] = 
                    getRegisterValue(&processor, getR2(instruction));
                  processor.gpr[getR2(instruction)] = temp;
                  break;
                  
      default   : printf("invalid opcode\n");
                  break;
    }
    
    if(processor.pc == backupPC)
      processor.pc += sizeof(uint32_t);
  }
  
  fflush(stdout);

  dumpProcessor(&processor);

  return EXIT_SUCCESS;
}