Module: L::C::CompilerClang
- Defined in:
- lib/rub/l/c/compiler/clang.rb
Overview
The Clang Compiler
Constant Summary collapse
- @@o_flags =
{ :none=>'-O0', :some=>'-O1', :full=>'-O3', :max =>'-O4', }
- @@of_flags =
{ nil=>[], :speed=>[], :size=>'-Os', }
Class Method Summary collapse
- .available? ⇒ Boolean
- .compile_command(opt, src, obj) ⇒ Object
- .do_compile_string(opt, str, obj) ⇒ Object
- .find ⇒ Object
- .generate_flags(opt) ⇒ Object
- .linker ⇒ Object
- .name ⇒ Object
Class Method Details
.available? ⇒ Boolean
33 34 35 |
# File 'lib/rub/l/c/compiler/clang.rb', line 33 def self.available? !!find end |
.compile_command(opt, src, obj) ⇒ Object
82 83 84 |
# File 'lib/rub/l/c/compiler/clang.rb', line 82 def self.compile_command(opt, src, obj) [find, '-c', *generate_flags(opt), "-o#{obj}", *src] end |
.do_compile_string(opt, str, obj) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rub/l/c/compiler/clang.rb', line 86 def self.do_compile_string(opt, str, obj) c = R::Command.new [find, '-c', '-xc', *generate_flags(opt), '-o', obj, '-'] c.stdin = str c.run c end |
.find ⇒ Object
37 38 39 40 41 |
# File 'lib/rub/l/c/compiler/clang.rb', line 37 def self.find @exe and return @exe @exe = ::C.find_command 'clang' end |
.generate_flags(opt) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rub/l/c/compiler/clang.rb', line 59 def self.generate_flags(opt) f = [] #f << '-emit-llvm' f << (@@o_flags[opt.optimize ] || []) f << (@@o_flags[opt.optimize_for] || []) f << opt.include_dirs.map do |d| "-I#{d}" end f << opt.define.map do |k, v| if v # -Dk if v is true else -Dk=v. "-D#{k}#{v.equal?(true)?"":"=#{v}"}" else "-U#{k}" end end f.flatten! end |
.linker ⇒ Object
43 44 45 |
# File 'lib/rub/l/c/compiler/clang.rb', line 43 def self.linker :clang end |
.name ⇒ Object
29 30 31 |
# File 'lib/rub/l/c/compiler/clang.rb', line 29 def self.name :clang end |