From a02677612671b2d2601856ac91f8beb88dc6c049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=B6rlein?= Date: Sat, 1 Jun 2019 14:13:12 +0200 Subject: [PATCH] #25: add method-kind __entry__ and geberate _entry-constants for static linking; generate bison++ files first --- Makefile | 9 +++++++++ bootstrap-cpp/Makefile | 2 +- bootstrap-cpp/Makefile.libs | 6 +++--- .../ast/nodes/declaration/MethodDeclNode.hpp | 2 +- .../src/poolc/ast/visitors/PrettyPrinter.cpp | 3 +++ .../src/poolc/backend/x86/X86Writer.cpp | 9 ++++++--- bootstrap-cpp/src/poolc/parser/Parser.h | 1 + bootstrap-cpp/src/poolc/parser/PoolParser.rr | 1 + bootstrap-cpp/src/poolc/parser/lex.cc | 1 + bootstrap-cpp/src/poolc/parser/parse.gram | 16 ++++++++++++++++ bootstrap-pool/src/pool/command/Store.pool | 8 +------- src/my/simple/TestCommand.pool | 8 +------- 12 files changed, 44 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index b9a7b77c..656767d0 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ diff --git a/bootstrap-cpp/Makefile b/bootstrap-cpp/Makefile index 5181584b..78a19aac 100644 --- a/bootstrap-cpp/Makefile +++ b/bootstrap-cpp/Makefile @@ -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)" diff --git a/bootstrap-cpp/Makefile.libs b/bootstrap-cpp/Makefile.libs index 32903780..5c6ed373 100644 --- a/bootstrap-cpp/Makefile.libs +++ b/bootstrap-cpp/Makefile.libs @@ -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 diff --git a/bootstrap-cpp/include/poolc/ast/nodes/declaration/MethodDeclNode.hpp b/bootstrap-cpp/include/poolc/ast/nodes/declaration/MethodDeclNode.hpp index c53c7300..0ce1951d 100644 --- a/bootstrap-cpp/include/poolc/ast/nodes/declaration/MethodDeclNode.hpp +++ b/bootstrap-cpp/include/poolc/ast/nodes/declaration/MethodDeclNode.hpp @@ -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: diff --git a/bootstrap-cpp/src/poolc/ast/visitors/PrettyPrinter.cpp b/bootstrap-cpp/src/poolc/ast/visitors/PrettyPrinter.cpp index c2dde1a9..5bd449c0 100644 --- a/bootstrap-cpp/src/poolc/ast/visitors/PrettyPrinter.cpp +++ b/bootstrap-cpp/src/poolc/ast/visitors/PrettyPrinter.cpp @@ -112,6 +112,9 @@ bool PrettyPrinter::visit(MethodDeclNode & methodDecl) { case abstract: line << "abstract "; break; + case entry: + line << "__entry__ "; + break; case naked: line << "__naked__ "; break; diff --git a/bootstrap-cpp/src/poolc/backend/x86/X86Writer.cpp b/bootstrap-cpp/src/poolc/backend/x86/X86Writer.cpp index 89f2552a..51d6e47c 100644 --- a/bootstrap-cpp/src/poolc/backend/x86/X86Writer.cpp +++ b/bootstrap-cpp/src/poolc/backend/x86/X86Writer.cpp @@ -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: @@ -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) { @@ -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"; @@ -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"; } } diff --git a/bootstrap-cpp/src/poolc/parser/Parser.h b/bootstrap-cpp/src/poolc/parser/Parser.h index 6e1ce983..0c237af4 100644 --- a/bootstrap-cpp/src/poolc/parser/Parser.h +++ b/bootstrap-cpp/src/poolc/parser/Parser.h @@ -73,6 +73,7 @@ class Parser: public ParserBase int makeCString(); int makeInt(); + int makeEntry(); int makeNaked(); int makePasm(); diff --git a/bootstrap-cpp/src/poolc/parser/PoolParser.rr b/bootstrap-cpp/src/poolc/parser/PoolParser.rr index 5df50b97..09130bdc 100644 --- a/bootstrap-cpp/src/poolc/parser/PoolParser.rr +++ b/bootstrap-cpp/src/poolc/parser/PoolParser.rr @@ -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(); } diff --git a/bootstrap-cpp/src/poolc/parser/lex.cc b/bootstrap-cpp/src/poolc/parser/lex.cc index 3cdcbe5d..7112af34 100644 --- a/bootstrap-cpp/src/poolc/parser/lex.cc +++ b/bootstrap-cpp/src/poolc/parser/lex.cc @@ -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; } diff --git a/bootstrap-cpp/src/poolc/parser/parse.gram b/bootstrap-cpp/src/poolc/parser/parse.gram index a09f845f..9bed32ae 100644 --- a/bootstrap-cpp/src/poolc/parser/parse.gram +++ b/bootstrap-cpp/src/poolc/parser/parse.gram @@ -55,6 +55,7 @@ %token CSTRING %token INT +%token ENTRY %token NAKED %token PASM @@ -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 &, MutableCollection &>(*$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(); } @@ -477,6 +492,7 @@ method_decl: } | '[' error '}' | GLOBAL '[' error '}' +| ENTRY '[' error '}' | NAKED '[' error '}' | ABSTRACT '[' error ';' ; diff --git a/bootstrap-pool/src/pool/command/Store.pool b/bootstrap-pool/src/pool/command/Store.pool index d54af072..b1b7c924 100644 --- a/bootstrap-pool/src/pool/command/Store.pool +++ b/bootstrap-pool/src/pool/command/Store.pool @@ -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); } diff --git a/src/my/simple/TestCommand.pool b/src/my/simple/TestCommand.pool index 28a403a3..f7c9804d 100644 --- a/src/my/simple/TestCommand.pool +++ b/src/my/simple/TestCommand.pool @@ -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); }