diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a50b07d --- /dev/null +++ b/.gitignore @@ -0,0 +1,331 @@ +# Created by https://www.toptal.com/developers/gitignore/api/linux,vim,c,cmake,macos,visualstudiocode,windows,node +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,vim,c,cmake,macos,visualstudiocode,windows,node + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/linux,vim,c,cmake,macos,visualstudiocode,windows,node + +build/ +*.bak \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5ecec23 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.5) +project(mie C) + +if (WIN32) + set(CMAKE_RC_COMPILER_INIT windres) + enable_language(RC) + SET(CMAKE_RC_COMPILE_OBJECT + " -O coff -i -o ") +endif () + +set(CMAKE_COMPILE_WARNING_AS_ERROR ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +if (NOT MIE_STATIC) + set(MIE_STATIC 0) +endif () + +if (MIE_STATIC) + set(Bluelib_STATIC TRUE) +endif () + +find_package(Bluelib REQUIRED) + +add_subdirectory(mie) +add_subdirectory(tool) diff --git a/cmake/FindBluelib.cmake b/cmake/FindBluelib.cmake new file mode 100644 index 0000000..648ceaa --- /dev/null +++ b/cmake/FindBluelib.cmake @@ -0,0 +1,189 @@ +#[=======================================================================[.rst: +FindBluelib +------------ + +Find the Bluelib library and header directories + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``Bluelib::Bluelib`` +The Bluelib library, if found + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Bluelib_FOUND`` +true if the Bluelib C headers and libraries were found +``Bluelib_INCLUDE_DIR`` +directories containing the Bluelib C headers. + +``Bluelib_LIBRARY`` +the C library to link against + +Hints +^^^^^ + +The user may set the environment variable ``Bluelib_PREFIX`` to the root +directory of a Bluelib library installation. +#]=======================================================================] + +set (Bluelib_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr/local/share + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ${Bluelib_PREFIX} + $ENV{Bluelib_PREFIX}) + +if (Bluelib_STATIC) + set(_lib_suffix "-s") +endif () + +set(supported_components Core Ds Term Cmd Io Serial Compress) +set(components ${Bluelib_FIND_COMPONENTS}) +string(REPLACE ";" ", " supported_components_string_list "${supported_components}") + +if (NOT components) + set(components ${supported_components}) +endif () + +set(required_vars) + +foreach (component ${components}) + if (NOT "${component}" IN_LIST supported_components) + message(FATAL_ERROR "'${component}' is not a valid Bluelib module.\nSupported modules: ${supported_components_string_list}") + endif () + + string(TOLOWER ${component} header_name) + set(lib_name ${header_name}${_lib_suffix}) + + if (NOT Bluelib_${component}_INCLUDE_DIR) + find_path(Bluelib_${component}_INCLUDE_DIR + NAMES blue/${header_name}.h ${Bluelib_FIND_ARGS} + PATH_SUFFIXES include + PATHS ${Bluelib_SEARCH_PATHS}) + endif () + + if (NOT Bluelib_${component}_LIBRARY) + find_library(Bluelib_${component}_LIBRARY + NAMES blue-${lib_name} ${Bluelib_FIND_ARGS} + PATH_SUFFIXES lib + PATHS ${Bluelib_SEARCH_PATHS}) + else () + # on Windows, ensure paths are in canonical format (forward slahes): + file(TO_CMAKE_PATH "${Bluelib_${component}_LIBRARY}" Bluelib_${component}_LIBRARY) + endif() + + list(APPEND required_vars Bluelib_${component}_INCLUDE_DIR Bluelib_${component}_LIBRARY) +endforeach (component) + +unset(Bluelib_FIND_ARGS) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Bluelib + REQUIRED_VARS ${required_vars}) + +if (Bluelib_FOUND) + set(created_targets) + foreach (component ${components}) + string(TOLOWER ${component} header_name) + set(lib_name ${header_name}${_lib_suffix}) + + if(NOT TARGET Bluelib::${component}) + add_library(Bluelib::${component} UNKNOWN IMPORTED) + set_target_properties(Bluelib::${component} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Bluelib_${component}_INCLUDE_DIR}") + target_compile_definitions(Bluelib::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1) + + if (Bluelib_STATIC) + target_compile_definitions(Bluelib::${component} INTERFACE BLUELIB_STATIC=1) + endif () + + set_target_properties(Bluelib::${component} PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}") + set(created_targets ${created_targets} ${component}) + endif () + endforeach (component) + + foreach (component ${created_targets}) + if ("${component}" STREQUAL "Ds") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core) + endif () + + if ("${component}" STREQUAL "Term") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()") + endif () + + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds) + endif () + + if ("${component}" STREQUAL "Serial") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()") + endif () + + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds) + endif () + + if ("${component}" STREQUAL "Cmd") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()") + endif () + + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()") + endif () + + if (NOT TARGET Bluelib::Term) + message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term) + endif () + + if ("${component}" STREQUAL "Io") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()") + endif () + + if (NOT TARGET Bluelib::Ds) + message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds) + endif () + + if ("${component}" STREQUAL "Compress") + if (NOT TARGET Bluelib::Core) + message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()") + endif () + + target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds) + endif () + endforeach (component) +endif() diff --git a/mie/CMakeLists.txt b/mie/CMakeLists.txt index ba9b1ac..1aae8e6 100644 --- a/mie/CMakeLists.txt +++ b/mie/CMakeLists.txt @@ -12,4 +12,4 @@ endif () target_include_directories(mie PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/) target_link_libraries(mie Bluelib::Core Bluelib::Ds) -target_compile_definitions(mie PRIVATE MIE_EXPORT=1 MIE_STATIC=${IVY_STATIC}) +target_compile_definitions(mie PRIVATE MIE_EXPORT=1 MIE_STATIC=${MIE_STATIC}) diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt new file mode 100644 index 0000000..bd36979 --- /dev/null +++ b/tool/CMakeLists.txt @@ -0,0 +1,18 @@ +file(GLOB tool_sources + *.c *.h + cmd/*.c cmd/*.h) + +if (WIN32) + set(rc_file ${CMAKE_CURRENT_SOURCE_DIR}/../res/win32/frontend.rc) +endif () + +add_executable(mie-tool ${tool_sources} ${rc_file}) +target_link_libraries( + mie-tool + mie + Bluelib::Core + Bluelib::Ds + Bluelib::Cmd) + +set_target_properties(mie-tool PROPERTIES OUTPUT_NAME "mie") +target_compile_definitions(mie-tool PRIVATE MIE_STATIC=${MIE_STATIC}) diff --git a/tool/cmd/cmd.h b/tool/cmd/cmd.h new file mode 100644 index 0000000..518d190 --- /dev/null +++ b/tool/cmd/cmd.h @@ -0,0 +1,10 @@ +#ifndef CMD_CMD_H_ +#define CMD_CMD_H_ + +enum command_id { + CMD_ROOT, + CMD_VALIDATE, + CMD_INTERNAL, +}; + +#endif diff --git a/tool/cmd/internal.c b/tool/cmd/internal.c new file mode 100644 index 0000000..be9aea9 --- /dev/null +++ b/tool/cmd/internal.c @@ -0,0 +1,50 @@ +#include "cmd.h" +#include +#include + +enum { + OPT_PRINT_SYMBOLS = 0x1000, + OPT_PRINT_KEYWORDS, +}; + +static int internal(const b_command* cmd, const b_arglist* args, const b_array* _) +{ +#if 0 + if (b_arglist_get_count(args, OPT_PRINT_SYMBOLS, B_COMMAND_INVALID_ID)) { + internal_lexer_print_symbol_tree(lex); + } + + if (b_arglist_get_count(args, OPT_PRINT_KEYWORDS, B_COMMAND_INVALID_ID)) { + internal_lexer_print_keyword_dict(lex); + } + +#endif + + return 0; +} + +B_COMMAND(CMD_INTERNAL, CMD_ROOT) +{ + B_COMMAND_NAME("internal"); + B_COMMAND_SHORT_NAME('X'); + B_COMMAND_DESC("internal frontend debugging tools."); + B_COMMAND_FUNCTION(internal); + + B_COMMAND_OPTION(OPT_PRINT_SYMBOLS) + { + B_OPTION_LONG_NAME("print-symbols"); + B_OPTION_SHORT_NAME('s'); + B_OPTION_DESC( + "print the symbol tree used by the language lexer."); + } + + B_COMMAND_OPTION(OPT_PRINT_KEYWORDS) + { + B_OPTION_LONG_NAME("print-keywords"); + B_OPTION_SHORT_NAME('k'); + B_OPTION_DESC( + "print the keyword dictionary used by the language lexer."); + } + + B_COMMAND_HELP_OPTION(); +} diff --git a/tool/cmd/root.c b/tool/cmd/root.c new file mode 100644 index 0000000..f703d5e --- /dev/null +++ b/tool/cmd/root.c @@ -0,0 +1,18 @@ +#include "cmd.h" + +#include + +B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID) +{ + B_COMMAND_NAME("mie"); + B_COMMAND_DESC("Mie IR manipulation tool."); + B_COMMAND_HELP_OPTION(); + B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT); + + B_COMMAND_USAGE() + { + B_COMMAND_USAGE_COMMAND_PLACEHOLDER(); + B_COMMAND_USAGE_OPT_PLACEHOLDER(); + B_COMMAND_USAGE_ARG_PLACEHOLDER(); + } +} diff --git a/tool/cmd/validate.c b/tool/cmd/validate.c new file mode 100644 index 0000000..2268dad --- /dev/null +++ b/tool/cmd/validate.c @@ -0,0 +1,29 @@ +#include "cmd.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + OPT_TEMP, +}; + +int validate(const b_command* cmd, const b_arglist* args, const b_array* _) +{ + return 0; +} + +B_COMMAND(CMD_VALIDATE, CMD_ROOT) +{ + B_COMMAND_NAME("validate"); + B_COMMAND_SHORT_NAME('V'); + B_COMMAND_DESC("validate a mie ir file."); + B_COMMAND_HELP_OPTION(); + B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT); + B_COMMAND_FUNCTION(validate); +} diff --git a/tool/main.c b/tool/main.c new file mode 100644 index 0000000..f0bbbb7 --- /dev/null +++ b/tool/main.c @@ -0,0 +1,8 @@ +#include "cmd/cmd.h" + +#include + +int main(int argc, const char **argv) +{ + return b_command_dispatch(CMD_ROOT, argc, argv); +}