Skip to content

Commit

Permalink
show de Block y dependencias arregladas
Browse files Browse the repository at this point in the history
Las dependencias no dependían de las dependencias!  Ahora sí.
  • Loading branch information
mgomezch committed May 27, 2012
1 parent 6b843f0 commit 817b94c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 23 deletions.
12 changes: 7 additions & 5 deletions tajadac/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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 $@
30 changes: 17 additions & 13 deletions tajadac/Makefile.real
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@


Expand All @@ -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"' \
Expand Down Expand Up @@ -105,9 +109,9 @@ location.hh parser.dot parser.output parser.tab.cc parser.tab.hh parser.xml posi
'w $<y' \
'q' \
| ed -s ./$<
@echo "Building parser"
@echo "Generating parser"
@$(YACC) $(YACCFLAGS) ./$<y



-include $(srcs:%.cc=%.d)
-include $(srcs:%.cc=dep/%.d) dep/parser.tab.d
6 changes: 4 additions & 2 deletions tajadac/Tajada/AST/AST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace Tajada {
namespace AST {
AST::~AST() {}

Tajada::Code::Block * AST::gen() {
return new Tajada::Code::Block;
Tajada::Code::Block * AST::gen(
Tajada::Code::Block * b
) {
return b;
}
}
}
4 changes: 3 additions & 1 deletion tajadac/Tajada/AST/AST.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace Tajada {
public:
virtual std::string show(unsigned int depth = 0) = 0;

virtual Tajada::Code::Block * gen();
virtual Tajada::Code::Block * gen(
Tajada::Code::Block * b
);

virtual ~AST() = 0;
};
Expand Down
51 changes: 51 additions & 0 deletions tajadac/Tajada/Code/Block.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <numeric>
#include <string>
#include <vector>

// 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"
;
}
}
}
10 changes: 8 additions & 2 deletions tajadac/Tajada/Code/Block.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ namespace Tajada {
namespace Code {
class Block {
public:
std::string label;

std::vector<Tajada::Code::Instruction *> instructions;
std::vector<Tajada::Code::Block *> successors;
std::vector<Tajada::Code::Block *> successors ;

Block(
std::string p_label
);

// TODO: show
std::string show();
};
}
}
Expand Down

0 comments on commit 817b94c

Please sign in to comment.