WIP on more dune

Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
Kakadu 2024-08-30 00:35:31 +03:00
parent 6761c1d0ef
commit 092d5f2f33
12 changed files with 174 additions and 66 deletions

View file

@ -1,3 +1,10 @@
(lang dune 3.3)
(cram enable)
(generate_opam_files true)
(package
(name Lama)
(synopsis "TODO")
(depends posix-uname))

7
runtime/dune Normal file
View file

@ -0,0 +1,7 @@
(rule
(target runtime.a)
(mode
(promote (until-clean)))
(deps Makefile gc.c gc.h runtime_common.h runtime.c runtime.h printf.S)
(action
(run make)))

View file

@ -1,6 +1,9 @@
RUNTIME=runtime32.a
all: gc_runtime.o runtime.o
ar rc runtime.a gc_runtime.o runtime.o
.DEFAULT := $(RUNTIME)
$(RUNTIME): gc_runtime.o runtime.o
ar rc $@ gc_runtime.o runtime.o
gc_runtime.o: gc_runtime.s
$(CC) -g -fstack-protector-all -m32 -c gc_runtime.s

7
runtime32/dune Normal file
View file

@ -0,0 +1,7 @@
(rule
(target runtime32.a)
(mode
(promote (until-clean)))
(deps Makefile gc_runtime.s runtime.c runtime.h)
(action
(run make)))

View file

@ -12,7 +12,10 @@ let[@ocaml.warning "-32"] main =
cmd#dump_AST (snd prog);
cmd#dump_source (snd prog);
match cmd#get_mode with
| `Default | `Compile -> ignore @@ X86_64.build cmd prog
| `Default | `Compile -> (
match cmd#march with
| `X86_32 -> ignore @@ X86_32.build cmd prog
| `AMD64 -> ignore @@ X86_64.build cmd prog)
| `BC -> SM.ByteCode.compile cmd (SM.compile cmd prog)
| _ ->
let rec read acc =

View file

@ -43,6 +43,7 @@ class options args =
val i = ref 1
val infile = ref (None : string option)
val outfile = ref (None : string option)
val march = ref `AMD64
val runtime_path = runtime_path_
val paths = ref [ runtime_path_ ]
val mode = ref (`Default : [ `Default | `Eval | `SM | `Compile | `BC ])
@ -79,6 +80,8 @@ class options args =
raise
(Commandline_error "Path expected after '-I' specifier")
| Some path -> self#add_include_path path)
| "-march=amd64" -> march := `AMD64
| "-march=x86" -> march := `X86_32
| "-s" -> self#set_mode `SM
| "-b" -> self#set_mode `BC
| "-i" -> self#set_mode `Eval
@ -139,6 +142,8 @@ class options args =
Some args.(j))
else None
method march : [ `AMD64 | `X86_32 ] = !march
method get_debug = ""
method get_mode = !mode
method get_output_option =

View file

@ -841,7 +841,8 @@ 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/runtime.a" cmd#get_debug cmd#get_output_option cmd#basename (Buffer.contents buf) inc in
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;
Sys.command gcc_cmdline
| `Compile ->
Sys.command (Printf.sprintf "gcc %s -m32 -c %s.s" cmd#get_debug cmd#basename)

View file

@ -1482,9 +1482,10 @@ let build cmd prog =
Buffer.add_string buf " ")
objs;
let gcc_cmdline =
Printf.sprintf "%s %s %s %s %s %s.s %s %s/runtime.a" compiler
compiler_flags linker_flags debug_flags cmd#get_output_option
cmd#basename (Buffer.contents buf) cmd#get_runtime_path
Printf.sprintf "%s %s %s %s %s %s.s %s %s/%s.a" compiler compiler_flags
linker_flags debug_flags cmd#get_output_option cmd#basename
(Buffer.contents buf) cmd#get_runtime_path
(match cmd#march with `X86_32 -> "runtime32" | `AMD64 -> "runtime")
in
Sys.command gcc_cmdline
| `Compile ->

View file

@ -1,10 +1,12 @@
SHELL := /bin/bash
.PHONY: all
SHELL := /bin/bash
FILES=$(wildcard *.lama)
ALL=$(sort $(FILES:.lama=.o))
LAMAC=../src/lamac
LAMAC ?= ../src/lamac
BDIR ?= .
all: $(ALL)
all: $(addprefix $(BDIR)/,$(ALL))
Fun.o: Ref.o
@ -12,18 +14,18 @@ Data.o: Ref.o Collection.o
Collection.o: List.o Ref.o
Array.o: List.o
$(BDIR)/Array.o: $(BDIR)/List.o
Ostap.o: List.o Collection.o Ref.o Fun.o Matcher.o
Buffer.o: List.o
$(BDIR)/Buffer.o: $(BDIR)/List.o
STM.o: List.o Fun.o
$(BDIR)/STM.o: $(BDIR)/List.o $(BDIR)/Fun.o
%.o: %.lama
LAMA=../runtime $(LAMAC) -g -I . -c $<
$(BDIR)/%.o: %.lama
LAMA=../runtime $(LAMAC) -g -I . -c $< -o $@
clean:
rm -Rf *.s *.o *.i *~
$(RM) -r *.s *.o *.i *~
pushd regression && make clean && popd

15
stdlib/amd64/dune Normal file
View file

@ -0,0 +1,15 @@
(rule
(deps ../List.lama ../Makefile ../../runtime/Std.i)
(targets List.i List.o)
(action
(progn
(setenv
BDIR
"amd64"
(setenv
LAMA
"../runtime"
(setenv
LAMAC
"../src/Driver.exe -I ../runtime"
(run make -C .. all)))))))

38
stdlib/x32/dune Normal file
View file

@ -0,0 +1,38 @@
(rule
(targets List.o List.i)
(deps
(:lama ../List.lama)
%{project_root}/runtime32/runtime32.a
%{project_root}/runtime32/Std.i)
(action
(setenv
LAMA
"../../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
-I
%{project_root}/runtime32
-c
%{lama}))))
(rule
(targets Array.o Array.i)
(deps
(:lama ../Array.lama)
%{project_root}/runtime32/Std.i
List.i
List.o)
(action
(setenv
LAMA
"../../runtime32"
(run
%{project_root}/src/Driver.exe
-march=x86
-I
.
-I
%{project_root}/runtime32
-c
%{lama}))))

19
tutorial/dune Normal file
View file

@ -0,0 +1,19 @@
(rule
(targets Hello.exe)
(deps Hello.lama)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"../runtime32"
(run
%{project_root}/src/Driver.exe
%{deps}
-march=x86
-I
../stdlib/x32
-I
../runtime32
-o
%{targets}))))