2019-10-06 19:55:12 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
Copyright (c) 2018-2019, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
2016-10-24 01:30:27 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE Compiler;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IMPORT ST := STATEMENTS, PARS, UTILS, PATHS, PROG, C := CONSOLE, ERRORS, STRINGS, mConst := CONSTANTS, WRITER, MSP430;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE Target (s: ARRAY OF CHAR): INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
VAR
|
2019-03-11 09:59:55 +01:00
|
|
|
res: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF s = mConst.Target_sConsole THEN
|
|
|
|
res := mConst.Target_iConsole
|
|
|
|
ELSIF s = mConst.Target_sGUI THEN
|
|
|
|
res := mConst.Target_iGUI
|
|
|
|
ELSIF s = mConst.Target_sDLL THEN
|
|
|
|
res := mConst.Target_iDLL
|
|
|
|
ELSIF s = mConst.Target_sKolibri THEN
|
|
|
|
res := mConst.Target_iKolibri
|
|
|
|
ELSIF s = mConst.Target_sObject THEN
|
|
|
|
res := mConst.Target_iObject
|
|
|
|
ELSIF s = mConst.Target_sConsole64 THEN
|
|
|
|
res := mConst.Target_iConsole64
|
|
|
|
ELSIF s = mConst.Target_sGUI64 THEN
|
|
|
|
res := mConst.Target_iGUI64
|
|
|
|
ELSIF s = mConst.Target_sDLL64 THEN
|
|
|
|
res := mConst.Target_iDLL64
|
|
|
|
ELSIF s = mConst.Target_sELF32 THEN
|
|
|
|
res := mConst.Target_iELF32
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF s = mConst.Target_sELFSO32 THEN
|
|
|
|
res := mConst.Target_iELFSO32
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF s = mConst.Target_sELF64 THEN
|
|
|
|
res := mConst.Target_iELF64
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF s = mConst.Target_sELFSO64 THEN
|
|
|
|
res := mConst.Target_iELFSO64
|
|
|
|
ELSIF s = mConst.Target_sMSP430 THEN
|
|
|
|
res := mConst.Target_iMSP430
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
res := 0
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN res
|
|
|
|
END Target;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE keys (VAR options: PROG.OPTIONS; VAR out: PARS.PATH);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
param: PARS.PATH;
|
|
|
|
i, j: INTEGER;
|
|
|
|
end: BOOLEAN;
|
|
|
|
value: INTEGER;
|
|
|
|
minor,
|
|
|
|
major: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
checking: SET;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-10-06 19:55:12 +02:00
|
|
|
out := "";
|
2019-09-26 22:23:06 +02:00
|
|
|
checking := options.checking;
|
2019-03-11 09:59:55 +01:00
|
|
|
end := FALSE;
|
2019-10-06 19:55:12 +02:00
|
|
|
i := 3;
|
2019-03-11 09:59:55 +01:00
|
|
|
REPEAT
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
|
|
|
|
IF param = "-stk" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
IF STRINGS.StrToInt(param, value) & (1 <= value) & (value <= 32) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
options.stack := value
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
END
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
ELSIF param = "-out" THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
2019-10-06 19:55:12 +02:00
|
|
|
ELSE
|
|
|
|
out := param
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF param = "-ram" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
IF STRINGS.StrToInt(param, value) THEN
|
|
|
|
options.ram := value
|
|
|
|
END;
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF param = "-rom" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
IF STRINGS.StrToInt(param, value) THEN
|
|
|
|
options.rom := value
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF param = "-nochk" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
ELSE
|
|
|
|
j := 0;
|
|
|
|
WHILE param[j] # 0X DO
|
|
|
|
|
|
|
|
IF param[j] = "p" THEN
|
|
|
|
EXCL(checking, ST.chkPTR)
|
|
|
|
ELSIF param[j] = "t" THEN
|
|
|
|
EXCL(checking, ST.chkGUARD)
|
|
|
|
ELSIF param[j] = "i" THEN
|
|
|
|
EXCL(checking, ST.chkIDX)
|
|
|
|
ELSIF param[j] = "b" THEN
|
|
|
|
EXCL(checking, ST.chkBYTE)
|
|
|
|
ELSIF param[j] = "c" THEN
|
|
|
|
EXCL(checking, ST.chkCHR)
|
|
|
|
ELSIF param[j] = "w" THEN
|
|
|
|
EXCL(checking, ST.chkWCHR)
|
|
|
|
ELSIF param[j] = "r" THEN
|
|
|
|
EXCL(checking, ST.chkCHR);
|
|
|
|
EXCL(checking, ST.chkWCHR);
|
|
|
|
EXCL(checking, ST.chkBYTE)
|
|
|
|
ELSIF param[j] = "a" THEN
|
|
|
|
checking := {}
|
|
|
|
END;
|
|
|
|
|
|
|
|
INC(j)
|
2019-09-26 22:23:06 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
ELSIF param = "-ver" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
IF STRINGS.StrToVer(param, major, minor) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
options.version := major * 65536 + minor
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF param = "-pic" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
options.pic := TRUE
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF param = "" THEN
|
|
|
|
end := TRUE
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.BadParam(param)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2017-11-02 17:36:50 +01:00
|
|
|
INC(i)
|
2019-09-26 22:23:06 +02:00
|
|
|
UNTIL end;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
options.checking := checking
|
2019-03-11 09:59:55 +01:00
|
|
|
END keys;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE main;
|
|
|
|
VAR
|
|
|
|
path: PARS.PATH;
|
|
|
|
inname: PARS.PATH;
|
|
|
|
ext: PARS.PATH;
|
|
|
|
app_path: PARS.PATH;
|
|
|
|
lib_path: PARS.PATH;
|
|
|
|
modname: PARS.PATH;
|
|
|
|
outname: PARS.PATH;
|
|
|
|
param: PARS.PATH;
|
|
|
|
temp: PARS.PATH;
|
|
|
|
target: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
bit_depth: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
time: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
options: PROG.OPTIONS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
options.stack := 2;
|
|
|
|
options.version := 65536;
|
|
|
|
options.pic := FALSE;
|
|
|
|
options.checking := ST.chkALL;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PATHS.GetCurrentDirectory(app_path);
|
|
|
|
lib_path := app_path;
|
|
|
|
|
|
|
|
UTILS.GetArg(1, inname);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
C.Ln;
|
|
|
|
C.String("Akron Oberon Compiler v"); C.Int(mConst.vMajor); C.String("."); C.Int2(mConst.vMinor);
|
|
|
|
C.String(" ("); C.Int(UTILS.bit_depth); C.StringLn("-bit)");
|
|
|
|
C.StringLn("Copyright (c) 2018-2019, Anton Krotov");
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF inname = "" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
C.Ln;
|
2019-10-06 19:55:12 +02:00
|
|
|
C.StringLn("Usage: Compiler <main module> <target> [optional settings]"); C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF UTILS.bit_depth = 64 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
C.StringLn('target = console | gui | dll | console64 | gui64 | dll64 | kos | obj | elfexe | elfso | elfexe64 | elfso64 | msp430'); C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF UTILS.bit_depth = 32 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
C.StringLn('target = console | gui | dll | kos | obj | elfexe | elfso | msp430'); C.Ln;
|
2017-11-02 17:36:50 +01:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
C.StringLn("optional settings:"); C.Ln;
|
2019-10-06 19:55:12 +02:00
|
|
|
C.StringLn(" -out <file name> output"); C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
C.StringLn(" -stk <size> set size of stack in megabytes"); C.Ln;
|
|
|
|
C.StringLn(' -nochk <"ptibcwra"> disable runtime checking (pointers, types, indexes,');
|
|
|
|
C.StringLn(' BYTE, CHR, WCHR)'); C.Ln;
|
2019-10-06 19:55:12 +02:00
|
|
|
C.StringLn(" -ver <major.minor> set version of program ('obj' target)"); C.Ln;
|
|
|
|
C.StringLn(" -ram <size> set size of RAM in bytes ('msp430' target)"); C.Ln;
|
|
|
|
C.StringLn(" -rom <size> set size of ROM in bytes ('msp430' target)"); C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
UTILS.Exit(0)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PATHS.split(inname, path, modname, ext);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF ext # mConst.FILE_EXT THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.Error(207)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF PATHS.isRelative(path) THEN
|
|
|
|
PATHS.RelPath(app_path, path, temp);
|
|
|
|
path := temp
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
UTILS.GetArg(2, param);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF param = "" THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.Error(205)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
target := Target(param);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF target = 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
ERRORS.Error(206)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE target OF
|
|
|
|
|mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iDLL64, mConst.Target_iELF64, mConst.Target_iELFSO64:
|
|
|
|
bit_depth := 64
|
|
|
|
|mConst.Target_iConsole, mConst.Target_iGUI, mConst.Target_iDLL,
|
|
|
|
mConst.Target_iKolibri, mConst.Target_iObject, mConst.Target_iELF32, mConst.Target_iELFSO32:
|
|
|
|
bit_depth := 32
|
|
|
|
|mConst.Target_iMSP430:
|
|
|
|
bit_depth := 16;
|
|
|
|
options.ram := MSP430.minRAM;
|
|
|
|
options.rom := MSP430.minROM
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF UTILS.bit_depth < bit_depth THEN
|
|
|
|
ERRORS.Error(206)
|
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "lib");
|
|
|
|
STRINGS.append(lib_path, UTILS.slash);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE target OF
|
|
|
|
|mConst.Target_iConsole, mConst.Target_iGUI, mConst.Target_iDLL:
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "Windows32")
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|mConst.Target_iKolibri, mConst.Target_iObject:
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "KolibriOS")
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|mConst.Target_iELF32, mConst.Target_iELFSO32:
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "Linux32")
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|mConst.Target_iELF64, mConst.Target_iELFSO64:
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "Linux64")
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iDLL64:
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, "Windows64")
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|mConst.Target_iMSP430:
|
|
|
|
STRINGS.append(lib_path, "MSP430")
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
STRINGS.append(lib_path, UTILS.slash);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
keys(options, outname);
|
|
|
|
IF outname = "" THEN
|
|
|
|
outname := path;
|
|
|
|
STRINGS.append(outname, modname);
|
|
|
|
CASE target OF
|
|
|
|
|mConst.Target_iConsole, mConst.Target_iGUI, mConst.Target_iConsole64, mConst.Target_iGUI64:
|
|
|
|
STRINGS.append(outname, ".exe")
|
|
|
|
|
|
|
|
|mConst.Target_iObject:
|
|
|
|
STRINGS.append(outname, ".obj")
|
|
|
|
|
|
|
|
|mConst.Target_iKolibri, mConst.Target_iELF32, mConst.Target_iELF64:
|
|
|
|
|
|
|
|
|mConst.Target_iELFSO32, mConst.Target_iELFSO64:
|
|
|
|
STRINGS.append(outname, ".so")
|
|
|
|
|
|
|
|
|mConst.Target_iDLL, mConst.Target_iDLL64:
|
|
|
|
STRINGS.append(outname, ".dll")
|
|
|
|
|
|
|
|
|mConst.Target_iMSP430:
|
|
|
|
STRINGS.append(outname, ".hex")
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF PATHS.isRelative(outname) THEN
|
|
|
|
PATHS.RelPath(app_path, outname, temp);
|
|
|
|
outname := temp
|
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
PARS.init(bit_depth, target, options);
|
|
|
|
|
|
|
|
PARS.program.dll := target IN {mConst.Target_iELFSO32, mConst.Target_iELFSO64, mConst.Target_iDLL, mConst.Target_iDLL64, mConst.Target_iObject};
|
|
|
|
PARS.program.obj := target = mConst.Target_iObject;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ST.compile(path, lib_path, modname, outname, target, options);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
time := UTILS.GetTickCount() - UTILS.time;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
C.Int(PARS.lines); C.String(" lines, ");
|
2019-03-11 09:59:55 +01:00
|
|
|
C.Int(time DIV 100); C.String("."); C.Int2(time MOD 100); C.String(" sec, ");
|
|
|
|
C.Int(WRITER.counter); C.StringLn(" bytes");
|
|
|
|
|
|
|
|
UTILS.Exit(0)
|
|
|
|
END main;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
main
|
2019-10-06 19:55:12 +02:00
|
|
|
END Compiler.
|