sim: highlight for instr
[calu.git] / 3b_sim / ccpu.cpp
index 873f1b7af8160baf9907fe600981e3226f24c0cd..9cf728bcca924f9875797fab4e41ba46ba4c66e0 100644 (file)
@@ -6,6 +6,29 @@
 
 //void registerExtension() {};
 
+const char* expression = "(;.*)|(r0)|(rX)|(r1[0-5])|(r[1-5])|(r[6-9])|(0x[a-fA-F0-9]+)|([-]?\\d+)";
+const char* format = "(?1$&)"
+                                       //Return-Register: violett
+                                       "(?2\033[0m\033[35m$&\033[0m\\3:)"
+                                       // Callee-saved Register: rot
+                                       "(?4\033[0m\033[31m$&\033[0m\\3:)"
+                                       //Argument-Register: gruen
+                                       "(?5\033[0m\033[32m$&\033[0m\\3:)"
+                                       // Temporary Register: gelb
+                                       "(?6\033[0m\033[33m$&\033[0m\\3:)"
+                                       // Zahlenwerte: tuerkis
+                                       "(?7\033[0m\033[36m$&\033[0m\\3:)"
+                                       "(?8\033[0m\033[36m$&\033[0m\\3:)";
+
+
+string CCpu::colorifyInstr(string instr)
+{
+       boost::regex e;
+       e.assign(expression);
+       return boost::regex_replace(instr, e, format, boost::match_default | boost::format_all);
+}
+
+
 void CCpu::tick()
 {
        // signal extensions
@@ -18,12 +41,12 @@ void CCpu::tick()
                throw string("Out of Instructions!");
        }
        if(this->conditionMet(instr->getCondition())) {
-               cout << color(green,black) << "Executing: " << color(white,black) << instr->toString() << endl;
+               cout << color(green,black) << "Executing: " << color(white,black) << colorifyInstr(instr->toString()) << endl;
                instr->execInstr();
                this->incPerfBy(instr->getClockCount());
        }
        else {
-               cout << color(red,black) << "Didn't Execute " << color(white,black) << instr->toString() << "; condition wasn't met" << endl;
+               cout << color(red,black) << "Didn't Execute " << color(white,black) << colorifyInstr(instr->toString()) << "; condition wasn't met" << endl;
                this->incPerf();
        }