Created
August 24, 2026 13:54
-
-
Save colematt/e963fc511f4e94de80f21b5d7cb8665f to your computer and use it in GitHub Desktop.
Multiple Listings with Minted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef int (*fp)(int); | |
| int square(int a){ | |
| return (a * a); | |
| } | |
| int main(){ | |
| fp func = square; | |
| int a = func(3); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define dso_local signext i32 @main() #0 !dbg !19 { | |
| %1 = alloca i32, align 4 | |
| %2 = alloca i32 (i32)*, align 8 | |
| %3 = alloca i32, align 4 | |
| store i32 0, i32* %1, align 4 | |
| store i32 (i32)* @square, i32 (i32)** %2, align 8, !dbg !25 | |
| %4 = load i32 (i32)*, i32 (i32)** %2, align 8, !dbg !28 | |
| %5 = call signext i32 %4(i32 signext 3), !dbg !28 | |
| store i32 %5, i32* %3, align 4, !dbg !27 | |
| %6 = load i32, i32* %3, align 4, !dbg !29 | |
| ret i32 %6, !dbg !30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 00000000000050 main: | |
| 50: 37 10 00 00 lui zero, 1 #TAG | |
| 54: 37 50 00 00 lui zero, 5 #CFL label | |
| 58: 13 01 01 fd addi sp, sp, -48 | |
| 5c: 23 34 11 02 sd ra, 40(sp) | |
| 60: 37 00 00 00 lui zero, 0 #TAG | |
| 64: 23 30 81 02 sd s0, 32(sp) | |
| 68: 13 04 01 03 addi s0, sp, 48 | |
| 000000000000006c .LBB1_1: #symbol | |
| 6c: 17 05 00 00 auipc a0, 0 | |
| 000000000000006c: R_RISCV_PCREL_HI20 square #Reloc | |
| 70: 37 00 00 00 lui zero, 0 #TAG | |
| 74: 13 05 05 00 mv a0, a0 | |
| 0000000000000074: R_RISCV_PCREL_LO12_I .LBB1_1 #Reloc | |
| ; ... | |
| 90: 37 00 04 00 lui zero, 64 #TAG | |
| 94: 83 35 84 fd ld a1, -40(s0) | |
| 98: 37 d0 02 00 lui zero, 45 #CFL label | |
| 9c: e7 80 05 00 jalr a1 | |
| ; ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \documentclass{article} | |
| \usepackage{graphicx} % Required for inserting images | |
| \usepackage{minted} | |
| \setminted{autogobble,fontsize=\scriptsize,frame=single,tabsize=2,breaklines=true} | |
| \setminted[c]{numbers=left} | |
| \setminted[llvm]{numbers=left} | |
| \setminted[objdump]{numbers=none} | |
| % \setminted[makefile]{numbers=left,breaklines=true,showtabs=true,tab=\color{red}{\rightarrowfill},tabsize=4} | |
| % \setminted[text]{numbers=left} | |
| \setmintedinline{fontsize=\normalsize,frame=none,numbers=none,breaklines=true} | |
| % Fix red boxes around pygments tokenization errors | |
| % see https://tex.stackexchange.com/a/401250/ | |
| \usepackage{etoolbox,xpatch} | |
| \makeatletter | |
| \AtBeginEnvironment{minted}{\dontdofcolorbox} | |
| \def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}} | |
| \xpatchcmd{\inputminted}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{} | |
| \xpatchcmd{\mintinline}{\minted@fvset}{\minted@fvset\dontdofcolorbox}{}{} | |
| \makeatother | |
| \title{Multiple Listing with Minted} | |
| \author{Matthew Cole} | |
| \date{February 2024} | |
| \begin{document} | |
| \maketitle | |
| This is an example of how to stack multiple listings in a single \texttt{listing} environment. | |
| \begin{listing} | |
| \inputminted{c}{listings/main.c} | |
| \inputminted{llvm}{listings/main.ll} | |
| \inputminted{asm}{listings/main.objdump} | |
| \caption{Demonstration of COGENT's compiler using the simple CFI. This contains compiler inserted code (0x58-0x68), many to one relationships (0x94-0x9C), relocation and symbol adjustments (0x6c-0x74), and a tag inserted between a relocation (0x70). Additionally it includes data that must be persisted from the IR (the function labels) to the backend inserted labels at (0x50) and (0x98).} | |
| \label{fig:cfiexample} | |
| \end{listing} | |
| \end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment