Skip to content

Commit

Permalink
Convert compiler.js to JS module. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Dec 6, 2023
1 parent c26fc38 commit 8b00e73
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/compiler.js → src/compiler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

// LLVM => JavaScript compiler, main entry point

const fs = require('fs');
globalThis.vm = require('vm');
globalThis.assert = require('assert');
globalThis.nodePath = require('path');
import * as fs from 'fs';
import * as path from 'path';
import * as vm from 'vm';
import * as url from 'url';
import assert from 'assert';

globalThis.vm = vm;
globalThis.assert = assert;
globalThis.nodePath = path;

globalThis.print = (x) => {
process.stdout.write(x + '\n');
Expand All @@ -22,9 +27,10 @@ globalThis.printErr = (x) => {

function find(filename) {
assert(filename);
const prefixes = [__dirname, process.cwd()];
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
const prefixes = [dirname, process.cwd()];
for (let i = 0; i < prefixes.length; ++i) {
const combined = nodePath.join(prefixes[i], filename);
const combined = path.join(prefixes[i], filename);
if (fs.existsSync(combined)) {
return combined;
}
Expand Down Expand Up @@ -96,7 +102,7 @@ if (!STRICT) {
// Main
// ===============================

B = new Benchmarker();
const B = new Benchmarker();

try {
runJSify();
Expand Down
2 changes: 1 addition & 1 deletion src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function isPowerOfTwo(x) {
}

/** @constructor */
function Benchmarker() {
globalThis.Benchmarker = function() {
const totals = {};
const ids = [];
const lastTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def compile_javascript(symbols_only=False):
args = [settings_file]
if symbols_only:
args += ['--symbols-only']
out = shared.run_js_tool(path_from_root('src/compiler.js'),
out = shared.run_js_tool(path_from_root('src/compiler.mjs'),
args, stdout=subprocess.PIPE, stderr=stderr_file,
cwd=path_from_root('src'), env=env, encoding='utf-8')
if symbols_only:
Expand Down
2 changes: 1 addition & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def generate_js_sym_info():
# mode of the js compiler that would generate a list of all possible symbols
# that could be checked in.
_, forwarded_data = emscripten.compile_javascript(symbols_only=True)
# When running in symbols_only mode compiler.js outputs a flat list of C symbols.
# When running in symbols_only mode compiler.mjs outputs a flat list of C symbols.
return json.loads(forwarded_data)


Expand Down
2 changes: 1 addition & 1 deletion tools/maint/gen_sig_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def extract_sig_info(sig_info, extra_settings=None, extra_cflags=None, cxx=False
settings.update(extra_settings)
with tempfiles.get_file('.json') as settings_json:
utils.write_file(settings_json, json.dumps(settings))
output = shared.run_js_tool(utils.path_from_root('src/compiler.js'),
output = shared.run_js_tool(utils.path_from_root('src/compiler.mjs'),
['--symbols-only', settings_json],
stdout=subprocess.PIPE, cwd=utils.path_from_root())
symbols = json.loads(output)['deps'].keys()
Expand Down
2 changes: 1 addition & 1 deletion tools/toolchain_profiler.results_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
ret.concat([out]);
}
return ret;
} else if (startsWith(basename, 'compiler.js')) {
} else if (startsWith(basename, 'compiler.mjs')) {
var posParams = findPositionalParams(cmdLine, []);
var interestingParams = [];
for(var i = 1; i < posParams.length; ++i) {
Expand Down

0 comments on commit 8b00e73

Please sign in to comment.