mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 14:58:50 +00:00
WIP on more dune
Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
parent
6761c1d0ef
commit
092d5f2f33
12 changed files with 174 additions and 66 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
(lang dune 3.3)
|
(lang dune 3.3)
|
||||||
|
|
||||||
(cram enable)
|
(cram enable)
|
||||||
|
|
||||||
|
(generate_opam_files true)
|
||||||
|
|
||||||
|
(package
|
||||||
|
(name Lama)
|
||||||
|
(synopsis "TODO")
|
||||||
|
(depends posix-uname))
|
||||||
|
|
|
||||||
7
runtime/dune
Normal file
7
runtime/dune
Normal 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)))
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
|
RUNTIME=runtime32.a
|
||||||
|
|
||||||
all: gc_runtime.o runtime.o
|
.DEFAULT := $(RUNTIME)
|
||||||
ar rc runtime.a gc_runtime.o runtime.o
|
|
||||||
|
$(RUNTIME): gc_runtime.o runtime.o
|
||||||
|
ar rc $@ gc_runtime.o runtime.o
|
||||||
|
|
||||||
gc_runtime.o: gc_runtime.s
|
gc_runtime.o: gc_runtime.s
|
||||||
$(CC) -g -fstack-protector-all -m32 -c gc_runtime.s
|
$(CC) -g -fstack-protector-all -m32 -c gc_runtime.s
|
||||||
|
|
|
||||||
7
runtime32/dune
Normal file
7
runtime32/dune
Normal 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)))
|
||||||
|
|
@ -12,7 +12,10 @@ let[@ocaml.warning "-32"] main =
|
||||||
cmd#dump_AST (snd prog);
|
cmd#dump_AST (snd prog);
|
||||||
cmd#dump_source (snd prog);
|
cmd#dump_source (snd prog);
|
||||||
match cmd#get_mode with
|
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)
|
| `BC -> SM.ByteCode.compile cmd (SM.compile cmd prog)
|
||||||
| _ ->
|
| _ ->
|
||||||
let rec read acc =
|
let rec read acc =
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class options args =
|
||||||
val i = ref 1
|
val i = ref 1
|
||||||
val infile = ref (None : string option)
|
val infile = ref (None : string option)
|
||||||
val outfile = ref (None : string option)
|
val outfile = ref (None : string option)
|
||||||
|
val march = ref `AMD64
|
||||||
val runtime_path = runtime_path_
|
val runtime_path = runtime_path_
|
||||||
val paths = ref [ runtime_path_ ]
|
val paths = ref [ runtime_path_ ]
|
||||||
val mode = ref (`Default : [ `Default | `Eval | `SM | `Compile | `BC ])
|
val mode = ref (`Default : [ `Default | `Eval | `SM | `Compile | `BC ])
|
||||||
|
|
@ -79,6 +80,8 @@ class options args =
|
||||||
raise
|
raise
|
||||||
(Commandline_error "Path expected after '-I' specifier")
|
(Commandline_error "Path expected after '-I' specifier")
|
||||||
| Some path -> self#add_include_path path)
|
| Some path -> self#add_include_path path)
|
||||||
|
| "-march=amd64" -> march := `AMD64
|
||||||
|
| "-march=x86" -> march := `X86_32
|
||||||
| "-s" -> self#set_mode `SM
|
| "-s" -> self#set_mode `SM
|
||||||
| "-b" -> self#set_mode `BC
|
| "-b" -> self#set_mode `BC
|
||||||
| "-i" -> self#set_mode `Eval
|
| "-i" -> self#set_mode `Eval
|
||||||
|
|
@ -139,6 +142,8 @@ class options args =
|
||||||
Some args.(j))
|
Some args.(j))
|
||||||
else None
|
else None
|
||||||
|
|
||||||
|
method march : [ `AMD64 | `X86_32 ] = !march
|
||||||
|
method get_debug = ""
|
||||||
method get_mode = !mode
|
method get_mode = !mode
|
||||||
|
|
||||||
method get_output_option =
|
method get_output_option =
|
||||||
|
|
|
||||||
|
|
@ -841,7 +841,8 @@ let build cmd prog =
|
||||||
let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in
|
let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in
|
||||||
let buf = Buffer.create 255 in
|
let buf = Buffer.create 255 in
|
||||||
List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs;
|
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
|
Sys.command gcc_cmdline
|
||||||
| `Compile ->
|
| `Compile ->
|
||||||
Sys.command (Printf.sprintf "gcc %s -m32 -c %s.s" cmd#get_debug cmd#basename)
|
Sys.command (Printf.sprintf "gcc %s -m32 -c %s.s" cmd#get_debug cmd#basename)
|
||||||
|
|
|
||||||
|
|
@ -1482,9 +1482,10 @@ let build cmd prog =
|
||||||
Buffer.add_string buf " ")
|
Buffer.add_string buf " ")
|
||||||
objs;
|
objs;
|
||||||
let gcc_cmdline =
|
let gcc_cmdline =
|
||||||
Printf.sprintf "%s %s %s %s %s %s.s %s %s/runtime.a" compiler
|
Printf.sprintf "%s %s %s %s %s %s.s %s %s/%s.a" compiler compiler_flags
|
||||||
compiler_flags linker_flags debug_flags cmd#get_output_option
|
linker_flags debug_flags cmd#get_output_option cmd#basename
|
||||||
cmd#basename (Buffer.contents buf) cmd#get_runtime_path
|
(Buffer.contents buf) cmd#get_runtime_path
|
||||||
|
(match cmd#march with `X86_32 -> "runtime32" | `AMD64 -> "runtime")
|
||||||
in
|
in
|
||||||
Sys.command gcc_cmdline
|
Sys.command gcc_cmdline
|
||||||
| `Compile ->
|
| `Compile ->
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
SHELL := /bin/bash
|
.PHONY: all
|
||||||
|
|
||||||
|
SHELL := /bin/bash
|
||||||
FILES=$(wildcard *.lama)
|
FILES=$(wildcard *.lama)
|
||||||
ALL=$(sort $(FILES:.lama=.o))
|
ALL=$(sort $(FILES:.lama=.o))
|
||||||
LAMAC=../src/lamac
|
LAMAC ?= ../src/lamac
|
||||||
|
BDIR ?= .
|
||||||
|
|
||||||
all: $(ALL)
|
all: $(addprefix $(BDIR)/,$(ALL))
|
||||||
|
|
||||||
Fun.o: Ref.o
|
Fun.o: Ref.o
|
||||||
|
|
||||||
|
|
@ -12,18 +14,18 @@ Data.o: Ref.o Collection.o
|
||||||
|
|
||||||
Collection.o: List.o Ref.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
|
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
|
$(BDIR)/%.o: %.lama
|
||||||
LAMA=../runtime $(LAMAC) -g -I . -c $<
|
LAMA=../runtime $(LAMAC) -g -I . -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -Rf *.s *.o *.i *~
|
$(RM) -r *.s *.o *.i *~
|
||||||
pushd regression && make clean && popd
|
pushd regression && make clean && popd
|
||||||
|
|
||||||
|
|
|
||||||
15
stdlib/amd64/dune
Normal file
15
stdlib/amd64/dune
Normal 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
38
stdlib/x32/dune
Normal 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
19
tutorial/dune
Normal 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}))))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue