Skip to content

Instantly share code, notes, and snippets.

View tshort's full-sized avatar

Tom Short tshort

  • Electric Power Research Institute
View GitHub Profile
@tshort
tshort / LLVM-uses-error.md
Created October 12, 2019 18:56
Uses error trying to fix up part of an LLVM IR

Test script that gives an error:

using LLVM 

ctx = Context()
mod = parse(LLVM.Module,  """
    %jl_value_t = type opaque
    define i64 @fun() {
    top:
@tshort
tshort / ccall.jl
Created July 3, 2019 12:59
Code to replace ccalls
using LLVM
using LLVM.Interop
using TypedCodeUtils
import TypedCodeUtils: reflect, filter, lookthrough, canreflect,
DefaultConsumer, Reflection, Callsite,
identify_invoke, identify_call, identify_foreigncall,
process_invoke, process_call
using MacroTools
@tshort
tshort / description.md
Last active October 12, 2019 17:41
Attempt to replace `inttoptr` with a direct call

I'm trying to replace inttoptr uses that happen when ccalls are generated. I've gotten as far as drilling down to the operand with inttoptr, but I can't figure out the next step.

using LLVM
ctx = Context()

mod = parse(LLVM.Module,  """
    define double @fun() {
    top:
      %0 = call double inttoptr (i32 -137186077 to double ()*)()
@tshort
tshort / embedded-languages-testing.jl
Last active June 18, 2019 02:27
Tests for syntax highlighting of embedded languages in Julia
function fun(a, b)
# hello World
return a + b # hi
end
"""
Hello World
"""
###############################################################
@tshort
tshort / llvm-addrspace-pass.md
Last active May 13, 2019 11:04
Broken LLVM.jl pass to remove address spaces

I'm attempting to make an LLVM.jl pass that removes address spaces. I'm doing this because LLVM's WebAssembly backend has errors because of the use of address spaces.

The pass removes addrspacecast instructions and removes address spaces in arguments of function declarations. To fix the arguments of function declarations, first create a new function with fixed arguments, then replace the original with that. The pass currently fails verify().

using LLVM
ctx = Context()
@tshort
tshort / ccalls.md
Created April 16, 2018 21:28
`ccall`'s from libjulia

Julia's runtime provides a lot of functionality used by base Julia code. A subset of this is needed to support basic data structures like arrays, dicts, and strings. Here is a list of the ccall's used by base Julia code. The most important ones for basic wasm support are:

# most important
abstractdict.jl
        :jl_eqtable_get
        :jl_eqtable_nextind
        :jl_eqtable_pop
        :jl_eqtable_put
        :jl_idtable_rehash
@tshort
tshort / description.md
Last active January 16, 2018 21:28
Example of using Makie.jl to pick points off of an image with the mouse/keyboard

Run the Julia code below, and it'll pop up a window with an image. Select the window. Move the mouse around, and hit the f key. A red marker should appear.

I used the keyboard with the mouse because my application had several different features I wanted to pick out. You could adapt this to use the mouse buttons.

@tshort
tshort / example.jl
Created July 27, 2017 13:22
Storage / CktElement issue in OpenDSSDirect
julia> using OpenDSSDirect
julia> using OpenDSSDirect.DSS
shell> cd C:\\PortableApps\\OpenDSS\\electricdss-git\\Distrib\\IEEETestCases\\13Bus
C:\PortableApps\OpenDSS\electricdss-git\Distrib\IEEETestCases\13Bus
julia> dss("redirect IEEE13Nodeckt.dss")
""
@tshort
tshort / config.js
Created July 16, 2017 18:13
MagicMirror setup
var config = {
port: 8080,
ipWhitelist: [], // Set [] to allow all IP addresses.
language: "en",
timeFormat: 12,
units: "imperial",
modules: [
{
module: 'MMM-ProfileSwitcher',
@tshort
tshort / complex-numbers-in-JuMP.jl
Created January 20, 2016 14:43
Example of complex numbers with JuMP
using JuMP
function Base.real{T <: JuMP.JuMPTypes}(x::Matrix{T})
@assert size(x,1) == 2
vec(x[1,:])
end
function Base.imag{T <: JuMP.JuMPTypes}(x::Matrix{T})
@assert size(x,1) == 2
vec(x[2,:])
end