From c0fc93c02587d16121457a37aa0f67ca6e3a2bc2 Mon Sep 17 00:00:00 2001 From: Martin Perner Date: Tue, 11 Jan 2011 14:54:11 +0100 Subject: [PATCH] sim: highlight for instr simple version --- 3b_sim/Makefile.flags | 4 ++-- 3b_sim/ccpu.cpp | 27 +++++++++++++++++++++++++-- 3b_sim/ccpu.hpp | 3 +++ 3b_sim/sim.cpp | 3 ++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/3b_sim/Makefile.flags b/3b_sim/Makefile.flags index 23cf272..8e15626 100644 --- a/3b_sim/Makefile.flags +++ b/3b_sim/Makefile.flags @@ -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 diff --git a/3b_sim/ccpu.cpp b/3b_sim/ccpu.cpp index 873f1b7..9cf728b 100644 --- a/3b_sim/ccpu.cpp +++ b/3b_sim/ccpu.cpp @@ -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(); } diff --git a/3b_sim/ccpu.hpp b/3b_sim/ccpu.hpp index 11f6152..4a87240 100644 --- a/3b_sim/ccpu.hpp +++ b/3b_sim/ccpu.hpp @@ -9,6 +9,7 @@ class Iinstr; +#include #include "Iinstr.hpp" @@ -63,6 +64,8 @@ class CCpu { int getStack() const; void setStack(const int); + string colorifyInstr(string instr); + CCpu(int,int,int); }; diff --git a/3b_sim/sim.cpp b/3b_sim/sim.cpp index 3200e92..6cd72b1 100644 --- a/3b_sim/sim.cpp +++ b/3b_sim/sim.cpp @@ -74,6 +74,7 @@ CCpu* global_cpu = NULL; vector breakpoints; + #include multimap dataCommentsStore, progCommentsStore, dataLabelStore, progLabelStore; @@ -403,7 +404,7 @@ void printPROG(const vector& 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()) { -- 2.25.1