mirror of
https://github.com/decompme/decomp.me.git
synced 2026-02-21 13:59:25 -06:00
Pascal language support (ido7.1Pascal compiler) (#570)
* Add 4 minimal IDOs and a "language" compiler flag * Update recomp version * Add compilers to list and json * Add presets and remove alphabetical sorting * Remove extra C IDOs * Convert language to an enum * get_file_extension function * Review * Proper Pascal test * Auto-imports grr...
This commit is contained in:
@@ -369,9 +369,10 @@ def download_n64():
|
||||
print(f"ido{version} already exists, skipping")
|
||||
else:
|
||||
download_tar(
|
||||
url=f"https://github.com/ethteck/ido-static-recomp/releases/download/v0.1/ido-{version}-recomp-{host_os.ido_os}-latest.tar.gz",
|
||||
url=f"https://github.com/ethteck/ido-static-recomp/releases/download/v0.2/ido-{version}-recomp-{host_os.ido_os}-latest.tar.gz",
|
||||
dest_name=f"ido{version}",
|
||||
)
|
||||
|
||||
# SN
|
||||
dest = COMPILERS_DIR / "gcc2.7.2sn"
|
||||
if dest.is_dir():
|
||||
|
||||
@@ -133,14 +133,18 @@ class CompilerWrapper:
|
||||
context = context.replace("\r\n", "\n")
|
||||
|
||||
with Sandbox() as sandbox:
|
||||
code_path = sandbox.path / "code.c"
|
||||
ext = compiler.language.get_file_extension()
|
||||
code_file = f"code.{ext}"
|
||||
ctx_file = f"ctx.{ext}"
|
||||
|
||||
code_path = sandbox.path / code_file
|
||||
object_path = sandbox.path / "object.o"
|
||||
with code_path.open("w") as f:
|
||||
f.write('#line 1 "ctx.c"\n')
|
||||
f.write(f'#line 1 "{ctx_file}"\n')
|
||||
f.write(context)
|
||||
f.write("\n")
|
||||
|
||||
f.write('#line 1 "code.c"\n')
|
||||
f.write(f'#line 1 "{code_file}"\n')
|
||||
f.write(code)
|
||||
f.write("\n")
|
||||
|
||||
@@ -148,7 +152,7 @@ class CompilerWrapper:
|
||||
|
||||
# Fix for MWCC line numbers in GC 3.0+
|
||||
if compiler.is_mwcc:
|
||||
ctx_path = sandbox.path / "ctx.c"
|
||||
ctx_path = sandbox.path / ctx_file
|
||||
ctx_path.touch()
|
||||
|
||||
# IDO hack to support -KPIC
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import enum
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from functools import cache
|
||||
@@ -37,6 +38,19 @@ CONFIG_PY = "config.py"
|
||||
COMPILER_BASE_PATH: Path = settings.COMPILER_BASE_PATH
|
||||
|
||||
|
||||
class Language(enum.Enum):
|
||||
C = "C"
|
||||
CXX = "C++"
|
||||
PASCAL = "Pascal"
|
||||
|
||||
def get_file_extension(self) -> str:
|
||||
return {
|
||||
Language.C: "c",
|
||||
Language.CXX: "cpp",
|
||||
Language.PASCAL: "p",
|
||||
}[self]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Compiler:
|
||||
id: str
|
||||
@@ -48,6 +62,7 @@ class Compiler:
|
||||
is_ido: ClassVar[bool] = False
|
||||
is_mwcc: ClassVar[bool] = False
|
||||
needs_wine = False
|
||||
language: Language = Language.C
|
||||
|
||||
@property
|
||||
def path(self) -> Path:
|
||||
@@ -123,10 +138,7 @@ def from_id(compiler_id: str) -> Compiler:
|
||||
|
||||
@cache
|
||||
def available_compilers() -> List[Compiler]:
|
||||
return sorted(
|
||||
_compilers.values(),
|
||||
key=lambda c: (c.platform.id, c.id),
|
||||
)
|
||||
return list(_compilers.values())
|
||||
|
||||
|
||||
@cache
|
||||
@@ -296,6 +308,15 @@ IDO71 = IDOCompiler(
|
||||
cc='IDO_CC="${COMPILER_DIR}/cc" "${COMPILER_DIR}/cc" -c -Xcpluscomm -G0 -non_shared -Wab,-r4300_mul -woff 649,838,712 -32 ${COMPILER_FLAGS} -o "${OUTPUT}" "${INPUT}"',
|
||||
)
|
||||
|
||||
# Pascal IDO
|
||||
IDO71PASCAL = IDOCompiler(
|
||||
id="ido7.1Pascal",
|
||||
platform=N64,
|
||||
cc='IDO_CC="${COMPILER_DIR}/cc" "${COMPILER_DIR}/cc" -c -Xcpluscomm -G0 -non_shared ${COMPILER_FLAGS} -o "${OUTPUT}" "${INPUT}"',
|
||||
base_id="ido7.1",
|
||||
language=Language.PASCAL,
|
||||
)
|
||||
|
||||
GCC272KMC = GCCCompiler(
|
||||
id="gcc2.7.2kmc",
|
||||
platform=N64,
|
||||
@@ -668,8 +689,9 @@ _all_compilers: List[Compiler] = [
|
||||
GCC272KMC,
|
||||
GCC272SN,
|
||||
GCC272SNEW,
|
||||
GCC281SNCXX,
|
||||
GCC281,
|
||||
GCC281SNCXX,
|
||||
IDO71PASCAL,
|
||||
# GC_WII
|
||||
MWCC_233_144,
|
||||
MWCC_233_159,
|
||||
@@ -863,6 +885,24 @@ _all_presets = [
|
||||
"-O2 -g2 -mips3",
|
||||
diff_flags=["-Mreg-names=32"],
|
||||
),
|
||||
Preset(
|
||||
"IDO 7.1 cc",
|
||||
IDO71,
|
||||
"-O1 -KPIC -mips2",
|
||||
diff_flags=["-Mreg-names=32"],
|
||||
),
|
||||
Preset(
|
||||
"IDO 7.1 libraries",
|
||||
IDO71,
|
||||
"-O2 -KPIC -mips2",
|
||||
diff_flags=["-Mreg-names=32"],
|
||||
),
|
||||
Preset(
|
||||
"IDO 7.1 Pascal",
|
||||
IDO71PASCAL,
|
||||
"-O2 -KPIC -mips2",
|
||||
diff_flags=["-Mreg-names=32"],
|
||||
),
|
||||
# GC_WII
|
||||
Preset(
|
||||
"Super Monkey Ball",
|
||||
|
||||
@@ -12,6 +12,7 @@ from django.test.testcases import TestCase
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from coreapp.compilers import Language
|
||||
|
||||
from coreapp import compilers, platforms
|
||||
|
||||
@@ -528,10 +529,13 @@ nop
|
||||
"""
|
||||
Ensure that we can run a simple compilation/diff for all available compilers
|
||||
"""
|
||||
code = "int func(void) { return 5; }"
|
||||
if compiler.language == Language.PASCAL:
|
||||
code = "function func(): integer; begin func := 5; end;"
|
||||
result = CompilerWrapper.compile_code(
|
||||
compiler,
|
||||
"",
|
||||
"int func(void) { return 5; }",
|
||||
code,
|
||||
"",
|
||||
"func",
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ from rest_framework.viewsets import GenericViewSet
|
||||
from coreapp import compilers, platforms
|
||||
from ..compiler_wrapper import CompilationResult, CompilerWrapper, DiffResult
|
||||
from ..decompiler_wrapper import DecompilerWrapper
|
||||
from ..compilers import Language
|
||||
|
||||
from ..decorators.django import condition
|
||||
|
||||
@@ -463,9 +464,13 @@ class ScratchViewSet(
|
||||
zip_f.writestr("metadata.json", json.dumps(metadata, indent=4))
|
||||
zip_f.writestr("target.s", scratch.target_assembly.source_asm.data)
|
||||
zip_f.writestr("target.o", scratch.target_assembly.elf_object)
|
||||
zip_f.writestr("code.c", scratch.source_code)
|
||||
|
||||
# TODO refactor #439
|
||||
language = Language.PASCAL if scratch.compiler == "ido7.1pascal" else "C"
|
||||
src_ext = Language(language).get_file_extension()
|
||||
zip_f.writestr(f"code.{src_ext}", scratch.source_code)
|
||||
if scratch.context:
|
||||
zip_f.writestr("ctx.c", scratch.context)
|
||||
zip_f.writestr(f"ctx.{src_ext}", scratch.context)
|
||||
|
||||
# Prevent possible header injection attacks
|
||||
safe_name = re.sub(r"[^a-zA-Z0-9_:]", "_", scratch.name)[:64]
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"gcc2.95.2-psyq": "gcc 2.95.2 (psyq)",
|
||||
"ido5.3": "IDO 5.3",
|
||||
"ido7.1": "IDO 7.1",
|
||||
"ido7.1Pascal": "IDO 7.1 Pascal",
|
||||
"mwcc_20_72": "2.0 build 72 (MW 1.2base)",
|
||||
"mwcc_20_79": "2.0 build 79 (MW 1.2sp2)",
|
||||
"mwcc_20_82": "2.0 build 82 (MW 1.2sp2p3)",
|
||||
|
||||
Reference in New Issue
Block a user