Class: Benchcc::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/benchcc/compiler.rb,
lib/benchcc/compiler.rb

Overview

Basic interface to compiler frontends.

Direct Known Subclasses

Clang, GCC

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.guess_from_binary(binary) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/benchcc/compiler.rb', line 149

def self.guess_from_binary(binary)
  stdout, stderr, status = Open3.capture3("#{binary} --version")
  case stdout
  when /\(GCC\)/
    return GCC.new(binary)
  when /clang/
    return Clang.new(binary)
  else
    raise ArgumentError("unknown compiler #{binary}")
  end
end

Instance Method Details

#compile_code(code, *args) ⇒ Object

compile_code: String -> CompilationResult

Compile the given string and return compilation statistics.

This method has the same behavior as compile_file, except the code is given as-is instead of being in a file. Either this method or compile_file must be implemented in subclasses.



84
85
86
87
88
89
90
91
# File 'lib/benchcc/compiler.rb', line 84

def compile_code(code, *args)
  tmp = Tempfile.new(["", '.cpp'])
  tmp.write(code)
  tmp.close
  compile_file(tmp.path, *args)
ensure
  tmp.unlink
end

#compile_file(file, *args) ⇒ Object

compile_file: Path -> CompilationResult

Compile the given file and return compilation statistics.

Additional compiler-specific arguments may be specified.

A CompilationError is be raised if the compilation fails for whatever reason. Either this method or compile_code must be implemented in subclasses.

Raises:

  • (ArgumentError)


71
72
73
74
75
# File 'lib/benchcc/compiler.rb', line 71

def compile_file(file, *args)
  raise ArgumentError, "invalid filename #{file}" unless File.file? file
  code = File.read(file)
  compile_code(code, *args)
end

#constexpr_depthObject

Maximum constexpr recursion depth supported by the compiler.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/benchcc/compiler.rb', line 53

def constexpr_depth
  raise NotImplementedError
end

#template_depthObject

Maximum template recursion depth supported by the compiler.

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/benchcc/compiler.rb', line 48

def template_depth
  raise NotImplementedError
end

#to_sObject

Show the name and the version of the compiler.

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/benchcc/compiler.rb', line 58

def to_s
  raise NotImplementedError
end