Fixed issues with a missing _main symbol

This commit is contained in:
Egor Sheremetov 2024-05-28 14:54:03 +02:00 committed by Roman Venediktov
parent eb8e9374f2
commit 87a489e2e3
2 changed files with 6 additions and 6 deletions

View file

@ -1014,7 +1014,7 @@ class env cmd imports =
{<funinfo = funinfo#register_closure f self#closure>}
method current_function =
match fundefs with Top _ -> "main" | Item (fd, _, _) -> fd.name
match fundefs with Top _ -> "_main" | Item (fd, _, _) -> fd.name
method private import_imports =
let paths = cmd#get_include_paths in
@ -1649,7 +1649,7 @@ let compile cmd ((imports, _), p) =
LABEL topname;
BEGIN
( topname,
(if topname = "main" then 2 else 0),
(if topname = "_main" then 2 else 0),
env#nlocals,
[],
[],

View file

@ -742,7 +742,7 @@ let compile cmd env imports code =
let env = env#enter f nargs nlocals has_closure in
( env,
[ (* Meta (Printf.sprintf "\t.type %s, @function" name) *) ]
@ (if f = "main" then []
@ (if f = "_main" then []
else
[
(* Meta
@ -791,7 +791,7 @@ let compile cmd env imports code =
Mov (r13, rsi);
Mov (r14, rcx);
]
@ (if f = "main" then
@ (if f = "_main" then
[
(* Align stack as main function is the only function that could be called without alignment. TODO *)
Mov (L 0xF, rax);
@ -826,7 +826,7 @@ let compile cmd env imports code =
Mov (rbp, rsp);
Pop rbp;
]
@ (if name = "main" then [ Binop ("^", rax, rax) ] else [])
@ (if name = "_main" then [ Binop ("^", rax, rax) ] else [])
@ [
Meta "\t.cfi_restore\t5";
Meta "\t.cfi_def_cfa\t4, 4";
@ -1260,7 +1260,7 @@ class env prg =
method gen_line =
let lab = Printf.sprintf ".L%d" nlabels in
( {<nlabels = nlabels + 1; first_line = false>},
if fname = "main" then
if fname = "_main" then
[ (* Meta (Printf.sprintf "\t.stabn 68,0,%d,%s" line lab); *) Label lab ]
else
(if first_line then