private function doPassThree()
 {
     if (max(array_column($this->OPTB_WOC, 'BLOCK')) == 0) {
         return $this->OPTB_WOC;
     } else {
         $OPTB_WOCnoBlock = $this->OPTB_WOC;
         $index = 0;
         foreach ($OPTB_WOCnoBlock as $_OPTB_WOCnoBlock) {
             $OPTB_WOCnoBlock[$index]['O_INDEX'] = $index;
             ++$index;
         }
         $loc = array();
         $block = array();
         foreach ($OPTB_WOCnoBlock as $key => $row) {
             $loc[$key] = $row['LOC'];
             $block[$key] = $row['BLOCK'];
         }
         array_multisort($block, SORT_ASC, array_keys($OPTB_WOCnoBlock), SORT_ASC, $OPTB_WOCnoBlock);
         $debugg = $OPTB_WOCnoBlock;
         $OPTB_WOCnoBlock = array_array_key_filter($OPTB_WOCnoBlock, array('O_INDEX', 'LABEL', 'OPCODE', 'OPERAND'), true);
         $index = 0;
         $line = 5;
         foreach ($OPTB_WOCnoBlock as $_OPTB_WOCnoBlock) {
             if ($_OPTB_WOCnoBlock['OPCODE'] == 'USE' || $_OPTB_WOCnoBlock['LABEL'] === '*' || $_OPTB_WOCnoBlock['OPCODE'] == 'END') {
                 unset($OPTB_WOCnoBlock[$index]);
             } else {
                 $OPTB_WOCnoBlock[$index]['LINE'] = $line;
                 $line += 5;
                 $OPTB_WOCnoBlock[$index]['LOC'] = '';
                 $OPTB_WOCnoBlock[$index]['OBJECTCODE'] = '';
                 $OPTB_WOCnoBlock[$index]['COMMENT'] = '';
             }
             ++$index;
         }
         //print_r($OPTB_WOCnoBlock);
         $generateObjectCode = new GenerateObjectCode($OPTB_WOCnoBlock);
         $OPTB_WOCnoBlock = $generateObjectCode->getAfterPassTwo();
         // fix unknown bug..
         $index = 0;
         $pervious_O_INDEX = 'no_value';
         foreach ($OPTB_WOCnoBlock as $_OPTB_WOCnoBlock) {
             if ($_OPTB_WOCnoBlock['OPCODE'] == 'LTORG') {
                 unset($OPTB_WOCnoBlock[$index]);
             }
             /*
             if(isset($_OPTB_WOCnoBlock['O_INDEX'])) {
             	if($_OPTB_WOCnoBlock['O_INDEX'] == $pervious_O_INDEX) {
             		++$OPTB_WOCnoBlock[$index]['O_INDEX'];
             	}
             	$pervious_O_INDEX = $OPTB_WOCnoBlock[$index]['O_INDEX'];
             }
             */
             ////$this->OPTB_WOC[$_OPTB_WOCnoBlock['O_INDEX']]['realBLOCK'] = $OPTB_WOCnoBlock[$index]['BLOCK'];
             ++$index;
         }
         $generateObjectCode->writeTxt(RESULT_PATH . OUTPUT_LOG_PREFIX . "optbnoBlock-woc.txt");
         $this->writeTxt(RESULT_PATH . OUTPUT_LOG_PREFIX . "optbnoHaveBlock-woc.txt");
         // the foreach solution fail.. for loop success . don't ask why . don't modify the code
         $previousO_INDEX = 'no_value';
         for ($i = 0; $i < count($OPTB_WOCnoBlock); ++$i) {
             if ($previousO_INDEX == 'no_value' && trim($OPTB_WOCnoBlock[$i]['LABEL']) == '*') {
                 $previousO_INDEX = $OPTB_WOCnoBlock[$i]['O_INDEX'];
             }
             if ($previousO_INDEX != 'no_value' && trim($OPTB_WOCnoBlock[$i]['LABEL']) == '*') {
                 $OPTB_WOCnoBlock[$i]['O_INDEX'] = ++$previousO_INDEX;
             }
         }
         //  $_OPTB_WOCnoBlock['OPERAND'] != '#MAXLEN')  fix unknow bug= =... kind of cheat-_-
         // so explain in other way. no idea why format 4 immediate address mode will fail in $OPTB_WOCnoBlock
         $index = 0;
         foreach ($OPTB_WOCnoBlock as $_OPTB_WOCnoBlock) {
             if (!empty($_OPTB_WOCnoBlock['O_INDEX']) && substr($_OPTB_WOCnoBlock['OPERAND'], 0, 1) != '#') {
                 $this->OPTB_WOC[$_OPTB_WOCnoBlock['O_INDEX']]['OBJECTCODE'] = $_OPTB_WOCnoBlock['OBJECTCODE'];
                 $this->OPTB_WOC[$_OPTB_WOCnoBlock['O_INDEX']]['realLOC'] = $_OPTB_WOCnoBlock['LOC'];
             }
             ++$index;
         }
         print_r_to_html(RESULT_PATH . OUTPUT_LOG_PREFIX . "optbnoBlock-woc.html", $OPTB_WOCnoBlock);
         print_r_to_html(RESULT_PATH . OUTPUT_LOG_PREFIX . "optbnoHaveBlock-woc.html", $this->OPTB_WOC);
         //$this->OPTB_WOC = $OPTB_WOCnoBlock;
         //$this->OPTB_WOC = $debugg;
         //$this->OPTB_WOC = $OPTB_WOCnoBlock;
         return $this->OPTB_WOC;
     }
 }
Esempio n. 2
0
 echo "You can review the result in sub folder \"result\"\n";
 // ObjectProgram
 $GenerateObjectProgram = new GenerateObjectProgram($OPTB_WOC);
 $obectProgramTxtFile = RESULT_PATH . $OUTPUT_LOG_PREFIX . "object-program.txt";
 $GenerateObjectProgram->writeTxt($obectProgramTxtFile);
 //*********************************************************
 // find out wrong object code
 //						my generate code	compare to 	original object code
 $originalCodeFile = ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectcode.txt';
 if (file_exists($originalCodeFile)) {
     $orignalCode = csv_to_array($originalCodeFile, "\t");
     echo "Compare Target : " . ORIGIN_FILE_PATH . $path_parts['filename'] . '-objectcode.txt' . "\n";
     $comKey = array("LOC", "LABEL", "OPCODE", "OPERAND", "OBJECTCODE");
     $keep = true;
     $OPTB_WOC = array_array_key_filter($OPTB_WOC, $comKey, $keep);
     $orignalCode = array_array_key_filter($orignalCode, $comKey, $keep);
     //print_r($OPTB_WOC);
     //print_r($orignalCode);
     //print_r( array_diff($OPTB_WOC, $orignalCode) );
     echo "LOC Differentiations : \n";
     print_r(array_diff(array_column($OPTB_WOC, 'LOC'), array_column($orignalCode, 'LOC')));
     echo "LABEL Differentiations : \n";
     print_r(array_diff(array_column($OPTB_WOC, 'LABEL'), array_column($orignalCode, 'LABEL')));
     echo "OPCODE Differentiations : \n";
     print_r(array_diff(array_column($OPTB_WOC, 'OPCODE'), array_column($orignalCode, 'OPCODE')));
     echo "OPERAND Differentiations : \n";
     print_r(array_diff(array_column($OPTB_WOC, 'OPERAND'), array_column($orignalCode, 'OPERAND')));
     echo "OBJECTCODE Differentiations : \n";
     print_r(array_diff(array_column($OPTB_WOC, 'OBJECTCODE'), array_column($orignalCode, 'OBJECTCODE')));
     // compare two files line by line
 } else {