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; } }
echo "\n"; if ($GenerateObjectCode->displayObjectCode() == false) { echo "Error, check your operand table\n"; } // ObjectCode // Operation table with object code array to html $OPTB_WOC = $GenerateObjectCode->getObjectCode(); $OPTB_passOne = $GenerateObjectCode->getAfterPassOne(); print_r_to_html(RESULT_PATH . $OUTPUT_LOG_PREFIX . "optb-woc.html", $OPTB_WOC, "Operation Table with Object Code"); print_r_to_html(RESULT_PATH . $OUTPUT_LOG_PREFIX . "optb-passOne.html", $OPTB_passOne, "Operation Table passOne"); // Symbol table array into to html $SYMTAB = $GenerateObjectCode->getSYMTAB(); print_r_to_html(RESULT_PATH . $OUTPUT_LOG_PREFIX . "symtab.html", $SYMTAB, "Symbol Table"); // generate result file $OPTB_WOCtxtFile = RESULT_PATH . $OUTPUT_LOG_PREFIX . "objectcode.txt"; $GenerateObjectCode->writeTxt($OPTB_WOCtxtFile); $GenerateObjectCode->writeCsv(RESULT_PATH . $OUTPUT_LOG_PREFIX . "optb-woc.csv"); $GenerateObjectCode->writeTxtPassOne(RESULT_PATH . $OUTPUT_LOG_PREFIX . "optb-passOne.txt"); // operation code array to html print_r_to_html(RESULT_PATH . $OUTPUT_LOG_PREFIX . "optab.html", $OPTAB, "Operation Code Table"); 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");