-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompiler.js
More file actions
43 lines (36 loc) · 1.35 KB
/
Copy pathcompiler.js
File metadata and controls
43 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let fs = require('fs');
let simas = require('./simas');
let common = require('./common');
// Compiled Simple Assembly
const compiledFileExtension = ".csa";
if(!process.argv[2]) {
process.stderr.write("Error: Please provide an input file to compile.\nUse the flag -h for help.\n");
process.exit(1);
}
if (process.argv[2] == "-h") {
process.stdout.write(common.compiler_information);
} else {
try {
var ins = "";
fs.readFile(process.argv[2], 'utf8', function (err, data) {
if (err) {
process.stderr.write("Error opening file: " + err.path + "\n");
process.exit(1);
}
ins = JSON.stringify(simas.run(data, false, process.argv[2], []), null, 0); // last argument could be 4
let target;
if (process.argv[2]) {
target = process.argv[2].replace(/\.[^/.]+$/, compiledFileExtension);
}
fs.writeFile(target, common.xString(ins), 'utf8', (err) => {
if (err) {
process.stderr.write('Error compiling to file:' + err.path + "\n");
return;
}
process.stdout.write('Compiled file: ' + process.argv[2] + ' to ' + target);
});
});
} catch(err) {
console.log("Something went wrong.");
}
}