kvs/квс_сборка.py

58 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""квс_сборка.py
Главный сборочный скрипт КВС
Последовательно запускает все этапы компиляции
"""
import sys
import subprocess
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Использование: python квс_сборка.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 + ".аст"
csv_file = base_name + ".csv"
elf_file = base_name + ".elf"
stages = [
("квсексер.py", [source_file, tokens_file], "Лексический анализ"),
("квс_парсер.py", [tokens_file, ast_file], "Парсинг"),
("квс_проход1.py", [ast_file, csv_file], "Первый проход: генерация кода и CSV"),
("квс_проход2.py", [csv_file], "2 проход"),
("квс_проход3.py", [ast_file, csv_file], "3 проход"),
("квс_проход4.py", [csv_file], "4 проход"),
("квс_проход5.py", [csv_file], "5 проход"),
("квс_проход6.py", [csv_file], "6 проход"),
("квс_финсбор.py", [csv_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)
if result.stdout:
print(result.stdout)
sys.exit(1)
if result.stdout:
print(result.stdout)
#print(f"\n=== Компиляция успешно завершена ===")
#print(f"Исполняемый файл: {elf_file}")
#print(f"Запустить: ./{elf_file}")