Skip to content

Commit

Permalink
Better CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
0x24a committed Aug 19, 2023
1 parent 9b707e5 commit ff832da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- --no-compile, 仅翻译为c++而不编译
- --debug, 显示所有调试信息
- --gcc-binary=xxx, 制定g++可执行文件位置
- --gcc-arg=xxx, 可添加多个
- --output=xxx, 输出的文件名

Examples:
`python3 sblang2c.py --debug some_file.sbl`
Expand All @@ -27,6 +29,12 @@ Examples:
`python3 sblang2c.py --gcc-binary=/opt/homebrew/bin/g++-13 --debug some_file.sbl`
转换some_file.sbl, 使用MacOS Homebrew安装的G++ 13进行编译并打印所有调试信息。

`python3 sblang2c.py --debug --gcc-arg=std=c++20 some_file.sbl`
使用C++20标准编译some_file.sbl, 输出全部调试信息。

`python3 sblang2c.py --debug --output=executable.exe some_file.sbl`
编译some_file.sbl, 输出全部调试信息并将最终的可执行文件输出为`executable.exe`

## 四、程序组成
- HEADS (保存在编译Runtime内) 需要引入的头文件
- HEAD 动态生成,用于声明命名空间
Expand Down
10 changes: 9 additions & 1 deletion sblang2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ def end(self):
nocomp="--no-compile" in argss
debug="--debug" in argss
gcc_executable="g++"
gcc_extra_args=[]
name_executeable=".".join(filename.split(".")[:-1])
for arg in argss:
arg=arg.split("=",1)
if len(arg) == 1:
continue
if arg[0] == "--gcc-binary":
gcc_executable=arg[1]
if arg[0] == "--gcc-arg":
gcc_extra_args.append("-"+arg[1])
if arg[0] == "--output":
name_executeable=arg[1]

if debug:
logging.basicConfig(level=logging.DEBUG)
name_executeable=".".join(filename.split(".")[:-1])
if len(args) < 2:
print(f"usage: {name} [options] [filename]")
exit(1)
Expand Down Expand Up @@ -68,6 +73,9 @@ def end(self):
exit(0)
print("-| Compiling with g++")
command=f"{gcc_executable} _sblang_temp.cpp -finput-charset=UTF-8 -std=c++20 -o {name_executeable}"
if gcc_extra_args != []:
for i in gcc_extra_args:
command+=" "+i
try:
os.remove(name_executeable)
except:
Expand Down
Binary file removed test_2numplus
Binary file not shown.

0 comments on commit ff832da

Please sign in to comment.