Skip to content

Deep insight of C++ in LLVM-IR and Assembly perspective.

License

Notifications You must be signed in to change notification settings

vpand/CppInLLVMAndAssembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppInLLVMAndAssembly

Deep insight of C++ in LLVM-IR and Assembly perspective.

Prerequisites

IDE

  • Visual Studio Code

Plugins

  • C/C++ IntelliSense from Microsoft
  • LLVM Syntax Highlighting from colejcummins
  • Markdown Preview Mermaid Support from Matt Bierner

CLI

  • CMake
  • Ninja (optional on macOS/Linux, mandatory on Windows)
  • ClangVMP

Disassembler

  • VMPStudio

Download

ClangVMP compiler and VMPStudio disassembler can be downloaded through VPAssistant at vpand.com.

CMake On Windows

In "x64 Native Tools Command Prompt for VS 2022" command prompt:

mkdir build
cmake -B build -G Ninja

CMake On macOS or Linux

mkdir build
cmake -B build

Build

build % cmake --build .
[1/6] Building CXX object llvmir\CMakeFiles\main-llvmir.dir\main.cpp.obj
Using config file ..\llvmir\clangvmp.json.
Using source file vmp config key : main.cpp.
llvmir: main
Created LLVM-IR partial file llvmir\CMakeFiles\main-llvmir.dir\main.cpp.ll.
[2/6] Building CXX object clangvmp\CMakeFiles\clangvmp-demo.dir\main.cpp.obj
Using config file ..\clangvmp\clangvmp.json.
Using source file vmp config key : main.cpp.
vmpre: main
vmp: main
+> Encoding UraniumVCPU function main (1/1)...
[5/6] Building CXX object coroutines\CMakeFiles\episode_coroutine.dir\main.cpp.obj
Using config file ..\coroutines\clangvmp.json.
Using source file vmp config key : main.cpp.
llvmir: Coroutine
llvmir: main
Created LLVM-IR partial file coroutines\CMakeFiles\episode_coroutine.dir\main.cpp.ll.
[6/6] Linking CXX executable coroutines\episode_coroutine.exe

C++

llvmir/main.cpp:
#include <stdio.h>

int main(int argc, const char *argv[]) {
  puts("Hello, world.");
  return 0;
}

clangvmp.json

llvmir/clangvmp.json:
{
  "main.cpp": {
    "llvmir": ["main"]
  }
}

LLVM-IR

build/llvmir/CMakeFiles/main-llvmir.dir/main.cpp.ll:
; Auto generated by ClangVMP v1.1.2

; Function Attrs: mustprogress noinline norecurse optnone ssp uwtable(sync)
define noundef i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4
  store ptr %1, ptr %5, align 8
  %6 = call i32 @puts(ptr noundef @.str)
  ret i32 0
}

Assembly

Copy from VMPStudio disassembler CPU window:
0000000100003F6C | FD 7B BF A9     | stp x29, x30, [sp, #-0x10]!
0000000100003F70 | FD 03 00 91     | mov x29, sp                
0000000100003F74 | 00 00 00 90     | adrp x0, #0x0              
0000000100003F78 | 00 60 3E 91     | add x0, x0, #0xf98         
0000000100003F7C | 04 00 00 94     | bl imp._puts               
0000000100003F80 | 00 00 80 52     | mov w0, #0x0               
0000000100003F84 | FD 7B C1 A8     | ldp x29, x30, [sp], #0x10  
0000000100003F88 | C0 03 5F D6     | ret                        

Episodes

About

Deep insight of C++ in LLVM-IR and Assembly perspective.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published