forked from microsoft/devicescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctool.ts
More file actions
53 lines (46 loc) · 1.56 KB
/
ctool.ts
File metadata and controls
53 lines (46 loc) · 1.56 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
44
45
46
47
48
49
50
51
52
53
import { readdirSync, readFileSync } from "node:fs"
import { compileBuf, getHost } from "./build"
import { CmdOptions } from "./command"
import * as path from "node:path"
import { testCompiler } from "@devicescript/compiler"
import { runTest } from "./run"
export interface CToolOptions {
empty?: boolean
test?: boolean
}
function readdir(folder: string) {
return readdirSync(folder).map(bn => path.join(folder, bn))
}
const ctest = "devs/compiler-tests"
const samples = "devs/samples"
const rtest = "devs/run-tests"
export async function ctool(options: CToolOptions & CmdOptions) {
if (options.empty) {
const res = await compileBuf(Buffer.from(""), { noVerify: true })
const buf = res.binary
let r = `__attribute__((aligned(sizeof(void *)))) static const uint8_t devs_empty_program[${buf.length}] = {`
for (let i = 0; i < buf.length; ++i) {
if ((i & 15) == 0) r += "\n"
r += "0x" + ("0" + buf[i].toString(16)).slice(-2) + ", "
}
r += "\n};"
console.log(r)
}
if (options.test) {
const files = readdir(ctest)
.concat(readdir(samples))
.filter(f => /\.ts$/.test(f))
for (const fn of files) {
console.log(`*** test ${fn}`)
const host = await getHost({
mainFileName: fn,
})
testCompiler(host, readFileSync(fn, "utf8"))
}
for (const fn of readdir(rtest)) {
console.log(`*** run ${fn}`)
await runTest(fn)
}
process.exit(0)
}
}