about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-05-30 16:35:10 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-18 17:01:22 -0700
commit1273f94cbb19608e6a4e02c54d8543f6fe648a47 (patch)
treef25be1eadea7cde0cf190fdb96687facd14c54fb
parent918eda59bee9a627919d11b7bc9f909d7a9676ff (diff)
downloadrust-1273f94cbb19608e6a4e02c54d8543f6fe648a47.tar.gz
rust-1273f94cbb19608e6a4e02c54d8543f6fe648a47.zip
Add commands :RustEmitIr and :RustEmitAsm
-rw-r--r--src/etc/vim/autoload/rust.vim33
-rw-r--r--src/etc/vim/doc/rust.txt21
-rw-r--r--src/etc/vim/ftplugin/rust.vim8
3 files changed, 62 insertions, 0 deletions
diff --git a/src/etc/vim/autoload/rust.vim b/src/etc/vim/autoload/rust.vim
index c5bf0c10751..c6b9b314da5 100644
--- a/src/etc/vim/autoload/rust.vim
+++ b/src/etc/vim/autoload/rust.vim
@@ -130,6 +130,39 @@ function! rust#CompleteExpand(lead, line, pos)
 	return glob(escape(a:lead, "*?[") . '*', 0, 1)
 endfunction
 
+" Emit {{{1
+
+function! rust#Emit(type, args)
+	call s:WithPath(function("s:Emit"), a:type, a:args)
+endfunction
+
+function! s:Emit(path, type, args)
+	try
+		let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
+
+		let args = [a:path, '--emit', a:type, '-o', '-'] + a:args
+		let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)")))
+		if v:shell_error
+			echohl WarningMsg
+			echo output
+			echohl None
+		else
+			new
+			silent put =output
+			1
+			d
+			if a:type == "ir"
+				setl filetype=llvm
+			elseif a:type == "asm"
+				setl filetype=asm
+			endif
+			setl buftype=nofile
+			setl bufhidden=hide
+			setl noswapfile
+		endif
+	endtry
+endfunction
+
 " Utility functions {{{1
 
 function! s:WithPath(func, ...)
diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt
index e0a647225a9..96ed69db635 100644
--- a/src/etc/vim/doc/rust.txt
+++ b/src/etc/vim/doc/rust.txt
@@ -107,6 +107,27 @@ COMMANDS                                                       *rust-commands*
 		If |g:rustc_path| is defined, it is used as the path to rustc.
 		Otherwise it is assumed rustc can be found in $PATH.
 
+:RustEmitIr [args]                                               *:RustEmitIr*
+		Compiles the current file to LLVM IR and displays the results
+		in a new split. If the current file has unsaved changes, it
+		will be saved first using |:update|. If the current file is an
+		unnamed buffer, it will be written to a temporary file first.
+
+		The arguments given to |:RustEmitIr| will be passed to rustc.
+
+		If |g:rustc_path| is defined, it is used as the path to rustc.
+		Otherwise it is assumed rustc can be found in $PATH.
+
+:RustEmitAsm [args]                                             *:RustEmitAsm*
+		Compiles the current file to assembly and displays the results
+		in a new split. If the current file has unsaved changes, it
+		will be saved first using |:update|. If the current file is an
+		unnamed buffer, it will be written to a temporary file first.
+
+		The arguments given to |:RustEmitAsm| will be passed to rustc.
+
+		If |g:rustc_path| is defined, it is used as the path to rustc.
+		Otherwise it is assumed rustc can be found in $PATH.
 
 ==============================================================================
 MAPPINGS                                                       *rust-mappings*
diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim
index ed5d721de08..65f9f4105ad 100644
--- a/src/etc/vim/ftplugin/rust.vim
+++ b/src/etc/vim/ftplugin/rust.vim
@@ -66,6 +66,12 @@ command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>
 " See |:RustExpand| for docs
 command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
 
+" See |:RustEmitIr| for docs
+command! -nargs=* -bar -buffer RustEmitIr call rust#Emit("ir", [<f-args>])
+
+" See |:RustEmitAsm| for docs
+command! -nargs=* -bar -buffer RustEmitAsm call rust#Emit("asm", [<f-args>])
+
 " Mappings {{{1
 
 " Bind ⌘R in MacVim to :RustRun
@@ -91,6 +97,8 @@ let b:undo_ftplugin = "
 		\|unlet! b:rust_last_rustc_args b:rust_last_args
 		\|delcommand RustRun
 		\|delcommand RustExpand
+		\|delcommand RustEmitIr
+		\|delcommand RustEmitAsm
 		\|nunmap <buffer> <D-r>
 		\|nunmap <buffer> <D-R>
 		\|nunmap <buffer> [[