Handle -march properly

Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
Kakadu 2024-09-05 14:50:27 +03:00
parent 55d595600d
commit 3f7f51b2f0
10 changed files with 51 additions and 14 deletions

View file

@ -1,4 +1,4 @@
RUNTIME=runtime32.a
RUNTIME=runtime.a
.DEFAULT := $(RUNTIME)

View file

@ -1,5 +1,5 @@
(rule
(target runtime32.a)
(target runtime.a)
(mode
(promote (until-clean)))
(deps Makefile gc_runtime.s runtime.c runtime.h)

View file

@ -22,8 +22,8 @@ let[@ocaml.warning "-32"] main =
try
let r = read_int () in
Printf.printf "> ";
read (acc @ [ r ])
with End_of_file -> acc
read (r :: acc)
with End_of_file -> List.rev acc
in
let input = read [] in
let output =

View file

@ -80,7 +80,7 @@ class options args =
raise
(Commandline_error "Path expected after '-I' specifier")
| Some path -> self#add_include_path path)
| "-march=amd64" -> march := `AMD64
| "-march=x86_64" | "-march=amd64" -> march := `AMD64
| "-march=x86" -> march := `X86_32
| "-s" -> self#set_mode `SM
| "-b" -> self#set_mode `BC

View file

@ -841,8 +841,7 @@ let build cmd prog =
let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in
let buf = Buffer.create 255 in
List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs;
let gcc_cmdline = Printf.sprintf "gcc %s -m32 %s %s.s %s %s/runtime32.a" cmd#get_debug cmd#get_output_option cmd#basename (Buffer.contents buf) inc in
Printf.printf " > %s\n%!" gcc_cmdline;
let gcc_cmdline = Printf.sprintf "gcc %s -m32 %s %s.s %s %s/runtime.a" cmd#get_debug cmd#get_output_option cmd#basename (Buffer.contents buf) inc in
Sys.command gcc_cmdline
| `Compile ->
Sys.command (Printf.sprintf "gcc %s -m32 -c %s.s" cmd#get_debug cmd#basename)

View file

@ -1464,7 +1464,13 @@ let build cmd prog =
cmd#dump_file "s" (genasm cmd prog);
cmd#dump_file "i" (Interface.gen prog);
let compiler =
match cmd#target_os with Darwin -> "clang" | Linux -> "gcc"
match (cmd#target_os, cmd#march) with
| Darwin, `AMD64 -> "clang"
| Darwin, `X86_32 ->
Printf.eprintf "X86_32 on darwin is not supported\n";
exit 1
| Linux, `AMD64 -> "gcc"
| Linux, `X86_32 -> "gcc -m32"
in
let compiler_flags, linker_flags =
match cmd#target_os with
@ -1489,7 +1495,9 @@ let build cmd prog =
in
Sys.command gcc_cmdline
| `Compile ->
Sys.command
(Printf.sprintf "%s %s %s -c -g %s.s" compiler compiler_flags
debug_flags cmd#basename)
let cmd =
Printf.sprintf "%s %s %s -c -g %s.s" compiler compiler_flags debug_flags
cmd#basename
in
Sys.command cmd
| _ -> invalid_arg "must not happen"

4
stdlib/.gitignore vendored
View file

@ -3,3 +3,7 @@
/*.log
*.i
*.s
*.exe
*.x32.exe
*.x64.exe

View file

@ -2,7 +2,9 @@
SHELL := /bin/bash
SRCDIR ?= .
$(info SRCDIR = $(SRCDIR))
FILES ?= $(wildcard $(SRCDIR)/*.lama)
$(info FILES = $(FILES))
OFILES = $(FILES:$(SRCDIR)/%=%)
OFILES := $(OFILES:.lama=.o)
$(info OFILES = $(OFILES))
@ -11,7 +13,7 @@ LAMAC ?= ../src/lamac
BDIR ?= .
all: $(addprefix $(BDIR)/,$(ALL))
$(info ALL = $(ALL))
$(info ALL = $(ALL), SRCDIR = $(SRCDIR))
$(BDIR)/Fun.o: $(BDIR)/Ref.o
$(BDIR)/Data.o: $(BDIR)/Ref.o $(BDIR)/Collection.o

View file

@ -3,6 +3,19 @@
../Makefile
../../runtime/Std.i
../List.lama
../Array.lama
../Buffer.lama
../Collection.lama
../Data.lama
../Fun.lama
../Lazy.lama
../List.lama
../Matcher.lama
../Ostap.lama
../Random.lama
../Ref.lama
../STM.lama
../Timer.lama
%{project_root}/src/Driver.exe)
(targets
List.i
@ -48,5 +61,3 @@
LAMAC
"../../src/Driver.exe -march=x86 -I ../runtime32"
(run make -j2 -f ../Makefile all)))))))
;)

View file

@ -3,6 +3,19 @@
../Makefile
../../runtime/Std.i
../List.lama
../Array.lama
../Buffer.lama
../Collection.lama
../Data.lama
../Fun.lama
../Lazy.lama
../List.lama
../Matcher.lama
../Ostap.lama
../Random.lama
../Ref.lama
../STM.lama
../Timer.lama
%{project_root}/src/Driver.exe)
(targets
List.i