2017-09-29 17:25:02 +02:00
|
|
|
import "../src/glue/js";
|
|
|
|
import { Compiler } from "../src/compiler";
|
|
|
|
import { Parser } from "../src/parser";
|
|
|
|
|
2017-10-07 14:29:43 +02:00
|
|
|
/* const files: Map<string,string> = new Map([
|
2017-10-02 12:52:15 +02:00
|
|
|
["main", `import { Test as TestAlias } from "./a"; export { TestAlias } from "./d"; if (1) {} export const a: i32 = 123;`],
|
2017-09-29 17:25:02 +02:00
|
|
|
["a", `export { Test } from "./b";`],
|
|
|
|
["b", `export { Test } from "./c";`],
|
2017-10-07 14:29:43 +02:00
|
|
|
["c", `export enum Test { ONE = 1, TWO = 1 + 1 }`],
|
2017-09-29 17:25:02 +02:00
|
|
|
["d", `export { Test as TestAlias } from "./b";`]
|
2017-10-07 14:29:43 +02:00
|
|
|
]); */
|
|
|
|
|
|
|
|
const files: Map<string,string> = new Map([
|
|
|
|
["main", `
|
|
|
|
export function add(a: i32, b: i32): i32 { let c: i32 = a + b; return c; }
|
|
|
|
`]
|
2017-09-29 17:25:02 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
const parser = new Parser();
|
|
|
|
parser.parseFile(<string>files.get("main"), "main", true);
|
|
|
|
do {
|
|
|
|
let nextFile = parser.nextFile();
|
|
|
|
if (!nextFile)
|
|
|
|
break;
|
|
|
|
if (!files.has(nextFile))
|
|
|
|
throw new Error("file not found: " + nextFile);
|
|
|
|
parser.parseFile(<string>files.get(nextFile), nextFile, false);
|
|
|
|
} while(true);
|
|
|
|
const program = parser.finish();
|
|
|
|
const compiler = new Compiler(program);
|
|
|
|
const module = compiler.compile();
|
|
|
|
|
2017-10-02 12:52:15 +02:00
|
|
|
console.log("names", program.names.keys());
|
|
|
|
console.log("exports", program.exports.keys());
|
2017-09-29 17:25:02 +02:00
|
|
|
|
2017-10-07 14:29:43 +02:00
|
|
|
module.optimize();
|
2017-09-29 17:25:02 +02:00
|
|
|
// module.validate(); // global initializers can't use i32.add etc. yet
|
2017-10-07 14:29:43 +02:00
|
|
|
if (!module.noEmit)
|
|
|
|
_BinaryenModulePrint(module.ref);
|
2017-09-29 17:25:02 +02:00
|
|
|
|
2017-10-02 12:52:15 +02:00
|
|
|
/* console.log("--- statements ---");
|
2017-09-29 17:25:02 +02:00
|
|
|
compiler.statements.forEach(stmt => {
|
|
|
|
_BinaryenExpressionPrint(stmt);
|
|
|
|
}); */
|