From 817b94c739b80bbb00474ec4ee38f9df22e65a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20G=C3=B3mez?= Date: Sat, 26 May 2012 23:54:10 -0430 Subject: [PATCH] show de Block y dependencias arregladas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las dependencias no dependían de las dependencias! Ahora sí. --- tajadac/Makefile | 12 +++++---- tajadac/Makefile.real | 30 ++++++++++++--------- tajadac/Tajada/AST/AST.cc | 6 +++-- tajadac/Tajada/AST/AST.hh | 4 ++- tajadac/Tajada/Code/Block.cc | 51 ++++++++++++++++++++++++++++++++++++ tajadac/Tajada/Code/Block.hh | 10 +++++-- 6 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 tajadac/Tajada/Code/Block.cc diff --git a/tajadac/Makefile b/tajadac/Makefile index ec8febf..402e2bb 100644 --- a/tajadac/Makefile +++ b/tajadac/Makefile @@ -1,15 +1,14 @@ SHELL = bash clean = \ - ./**/*.d \ ./**/*.gch \ ./**/*.gen.* \ - ./**/*.o \ ./**/*.out \ ./**/*.output \ - ./**/*.tab.cc \ - ./**/*.yy \ + ./parser.yy \ + dep \ location.hh \ + obj \ parser.dot \ parser.tab.cc \ parser.tab.hh \ @@ -18,10 +17,13 @@ clean = \ stack.hh \ tajadac \ + + all: clean: - shopt -s globstar && rm -f $(clean) + @echo "Cleaning" + @shopt -s globstar && rm -rf $(clean) %: @$(MAKE) --no-print-directory -f Makefile.real $@ diff --git a/tajadac/Makefile.real b/tajadac/Makefile.real index 1ceb5cd..472a7de 100644 --- a/tajadac/Makefile.real +++ b/tajadac/Makefile.real @@ -24,18 +24,20 @@ build-exec = $(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS:%=-l%) srcs := $(shell find . -type f -name '*.cc') -%.d: %.cc +dep/%.d: %.cc @echo "Calculating dependencies for $<" + @mkdir -p $(dir $@) @$(CXX) $(CXXFLAGS) -E -MM -MF $@ $< - @printf '%s\n' \ - '1s@^@$(dir $@)@' \ - 'wq' \ + @printf '%s\n' \ + '1s@^@$@ obj/$(dir $<)@' \ + 'wq' \ | ed -s ./$@ -%.o: %.cc +obj/%.o: %.cc @echo "Building $<" + @mkdir -p $(dir $@) @$(CXX) $(CXXFLAGS) -c ./$< -o $@ @@ -46,20 +48,22 @@ all: tajadac -tajadac: $(srcs:%.cc=%.o) lex.o main.o parser.tab.o scope.o +tajadac: $(srcs:%.cc=obj/%.o) @echo "Linking $@" @$(build-exec) -# .d: parser.tab.hh stack.hh location.hh position.hh - lex.d: parser.tab.hh stack.hh location.hh position.hh - main.d: parser.tab.hh stack.hh location.hh position.hh - parser.tab.d: parser.tab.hh stack.hh location.hh position.hh - scope.d: location.hh +# .d: parser.tab.hh stack.hh location.hh position.hh + dep/lex.d: parser.tab.hh stack.hh location.hh position.hh + dep/main.d: parser.tab.hh stack.hh location.hh position.hh + dep/parser.tab.d: parser.tab.hh stack.hh location.hh position.hh + dep/scope.d: location.hh #ast.gen.cc ast.gen.hh: make_ast_classes data/ast/classes data/ast/members # ./make_ast_classes data/ast/classes data/ast/members ast.gen.cc ast.gen.hh +dep/parser.tab.d: parser.tab.cc + location.hh parser.dot parser.output parser.tab.cc parser.tab.hh parser.xml position.hh stack.hh token_data.out token_data_line.out: parser.y tokens.hh Makefile @printf '%s\n' \ '#include "tokens.hh"' \ @@ -105,9 +109,9 @@ location.hh parser.dot parser.output parser.tab.cc parser.tab.hh parser.xml posi 'w $ +#include +#include + +// Class: +#include "Tajada/Code/Block.hh" + +namespace Tajada { + namespace Code { + Block::Block( + std::string p_label + ): + label(p_label) + {} + + std::string Block::show() { + return + u8"[" + this->label + u8"] {\n" + + std::accumulate( + this->instructions.begin(), + this->instructions.end(), + std::string(), + [](std::string acc, Tajada::Code::Instruction * i) { + return + acc + + u8" " + + i->show() + + u8";\n" + ; + } + ) + + u8"} → [" + + ( + this->successors.empty() + ? u8"" + : + std::accumulate( + this->successors.begin(), + --this->successors.end(), + std::string(), + [](std::string acc, Tajada::Code::Block * b) { + return acc + u8", " + b->label; + } + ) + + this->successors.back()->label + ) + + u8"]\n" + ; + } + } +} diff --git a/tajadac/Tajada/Code/Block.hh b/tajadac/Tajada/Code/Block.hh index 8d07e85..54ccc8b 100644 --- a/tajadac/Tajada/Code/Block.hh +++ b/tajadac/Tajada/Code/Block.hh @@ -10,10 +10,16 @@ namespace Tajada { namespace Code { class Block { public: + std::string label; + std::vector instructions; - std::vector successors; + std::vector successors ; + + Block( + std::string p_label + ); - // TODO: show + std::string show(); }; } }