FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
modelscript/packages/language/src/codegen/alias.ts at main · modelscript/modelscript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
modelscript
/
modelscript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
3
Star
12
Code
Issues
1
Pull requests
5
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
modelscript
/
packages
/
language
/
src
/
codegen
/
alias.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (49 loc) · 1.74 KB
Breadcrumbs
modelscript
/
packages
/
language
/
src
/
codegen
/
alias.ts
Copy path
File metadata and controls
62 lines (49 loc) · 1.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// --- Steensgaard Points-To Alias Analysis ---
// Zero-GC Union-Find Disjoint Set data structure in WASM linear memory.
export
function
generateAliasAnalysis
(
)
:
string
{
return
`
import { allocGen0 } from "./arena";
// --- Steensgaard Disjoint-Set Alias Environment ---
let aliasParentBuf: u32 = 0;
let aliasRankBuf: u32 = 0;
let aliasCapacity: u32 = 0;
export function initAliasEnvironment(maxVars: u32): void {
if (maxVars == 0) return;
aliasCapacity = maxVars;
aliasParentBuf = allocGen0(maxVars * 4);
aliasRankBuf = allocGen0(maxVars * 4);
for (let i: u32 = 0; i < maxVars; i++) {
store<u32>(aliasParentBuf + i * 4, i);
store<u32>(aliasRankBuf + i * 4, 0);
}
}
export function findAliasRoot(varId: u32): u32 {
if (varId >= aliasCapacity || aliasParentBuf == 0) return varId;
let parent = load<u32>(aliasParentBuf + varId * 4);
if (parent == varId) return varId;
// Path compression
let root = findAliasRoot(parent);
store<u32>(aliasParentBuf + varId * 4, root);
return root;
}
export function unifyAlias(var1: u32, var2: u32): void {
let root1 = findAliasRoot(var1);
let root2 = findAliasRoot(var2);
if (root1 == root2) return;
let rank1 = load<u32>(aliasRankBuf + root1 * 4);
let rank2 = load<u32>(aliasRankBuf + root2 * 4);
// Union by rank
if (rank1 < rank2) {
store<u32>(aliasParentBuf + root1 * 4, root2);
} else if (rank1 > rank2) {
store<u32>(aliasParentBuf + root2 * 4, root1);
} else {
store<u32>(aliasParentBuf + root2 * 4, root1);
store<u32>(aliasRankBuf + root1 * 4, rank1 + 1);
}
}
export function areAliased(var1: u32, var2: u32): boolean {
return findAliasRoot(var1) == findAliasRoot(var2);
}
`
;
}
Back
|
FazBrowse Home
|
New Git URL