mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Previously, the "View IR Documentation" functionality for LLVM IR casting operations would not work at all, generating errors similar to the following: > There was an error fetching the documentation for this opcode (Error: Unknown opcode 'FPTRUNC'). This is because the generated documentation adds the `-to` suffix to all casting operations, causing a mismatch with the instruction's real name in the IR. Here are minimal examples for all casting instructions: - [`trunc`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:'define+dso_local+noundef+i8+@main()+%7B%0Aentry:%0A++%25X+%3D+trunc+i32+257+to+i8+%0A++ret+i8+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:11,endLineNumber:3,positionColumn:11,positionLineNumber:3,selectionStartColumn:11,selectionStartLineNumber:3,startColumn:11,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`zext`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:6,startColumn:1,startLineNumber:6),source:'define+dso_local+noundef+i64+@main()+%7B%0Aentry:%0A++%25X+%3D+zext+i32+257+to+i64+%0A++ret+i64+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:12,endLineNumber:3,positionColumn:12,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`sext`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:'define+dso_local+noundef+i16+@main()+%7B%0Aentry:%0A++%25X+%3D+sext+i8++-1+to+i16+%0A++ret+i16+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:12,endLineNumber:3,positionColumn:12,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`fptrunc`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:6,startColumn:1,startLineNumber:6),source:'define+dso_local+noundef+float+@main()+%7B%0Aentry:%0A++%25X+%3D+fptrunc+double+16777217.0+to+float+%0A++ret+float+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:15,endLineNumber:3,positionColumn:15,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`fpext`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:'define+dso_local+noundef+double+@main()+%7B%0Aentry:%0A++%25X+%3D+fpext+float+3.125+to+double%0A++ret+double+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:13,endLineNumber:3,positionColumn:13,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`fptoui`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:6,positionColumn:1,positionLineNumber:6,selectionStartColumn:1,selectionStartLineNumber:6,startColumn:1,startLineNumber:6),source:'define+dso_local+noundef+i32+@main()+%7B%0Aentry:%0A++%25X+%3D+fptoui+double+123.0+to+i32%0A++ret+i32+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`fptosi`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:2,endLineNumber:5,positionColumn:2,positionLineNumber:5,selectionStartColumn:2,selectionStartLineNumber:5,startColumn:2,startLineNumber:5),source:'define+dso_local+noundef+i32+@main()+%7B%0Aentry:%0A++%25X+%3D+fptosi+double+123.0+to+i32%0A++ret+i32+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:14,endLineNumber:3,positionColumn:14,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`uitofp`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:10,endLineNumber:3,positionColumn:10,positionLineNumber:3,selectionStartColumn:10,selectionStartLineNumber:3,startColumn:10,startLineNumber:3),source:'define+dso_local+noundef+float+@main()+%7B%0Aentry:%0A++%25X+%3D+uitofp+i32+257+to+float%0A++ret+float+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:14,endLineNumber:3,positionColumn:14,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`sitofp`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:15,endLineNumber:4,positionColumn:15,positionLineNumber:4,selectionStartColumn:15,selectionStartLineNumber:4,startColumn:15,startLineNumber:4),source:'define+dso_local+noundef+float+@main()+%7B%0Aentry:%0A++%25X+%3D+sitofp+i32+257+to+float%0A++ret+float+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`ptrtoint`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:7,positionColumn:1,positionLineNumber:7,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:'define+dso_local+noundef+i64+@main()+%7B%0Aentry:%0A++%25P+%3D+alloca+i32%0A++%25X+%3D+ptrtoint+ptr+%25P+to+i64%0A++ret+i64+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:16,endLineNumber:4,positionColumn:16,positionLineNumber:4,selectionStartColumn:8,selectionStartLineNumber:4,startColumn:8,startLineNumber:4),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`ptrtoaddr`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:17,endLineNumber:4,positionColumn:17,positionLineNumber:4,selectionStartColumn:17,selectionStartLineNumber:4,startColumn:17,startLineNumber:4),source:'define+dso_local+noundef+i64+@main()+%7B%0Aentry:%0A++%25P+%3D+alloca+i32%0A++%25X+%3D+ptrtoaddr+ptr+%25P+to+i64%0A++ret+i64+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:2,endLineNumber:6,positionColumn:2,positionLineNumber:6,selectionStartColumn:2,selectionStartLineNumber:6,startColumn:2,startLineNumber:6),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`inttoptr`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:13,endLineNumber:4,positionColumn:13,positionLineNumber:4,selectionStartColumn:13,selectionStartLineNumber:4,startColumn:13,startLineNumber:4),source:'define+dso_local+noundef+ptr+@main()+%7B%0Aentry:%0A++%25X+%3D+inttoptr+i32+255+to+ptr%0A++ret+ptr+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:16,endLineNumber:3,positionColumn:16,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`bitcast`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:28,endLineNumber:3,positionColumn:28,positionLineNumber:3,selectionStartColumn:28,selectionStartLineNumber:3,startColumn:28,startLineNumber:3),source:'define+dso_local+noundef+i8+@main()+%7B%0Aentry:%0A++%25X+%3D+bitcast+i8+255+to+i8%0A++ret+i8+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:15,endLineNumber:3,positionColumn:15,positionLineNumber:3,selectionStartColumn:8,selectionStartLineNumber:3,startColumn:8,startLineNumber:3),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) - [`addrspacecast`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:7,endLineNumber:2,positionColumn:7,positionLineNumber:2,selectionStartColumn:7,selectionStartLineNumber:2,startColumn:7,startLineNumber:2),source:'define+dso_local+noundef+ptr+addrspace(1)+@main()+%7B%0Aentry:%0A++%25P+%3D+alloca+i32%0A++%25X+%3D+addrspacecast+ptr+%25P+to+ptr+addrspace(1)%0A++ret+ptr+addrspace(1)+%25X%0A%7D%0A'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:35.25084847852495,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:llvm,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:31.41581818814172,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:14,fontUsePx:'0',j:2,selection:(endColumn:21,endLineNumber:4,positionColumn:21,positionLineNumber:4,selectionStartColumn:8,selectionStartLineNumber:4,startColumn:8,startLineNumber:4),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+clang+(trunk)+(Editor+%231,+Compiler+%232)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) The suggested fix is to: - Remove the trailing `-to` from any instruction parsed from the LLVM IR docs, as it is _probably_ a casting operation. - Add `ptrtoaddr` to the `llvmStatements` list, as it didn't seem to be recognized as an operation otherwise (and so failed the precondition to have a 'View IR Documentation' link). The diff for the generated documentation may seem larger than expected, that's because the IDs of the embedded HTML seem to have changed since last time.
396 lines
12 KiB
TypeScript
396 lines
12 KiB
TypeScript
// Copyright (c) 2018, Compiler Explorer Authors
|
|
// All rights reserved.
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are met:
|
|
//
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
// this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above copyright
|
|
// notice, this list of conditions and the following disclaimer in the
|
|
// documentation and/or other materials provided with the distribution.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import * as monaco from 'monaco-editor';
|
|
|
|
// This definition is based on the official LLVM vim syntax:
|
|
// http://llvm.org/svn/llvm-project/llvm/trunk/utils/vim/syntax/llvm.vim
|
|
// For VIM regex syntax, see: http://vimdoc.sourceforge.net/htmldoc/pattern.html
|
|
export function definition(): monaco.languages.IMonarchLanguage {
|
|
return {
|
|
// llvmType
|
|
types: [
|
|
'void',
|
|
'half',
|
|
'float',
|
|
'double',
|
|
'x86_fp80',
|
|
'fp128',
|
|
'ppc_fp128',
|
|
'label',
|
|
'metadata',
|
|
'x86_mmx',
|
|
'type',
|
|
'label',
|
|
'opaque',
|
|
'token',
|
|
'ptr',
|
|
],
|
|
// llvmStatement
|
|
statements: [
|
|
'add',
|
|
'addrspacecast',
|
|
'alloca',
|
|
'and',
|
|
'arcp',
|
|
'ashr',
|
|
'atomicrmw',
|
|
'bitcast',
|
|
'br',
|
|
'catchpad',
|
|
'catchswitch',
|
|
'catchret',
|
|
'call',
|
|
'cleanuppad',
|
|
'cleanupret',
|
|
'cmpxchg',
|
|
'eq',
|
|
'exact',
|
|
'extractelement',
|
|
'extractvalue',
|
|
'fadd',
|
|
'fast',
|
|
'fcmp',
|
|
'fdiv',
|
|
'fence',
|
|
'fmul',
|
|
'fpext',
|
|
'fptosi',
|
|
'fptoui',
|
|
'fptrunc',
|
|
'free',
|
|
'frem',
|
|
'fsub',
|
|
'getelementptr',
|
|
'icmp',
|
|
'inbounds',
|
|
'indirectbr',
|
|
'insertelement',
|
|
'insertvalue',
|
|
'inttoptr',
|
|
'invoke',
|
|
'landingpad',
|
|
'load',
|
|
'lshr',
|
|
'malloc',
|
|
'max',
|
|
'min',
|
|
'mul',
|
|
'nand',
|
|
'ne',
|
|
'ninf',
|
|
'nnan',
|
|
'nsw',
|
|
'nsz',
|
|
'nuw',
|
|
'oeq',
|
|
'oge',
|
|
'ogt',
|
|
'ole',
|
|
'olt',
|
|
'one',
|
|
'or',
|
|
'ord',
|
|
'phi',
|
|
'ptrtoaddr',
|
|
'ptrtoint',
|
|
'resume',
|
|
'ret',
|
|
'sdiv',
|
|
'select',
|
|
'sext',
|
|
'sge',
|
|
'sgt',
|
|
'shl',
|
|
'shufflevector',
|
|
'sitofp',
|
|
'sle',
|
|
'slt',
|
|
'srem',
|
|
'store',
|
|
'sub',
|
|
'switch',
|
|
'trunc',
|
|
'udiv',
|
|
'ueq',
|
|
'uge',
|
|
'ugt',
|
|
'uitofp',
|
|
'ule',
|
|
'ult',
|
|
'umax',
|
|
'umin',
|
|
'une',
|
|
'uno',
|
|
'unreachable',
|
|
'unwind',
|
|
'urem',
|
|
'va_arg',
|
|
'xchg',
|
|
'xor',
|
|
'zext',
|
|
],
|
|
// llvmKeyword
|
|
keywords: [
|
|
'acq_rel',
|
|
'acquire',
|
|
'addrspace',
|
|
'alias',
|
|
'align',
|
|
'alignstack',
|
|
'allocalign',
|
|
'allocptr',
|
|
'alwaysinline',
|
|
'appending',
|
|
'argmemonly',
|
|
'arm_aapcscc',
|
|
'arm_aapcs_vfpcc',
|
|
'arm_apcscc',
|
|
'asm',
|
|
'atomic',
|
|
'available_externally',
|
|
'blockaddress',
|
|
'builtin',
|
|
'byref',
|
|
'byval',
|
|
'c',
|
|
'catch',
|
|
'caller',
|
|
'cc',
|
|
'ccc',
|
|
'cleanup',
|
|
'coldcc',
|
|
'comdat',
|
|
'common',
|
|
'constant',
|
|
'datalayout',
|
|
'dead_on_unwind',
|
|
'declare',
|
|
'default',
|
|
'define',
|
|
'deplibs',
|
|
'dereferenceable',
|
|
'dereferenceable_or_null',
|
|
'distinct',
|
|
'dllexport',
|
|
'dllimport',
|
|
'dso_local',
|
|
'dso_preemptable',
|
|
'elementtype',
|
|
'except',
|
|
'external',
|
|
'externally_initialized',
|
|
'extern_weak',
|
|
'fastcc',
|
|
'filter',
|
|
'from',
|
|
'gc',
|
|
'global',
|
|
'hhvmcc',
|
|
'hhvm_ccc',
|
|
'hidden',
|
|
'immarg',
|
|
'inalloca',
|
|
'initialexec',
|
|
'inlinehint',
|
|
'inreg',
|
|
'inteldialect',
|
|
'intel_ocl_bicc',
|
|
'internal',
|
|
'linkonce',
|
|
'linkonce_odr',
|
|
'localdynamic',
|
|
'localexec',
|
|
'local_unnamed_addr',
|
|
'minsize',
|
|
'module',
|
|
'monotonic',
|
|
'msp430_intrcc',
|
|
'musttail',
|
|
'naked',
|
|
'nest',
|
|
'noalias',
|
|
'nobuiltin',
|
|
'nocapture',
|
|
'nofree',
|
|
'nofpclass',
|
|
'noimplicitfloat',
|
|
'noinline',
|
|
'nonlazybind',
|
|
'nonnull',
|
|
'norecurse',
|
|
'noredzone',
|
|
'noreturn',
|
|
'noundef',
|
|
'nounwind',
|
|
'optnone',
|
|
'optsize',
|
|
'personality',
|
|
'preallocated',
|
|
'private',
|
|
'protected',
|
|
'ptx_device',
|
|
'ptx_kernel',
|
|
'readnone',
|
|
'readonly',
|
|
'release',
|
|
'returned',
|
|
'returns_twice',
|
|
'sanitize_address',
|
|
'sanitize_memory',
|
|
'sanitize_thread',
|
|
'section',
|
|
'seq_cst',
|
|
'sideeffect',
|
|
'signext',
|
|
'syncscope',
|
|
'source_filename',
|
|
'speculatable',
|
|
'spir_func',
|
|
'spir_kernel',
|
|
'sret',
|
|
'ssp',
|
|
'sspreq',
|
|
'sspstrong',
|
|
'strictfp',
|
|
'swiftasync',
|
|
'swiftcc',
|
|
'swifterror',
|
|
'swiftself',
|
|
'tail',
|
|
'target',
|
|
'thread_local',
|
|
'to',
|
|
'triple',
|
|
'unnamed_addr',
|
|
'unordered',
|
|
'uselistorder',
|
|
'uselistorder_bb',
|
|
'uwtable',
|
|
'volatile',
|
|
'weak',
|
|
'weak_odr',
|
|
'within',
|
|
'writable',
|
|
'writeonly',
|
|
'x86_64_sysvcc',
|
|
'win64cc',
|
|
'x86_fastcallcc',
|
|
'x86_stdcallcc',
|
|
'x86_thiscallcc',
|
|
'zeroext',
|
|
],
|
|
|
|
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
|
|
tokenizer: {
|
|
root: [
|
|
[/[,(){}<>[\]]/, 'delimiters'],
|
|
[/i\d+\**/, 'type'], // llvmType
|
|
|
|
// Misc syntax.
|
|
[/[%@!]\d+/, 'variable.name'], // llvmNoName
|
|
[/-?\d+\.\d*(e[+-]\d+)?/, 'number.float'], // llvmFloat
|
|
[/0[xX][0-9A-Fa-f]+/, 'number.hex'], // llvmFloat
|
|
[/-?\d+/, 'number'], // llvmNumber
|
|
[/\b(true|false)\b/, 'keyword'], // llvmBoolean
|
|
[/\b(zeroinitializer|undef|null|none)\b/, 'constant'], // llvmConstant
|
|
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-terminated string
|
|
[/"/, 'string', '@string'], // push to string state
|
|
// slightly modified to support demangled function signatures as labels for llvm ir control flow graphs
|
|
[/[-a-zA-Z$._][-a-zA-Z$._0-9]*(?:\([^:]+\))?:/, 'tag'], // llvmLabel
|
|
[/[%@][-a-zA-Z$._][-a-zA-Z$._0-9]*/, 'variable.name'], // llvmIdentifier
|
|
|
|
// Named metadata and specialized metadata keywords.
|
|
[/![-a-zA-Z$._][-a-zA-Z$._0-9]*(?=\s*)$/, 'identifier'], // llvmIdentifier
|
|
[/![-a-zA-Z$._][-a-zA-Z$._0-9]*(?=\s*[=!])/, 'identifier'], // llvmIdentifier
|
|
[/![A-Za-z]+(?=\s*\()/, 'type'], // llvmType
|
|
[/\bDW_TAG_[a-z_]+\b/, 'constant'], // llvmConstant
|
|
[/\bDW_ATE_[a-zA-Z_]+\b/, 'constant'], // llvmConstant
|
|
[/\bDW_OP_[a-zA-Z0-9_]+\b/, 'constant'], // llvmConstant
|
|
[/\bDW_LANG_[a-zA-Z0-9_]+\b/, 'constant'], // llvmConstant
|
|
[/\bDW_VIRTUALITY_[a-z_]+\b/, 'constant'], // llvmConstant
|
|
[/\bDIFlag[A-Za-z]+\b/, 'constant'], // llvmConstant
|
|
|
|
// Syntax-highlight lit test commands and bug numbers.
|
|
[/;\s*PR\d*\s*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;\s*REQUIRES:.*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;\s*RUN:.*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;\s*CHECK:.*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;\s*CHECK-(?:NEXT|NOT|DAG|SAME|LABEL):.*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;\s*XFAIL:.*$/, 'comment.doc'], // llvmSpecialComment
|
|
[/;.*$/, 'comment'],
|
|
[/[*#=!]/, 'operators'],
|
|
[
|
|
/[a-z_$][\w$]*/,
|
|
{
|
|
cases: {
|
|
'@statements': 'operators',
|
|
'@keywords': 'keyword',
|
|
'@types': 'type',
|
|
'@default': 'identifier',
|
|
},
|
|
},
|
|
],
|
|
[/[ \t\r\n]+/, 'white'],
|
|
],
|
|
string: [
|
|
[/[^\\"]+/, 'string'],
|
|
[/@escapes/, 'string.escape'],
|
|
[/\\./, 'string.escape.invalid'],
|
|
[/"/, 'string', '@pop'],
|
|
],
|
|
},
|
|
};
|
|
}
|
|
|
|
const config: monaco.languages.LanguageConfiguration = {
|
|
comments: {
|
|
lineComment: ';',
|
|
},
|
|
brackets: [
|
|
['{', '}'],
|
|
['[', ']'],
|
|
['(', ')'],
|
|
],
|
|
autoClosingPairs: [
|
|
{open: '[', close: ']'},
|
|
{open: '{', close: '}'},
|
|
{open: '(', close: ')'},
|
|
{open: "'", close: "'", notIn: ['string', 'comment']},
|
|
{open: '"', close: '"', notIn: ['string']},
|
|
],
|
|
surroundingPairs: [
|
|
{open: '{', close: '}'},
|
|
{open: '[', close: ']'},
|
|
{open: '(', close: ')'},
|
|
{open: '"', close: '"'},
|
|
{open: "'", close: "'"},
|
|
],
|
|
};
|
|
|
|
monaco.languages.register({id: 'llvm-ir'});
|
|
monaco.languages.setMonarchTokensProvider('llvm-ir', definition());
|
|
monaco.languages.setLanguageConfiguration('llvm-ir', config);
|