diff options
| author | Julian Blake Kongslie | 2022-06-26 21:48:45 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-06-26 22:06:21 -0700 |
| commit | e7c2eeb6c82d5341019cbb00cfefc55c8a27f232 (patch) | |
| tree | d8293bce0cb5323133f849390e60419c16636b18 | |
| parent | Significant changes, and a working "ISA" that just computes fib(n). (diff) | |
| download | issim-e7c2eeb6c82d5341019cbb00cfefc55c8a27f232.tar.xz | |
Move a bunch of code from headers to separate compilation units.
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 23 | ||||
| -rw-r--r-- | aisa/aisa.cpp | 14 | ||||
| -rw-r--r-- | aisa/aisa.h | 6 | ||||
| -rw-r--r-- | fib/fib.cpp (renamed from isa/fib/fib.h) | 41 | ||||
| -rw-r--r-- | fib/fib.d | 1 | ||||
| -rw-r--r-- | fib/fib.h | 34 | ||||
| -rw-r--r-- | main.cpp | 6 |
7 files changed, 88 insertions, 37 deletions
| @@ -8,7 +8,7 @@ CHRONIC ?= chronic | |||
| 8 | 8 | ||
| 9 | PKGS := fmt | 9 | PKGS := fmt |
| 10 | PKG_FLAGS := $(shell pkg-config --cflags ${PKGS}) | 10 | PKG_FLAGS := $(shell pkg-config --cflags ${PKGS}) |
| 11 | PKG_LIBS := -Wl,--push-state,--as-needed $(shell pkg-config --libs ${PKGS}) -Wl,--pop-state | 11 | PKG_LIBS := -Wl,--push-state,--as-needed,--start-group $(shell pkg-config --libs ${PKGS}) -Wl,--end-group,--pop-state |
| 12 | 12 | ||
| 13 | CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${PKG_FLAGS} ${OPTIMIZE} ${DEBUG} | 13 | CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${PKG_FLAGS} ${OPTIMIZE} ${DEBUG} |
| 14 | 14 | ||
| @@ -28,7 +28,7 @@ endef | |||
| 28 | export GITTAGCPP | 28 | export GITTAGCPP |
| 29 | 29 | ||
| 30 | ifneq ($(shell which ${IWYU}),) | 30 | ifneq ($(shell which ${IWYU}),) |
| 31 | iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp ${CXXFLAGS} $(1) | 31 | iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp -Xiwyu --no_fwd_decls ${CXXFLAGS} $(1) |
| 32 | else | 32 | else |
| 33 | $(warning Not using IWYU) | 33 | $(warning Not using IWYU) |
| 34 | iwyu = | 34 | iwyu = |
| @@ -36,6 +36,10 @@ endif | |||
| 36 | 36 | ||
| 37 | libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) | 37 | libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) |
| 38 | 38 | ||
| 39 | define mksodeps = | ||
| 40 | $(1)_SODEPS := | ||
| 41 | endef | ||
| 42 | |||
| 39 | define mklib = | 43 | define mklib = |
| 40 | 44 | ||
| 41 | ifneq ($(wildcard $(1)/*.cpp),) | 45 | ifneq ($(wildcard $(1)/*.cpp),) |
| @@ -44,9 +48,9 @@ $(call libname,$(1).a): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) | |||
| 44 | @mkdir -p $$(dir $$@) | 48 | @mkdir -p $$(dir $$@) |
| 45 | $${AR} cr $$@ $$+ | 49 | $${AR} cr $$@ $$+ |
| 46 | 50 | ||
| 47 | $(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) | 51 | $(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) $${$(1)_SODEPS} |
| 48 | @mkdir -p $$(dir $$@) | 52 | @mkdir -p $$(dir $$@) |
| 49 | $${CXX} $${CXXFLAGS} -shared -o $$@ $$+ ${PKG_LIBS} | 53 | $${CXX} $${CXXFLAGS} -shared -o $$@ -Wl,--start-group $$+ -Wl,--end-group |
| 50 | 54 | ||
| 51 | PARTARS += $(call libname,$(1).a) | 55 | PARTARS += $(call libname,$(1).a) |
| 52 | PARTSOS += $(call libname,$(1).so) | 56 | PARTSOS += $(call libname,$(1).so) |
| @@ -73,6 +77,11 @@ PARTARS := | |||
| 73 | PARTSOS := | 77 | PARTSOS := |
| 74 | IWYU_CPPS := | 78 | IWYU_CPPS := |
| 75 | 79 | ||
| 80 | $(foreach part,${PARTS},$(eval $(call mksodeps,${part}))) | ||
| 81 | |||
| 82 | DEPFILES := $(shell find -mindepth 1 -name .\* -prune -o -type f -name \*.d -print) | ||
| 83 | include ${DEPFILES} | ||
| 84 | |||
| 76 | $(foreach part,${PARTS},$(eval $(call mklib,${part}))) | 85 | $(foreach part,${PARTS},$(eval $(call mklib,${part}))) |
| 77 | 86 | ||
| 78 | MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) | 87 | MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) |
| @@ -92,11 +101,11 @@ issim-static: build/issim-static | |||
| 92 | 101 | ||
| 93 | build/issim-dynamic: ${MAINOBJS} ${PARTSOS} | 102 | build/issim-dynamic: ${MAINOBJS} ${PARTSOS} |
| 94 | @mkdir -p $(dir $@) | 103 | @mkdir -p $(dir $@) |
| 95 | ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} | 104 | ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} |
| 96 | 105 | ||
| 97 | build/issim-static: ${MAINOBJS} ${PARTARS} | 106 | build/issim-static: ${MAINOBJS} ${PARTARS} |
| 98 | @mkdir -p $(dir $@) | 107 | @mkdir -p $(dir $@) |
| 99 | ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} | 108 | ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} |
| 100 | 109 | ||
| 101 | clean: | 110 | clean: |
| 102 | rm -rf build issim issim-static | 111 | rm -rf build issim issim-static |
| @@ -107,8 +116,6 @@ build/git-tag.cpp: | |||
| 107 | @echo "$$GITTAGCPP" > $@ | 116 | @echo "$$GITTAGCPP" > $@ |
| 108 | .PHONY: build/git-tag.cpp | 117 | .PHONY: build/git-tag.cpp |
| 109 | 118 | ||
| 110 | include $(shell find -type f -name \*.d) | ||
| 111 | |||
| 112 | build/%.o: %.cpp | 119 | build/%.o: %.cpp |
| 113 | @mkdir -p $(dir $@) | 120 | @mkdir -p $(dir $@) |
| 114 | @$(call iwyu,$<) | 121 | @$(call iwyu,$<) |
diff --git a/aisa/aisa.cpp b/aisa/aisa.cpp new file mode 100644 index 0000000..811c882 --- /dev/null +++ b/aisa/aisa.cpp | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #include <memory> | ||
| 2 | #include <optional> | ||
| 3 | #include <utility> | ||
| 4 | |||
| 5 | #include "aisa/aisa.h" | ||
| 6 | |||
| 7 | namespace aisa { | ||
| 8 | |||
| 9 | std::optional<std::pair<std::unique_ptr<const Step>, regval_t>> Task::step(regval_t environment_val) const { return {}; } | ||
| 10 | |||
| 11 | MemInfo Step::meminfo(const Wires &wires) const { return {}; } | ||
| 12 | void Step::evaluate(Wires &wires) const { } | ||
| 13 | |||
| 14 | } | ||
diff --git a/aisa/aisa.h b/aisa/aisa.h index 4488529..e4e1074 100644 --- a/aisa/aisa.h +++ b/aisa/aisa.h | |||
| @@ -31,7 +31,7 @@ namespace aisa { | |||
| 31 | 31 | ||
| 32 | virtual std::string disasm() const = 0; | 32 | virtual std::string disasm() const = 0; |
| 33 | 33 | ||
| 34 | virtual std::optional<std::pair<std::unique_ptr<const Step>, regval_t>> step(regval_t environment_val) const { return {}; } | 34 | virtual std::optional<std::pair<std::unique_ptr<const Step>, regval_t>> step(regval_t environment_val) const; |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | struct MemInfo { | 37 | struct MemInfo { |
| @@ -78,8 +78,8 @@ namespace aisa { | |||
| 78 | 78 | ||
| 79 | MOp mop = MOp::NONE; | 79 | MOp mop = MOp::NONE; |
| 80 | 80 | ||
| 81 | virtual MemInfo meminfo(const Wires &wires) const { return {}; } | 81 | virtual MemInfo meminfo(const Wires &wires) const; |
| 82 | virtual void evaluate(Wires &wires) const { }; | 82 | virtual void evaluate(Wires &wires) const; |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | } | 85 | } |
diff --git a/isa/fib/fib.h b/fib/fib.cpp index 13801c8..8ff7718 100644 --- a/isa/fib/fib.h +++ b/fib/fib.cpp | |||
| @@ -1,30 +1,17 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <fmt/core.h> | 1 | #include <fmt/core.h> |
| 4 | #include <memory> | 2 | #include <memory> |
| 5 | #include <optional> | 3 | #include <optional> |
| 6 | #include <string> | 4 | #include <string> |
| 5 | #include <type_traits> | ||
| 7 | #include <utility> | 6 | #include <utility> |
| 8 | #include <vector> | 7 | #include <vector> |
| 9 | 8 | ||
| 10 | #include "aisa/aisa.h" | 9 | #include "aisa/aisa.h" |
| 10 | #include "fib/fib.h" | ||
| 11 | 11 | ||
| 12 | namespace isa::fib { | 12 | namespace fib { |
| 13 | 13 | ||
| 14 | namespace Reg { | 14 | namespace Reg { |
| 15 | enum { | ||
| 16 | ENV_TOP, | ||
| 17 | ENV_FIB, | ||
| 18 | |||
| 19 | AREG, | ||
| 20 | ATMP, | ||
| 21 | |||
| 22 | PC, | ||
| 23 | |||
| 24 | A, | ||
| 25 | B, | ||
| 26 | Q, | ||
| 27 | }; | ||
| 28 | 15 | ||
| 29 | const char *disasm(aisa::regnum_t x) | 16 | const char *disasm(aisa::regnum_t x) |
| 30 | { | 17 | { |
| @@ -40,6 +27,7 @@ namespace isa::fib { | |||
| 40 | default: return "???"; | 27 | default: return "???"; |
| 41 | } | 28 | } |
| 42 | } | 29 | } |
| 30 | |||
| 43 | } | 31 | } |
| 44 | 32 | ||
| 45 | struct StepAdd : public aisa::Step { | 33 | struct StepAdd : public aisa::Step { |
| @@ -277,12 +265,19 @@ namespace isa::fib { | |||
| 277 | } | 265 | } |
| 278 | }; | 266 | }; |
| 279 | 267 | ||
| 280 | template<unsigned int WORD=1> struct Fib : public aisa::ISA { | 268 | template<unsigned int WORD> std::pair<std::unique_ptr<const aisa::Task>, aisa::regval_t> Fib<WORD>::initial_task() const |
| 281 | std::pair<std::unique_ptr<const aisa::Task>, aisa::regval_t> initial_task() const override | 269 | { |
| 282 | { | 270 | auto t = std::make_unique<TaskTop<WORD>>(); |
| 283 | auto t = std::make_unique<TaskTop<WORD>>(); | 271 | return {std::move(t), 0}; |
| 284 | return {std::move(t), 0}; | 272 | } |
| 285 | } | 273 | |
| 286 | }; | 274 | template struct Fib<1>; |
| 275 | template struct Fib<2>; | ||
| 276 | template struct Fib<3>; | ||
| 277 | template struct Fib<4>; | ||
| 278 | template struct Fib<5>; | ||
| 279 | template struct Fib<6>; | ||
| 280 | template struct Fib<7>; | ||
| 281 | template struct Fib<8>; | ||
| 287 | 282 | ||
| 288 | } | 283 | } |
diff --git a/fib/fib.d b/fib/fib.d new file mode 100644 index 0000000..a6d18cc --- /dev/null +++ b/fib/fib.d | |||
| @@ -0,0 +1 @@ | |||
| fib_SODEPS += build/libaisa.so | |||
diff --git a/fib/fib.h b/fib/fib.h new file mode 100644 index 0000000..6719d06 --- /dev/null +++ b/fib/fib.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <memory> | ||
| 4 | #include <utility> | ||
| 5 | |||
| 6 | #include "aisa/aisa.h" | ||
| 7 | |||
| 8 | namespace fib { | ||
| 9 | |||
| 10 | namespace Reg { | ||
| 11 | |||
| 12 | enum { | ||
| 13 | ENV_TOP, | ||
| 14 | ENV_FIB, | ||
| 15 | |||
| 16 | AREG, | ||
| 17 | ATMP, | ||
| 18 | |||
| 19 | PC, | ||
| 20 | |||
| 21 | A, | ||
| 22 | B, | ||
| 23 | Q, | ||
| 24 | }; | ||
| 25 | |||
| 26 | const char *disasm(aisa::regnum_t x); | ||
| 27 | |||
| 28 | } | ||
| 29 | |||
| 30 | template<unsigned int WORD=1> struct Fib : public aisa::ISA { | ||
| 31 | std::pair<std::unique_ptr<const aisa::Task>, aisa::regval_t> initial_task() const override; | ||
| 32 | }; | ||
| 33 | |||
| 34 | } | ||
| @@ -8,8 +8,8 @@ | |||
| 8 | #include "aisa/aisa.h" | 8 | #include "aisa/aisa.h" |
| 9 | #include "aisa/async.h" | 9 | #include "aisa/async.h" |
| 10 | #include "aisa/simple-models.h" | 10 | #include "aisa/simple-models.h" |
| 11 | #include "fib/fib.h" | ||
| 11 | #include "git-tag.h" | 12 | #include "git-tag.h" |
| 12 | #include "isa/fib/fib.h" | ||
| 13 | 13 | ||
| 14 | const bool show_mem_fetch = false; | 14 | const bool show_mem_fetch = false; |
| 15 | const bool show_mem_store = true; | 15 | const bool show_mem_store = true; |
| @@ -21,7 +21,7 @@ int main(int argc, const char *argv[]) | |||
| 21 | { | 21 | { |
| 22 | std::cout << "Version " << GIT_TAG << "\n"; | 22 | std::cout << "Version " << GIT_TAG << "\n"; |
| 23 | 23 | ||
| 24 | isa::fib::Fib<2> fib; | 24 | fib::Fib<2> fib; |
| 25 | 25 | ||
| 26 | struct Eval : public aisa::AsyncEval<Eval>, aisa::PagedMem<>, aisa::TaskStack, aisa::VectorRF { | 26 | struct Eval : public aisa::AsyncEval<Eval>, aisa::PagedMem<>, aisa::TaskStack, aisa::VectorRF { |
| 27 | bool fetch_mem(aisa::byte_t *bytes, aisa::addr_t addr, aisa::addr_t size) | 27 | bool fetch_mem(aisa::byte_t *bytes, aisa::addr_t addr, aisa::addr_t size) |
| @@ -55,7 +55,7 @@ int main(int argc, const char *argv[]) | |||
| 55 | { | 55 | { |
| 56 | if (aisa::VectorRF::store_reg(rn, rv)) { | 56 | if (aisa::VectorRF::store_reg(rn, rv)) { |
| 57 | if (show_regs) | 57 | if (show_regs) |
| 58 | fmt::print(".{} = {}\n", isa::fib::Reg::disasm(rn), rv); | 58 | fmt::print(".{} = {}\n", fib::Reg::disasm(rn), rv); |
| 59 | return true; | 59 | return true; |
| 60 | } | 60 | } |
| 61 | return false; | 61 | return false; |
