commit 80b801753ece3c2c5465e9cb1b1ecb2b1d4d2d89 Author: Taylor Bockman Date: Wed Jul 5 23:39:11 2017 -0700 Initial code, documentation in the README.md, etc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e94c98f --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# CMake +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..61e2649 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required (VERSION 3.8) + +set (CMAKE_CXX_STANDARD 11) + +set (CMAKE_C_COMPILER "clang") +set (CMAKE_CXX_COMPILER "clang++") +set (CMAKE_C_COMPILER_ID "Clang") +set (CMAKE_CXX_COMPILER_ID "Clang") +set (CMAKE_VERBOSE_MAKEFILE ON) + +project (uvm) + +set (uvm_VERSION_MAJOR 0) +set (uvm_VERSION_MINOR 1) +set (uvm_VERSION_PATCH 0) + +set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) + +file(GLOB uvm "include/*") +file(GLOB uvm "src/*") + +add_executable(${PROJECT_NAME} ${uvm_SRC} ${uvm_INCLUDE}) +target_link_libraries( + ${PROJECT_NAME} +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..27d8b42 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# uVM - Micro Virtual Machine + +uVM is simply an experiment ins developing a working virtual machine with it's own bytecode. + +## Requirements + +* CMake version 3.8 or higher +* Clang and Clang++ + +## Building + +1. `git clone` the repository +2. `cmake .` +3. `make` + +## Architecture + +uVM is a _stack machine_. That is, it gets all of it's arguments from the stack, and returns the result +of the computation back to the stack when it's done. + +There are some exceptions to this. In particular the current version of uvm supports a single variable, +called `0`, that can be written to using `xpop0` where x is the datatype of the thing getting taken off +the stack. + +Additionally `0` can be placed on the top of the stack using `xpush0`. + +## uVM Instruction Set + +uVM possesses the standard issue instruction set you might expect in a simple VM: + +| Instruction | Opcode | Action | +| ------------ | ------ | ------------------------------------------------------------------------------ | +| ipush _X_ | 0 | Pushes _integer_ X onto the stack | +| ipush0 | 1 | Pushes the _integer_ in `0` onto the stack | +| ipop0 | 2 | Pops the top _integer_ of the stack off and into variable 0 | +| icmp | 3 | Compares the top two items on the stack together and returns a boolean result | +| iadd | 4 | Adds the top two _integer_ arguments of the stack together | +| isub | 5 | Subtracts the top two _integer_ arguments of the stack from each other | +| jmp _LABEL_ | 6 | Unconditional jump to _label_ | +| jc _LABEL_ | 7 | Jump if the top of the stack is a 1 | + + +As I learn more about VM development this instruction set will likely become much more robust. diff --git a/include/decoder.h b/include/decoder.h new file mode 100644 index 0000000..bcc6a0a --- /dev/null +++ b/include/decoder.h @@ -0,0 +1,25 @@ +// This file is part of UVM. +// +// UVM is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// UVM is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with UVM. If not, see . +// +// + + +#ifndef DECODER_H_ +#define DECODER_H_ + + + + +#endif // DECODER_H_ diff --git a/include/opcodes.h b/include/opcodes.h new file mode 100644 index 0000000..788d6e5 --- /dev/null +++ b/include/opcodes.h @@ -0,0 +1,33 @@ +// This file is part of UVM. +// +// UVM is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// UVM is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with UVM. If not, see . +// +// + + +#ifndef OPCODES_H_ +#define OPCODES_H_ + +// Instructions + +#define IPUSH 0x0 +#define IPUSH0 0x1 +#define IPOP0 0x2 +#define CMP 0x3 +#define IADD 0x4 +#define ISUB 0x5 +#define JMP 0x6 +#define JC 0x7 + +#endif // OPCODES_H_ diff --git a/src/uvm.cc b/src/uvm.cc new file mode 100644 index 0000000..cc7154b --- /dev/null +++ b/src/uvm.cc @@ -0,0 +1,16 @@ +// This file is part of UVM. +// +// UVM is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// UVM is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with UVM. If not, see . +// +//