Skip to content

Commit

Permalink
#25: add method-kind __entry__ and geberate _entry-constants for stat…
Browse files Browse the repository at this point in the history
…ic linking; generate bison++ files first
  • Loading branch information
mwoerlein committed Jun 1, 2019
1 parent 1c069d0 commit a026776
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
all clean:
@$(MAKE) -sC bootstrap-cpp $@
@$(MAKE) -sC bootstrap-pool $@


POOLSC=./bootstrap-cpp/bin/poolbsc
PSC_FLAGS=--binding linux::elf -t 0x10000 --classpath ./src --classpath ./bootstrap-pool/src --classpath ../gridos/src
/tmp/pooltest: ./src/my/simple/TestCommand.pool $(POOLSC)
@echo "build pooltest (pool)"
@echo "$(POOLSC) $(PSC_FLAGS) --output $@ my::simple::TestCommand2"
@$(POOLSC) $(PSC_FLAGS) --output $@ my::simple::TestCommand2
@chmod a+x $@
2 changes: 1 addition & 1 deletion bootstrap-cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ STOREBLIBS = linux.a sys.a
all: clean $(BINDIR)/pbasm $(BINDIR)/poolbc $(BINDIR)/poolbsc $(BINDIR)/storeb

clean:
@rm -rf $(BINDIR) $(OBJDIR) $(LIBDIR) $(SRCDIR)/poolc/parser/parse.cc $(SRCDIR)/poolc/parser/PoolParser.cc $(SRCDIR)/pasm/i386/PasmParser.cpp
@rm -rf $(BINDIR) $(OBJDIR) $(LIBDIR) $(SRCDIR)/poolc/parser/Parserbase.h $(SRCDIR)/poolc/parser/parse.cc $(SRCDIR)/poolc/parser/PoolParser.cc $(SRCDIR)/pasm/i386/PasmParser.cpp

$(BINDIR)/pbasm: $(SRCDIR)/commands/pbasm.cpp $(PBASMLIBS:%=$(LIBDIR)/%) $(BINDIR)
@echo "build pbasm (cpp)"
Expand Down
6 changes: 3 additions & 3 deletions bootstrap-cpp/Makefile.libs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ LIBRE2CSRC2=$(shell find $(SRCDIR)/$(LIBNAME)/ -type f -name '*.rr')
LIBCCSRC=$(shell find $(SRCDIR)/$(LIBNAME)/ -type f -name '*.cc')
LIBBISONSRC=$(shell find $(SRCDIR)/$(LIBNAME)/ -type f -name '*.gram')
LIBOBJS=\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.cpp,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBSRC))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.gram,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBBISONSRC))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.re,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBRE2CSRC))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.rr,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBRE2CSRC2))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.gram,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBBISONSRC))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.cc,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBCCSRC))
$(patsubst $(SRCDIR)/$(LIBNAME)/%.cc,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBCCSRC))\
$(patsubst $(SRCDIR)/$(LIBNAME)/%.cpp,$(OBJDIR)/$(LIBNAME)/%.o,$(LIBSRC))

.PHONY: all none

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "poolc/ast/collection/NodeList.hpp"
#include "poolc/ast/nodes/InstructionNode.hpp"

enum method_kind { abstract, naked, normal };
enum method_kind { abstract, naked, normal, entry };

class MethodDeclNode: virtual public Node {
public:
Expand Down
3 changes: 3 additions & 0 deletions bootstrap-cpp/src/poolc/ast/visitors/PrettyPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ bool PrettyPrinter::visit(MethodDeclNode & methodDecl) {
case abstract:
line << "abstract ";
break;
case entry:
line << "__entry__ ";
break;
case naked:
line << "__naked__ ";
break;
Expand Down
9 changes: 6 additions & 3 deletions bootstrap-cpp/src/poolc/backend/x86/X86Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ bool X86Writer::visit(MethodDeclNode & methodDef) {
switch (methodDef.kind) {
case abstract:
break;
case entry:
elem() << "_entry_class_desc := " << classStart() << "\n";
elem() << "_entry_global_func := " << methodDecl(&methodDef) << "\n";
case normal:
LABEL(methodDecl(&methodDef));
default:
Expand Down Expand Up @@ -378,7 +381,7 @@ void X86Writer::write(PIRBasicBlock &block) {
MethodDeclNode *methodDecl = block.method.scope().getMethodDeclNode();
switch (block.kind) {
case bb_entry: {
if (methodDecl->kind == normal) {
if (methodDecl->kind == normal || methodDecl->kind == entry) {
code() << "pushl %ebp; movl %esp, %ebp\n";
int localVariables = curMethod->tempCount() + curMethod->spillCount();
if (localVariables) {
Expand All @@ -401,7 +404,7 @@ void X86Writer::write(PIRBasicBlock &block) {
break;
}
case bb_exit: {
if (methodDecl->kind == normal) {
if (methodDecl->kind == normal || methodDecl->kind == entry) {
LABEL(methodDeclBlock(methodDecl, &block));
// treat all registers callee save until register allocation (#11) and enhanced inline asm (#14)
code() << "popad\n";
Expand All @@ -422,7 +425,7 @@ void X86Writer::write(PIRBasicBlock &block) {
if (block.cond) {
write(*block.cond, *block.condNext);
}
if (methodDecl->kind == normal || block.next->kind == bb_block) {
if (methodDecl->kind == normal || methodDecl->kind == entry || block.next->kind == bb_block) {
code() << "jmp " << methodDeclBlock(methodDecl, block.next) << "\n";
}
}
Expand Down
1 change: 1 addition & 0 deletions bootstrap-cpp/src/poolc/parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Parser: public ParserBase
int makeCString();
int makeInt();

int makeEntry();
int makeNaked();
int makePasm();

Expand Down
1 change: 1 addition & 0 deletions bootstrap-cpp/src/poolc/parser/PoolParser.rr
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ int PoolParser::lex()
"cstring" { setLocation(); return parser->makeCString(); }
"int" { setLocation(); return parser->makeInt(); }

"__entry__" { setLocation(); return parser->makeEntry(); }
"__naked__" { setLocation(); return parser->makeNaked(); }
"__pasm__" { setLocation(); return parser->makePasm(); }

Expand Down
1 change: 1 addition & 0 deletions bootstrap-cpp/src/poolc/parser/lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int Parser::makeAny() { return ANY; }
int Parser::makeCString() { return CSTRING; }
int Parser::makeInt() { return INT; }

int Parser::makeEntry() { return ENTRY; }
int Parser::makeNaked() { return NAKED; }
int Parser::makePasm() { return PASM; }

Expand Down
16 changes: 16 additions & 0 deletions bootstrap-cpp/src/poolc/parser/parse.gram
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
%token CSTRING
%token INT

%token ENTRY
%token NAKED
%token PASM

Expand Down Expand Up @@ -445,6 +446,20 @@ method_decl:
$$->last_line = @11.last_line;
$$->last_column = @11.last_column;

$3->destroy();
$7->destroy();
}
| ENTRY '[' type_list_empty ']' ID '(' variable_decl_list_empty ')' '{' instruction_block '}'
{
$$ = &driver.env().create<MethodDeclNode, String&, BlockInstNode&, MutableCollection<TypeRefNode> &, MutableCollection<VariableDeclNode> &>(*$5, *$10, *$3, *$7);
$$->global = true;
$$->kind = entry;

$$->first_line = @1.first_line;
$$->first_column = @1.first_column;
$$->last_line = @11.last_line;
$$->last_column = @11.last_column;

$3->destroy();
$7->destroy();
}
Expand Down Expand Up @@ -477,6 +492,7 @@ method_decl:
}
| '[' error '}'
| GLOBAL '[' error '}'
| ENTRY '[' error '}'
| NAKED '[' error '}'
| ABSTRACT '[' error ';'
;
Expand Down
8 changes: 1 addition & 7 deletions bootstrap-pool/src/pool/command/Store.pool
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ Storage Bootstrap Builder.
}

// methods
global [int] __entry__(int argc, int argv) {
// TODO: generate automatically via new __entry__ flag for method or via naming convention?
__pasm__(<"
_entry_class_desc := _pool_command_Store
_entry_global_func := _c304b04e_md___entry__
">);

__entry__ [int] entry(int argc, int argv) {
Store store = linux::Runtime:buildRuntime().createInstance(Store:CLASSNAME);
return store.execute(argc, argv);
}
Expand Down
8 changes: 1 addition & 7 deletions src/my/simple/TestCommand.pool
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ Pool Test Command.
}

// methods
global [int] __entry__(int argc, int argv) {
// TODO: generate automatically via new __entry__ flag for method or via naming convention?
__pasm__(<"
_entry_class_desc := _my_simple_TestCommand
_entry_global_func := _491d8eb7_md___entry__
">);

__entry__ [int] entry(int argc, int argv) {
TestCommand command = linux::Runtime:buildRuntime().createInstance(TestCommand:CLASSNAME);
return command.execute(argc, argv);
}
Expand Down

0 comments on commit a026776

Please sign in to comment.