Bitsmith.Llvm 0.7.1

dotnet add package Bitsmith.Llvm --version 0.7.1
                    
NuGet\Install-Package Bitsmith.Llvm -Version 0.7.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitsmith.Llvm" Version="0.7.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitsmith.Llvm" Version="0.7.1" />
                    
Directory.Packages.props
<PackageReference Include="Bitsmith.Llvm" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitsmith.Llvm --version 0.7.1
                    
#r "nuget: Bitsmith.Llvm, 0.7.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitsmith.Llvm@0.7.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitsmith.Llvm&version=0.7.1
                    
Install as a Cake Addin
#tool nuget:?package=Bitsmith.Llvm&version=0.7.1
                    
Install as a Cake Tool

Bitsmith

Pure C# LLVM bitcode writer. No libllvm dependency.

  • Targets LLVM 15 (opaque pointers).
  • .NET 8 / .NET Standard 2.1.
  • Generates .bc files readable by llvm-dis, lli, llc.

Install

dotnet add package Bitsmith.Llvm

Usage

using Bitsmith.Llvm.IR;
using Bitsmith.Llvm.Writer;

var module = new Module
{
    SourceFileName = "add.ll",
    TargetTriple = "x86_64-unknown-linux-gnu",
    DataLayout = "e-m:e-p:64:64-i64:64-n8:16:32:64-S128",
};
var t = module.Types;
var i32 = t.Int32;

// define i32 @add(i32 %a, i32 %b) { ret i32 add %a, %b }
var fn = module.CreateFunction("add", t.GetFunction(i32, new LlvmType[] { i32, i32 }));
var bb = fn.AppendBlock("entry");
var sum = bb.Append(new BinaryOperator(BinaryOpcode.Add, fn.Parameters[0], fn.Parameters[1]));
bb.Append(new ReturnInstruction(t.Void, sum));

new ModuleWriter(module).WriteToFile("add.bc");

llvm-dis add.bc reproduces the IR.

Coverage

The IR model and writer cover the typical LLVM 15 surface for hand-written or compiler-emitted modules:

  • Types: all primitives (i1..i64, half/bfloat/float/double/fp128/x86_fp80/ppc_fp128, x86_mmx/x86_amx, token), opaque pointers with address spaces, structs (literal + identified, with forward declaration), arrays, fixed and scalable vectors, function types with vararg.
  • Constants: integer (incl. wide ApInt), float (all precisions), null/undef/poison, aggregate, string/cstring, constant cast expressions (trunc/zext/sext/fptrunc/fpext/fptoui/fptosi/uitofp/sitofp/ptrtoint/inttoptr/bitcast/addrspacecast), GEP (inbounds), icmp/fcmp, blockaddress, inline asm.
  • Globals: GlobalVariable, GlobalAlias, GlobalIFunc, comdat, sections, dso_local, dllstorageclass, thread_local, unnamed_addr, prefix/prologue data, personality functions, GC strategy.
  • Attributes: enum / int / typed (byval(T), sret(T), elementtype(T)) / string-form, on parameters, return values, function bodies, and call sites.
  • Instructions: full set including fneg, freeze, va_arg, extractvalue/insertvalue, invoke/landingpad/resume, callbr, indirectbr, funclet EH (catchpad/catchret/catchswitch/cleanuppad/cleanupret), atomics (fence/atomicrmw/cmpxchg/atomic load+store), GEP, phi, select, vector ops, casts, cmp.
  • Calls: calling conventions, fast-math flags, callsite attributes, operand bundles, inline asm callees.
  • Debug info: DICompileUnit, DIFile, DISubprogram, DISubroutineType, DIBasicType/DIDerivedType/DICompositeType/DIStringType, DILocation, DILexicalBlock/DILexicalBlockFile, DILocalVariable/DIGlobalVariable/DIGlobalVariableExpression, DISubrange/DIGenericSubrange, DIEnumerator, DITemplateTypeParameter/DITemplateValueParameter, DINamespace/DIImportedEntity, DIObjCProperty, DIMacro/DIMacroFile, DIModule/DICommonBlock, DILabel, DIArgList, DIExpression. llvm.dbg.declare / llvm.dbg.value / llvm.dbg.label intrinsics with function-local ValueAsMetadata. METADATA_STRINGS bundle encoding.
  • Instruction metadata attachments: !invariant.load, !invariant.group, !range, !nonnull, !alias.scope, !noalias, and other arbitrary kinds via Instruction.AddAttachment(kindName, md). Kind ids are allocated on demand and the per-function METADATA_ATTACHMENT_BLOCK mixes the function-level !dbg with per-instruction attachments.
  • Bitstream: full abbreviation support (Fixed/VBR/Array/Char6/Blob), BLOCKINFO_BLOCK for shared abbrevs, function-local VALUE_SYMTAB_BLOCK and CONSTANTS_BLOCK.

Out of scope

LTO-only and CFI-only features are intentionally not implemented. They aren't required to produce valid LLVM 15 bitcode that round-trips through llvm-dis / lli / llc:

  • SYMTAB_BLOCK / SUMMARY_BLOCK / METADATA_INDEX (LTO indexing)
  • USELIST_BLOCK (use-list ordering preservation; only matters if a downstream consumer re-serializes the IR)
  • SYNC_SCOPE_NAMES_BLOCK (custom named synchscopes)
  • DSOLocalEquivalent / NoCFIValue / ConstantPtrAuth constants

There is also no bitcode reader; Bitsmith is writer-only by design.

Testing

dotnet test

Round-trip integration tests require llvm-dis / llvm-bcanalyzer from LLVM 15 on PATH. They skip cleanly when the binaries are absent.

Release

Versioned via MinVer. Pushing a tag vX.Y.Z triggers .github/workflows/release.yml, which packs and publishes to NuGet (NUGET_API_KEY secret required).

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.1 100 5/24/2026
0.7.0 93 5/15/2026