Made the IncludePreprocessor a bit more robust (added -I option to dasm)

This commit is contained in:
OmniaX-Dev 2026-03-20 01:41:22 +01:00
parent 2486e5e4c0
commit 16b706175d
6 changed files with 120 additions and 83 deletions

View file

@ -3,7 +3,7 @@
.entry _kernel0_main .entry _kernel0_main
.header KERNEL0_BOOT .header KERNEL0_BOOT
@include <../../sdk/bios_api.dss> @include <sdk/bios_api.dss>
@include <../drivers/display_driver.dss> @include <../drivers/display_driver.dss>
@include <../drivers/keyboard_driver.dss> @include <../drivers/keyboard_driver.dss>
@include <memory.dss> @include <memory.dss>

View file

@ -6,19 +6,19 @@ green='\033[0;32m'
clear='\033[0m' clear='\033[0m'
printf "${green}Flashing BIOS...\n${clear}" printf "${green}Flashing BIOS...\n${clear}"
./dasm dss/bios/entry.dss -o dragon/bios.bin $1 ./dasm dss/bios/entry.dss -o dragon/bios.bin -I dss $1
printf "\n${green}Compiling Drake...\n${clear}" printf "\n${green}Compiling Drake...\n${clear}"
printf "\n${green}1) loader.dss\n${clear}" printf "\n${green}1) loader.dss\n${clear}"
./dasm dss/drake/loader.dss -o dragon/drake_loader.bin $1 ./dasm dss/drake/loader.dss -o dragon/drake_loader.bin -I dss $1
./dtools load-binary dragon/disk1.dr dragon/drake_loader.bin 0x00000000 ./dtools load-binary dragon/disk1.dr dragon/drake_loader.bin 0x00000000
printf "\n${green}2) bootsector.dss\n${clear}" printf "\n${green}2) bootsector.dss\n${clear}"
./dasm dss/drake/bootsector.dss -o dragon/drake_bootsector.bin $1 ./dasm dss/drake/bootsector.dss -o dragon/drake_bootsector.bin -I dss $1
./dtools load-binary dragon/disk1.dr dragon/drake_bootsector.bin 0x00000400 ./dtools load-binary dragon/disk1.dr dragon/drake_bootsector.bin 0x00000400
printf "\n${green}Compiling DragonOS...\n${clear}" printf "\n${green}Compiling DragonOS...\n${clear}"
printf "\n${green}1) kernel0.dss\n${clear}" printf "\n${green}1) kernel0.dss\n${clear}"
./dasm dss/DragonOS/kernel0/kernel0.dss -o dragon/kernel0.bin $1 ./dasm dss/DragonOS/kernel0/kernel0.dss -o dragon/kernel0.bin -I dss $1
./dtools load-binary dragon/disk1.dr dragon/kernel0.bin 0x00018000 ./dtools load-binary dragon/disk1.dr dragon/kernel0.bin 0x00018000
printf "\n" printf "\n"

View file

@ -3,6 +3,7 @@
#include <ostd/utils/Utils.hpp> #include <ostd/utils/Utils.hpp>
#include <ostd/io/IOHandlers.hpp> #include <ostd/io/IOHandlers.hpp>
#include <unordered_map> #include <unordered_map>
#include <vector>
namespace dragon namespace dragon
{ {
@ -96,6 +97,7 @@ namespace dragon
bool save_exports { true }; bool save_exports { true };
ostd::String disassembly_file_path { "" }; ostd::String disassembly_file_path { "" };
std::vector<ostd::String> cpu_extensions; std::vector<ostd::String> cpu_extensions;
std::vector<ostd::String> include_directories;
}; };
public: public:
@ -108,6 +110,7 @@ namespace dragon
inline static const int32_t RETURN_VAL_CLOSE_PROGRAM = 512; inline static const int32_t RETURN_VAL_CLOSE_PROGRAM = 512;
inline static const int32_t RETURN_VAL_TOO_FEW_ARGUMENTS = 1; inline static const int32_t RETURN_VAL_TOO_FEW_ARGUMENTS = 1;
inline static const int32_t RETURN_VAL_MISSING_PARAM = 2; inline static const int32_t RETURN_VAL_MISSING_PARAM = 2;
inline static const int32_t RETURN_VAL_INVALID_PARAM = 3;
}; };
public: public:

View file

@ -1,5 +1,6 @@
#include "Assembler.hpp" #include "Assembler.hpp"
#include <ostd/math/Random.hpp> #include <ostd/math/Random.hpp>
#include <ostd/io/FileSystem.hpp>
namespace dragon namespace dragon
{ {
@ -35,6 +36,19 @@ namespace dragon
i++; i++;
args.dest_file_path = argv[i]; args.dest_file_path = argv[i];
} }
else if (edit == "-I" || edit == "--include-path")
{
if (i == argc - 1)
return RETURN_VAL_MISSING_PARAM;
i++;
ostd::String _include = argv[i];
_include.trim();
if (!_include.endsWith("/"))
_include.add("/");
if (!ostd::FileSystem::directoryExists(_include))
return RETURN_VAL_INVALID_PARAM;
args.include_directories.push_back(_include);
}
else if (edit == "--save-disassembly") else if (edit == "--save-disassembly")
{ {
if (i == argc - 1) if (i == argc - 1)
@ -111,6 +125,9 @@ namespace dragon
tmpCommand = "--debug, -D"; tmpCommand = "--debug, -D";
tmpCommand.addRightPadding(commandLength); tmpCommand.addRightPadding(commandLength);
out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to enable debug mode.").reset().nl(); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used to enable debug mode.").reset().nl();
tmpCommand = "--include-path, -I <include-directory-path>";
tmpCommand.addRightPadding(commandLength);
out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Used specify an include directory path (absolute or relative to the <dasm> executable location).").reset().nl();
tmpCommand = "--help"; tmpCommand = "--help";
tmpCommand.addRightPadding(commandLength); tmpCommand.addRightPadding(commandLength);
out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Displays this help message.").reset().nl(); out.fg(ostd::ConsoleColors::Blue).p(tmpCommand).fg(ostd::ConsoleColors::Green).p("Displays this help message.").reset().nl();

View file

@ -1,6 +1,7 @@
#include "Assembler.hpp" #include "Assembler.hpp"
#include <ostd/io/File.hpp> #include <ostd/io/File.hpp>
#include <ostd/io/FileSystem.hpp>
namespace dragon namespace dragon
{ {
@ -72,7 +73,7 @@ namespace dragon
if (!line.startsWith("<") || !line.endsWith(">")) if (!line.startsWith("<") || !line.endsWith(">"))
return false; return false;
line.substr(1, line.len() - 1).trim(); line.substr(1, line.len() - 1).trim();
auto file_lines = __load_file(m_directory + line); auto file_lines = __load_file(line);
if (file_lines.size() == 0) if (file_lines.size() == 0)
return false; return false;
lines.erase(lines.begin() + i); lines.erase(lines.begin() + i);
@ -91,12 +92,27 @@ namespace dragon
std::vector<ostd::String> IncludePreprocessor::__load_file(const ostd::String& filePath) std::vector<ostd::String> IncludePreprocessor::__load_file(const ostd::String& filePath)
{ {
ostd::TextFileBuffer file(filePath); const auto& include_dirs = Assembler::Application::args.include_directories;
if (!file.exists())
return { }; //TODO: Error if (ostd::FileSystem::fileExists(m_directory + filePath))
{
ostd::TextFileBuffer file(m_directory + filePath);
ostd::String source = file.rawContent(); ostd::String source = file.rawContent();
return ostd::String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData(); return ostd::String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData();
} }
for (const auto& dir : include_dirs)
{
if (ostd::FileSystem::fileExists(dir + filePath))
{
ostd::TextFileBuffer file(dir + filePath);
ostd::String source = file.rawContent();
return ostd::String(source.replaceAll("\t", " ")).tokenize("\n", false).getRawData();
}
}
return { }; //TODO: Error
}
} }
} }

View file

@ -1,6 +1,7 @@
#include "DisassemblyLoader.hpp" #include "DisassemblyLoader.hpp"
#include <ostd/io/File.hpp> #include <ostd/io/File.hpp>
#include <ostd/io/FileSystem.hpp>
#include <ostd/io/Serial.hpp> #include <ostd/io/Serial.hpp>
#include <algorithm> #include <algorithm>
@ -92,7 +93,7 @@ namespace dragon
void DisassemblyLoader::loadDirectory(const ostd::String& directoryPath) void DisassemblyLoader::loadDirectory(const ostd::String& directoryPath)
{ {
auto list = ostd::Utils::listFilesInDirectory(directoryPath); auto list = ostd::FileSystem::listFilesInDirectory(directoryPath);
for (auto& path : list) for (auto& path : list)
loadFile(path.string()); loadFile(path.string());
} }