42 Commits

Author SHA1 Message Date
zzy
c01e6e1db4 feat(ir): 添加IR库的基础结构和定义
- 创建IR库的cbuild.toml配置文件,添加对scc_core的依赖
- 新增ir_def.h头文件,定义IR类型、节点、基本块和函数的数据结构
- 添加ir_builtin.h和ir_builtin.c,提供内置的i32类型和零值常量
- 实现ir_dump.h和ir_dump.c,提供IR转储功能的接口
- 创建scc_ir.h和scc_ir.c,实现IR对象的初始化和分配功能
- 添加测试文件test_ir.c用于验证IR库功能
- 定义了完整的IR节点类型枚举和操作类型枚举
2026-01-08 13:43:35 +08:00
zzy
b753ae0911 refactor(lex_parser): 重命名libcore为scc_core并重构头文件包含
- 将依赖项从libcore重命名为scc_core
- 更新头文件包含路径从<libcore.h>到<scc_core.h>
- 保持原有功能不变

refactor(lexer): 重命名libcore为scc_core并添加词法流式解析功能

- 将依赖项从libcore重命名为scc_core
- 移除不再需要的scc_lexer_token结构体定义
- 重命名struct cc_lexer为struct scc_lexer
- 添加scc_lexer_stream_t流式解析器相关定义和实现
- 新增lexer_stream.c文件实现流式token缓冲功能

refactor(lexer_log): 重命名logger变量和头文件定义

- 将头文件保护宏从__SMCC_LEXER_LOG_H__改为__SCC_LEXER_LOG_H__
- 将logger变量从__smcc_lexer_log改为__scc_lexer_log
- 更新头文件包含从<libcore.h>到<scc_core.h>

refactor(lexer_token): 重新组织token头文件结构

- 将头文件保护宏从__SMCC_CC_TOKEN_H__改为__SCC_LEXER_TOKEN_H__
- 更新头文件包含从<libcore.h>到<scc_core.h>
- 将scc_lexer_token结构体定义移至该文件

refactor(lexer): 简化token匹配代码格式

- 移除LCC相关的注释内容
- 优化括号符号的token匹配代码格式,使用clang-format控制

refactor(pprocessor): 更新依赖项名称和头文件包含

- 将libcore重命名为scc_core
- 将libutils重命名为scc_utils
- 更新头文件包含路径

refactor(runtime): 重命名libcore为scc_core并重构目录结构

- 将libcore目录重命名为scc_core
- 将libutils目录重命名为scc_utils
- 更新所有相关的头文件包含路径
- 修改cbuild.toml中的包名称
- 更新core_vec.h中的宏定义以支持标准库模式
2026-01-08 11:22:27 +08:00
zzy
09f4ac8de0 feat(lex_parser, pprocessor): replace consume with next and remove stream resets
- Replace `scc_probe_stream_consume` with `scc_probe_stream_next` for consistent stream advancement
- Remove redundant `scc_probe_stream_reset` calls before peeking, as `next` and `peek` handle state
- Update `scc_cstring_new` to `scc_cstring_create` and `scc_pos_init` to `scc_pos_create` for naming consistency
- Change `scc_pp_macro_get` parameter to `const scc_cstring_t*` for better const-correctness
- Improves code clarity and maintains proper stream position tracking
2025-12-28 10:49:29 +08:00
zzy
07f5d9331b feat(lexer, preprocessor): replace cstring conversion with copy and refactor macro expansion
- Replace `scc_cstring_from_cstr(scc_cstring_as_cstr(...))` with `scc_cstring_copy()` in lexer to fix memory leaks
- Extract macro expansion logic into separate `expand_macro.c` file
- Remove `expand_stack` parameter from `scc_pp_expand_macro()` function
- Add new parsing functions for macro replacement lists and arguments
- Add string utility functions for whitespace trimming and string joining
- Update memory stream documentation for clarity
2025-12-15 20:24:39 +08:00
zzy
73d74f5e13 refactor(pprocessor): rename macro table type and update function names
- Change `scc_macro_table_t` to `scc_pp_macro_table_t` for consistency
- Rename `scc_pp_macro_create` to `scc_pp_macro_new` for naming convention
- Remove unused `scc_pp_compress_whitespace` function
- Update macro table function names: `scc_pp_find_macro` → `scc_pp_macro_table_get`, `scc_pp_remove_macro` → `scc_pp_macro_table_remove`
- Add new `scc_pp_macro_table_set` function for setting macros
- Update all function signatures to use new type name
- Remove commented-out whitespace compression code from implementation
2025-12-14 12:59:03 +08:00
zzy
ce8031b21f feat(parse): implement # and ## operator handling in macro expansion
- Add support for # (stringify) and ## (concatenation) operators in macro replacement lists
- Implement scc_pp_expand_string_unsafe() to process operator tokens during macro expansion
- Add helper macros to identify blank, stringify, and concatenation tokens in replacement lists
- Include missing headers (ctype.h, string.h) for character handling functions
- Update object macro expansion to use new string expansion function instead of simple concatenation
- Improve whitespace handling in macro replacement parsing to prevent interference with operator processing
2025-12-13 18:29:21 +08:00
zzy
07a76d82f4 feat(lex_parser, pprocessor): rename identifier header check and add macro system
- Rename `scc_lex_parse_is_identifier_header` to `scc_lex_parse_is_identifier_prefix` for clarity and add a TODO comment
- Update lexer to use the renamed function for consistency
- Fix package and dependency names in `cbuild.toml` (`smcc_pprocesser` → `scc_pprocesser`, `smcc_lex_parser` → `lex_parser`)
- Introduce new macro system with header file `pp_macro.h` defining macro types, structures, and management functions
- Refactor preprocessor initialization and cleanup in `pprocessor.c` to use new macro table and stream handling
- Replace legacy `hashmap` with `scc_pp_macro_table_t` for macro storage
- Improve error handling and resource management in preprocessor lifecycle
2025-12-13 16:09:46 +08:00
zzy
874a58281f feat(lex_parser): rename functions and update header guard prefix
- Change header guard from `__SMCC_LEX_PARSER_H__` to `__SCC_LEX_PARSER_H__`
- Prefix all lexer functions with `scc_` (e.g., `lex_parse_char` → `scc_lex_parse_char`)
- Add new helper function `scc_lex_parse_is_identifier_header`
- Update references in source and test files to use new function names
- Replace `core_stream_eof` with `scc_stream_eof` for consistency
2025-12-13 14:06:13 +08:00
zzy
94d3f46fac refactor(lex_parser): replace core_pos_* functions with scc_pos_* equivalents
Update all position tracking calls in lex_parser.c to use the scc_pos_* function family (scc_pos_next, scc_pos_next_line) instead of the deprecated core_pos_* variants. This ensures consistency with the scc naming convention and prepares for future removal of the old core functions.
2025-12-12 21:33:51 +08:00
zzy
897ef449fb feat: add atomic profile update flag and update clean command
- Add `-fprofile-update=atomic` flag to both GCC and Clang compiler configurations for thread-safe coverage data updates
- Change `--all` argument in clean command to default to True and add `-a` short option for consistency with common CLI patterns
2025-12-11 17:30:33 +08:00
zzy
3aaf3a3991 feat: add SCF format library and rename components to SCC prefix
- Introduce new SCF (SCC Format) library with header, implementation, and test files
- SCF is a minimal executable/linkable format focused on internal linking with external symbol import/export abstraction
- Rename lexer and lex_parser packages from 'smcc_' to 'scc_' prefix for consistency
- Update hashmap implementation to use 'scc_' prefix for types and structures
- Add build configuration for new format library with dependencies on libcore and libutils
2025-12-11 17:29:12 +08:00
zzy
d88fa3b8d3 feat: rename core types to scc prefix for consistency
Updated type names from `core_*` to `scc_*` across lex_parser and stream modules to maintain naming consistency within the SCC codebase. This includes changes to function signatures and internal usage of types like `core_probe_stream_t`, `core_pos_t`, and `cstring_t` to their `scc_*` counterparts.
2025-12-11 13:00:29 +08:00
zzy
35c13ee30a feat: add internationalization support with Chinese translations
- Introduce Translator class for simple i18n with English and Chinese locales
- Add concurrent.futures, os, and locale imports for parallel execution and language detection
- Implement automatic language detection based on system locale
- Provide translation keys for build messages, test results, and command outputs
- Support dynamic language switching via set_language method
2025-12-11 12:27:11 +08:00
zzy
098e41d3e5 feat(cbuild): refactor and enhance C build system with new features
- Refactor logging system with simplified ColorFormatter and improved output formatting
- Add test command with regex pattern matching and timeout support
- Implement file size formatting utility for build output
- Remove unused imports and streamline code structure
- Update .gitignore to exclude external/ directory
- Improve error handling and subprocess management in test execution
- Optimize build dependency resolution with topological sorting
- Enhance configuration parsing and target management

The changes focus on code quality improvements, adding testing capabilities, and optimizing the build process for better performance and maintainability.
2025-12-10 22:21:37 +08:00
zzy
186602a301 feat(core): rename string and stream functions for clarity
- Rename `cstring_push` to `cstring_append_ch` and `cstring_push_cstr` to `cstring_append_cstr` for consistent naming with new `cstring_append` function
- Update all callers in lexer and tests to use new function names
- Rename stream `destroy` method to `drop` for consistency with resource management conventions
- Fix potential overflow in string capacity calculation by adjusting growth logic
2025-12-09 18:04:53 +08:00
zzy
36bff64a91 feat 重构stream流API并适配lex_parse和lexer 2025-12-08 23:04:11 +08:00
zzy
1ab07a5815 feat(cbuild): 重构依赖解析器并新增依赖树打印功能
- 修改 `DependencyResolver.resolve` 方法返回类型为 `None`,不再返回依赖映射副本
- 新增 `print_tree` 方法用于打印格式化的依赖树结构
- 调整 `get_sorted_dependencies` 和 `get_all_contexts` 返回值类型为 `PackageConfig` 列表
- 在 `CPackageBuilder.tree` 中调用新的 `print_tree` 方法以简化逻辑
- 添加 `DummyCompiler` 类作为占位编译器实现
- 优化 argparse 命令行参数结构,将通用参数移到子命令中
- 改进编译器初始化逻辑,增加对参数存在性的检查
- 移除 clean 子命令中的 --all 参数选项
2025-11-27 15:25:45 +08:00
zzy
ed829bdc21 feat(cbuild): 重构依赖解析器并增强命令行功能
- 将 `resolved_deps` 重命名为 `deps` 并新增 `dep_map` 用于存储依赖关系
- 新增 `get_dependencies_of` 方法以获取指定包的直接依赖列表
- 实现递归打印依赖树的功能,优化 `tree` 命令展示效果
- 引入分层命令行参数解析,支持子命令及更多选项(如 --record、--args 等)
- 改进日志输出与构建模式提示信息,使其更准确反映当前构建状态
- 编译器类中增加命令记录机制,便于调试和回溯执行过程
2025-11-27 12:15:45 +08:00
zzy
e6a76e7a86 feat(lex_parser): 提取字符判断函数并增强解析器断言
将 `is_next_line` 内联函数重命名为 `lex_parse_is_endline` 并新增 `lex_parse_is_whitespace` 函数,统一用于词法解析中的字符分类。同时加强多个解析函数的输入参数断言,提升代码健壮性。

此外,修正了 `lex_parse_skip_whitespace` 中的逻辑错误,并优化部分注释和控制流结构。

feat(pprocessor): 初始化预处理器模块并添加基础功能实现

新增预处理器模块 `pprocessor`,包括宏定义、条件编译状态管理以及基本的指令解析框架。实现了标识符解析、空白跳过、关键字查找等功能,并初步支持 `#define` 指令的对象类宏替换。

该提交还引入了一组测试用例,覆盖多种宏展开场景及边界情况,确保预处理器的核心行为符合预期。
2025-11-24 22:44:08 +08:00
zzy
871d031ceb feat(lex_parser): 初始化词法解析器模块
新增词法解析器库 `smcc_lex_parser`,包含基础的词法规则解析功能:
- 支持字符、字符串、数字、标识符的解析
- 支持跳过注释、空白符、行尾等辅助函数
- 提供对应的单元测试用例,覆盖各类合法与非法输入情况

该模块依赖 `libcore`,并被 `smcc_lex` 模块引用以支持更上层的词法分析逻辑。
2025-11-23 22:53:46 +08:00
zzy
67af0c6bf2 feat(cbuild): 引入构建缓存机制与编译模式支持
新增了基于文件修改时间和内容哈希的构建缓存功能,能够有效避免不必要的重复编译。同时增加了多种编译模式(如 debug、release、test 等)及其对应的默认编译选项,提升了构建过程的灵活性和效率。

- 添加 `BuildCache` 类用于管理缓存逻辑
- 支持通过 `CompilerBuildMode` 枚举选择不同构建模式
- 在 `CPackageBuilder` 中集成缓存判断与更新流程
- 优化日志输出及部分代码结构以提升可读性
2025-11-22 17:03:48 +08:00
zzy
fa5611dabd fix(log): 修复默认日志实例命名冲突并优化宏定义
将 `logger_root` 重命名为 `__default_logger_root` 以避免潜在的符号冲突,
同时简化日志宏定义逻辑,提升代码可读性与维护性。此外,为防止 clang-format
格式化影响日志宏的排版,添加了 clang-format 开关注释。

refactor(memory): 优化 memcmp 函数中的 switch-case 结构

在 `smcc_memcmp` 函数中为每个 case 添加 `/* fall through */` 注释,
明确表示故意穿透到下一个 case,提高代码意图的清晰度,并增强静态分析工具的兼容性。
2025-11-22 16:59:28 +08:00
zzy
63f6f13883 feat(cbuild): 重构构建系统并迁移至 tools/cbuild
将 `cbuild.py` 迁移至 `tools/cbuild/` 并进行大量功能增强。引入依赖解析器、支持颜色日志输出、
改进包配置默认值处理、完善构建目标识别与拓扑排序依赖管理。同时添加 `.gitignore` 和
`pyproject.toml` 以支持标准 Python 包结构,并更新 README 文档。

新增命令支持:tree(显示依赖树)、clean(带文件统计)、test(运行测试)等,
优化了 Windows 平台下的可执行文件扩展名处理逻辑。

移除了旧的 `wc.py` 行数统计脚本。
2025-11-22 15:08:49 +08:00
zzy
d6941e1d2f feat(cbuild): 添加构建路径去重与相对化处理
新增 `_path_collection` 方法用于统一处理路径的解析、去重及相对化,
优化对象文件路径生成逻辑,支持更安全的路径映射机制,防止文件冲突。
同时添加对构建目录的清理功能(clean 命令),完善构建生命周期管理。

主要变更包括:
- 引入 `hashlib` 模块以支持路径哈希命名
- 重构 `get_build_components` 和 `get_object_path` 方法
- 新增 `clean` 命令及相关实现
- 改进命令行参数支持,增加 "clean" 选项
2025-11-21 18:03:10 +08:00
zzy
a3322f0d4c feat(runtime): 添加字符串和内存操作工具函数
- 在 `core_mem.h` 中新增 `smcc_strhash32`、`smcc_strlen` 和 `smcc_strcmp` 函数,
  提供 C 字符串的哈希、长度获取和比较功能
- 完善 `core_str.h` 中 `cstring_t` 结构体及相关操作函数的注释说明
- 更新 `core_str.h` 头文件保护宏命名,增强模块标识一致性
- 修改 `core_vec.h` 文件头部保护宏名称以匹配实际文件名

另外,在 lexer 测试运行代码中引入日志相关头文件并调整日志级别设置逻辑。
2025-11-21 17:52:42 +08:00
zzy
164bab0f13 fix(lexer): 修复词法分析器中的关键字比较与字符串处理逻辑
修正了关键字表的注释,明确要求其必须按字典序排列以确保二分查找正确性。
在词法分析过程中,修复标识符解析时对 `cstring` 的使用问题,并调整 token 类型赋值顺序,
避免潜在的未定义行为。同时新增测试文件用于验证操作符、关键字及各类字面量的识别准确性,
并更新测试运行器的日志级别控制参数。
2025-11-20 22:49:22 +08:00
zzy
f29fd92fdf feat(core): 添加字符串长度计算函数并优化数据结构定义
- 在 `core_mem.h` 中新增 `smcc_strlen` 函数,用于计算字符串长度
- 调整 `VEC` 宏定义参数,移除冗余的 name 参数,增强结构体声明一致性
- 修改 `cstring_from_cstr` 返回值字段顺序,保持代码风格统一
- 在 `libcore.h` 中增加日志相关宏定义的保护判断,防止重复定义冲突
2025-11-20 22:26:49 +08:00
zzy
d1fafa830d format using clang-format to formate code 2025-11-20 17:55:08 +08:00
zzy
9762cf8a2b feat(log): 支持设置多个日志级别的组合
将 `log_set_level` 函数的参数类型从 `log_level_t` 改为 `int`,
以支持传入多个日志级别的按位或组合。

同时调整测试代码中的日志级别设置方式,并修复部分逻辑引用问题,以及#未知宏跳过更多的行的bug。
2025-11-20 14:30:14 +08:00
zzy
47b56d52f6 feat(core): 重构词法分析器流接口并迁移至 core 库
将 lexer_stream 抽象为 core_stream,统一运行时核心组件的输入流模型。
移除了旧的 `lexer_stream.h` 定义,并将其功能完整迁移至 `core_stream.h` 中。
更新了内存流实现以适配新的 core_stream 接口,并修复部分资源释放问题。
同时调整日志模块包含方式,增强模块间解耦能力。

此变更影响词法分析器对输入流的操作方式,所有涉及 stream 的类型与函数均已替换为 core 前缀版本。
测试用例同步更新并验证通过。
2025-11-20 14:17:03 +08:00
zzy
5c24f35c87 feat 新的运行时环境 2025-11-20 11:22:37 +08:00
zzy
e22811f2f5 feat(build): 引入新的 Python 构建系统并移除旧 Makefile
新增基于 Python 的构建脚本 `cbuild.py`,支持包管理、依赖解析和模块化编译。
同时添加 `.gitignore` 忽略 `build` 目录,并在 `justfile` 中更新构建命令。
移除了原有的 `lib/Makefile` 和主目录下的相关 make 规则,统一使用新构建系统。
2025-11-20 10:44:59 +08:00
ZZY
8d97fe896c chore: 更新 .gitignore 文件
- 添加 docs 文件夹到忽略列表,以忽略 Doxygen 生成的文件
- 保持原有的忽略规则不变
2025-04-05 23:11:39 +08:00
ZZY
c800b48ca2 refactor(riscv32): 重构 RISC-V 指令定义
- 在 riscv32_def.h 中添加 RV_INSTRUCTIONS 宏,列出所有指令
- 在 riscv32_mcode.c 中使用宏定义指令数组,减少代码重复
- 此重构简化了指令添加和修改的过程,提高了代码可维护性
2025-04-02 15:56:51 +08:00
ZZY
1cf26c43f3 bugfix 添加lib的修改 2025-04-01 23:28:15 +08:00
ZZY
b57f21556a stable 重构文件结构
抽象出Machine Code
2025-04-01 23:27:25 +08:00
ZZY
74f43a1ab7 stable 2025-04-01 00:13:21 +08:00
ZZY
2b4857001c feat(frontend): 重构词法分析器
- 添加 .gitignore 文件,忽略编译器生成的二进制文件
- 重构 lexer.c 文件,改进了关键字处理和字符串处理
- 更新前端的前端、解析器和 AST 相关文件,以适应新的词法分析器
- 优化了 token 相关的定义和函数,引入了新的 token 类型
2025-03-23 12:13:16 +08:00
ZZY
05c637e594 refactor: 重构前端代码并添加日志功能
- 重命名和重构了多个文件,包括 lexer、parser 和 AST 相关代码
- 添加了日志功能,使用 LOG_* 宏替代原有的 error 和 warn 函数
- 优化了错误处理和内存分配方式
- 调整了代码结构,提高了模块化和可读性
2025-03-19 12:22:55 +08:00
ZZY
172d72b0a0 feat(backend/riscv32): 实现基础的编译器功能
- 完成 RV32IMA 指令集的代码生成
- 添加整数运算、分支、调用等基本指令支持
- 实现从 IR 到机器码的转换
- 添加简单的测试用例和测试框架
2025-03-08 16:50:21 +08:00
ZZY
95bf44eb3f feat add func call and rewrite codes 2025-03-07 12:29:53 +08:00
ZZY
09299e339c init basic 2025-03-05 15:45:19 +08:00