sim: highlight for instr
authorMartin Perner <martin@perner.cc>
Tue, 11 Jan 2011 13:54:11 +0000 (14:54 +0100)
committerMartin Perner <martin@perner.cc>
Tue, 11 Jan 2011 13:54:41 +0000 (14:54 +0100)
simple version

3b_sim/Makefile.flags
3b_sim/ccpu.cpp
3b_sim/ccpu.hpp
3b_sim/sim.cpp

index 23cf2723ab098c80c6c26a9d7e62ebb50665e5a2..8e156266e0e06645905c92a502f275fcde3094e1 100644 (file)
@@ -3,10 +3,10 @@ OSTYPE = $(shell lsb_release -i -s | tr -d "\n")
 
 ifeq ("$(OSTYPE)", "CentOS")
 CC := g++44
-CPPPROGOPT :=-rdynamic -ldl -lboost_program_options-gcc41-mt-1_37 -lreadline -lcurses
+CPPPROGOPT :=-rdynamic -ldl -lboost_program_options-gcc41-mt-1_37 -lboost_regex-gcc41-mt-1_37 -lreadline -lcurses
 else
 CC := g++
-CPPPROGOPT :=-rdynamic -ldl -lboost_program_options -lreadline
+CPPPROGOPT :=-rdynamic -ldl -lboost_program_options -lboost_regex -lreadline
 endif
 
 CPPFLAGS := -g3 -O2 -std=c++0x -Wnon-virtual-dtor -Weffc++ -pedantic -Werror -Wall -Wextra -W -Wshadow -fno-common -pedantic-errors -Wpointer-arith -Wcast-qual -Wcast-align -Woverloaded-virtual -Wswitch-default -Wempty-body -Wlogical-op
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();
        }
 
index 11f615212b9c32ea4e5798cc3da5f11e64a313ec..4a8724004733e5812d3006f57bb4ede00e7ad5c5 100644 (file)
@@ -9,6 +9,7 @@
 
 class Iinstr;
 
+#include <boost/regex.hpp>
 #include "Iinstr.hpp"
 
 
@@ -63,6 +64,8 @@ class CCpu {
                int getStack() const;
                void setStack(const int);
 
+               string colorifyInstr(string instr);
+
                CCpu(int,int,int);
 
 };
index 3200e92a798370baf0ada9c066d7a80fc3d9e65c..6cd72b16cce203b21229d2e44ade6b6a195eac20 100644 (file)
@@ -74,6 +74,7 @@ CCpu* global_cpu = NULL;
 
 vector<CDat> breakpoints;
 
+
 #include <map>
 
 multimap<int,string> dataCommentsStore, progCommentsStore, dataLabelStore, progLabelStore;
@@ -403,7 +404,7 @@ void printPROG(const vector<string>& in)
                        cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": NOP";
                }
                else {
-                       cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": " << std::dec << pi->toString();
+                       cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": " << std::dec << global_cpu->colorifyInstr(pi->toString());
                }
                auto iter = progLineCommentStore.find(i);
                if(iter != progLineCommentStore.end()) {