diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..760dc4c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "hw_html/xmlParser"] + path = hw_html/xmlParser + url = https://github.com/lookup69/xmlParser +[submodule "hw_html/CTML"] + path = hw_html/CTML + url = https://github.com/tinfoilboy/CTML diff --git a/hw_html/CMakeLists.txt b/hw_html/CMakeLists.txt new file mode 100644 index 0000000..cc6e897 --- /dev/null +++ b/hw_html/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.0) +project(hw_html CXX) +add_definitions(-g) +add_executable(${PROJECT_NAME} html.cpp main.cpp mcureg.cpp) +add_library(xmlParser xmlParser/xmlParser.cpp) +add_subdirectory(CTML) +target_include_directories(xmlParser PUBLIC xmlParser) +target_link_libraries(${PROJECT_NAME} PRIVATE xmlParser CTML) +target_include_directories(${PROJECT_NAME} PRIVATE .) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -std=c++17) diff --git a/hw_html/CTML b/hw_html/CTML new file mode 160000 index 0000000..45cf94c --- /dev/null +++ b/hw_html/CTML @@ -0,0 +1 @@ +Subproject commit 45cf94c34d31db1a30413a57617608a7c4bae343 diff --git a/hw_html/html.cpp b/hw_html/html.cpp new file mode 100644 index 0000000..dee58ce --- /dev/null +++ b/hw_html/html.cpp @@ -0,0 +1,43 @@ +#include "html.hpp" +#include +#include +#include +#include + +html::html() : + f(nullptr) +{ +} + +html::~html() +{ + if (f) + fclose(f); +} + +html::error html::open(const char *const path) +{ + if (!path) + return html::INVALID_PATH; + + f = fopen(path, "wb"); + + if (!f) + { + fprintf(stderr, "could not open %s for writing, reason: %s\n", path, + strerror(errno)); + return html::OPEN_ERR; + } + + CTML::Document doc; + + doc.AppendNodeToHead(CTML::Node("TITLE", "A9 register map")); + + if (fprintf(f, "%s\n", doc.ToString().c_str()) < 0) + { + fprintf(stderr, "HTML write error\n"); + return html::WRITE_ERR; + } + + return html::OK; +} diff --git a/hw_html/html.hpp b/hw_html/html.hpp new file mode 100644 index 0000000..f9f1c29 --- /dev/null +++ b/hw_html/html.hpp @@ -0,0 +1,21 @@ +#include +#include + +class html +{ +public: + enum error + { + OK, + INVALID_PATH, + OPEN_ERR, + WRITE_ERR + }; + + html(); + virtual ~html(); + error open(const char *path); + +protected: + FILE *f; +}; diff --git a/hw_html/main.cpp b/hw_html/main.cpp new file mode 100644 index 0000000..1c90b27 --- /dev/null +++ b/hw_html/main.cpp @@ -0,0 +1,114 @@ +#include "html.hpp" +#include "mcureg.hpp" +#include +#include +#include +#include + +int main(const int argc, const char *const argv[]) +{ + if (argc != 3) + { + fprintf(stderr, "%s <8955_hard.xml-path> \n", argv[0]); + return EXIT_FAILURE; + } + + const char *const inpath = argv[1]; + const char *const outpath = argv[2]; + + html html; + + if (html.open(outpath)) + return EXIT_FAILURE; + + XMLResults res; + XMLNode root = XMLNode::parseFile(inpath, "bigarchive", &res); + + if (res.error != eXMLErrorNone) + { + fprintf(stderr, "Open %s failed, line %d, column %d, reason: %s.\n", + inpath, res.nLine, res.nColumn, XMLNode::getError(res.error)); + return EXIT_FAILURE; + } + + int n = 0; + + for (int i = 0; i < root.nChildNode("archive"); i++) + { + const XMLNode archive = root.getChildNode("archive", &n); + const char *const relative = archive.getAttribute("relative"); + + if (!relative) + continue; + + int n = 0; + + for (int i = 0; i < archive.nChildNode("module"); i++) + { + const XMLNode module = archive.getChildNode("module", &n); + const char *const name = module.getAttribute("name"); + + if (!name) + continue; + + printf("module %s\n", name); + int n = 0; + + for (int i = 0; i < module.nChildNode("reg"); i++) + { + const XMLNode reg = module.getChildNode("reg", &n); + const char *const name = reg.getAttribute("name"); + + if (!name) + continue; + + printf("\treg %s\n", name); + + int n = 0; + + for (int i = 0; i < reg.nChildNode("bits"); i++) + { + const XMLNode bits = reg.getChildNode("bits", &n); + const char *const name = bits.getAttribute("name"); + mcureg::access access = mcureg::UNDEF; + const char *const access_cs = bits.getAttribute("access"); + + if (!access_cs) + continue; + + const std::string access_s = access_cs; + + if (access_s == "rsv") + access = mcureg::RSV; + else if (access_s == "w1c") + access = mcureg::W1C; + else if (access_s == "w1s") + access = mcureg::W1S; + else if (access_s == "rc") + access = mcureg::RC; + else if (access_s == "rs") + access = mcureg::RS; + else if (access_s == "rw") + access = mcureg::RW; + else if (access_s == "c") + access = mcureg::C; + else if (access_s == "s") + access = mcureg::S; + else if (access_s == "r") + access = mcureg::R; + else if (access_s == "w") + access = mcureg::W; + + if (access == mcureg::UNDEF) + fprintf(stderr, "%s: undefined access\n", name); + else + { + printf("\t\t%s, access %s\n", name, access_cs); + } + } + } + } + } + + return EXIT_SUCCESS; +} diff --git a/hw_html/mcureg.cpp b/hw_html/mcureg.cpp new file mode 100644 index 0000000..f894d42 --- /dev/null +++ b/hw_html/mcureg.cpp @@ -0,0 +1,5 @@ +#include "mcureg.hpp" + +mcureg::mcureg(mcureg::access access) +{ +} diff --git a/hw_html/mcureg.hpp b/hw_html/mcureg.hpp new file mode 100644 index 0000000..8d99de2 --- /dev/null +++ b/hw_html/mcureg.hpp @@ -0,0 +1,8 @@ +class mcureg +{ +public: + enum access {UNDEF, C, R, S, W, RC, RS, RW, RSV, W1C, W1S}; + + explicit mcureg(access access); + virtual ~mcureg() = default; +}; diff --git a/hw_html/xmlParser b/hw_html/xmlParser new file mode 160000 index 0000000..ad1e7bc --- /dev/null +++ b/hw_html/xmlParser @@ -0,0 +1 @@ +Subproject commit ad1e7bcf1f28980d83c442d1d10d47a5fd2c1851