2026-05-02 23:04:46 +03:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
Главный сборочный скрипт КВС
|
|
|
|
|
|
Последовательно запускает все этапы компиляции
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
|
|
print("Использование: python kvs_build.py <файл.квс>")
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
source_file = sys.argv[1]
|
|
|
|
|
|
if not source_file.endswith('.квс'):
|
|
|
|
|
|
print("Ошибка: файл должен иметь расширение .квс")
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
base_name = source_file[:-4]
|
|
|
|
|
|
|
|
|
|
|
|
tokens_file = base_name + ".токены"
|
|
|
|
|
|
ast_file = base_name + ".аст"
|
|
|
|
|
|
pass1_file = base_name + ".проход1"
|
|
|
|
|
|
csv_file = base_name + ".csv"
|
|
|
|
|
|
elf_file = base_name + ".elf"
|
|
|
|
|
|
|
|
|
|
|
|
stages = [
|
|
|
|
|
|
("kvs_lexer.py", [source_file, tokens_file], "Лексический анализ"),
|
|
|
|
|
|
("kvs_parser.py", [tokens_file, ast_file], "Парсинг"),
|
|
|
|
|
|
("kvs_pass1.py", [ast_file, pass1_file], "Первый проход"),
|
|
|
|
|
|
("kvs_pass2.py", [ast_file, pass1_file, csv_file], "Второй проход и генерация CSV"),
|
2026-05-17 22:37:32 +03:00
|
|
|
|
("kvs_verify.py", [pass1_file, csv_file], "Проверка размеров инструкций"),
|
2026-05-02 23:04:46 +03:00
|
|
|
|
("kvs_builder.py", [csv_file, pass1_file, elf_file], "Сборка ELF"),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
for script, args, description in stages:
|
|
|
|
|
|
print(f"\n=== {description} ===")
|
|
|
|
|
|
cmd = [sys.executable, script] + args
|
|
|
|
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
|
|
|
|
|
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
|
print(f"ОШИБКА на этапе '{description}':")
|
|
|
|
|
|
print(result.stderr)
|
2026-05-17 22:37:32 +03:00
|
|
|
|
if result.stdout:
|
|
|
|
|
|
print(result.stdout)
|
2026-05-02 23:04:46 +03:00
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
2026-05-17 22:37:32 +03:00
|
|
|
|
# Для верификатора показываем stdout (там детали проверки)
|
|
|
|
|
|
if result.stdout:
|
|
|
|
|
|
print(result.stdout)
|
2026-05-02 23:04:46 +03:00
|
|
|
|
|
|
|
|
|
|
print(f"\n=== Компиляция успешно завершена ===")
|
|
|
|
|
|
print(f"Исполняемый файл: {elf_file}")
|
|
|
|
|
|
print(f"Запустить: ./{elf_file}")
|