-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.js
80 lines (72 loc) · 2.48 KB
/
utility.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* -*- Mode: Javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
"use strict";
function assert(x)
{
if (!x)
throw "assertion failed: " + (Error().stack);
}
function xprint(x, padding)
{
if (!padding)
padding = "";
if (x instanceof Array) {
print(padding + "[");
for (var elem of x)
xprint(elem, padding + " ");
print(padding + "]");
} else if (x instanceof Object) {
print(padding + "{");
for (var prop in x) {
print(padding + " " + prop + ":");
xprint(x[prop], padding + " ");
}
print(padding + "}");
} else {
print(padding + x);
}
}
function sameBlockId(id0, id1)
{
if (id0.Kind != id1.Kind)
return false;
if (!sameVariable(id0.Variable, id1.Variable))
return false;
if (id0.Kind == "Loop" && id0.Loop != id1.Loop)
return false;
return true;
}
function sameVariable(var0, var1)
{
assert("Name" in var0 || var0.Kind == "This" || var0.Kind == "Return");
assert("Name" in var1 || var1.Kind == "This" || var1.Kind == "Return");
if ("Name" in var0)
return "Name" in var1 && var0.Name[0] == var1.Name[0];
return var0.Kind == var1.Kind;
}
function otherDestructorName(name)
{
// gcc's information for destructors can be pretty messed up. Some functions
// have destructors with no arguments, some have destructors with an int32
// argument, some have both, and which one matches what the programmer wrote
// is anyone's guess. Work around this by treating calls to one destructor
// form as a call to both destructor forms.
if (!/::~/.test(name))
return null;
if (/\(int32\)/.test(name))
return name.replace("(int32)","()");
if (/\(\)/.test(name))
return name.replace("()","(int32)");
return null;
}
function xdbLibrary()
{
var lib = ctypes.open("./xdb.so");
return {
open: lib.declare("xdb_open", ctypes.default_abi, ctypes.void_t, ctypes.char.ptr),
min_data_stream: lib.declare("xdb_min_data_stream", ctypes.default_abi, ctypes.int),
max_data_stream: lib.declare("xdb_max_data_stream", ctypes.default_abi, ctypes.int),
read_key: lib.declare("xdb_read_key", ctypes.default_abi, ctypes.char.ptr, ctypes.int),
read_entry: lib.declare("xdb_read_entry", ctypes.default_abi, ctypes.char.ptr, ctypes.char.ptr),
free_string: lib.declare("xdb_free", ctypes.default_abi, ctypes.void_t, ctypes.char.ptr)
};
}