Skip to content

Instantly share code, notes, and snippets.

View yurydelendik's full-sized avatar

Yury Delendik yurydelendik

View GitHub Profile
@yurydelendik
yurydelendik / gist:f2b846dae7cb29c86d23
Last active April 26, 2024 20:39
PDF.js get/show hightlight
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
@yurydelendik
yurydelendik / dwarf-wasm.md
Last active April 26, 2024 20:18
DWARF for WebAssembly target
@yurydelendik
yurydelendik / !wasmllvm.md
Last active February 23, 2024 05:08
Using WebAssembly in LLVM

NOTE: the content is out-of-date. All development is moved to the https://github.com/yurydelendik/wasmception

Using WebAssembly in LLVM

Compiling

# locations, e.g.
export WORKDIR=~/llvmwasm; mkdir -p $WORKDIR
export INSTALLDIR=$WORKDIR
@yurydelendik
yurydelendik / .htaccess
Last active August 7, 2023 14:01
CORS for pdf.js
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://mozilla.github.io"
</IfModule>
@yurydelendik
yurydelendik / x-scopes.md
Created August 1, 2018 19:30
Experimental "x-scopes" source maps extension

Experimental "x-scopes" source maps extension

This is crude attempt to add DWARF-like information to the existing wasm source maps. It is not intendent to be used as a final solution, but provides overview of the information that can be used by a consumer/debugger of wasm code.

The source maps JSON is extended to add the x-scopes field at the top level that will contains all information generated by LLVM's llvm-dwarfdump command. To reduce burden of parsing at the consumer side, the dump will be converted to the JSON using following rules:

  1. DW_TAG_xxx entity will be converted to a JS object with tag field with xxx value.
  2. If the above entry has nested level of children, the children field will be added and will contain JS array.
  3. DW_AT_yyy attributes will be assigned at fields to the enclosing object with yyy name. Theirs values will be:
@yurydelendik
yurydelendik / get_dwarf_info.py
Last active March 20, 2022 17:54
Extarct DWARF-like information from binary WASM
#!/usr/bin/env python
"""Utility to extract .debug_info section and print that in JSON format.
"""
import argparse
from collections import OrderedDict
import json
import logging
from math import ceil, log
import os
@yurydelendik
yurydelendik / record.html
Last active August 3, 2021 06:39
Record and playback audio.
<!DOCTYPE html>
<html>
<head>
<title>Capture sound</title>
<meta charset="utf-8">
</head>
<body>
<div id="ask_donate">
<button id="donate">Donate the noise</button>
</div>
@yurydelendik
yurydelendik / README.md
Last active September 12, 2020 18:24
Build wasm maps from C++ file
@yurydelendik
yurydelendik / fib-frames.dump
Created July 30, 2020 14:22
fib.wat with cranelift
.debug_frame contents:
00000000 00000014 ffffffff CIE
Version: 1
Augmentation: ""
Code alignment factor: 1
Data alignment factor: -8
Return address column: 16
DW_CFA_def_cfa: reg7 +8
diff --git a/lld/test/wasm/debuginfo.test b/lld/test/wasm/debuginfo.test
index 59c36979b4b..2566b74d93b 100644
--- a/lld/test/wasm/debuginfo.test
+++ b/lld/test/wasm/debuginfo.test
@@ -45,7 +45,7 @@ CHECK-NEXT: DW_AT_name ("hi_foo.c")
CHECK: DW_TAG_variable
CHECK-NEXT: DW_AT_name ("y")
-CHECK-NEXT: DW_AT_type (0x000000a1 "int[2]")
+CHECK-NEXT: DW_AT_type (0x000000a7 "int[2]")