Skip to content

Commit

Permalink
feat(compiler)!: Custom Grain object files
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed May 3, 2024
1 parent fc19761 commit 567b24c
Show file tree
Hide file tree
Showing 41 changed files with 1,007 additions and 1,481 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _build/
.installed-pkgs
notes.org
node_modules/
*.gro
*.wasm
*.wasm.map
*.wat
Expand Down
2 changes: 1 addition & 1 deletion cli/bin/grain.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ program
.action(function (file, options, program) {
const success = exec.grainc(file, options, program);
if (success) {
const outFile = options.o ?? file.replace(/\.gr$/, ".gr.wasm");
const outFile = options.o ?? file.replace(/\.gr$/, ".wasm");
exec.grainrun(unprocessedArgs, outFile, options, program);
}
});
Expand Down
4 changes: 2 additions & 2 deletions compiler/grainc/grainc.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ let compile_file = (name, outfile_arg) => {
try({
let outfile =
Option.value(
~default=Compile.default_output_filename(name),
~default=Compile.default_wasm_filename(name),
outfile_arg,
);
let hook =
if (Grain_utils.Config.statically_link^) {
Compile.stop_after_assembled;
} else {
Compile.stop_after_object_file_emitted;
Compile.stop_after_object_emitted;
};
ignore(Compile.compile_file(~is_root_file=true, ~hook, ~outfile, name));
}) {
Expand Down
11 changes: 4 additions & 7 deletions compiler/src/codegen/comp_utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ let rec compile_const = (c): Literal.t => {
| MConstU16(n) => Literal.int32(conv_short_int(n, Uint16Type))
| MConstU32(n) => Literal.int32(conv_uint32(n))
| MConstU64(n) => Literal.int64(conv_uint64(n))
| MConstF32(n) => Literal.float32(conv_float32(n))
| MConstF64(n) => Literal.float64(conv_float64(n))
| MConstF32(n) => Literal.float32(conv_float32(Int64.float_of_bits(n)))
| MConstF64(n) => Literal.float64(conv_float64(Int64.float_of_bits(n)))
| MConstChar(c) => Literal.int32(conv_char(c))
| MConstLiteral(MConstI8(n))
| MConstLiteral(MConstI16(n))
Expand All @@ -90,8 +90,8 @@ let rec compile_const = (c): Literal.t => {
| MConstLiteral(MConstU16(n))
| MConstLiteral(MConstU32(n)) => Literal.int32(n)
| MConstLiteral(MConstU64(n)) => Literal.int64(n)
| MConstLiteral(MConstF32(n)) => Literal.float32(n)
| MConstLiteral(MConstF64(n)) => Literal.float64(n)
| MConstLiteral(MConstF32(n)) => Literal.float32(Int64.float_of_bits(n))
| MConstLiteral(MConstF64(n)) => Literal.float64(Int64.float_of_bits(n))
| MConstLiteral(MConstChar(c)) => Literal.int32(conv_char(c))
};
};
Expand Down Expand Up @@ -344,6 +344,3 @@ let write_universal_exports =
)
);
};

let compiling_wasi_polyfill = name =>
Option.is_some(Config.wasi_polyfill^) && Config.wasi_polyfill^ == name;
2 changes: 0 additions & 2 deletions compiler/src/codegen/comp_utils.rei
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,3 @@ let get_exported_names:

let write_universal_exports:
(Module.t, Cmi_format.cmi_infos, Hashtbl.t(string, string)) => unit;

let compiling_wasi_polyfill: option(string) => bool;
Loading

0 comments on commit 567b24c

Please sign in to comment.