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
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
Copyright (c) 2018-2020, 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,
|
2020-10-13 09:58:51 +02:00
|
|
|
ERRORS, STRINGS, WRITER, MSP430, THUMB, TARGETS, SCAN;
|
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;
|
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
|
|
|
|
|
|
|
BEGIN
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param = "-lower" THEN
|
|
|
|
options.lower := TRUE
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
options.version := 65536;
|
|
|
|
options.pic := FALSE;
|
2020-10-13 09:58:51 +02:00
|
|
|
options.lower := 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);
|
|
|
|
lib_path := app_path;
|
|
|
|
|
|
|
|
UTILS.GetArg(1, inname);
|
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
C.String(" ("); C.Int(UTILS.bit_depth); C.StringLn("-bit)");
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn("Copyright (c) 2018-2020, 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;
|
2020-10-13 09:58:51 +02:00
|
|
|
C.StringLn(" -lower allow lower case for keywords"); C.Ln;
|
|
|
|
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;
|
2019-03-11 09:59:55 +01:00
|
|
|
UTILS.Exit(0)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn("--------------------------------------------");
|
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
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.MSP430 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;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.STM32CM3 THEN
|
|
|
|
options.ram := THUMB.STM32_minRAM;
|
|
|
|
options.rom := THUMB.STM32_minROM
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
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;
|
2020-05-25 22:48:33 +02:00
|
|
|
C.StringLn("--------------------------------------------");
|
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.
|