diff options
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | README | 15 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | asm/intel64/all_ops.h | 3 | ||||
-rw-r--r-- | asm/intel64/nop.cpp | 11 | ||||
-rw-r--r-- | asm/intel64/nop.h | 13 | ||||
-rw-r--r-- | asm/intel64/ret.cpp | 12 | ||||
-rw-r--r-- | asm/intel64/ret.h | 12 | ||||
-rw-r--r-- | asm/intel64/trivials.cpp | 19 | ||||
-rw-r--r-- | asm/intel64/trivials.h | 24 | ||||
-rw-r--r-- | debian/control | 1 | ||||
-rw-r--r-- | systemtest/config/unix.exp | 0 | ||||
-rw-r--r-- | systemtest/lib/mcc.exp | 0 | ||||
-rw-r--r-- | systemtest/mcc-compile.tests/compile.exp | 1 | ||||
-rw-r--r-- | systemtest/mcc-execute.tests/exitcodes.exp | 18 | ||||
-rw-r--r-- | systemtest/mcc-execute.tests/test.cpp | 1 | ||||
-rw-r--r-- | systemtest/mcc-execute.tests/test1.cpp | 1 |
17 files changed, 90 insertions, 54 deletions
@@ -57,9 +57,8 @@ PROGSRC=\ asm/intel64/jmp.cpp \ asm/intel64/mov.cpp \ asm/intel64/mul.cpp \ - asm/intel64/nop.cpp \ - asm/intel64/ret.cpp \ asm/intel64/sub.cpp \ + asm/intel64/trivials.cpp \ asm/intel64/xor.cpp \ asm/intel64/codes.cpp \ asm/intel64/encode.cpp \ @@ -99,6 +98,11 @@ SRC=$(PROGSRC) mcc.cpp all: test-$(PROJECTNAME) mcc ./test-$(PROJECTNAME) --gtest_filter='CppTest.compile' +systemtest: + #./mcc systemtest/mcc-execute.tests/test.cpp + ./mcc systemtest/mcc-execute.tests/test1.cpp + runtest --all --srcdir systemtest --tool mcc + # testsuite ---------------------------------------------- test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ @@ -127,12 +131,14 @@ ADD_DEP=Makefile clean: -rm -f test-$(PROJECTNAME) mcc tempfile.txt -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f + -rm -f systemtest/mcc-execute.tests/test1 + -rm -f *.log *.sum zip: clean -rm -f ../$(PROJECTNAME).zip zip -r ../$(PROJECTNAME).zip * ls -l ../$(PROJECTNAME).zip -.PHONY: clean all zip dep +.PHONY: clean all zip dep systemtest -include $(wildcard $(SRC:.cpp=.d)) @@ -0,0 +1,15 @@ +MCC - Mini Compiler Collection +============================== + +Build +----- + +make clean - Clean all +make - Build all +make systemtest - Run all system tests + +Directories +----------- + +tests/ : Unit tests +systemtest/ : System tests with dejagnu @@ -1,5 +1,4 @@ Asm: Register indirection -test: expect/dejagnu cpp.cpp: eval w/ Data vs. Node encode.cpp: support temporaries diff --git a/asm/intel64/all_ops.h b/asm/intel64/all_ops.h index 82f518f..c41734c 100644 --- a/asm/intel64/all_ops.h +++ b/asm/intel64/all_ops.h @@ -10,7 +10,6 @@ #include "jmp.h" #include "mov.h" #include "mul.h" -#include "nop.h" -#include "ret.h" #include "sub.h" +#include "trivials.h" #include "xor.h" diff --git a/asm/intel64/nop.cpp b/asm/intel64/nop.cpp deleted file mode 100644 index 2d99278..0000000 --- a/asm/intel64/nop.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "nop.h" - -#include <asm/assembler.h> - -namespace { - -bool registered { registerOp("nop", [](Asm::Args& args) -> std::shared_ptr<Op>{ - return std::make_shared<Op_nop>(); - }) }; - -} diff --git a/asm/intel64/nop.h b/asm/intel64/nop.h deleted file mode 100644 index 233b2ef..0000000 --- a/asm/intel64/nop.h +++ /dev/null @@ -1,13 +0,0 @@ -// No Operation - -#pragma once - -#include <asm/chunk.h> - -class Op_nop: public OpSimple -{ -public: - Op_nop() : OpSimple({ 0x90 }) {} - -}; - diff --git a/asm/intel64/ret.cpp b/asm/intel64/ret.cpp deleted file mode 100644 index c42ad8a..0000000 --- a/asm/intel64/ret.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "ret.h" - -#include <asm/assembler.h> - -namespace { - -bool registered { registerOp("ret", [](Asm::Args& args) -> std::shared_ptr<Op>{ - return std::make_shared<Op_ret>(); - }) }; - -} - diff --git a/asm/intel64/ret.h b/asm/intel64/ret.h deleted file mode 100644 index 7e7f68c..0000000 --- a/asm/intel64/ret.h +++ /dev/null @@ -1,12 +0,0 @@ -// Return from procedure - -#pragma once - -#include <asm/chunk.h> - -class Op_ret: public OpSimple -{ -public: - Op_ret() : OpSimple({ 0xC3 }) {} // near return; TODO: far return is 0xCB -}; - diff --git a/asm/intel64/trivials.cpp b/asm/intel64/trivials.cpp new file mode 100644 index 0000000..dd89ecd --- /dev/null +++ b/asm/intel64/trivials.cpp @@ -0,0 +1,19 @@ +#include "trivials.h" + +#include <asm/assembler.h> + +namespace { + +bool registered { + registerOp("nop", [](Asm::Args& args) -> std::shared_ptr<Op>{ + return std::make_shared<Op_nop>(); + }) && + registerOp("ret", [](Asm::Args& args) -> std::shared_ptr<Op>{ + return std::make_shared<Op_ret>(); + }) && + registerOp("syscall", [](Asm::Args& args) -> std::shared_ptr<Op>{ + return std::make_shared<Op_syscall>(); + }) +}; + +} diff --git a/asm/intel64/trivials.h b/asm/intel64/trivials.h new file mode 100644 index 0000000..72ea3f8 --- /dev/null +++ b/asm/intel64/trivials.h @@ -0,0 +1,24 @@ +// Trivial Operations, without arguments + +#pragma once + +#include <asm/chunk.h> + +// No Operation +class Op_nop: public OpSimple +{ +public: Op_nop() : OpSimple({ 0x90 }) {} +}; + +// Return from procedure +class Op_ret: public OpSimple +{ +public: Op_ret() : OpSimple({ 0xC3 }) {} // near return; TODO: far return is 0xCB +}; + +// Syscall +class Op_syscall: public OpSimple +{ +public: Op_syscall() : OpSimple({ 0x0F, 0x05 }) {} +}; + diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..181df4a --- /dev/null +++ b/debian/control @@ -0,0 +1 @@ +Depends: dejagnu, expect diff --git a/systemtest/config/unix.exp b/systemtest/config/unix.exp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/systemtest/config/unix.exp diff --git a/systemtest/lib/mcc.exp b/systemtest/lib/mcc.exp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/systemtest/lib/mcc.exp diff --git a/systemtest/mcc-compile.tests/compile.exp b/systemtest/mcc-compile.tests/compile.exp new file mode 100644 index 0000000..7866d6f --- /dev/null +++ b/systemtest/mcc-compile.tests/compile.exp @@ -0,0 +1 @@ +# https://www.embecosm.com/appnotes/ean8/ean8-howto-dejagnu-1.0.html diff --git a/systemtest/mcc-execute.tests/exitcodes.exp b/systemtest/mcc-execute.tests/exitcodes.exp new file mode 100644 index 0000000..6e8b632 --- /dev/null +++ b/systemtest/mcc-execute.tests/exitcodes.exp @@ -0,0 +1,18 @@ +# https://www.embecosm.com/appnotes/ean8/ean8-howto-dejagnu-1.0.html + +spawn systemtest/mcc-execute.tests/test1 + +expect eof + +lassign [wait] pid spawnid os_error_flag value + +if {$os_error_flag == 0} { + if {$value == 3} { + pass "exit status: $value" + } else { + fail "exit status: $value" + } +} else { + fail "errno: $value" +} + diff --git a/systemtest/mcc-execute.tests/test.cpp b/systemtest/mcc-execute.tests/test.cpp new file mode 100644 index 0000000..40cbb54 --- /dev/null +++ b/systemtest/mcc-execute.tests/test.cpp @@ -0,0 +1 @@ +int main() { return 1; } diff --git a/systemtest/mcc-execute.tests/test1.cpp b/systemtest/mcc-execute.tests/test1.cpp new file mode 100644 index 0000000..3a03f6f --- /dev/null +++ b/systemtest/mcc-execute.tests/test1.cpp @@ -0,0 +1 @@ +int main() { return 1 + 2; } |