2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2023-01-21 15:34:25 +01:00
|
|
|
Copyright (c) 2018-2023, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
2016-10-24 01:30:27 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE Compiler;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IMPORT ST := STATEMENTS, PARS, UTILS, PATHS, PROG, C := CONSOLE,
|
2021-09-03 19:21:37 +02:00
|
|
|
ERRORS, STRINGS, WRITER, MSP430, THUMB, TARGETS, SCAN, TEXTDRV;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
CONST
|
|
|
|
|
|
|
|
DEF_WINDOWS = "WINDOWS";
|
|
|
|
DEF_LINUX = "LINUX";
|
|
|
|
DEF_KOLIBRIOS = "KOLIBRIOS";
|
|
|
|
DEF_CPU_X86 = "CPU_X86";
|
|
|
|
DEF_CPU_X8664 = "CPU_X8664";
|
|
|
|
|
|
|
|
|
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;
|
2020-10-13 09:58:51 +02:00
|
|
|
_end: BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
value: INTEGER;
|
|
|
|
minor,
|
|
|
|
major: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
checking: SET;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2021-09-03 19:21:37 +02:00
|
|
|
|
|
|
|
PROCEDURE getVal (VAR i: INTEGER; VAR value: INTEGER);
|
|
|
|
VAR
|
|
|
|
param: PARS.PATH;
|
|
|
|
val: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
IF STRINGS.StrToInt(param, val) THEN
|
|
|
|
value := val
|
|
|
|
END;
|
|
|
|
IF param[0] = "-" THEN
|
|
|
|
DEC(i)
|
|
|
|
END
|
|
|
|
END getVal;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2023-01-21 15:34:25 +01:00
|
|
|
options.lower := TRUE;
|
2019-10-06 19:55:12 +02:00
|
|
|
out := "";
|
2019-09-26 22:23:06 +02:00
|
|
|
checking := options.checking;
|
2020-10-13 09:58:51 +02: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
|
|
|
|
|
2021-09-03 19:21:37 +02:00
|
|
|
ELSIF param = "-tab" THEN
|
|
|
|
getVal(i, options.tab)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF param = "-ram" THEN
|
2021-09-03 19:21:37 +02:00
|
|
|
getVal(i, options.ram)
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
ELSIF param = "-rom" THEN
|
2021-09-03 19:21:37 +02:00
|
|
|
getVal(i, options.rom)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
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)
|
2021-06-15 19:33:16 +02:00
|
|
|
ELSIF param[j] = "s" THEN
|
|
|
|
EXCL(checking, ST.chkSTK)
|
2019-03-11 09:59:55 +01:00
|
|
|
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
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param = "-lower" THEN
|
|
|
|
options.lower := TRUE
|
|
|
|
|
2023-01-21 15:34:25 +01:00
|
|
|
ELSIF param = "-upper" THEN
|
|
|
|
options.lower := FALSE
|
|
|
|
|
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
|
|
|
|
2022-01-05 21:42:22 +01:00
|
|
|
ELSIF param = "-uses" THEN
|
|
|
|
options.uses := TRUE
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param = "-def" THEN
|
|
|
|
INC(i);
|
|
|
|
UTILS.GetArg(i, param);
|
|
|
|
SCAN.NewDef(param)
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF param = "" THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
_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)
|
2020-10-13 09:58:51 +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
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE OutTargetItem (target: INTEGER; text: ARRAY OF CHAR);
|
|
|
|
VAR
|
|
|
|
width: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
width := 15;
|
|
|
|
width := width - LENGTH(TARGETS.Targets[target].ComLinePar) - 4;
|
|
|
|
C.String(" '"); C.String(TARGETS.Targets[target].ComLinePar); C.String("'");
|
|
|
|
WHILE width > 0 DO
|
|
|
|
C.String(20X);
|
|
|
|
DEC(width)
|
|
|
|
END;
|
|
|
|
C.StringLn(text)
|
|
|
|
END OutTargetItem;
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
2021-09-03 19:21:37 +02:00
|
|
|
options.tab := TEXTDRV.defTabSize;
|
2019-09-26 22:23:06 +02:00
|
|
|
options.version := 65536;
|
|
|
|
options.pic := FALSE;
|
2020-10-13 09:58:51 +02:00
|
|
|
options.lower := FALSE;
|
2022-01-05 21:42:22 +01:00
|
|
|
options.uses := FALSE;
|
2019-09-26 22:23:06 +02:00
|
|
|
options.checking := ST.chkALL;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PATHS.GetCurrentDirectory(app_path);
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
UTILS.GetArg(0, temp);
|
|
|
|
PATHS.split(temp, path, modname, ext);
|
|
|
|
IF PATHS.isRelative(path) THEN
|
|
|
|
PATHS.RelPath(app_path, path, temp);
|
|
|
|
path := temp
|
|
|
|
END;
|
|
|
|
lib_path := path;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
UTILS.GetArg(1, inname);
|
2021-06-15 19:33:16 +02:00
|
|
|
STRINGS.replace(inname, "\", UTILS.slash);
|
|
|
|
STRINGS.replace(inname, "/", UTILS.slash);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
C.Ln;
|
2020-05-25 22:48:33 +02:00
|
|
|
C.String("Akron Oberon Compiler v"); C.Int(UTILS.vMajor); C.String("."); C.Int2(UTILS.vMinor);
|
2021-06-15 19:33:16 +02:00
|
|
|
C.String(" ("); C.Int(UTILS.bit_depth); C.StringLn("-bit) " + UTILS.Date);
|
2023-01-21 15:34:25 +01:00
|
|
|
C.StringLn("Copyright (c) 2018-2023, Anton Krotov");
|
2019-09-26 22:23:06 +02:00
|
|
|
|
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;
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn("target =");
|
2019-03-11 09:59:55 +01:00
|
|
|
IF UTILS.bit_depth = 64 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutTargetItem(TARGETS.Win64C, "Windows64 Console");
|
|
|
|
OutTargetItem(TARGETS.Win64GUI, "Windows64 GUI");
|
|
|
|
OutTargetItem(TARGETS.Win64DLL, "Windows64 DLL");
|
|
|
|
OutTargetItem(TARGETS.Linux64, "Linux64 Exec");
|
|
|
|
OutTargetItem(TARGETS.Linux64SO, "Linux64 SO")
|
2017-11-02 17:36:50 +01:00
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutTargetItem(TARGETS.Win32C, "Windows32 Console");
|
|
|
|
OutTargetItem(TARGETS.Win32GUI, "Windows32 GUI");
|
|
|
|
OutTargetItem(TARGETS.Win32DLL, "Windows32 DLL");
|
|
|
|
OutTargetItem(TARGETS.Linux32, "Linux32 Exec");
|
|
|
|
OutTargetItem(TARGETS.Linux32SO, "Linux32 SO");
|
|
|
|
OutTargetItem(TARGETS.KolibriOS, "KolibriOS Exec");
|
|
|
|
OutTargetItem(TARGETS.KolibriOSDLL, "KolibriOS DLL");
|
|
|
|
OutTargetItem(TARGETS.MSP430, "MSP430x{1,2}xx microcontrollers");
|
|
|
|
OutTargetItem(TARGETS.STM32CM3, "STM32 Cortex-M3 microcontrollers");
|
|
|
|
C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
C.StringLn("optional settings:"); C.Ln;
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn(" -out <file name> output"); C.Ln;
|
|
|
|
C.StringLn(" -stk <size> set size of stack in Mbytes (Windows, Linux, KolibriOS)"); C.Ln;
|
|
|
|
C.StringLn(" -nochk <'ptibcwra'> disable runtime checking (pointers, types, indexes,");
|
|
|
|
C.StringLn(" BYTE, CHR, WCHR)"); C.Ln;
|
2023-01-21 15:34:25 +01:00
|
|
|
C.StringLn(" -lower allow lower case for keywords (default)"); C.Ln;
|
|
|
|
C.StringLn(" -upper only upper case for keywords"); C.Ln;
|
2020-10-13 09:58:51 +02:00
|
|
|
C.StringLn(" -def <identifier> define conditional compilation symbol"); C.Ln;
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn(" -ver <major.minor> set version of program (KolibriOS DLL)"); C.Ln;
|
|
|
|
C.StringLn(" -ram <size> set size of RAM in bytes (MSP430) or Kbytes (STM32)"); C.Ln;
|
|
|
|
C.StringLn(" -rom <size> set size of ROM in bytes (MSP430) or Kbytes (STM32)"); C.Ln;
|
2021-09-03 19:21:37 +02:00
|
|
|
C.StringLn(" -tab <width> set width for tabs"); C.Ln;
|
2022-01-05 21:42:22 +01:00
|
|
|
C.StringLn(" -uses list imported modules"); C.Ln;
|
2019-03-11 09:59:55 +01:00
|
|
|
UTILS.Exit(0)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
C.Dashes;
|
2019-03-11 09:59:55 +01:00
|
|
|
PATHS.split(inname, path, modname, ext);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF ext # UTILS.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;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
SCAN.NewDef(param);
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.Select(param) THEN
|
|
|
|
target := TARGETS.target
|
|
|
|
ELSE
|
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
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF TARGETS.CPU = TARGETS.cpuMSP430 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
options.ram := MSP430.minRAM;
|
|
|
|
options.rom := MSP430.minROM
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF (TARGETS.CPU = TARGETS.cpuTHUMB) & (TARGETS.OS = TARGETS.osNONE) THEN
|
|
|
|
options.ram := THUMB.minRAM;
|
|
|
|
options.rom := THUMB.minROM
|
2020-05-25 22:48:33 +02:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF UTILS.bit_depth < TARGETS.BitDepth THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
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);
|
2020-05-25 22:48:33 +02:00
|
|
|
STRINGS.append(lib_path, TARGETS.LibDir);
|
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);
|
2021-09-03 19:21:37 +02:00
|
|
|
TEXTDRV.setTabSize(options.tab);
|
2019-10-06 19:55:12 +02:00
|
|
|
IF outname = "" THEN
|
|
|
|
outname := path;
|
|
|
|
STRINGS.append(outname, modname);
|
2020-05-25 22:48:33 +02:00
|
|
|
STRINGS.append(outname, TARGETS.FileExt)
|
2019-10-06 19:55:12 +02:00
|
|
|
ELSE
|
|
|
|
IF PATHS.isRelative(outname) THEN
|
|
|
|
PATHS.RelPath(app_path, outname, temp);
|
|
|
|
outname := temp
|
|
|
|
END
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PARS.init(options);
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
CASE TARGETS.OS OF
|
|
|
|
|TARGETS.osNONE:
|
|
|
|
|TARGETS.osWIN32,
|
|
|
|
TARGETS.osWIN64: SCAN.NewDef(DEF_WINDOWS)
|
|
|
|
|TARGETS.osLINUX32,
|
|
|
|
TARGETS.osLINUX64: SCAN.NewDef(DEF_LINUX)
|
|
|
|
|TARGETS.osKOS: SCAN.NewDef(DEF_KOLIBRIOS)
|
|
|
|
END;
|
|
|
|
|
|
|
|
CASE TARGETS.CPU OF
|
|
|
|
|TARGETS.cpuX86: SCAN.NewDef(DEF_CPU_X86)
|
|
|
|
|TARGETS.cpuAMD64: SCAN.NewDef(DEF_CPU_X8664)
|
|
|
|
|TARGETS.cpuMSP430:
|
|
|
|
|TARGETS.cpuTHUMB:
|
|
|
|
|TARGETS.cpuRVM32I:
|
|
|
|
|TARGETS.cpuRVM64I:
|
|
|
|
END;
|
|
|
|
|
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;
|
2021-06-15 19:33:16 +02:00
|
|
|
C.Dashes;
|
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
|
2020-05-25 22:48:33 +02:00
|
|
|
END Compiler.
|