Module: FlagFactory

Defined in:
lib/flag_factory.rb

Overview

This module generates Flags with a specific domain. For an explaination of the domain of a Flag see the documentation of the Flag class.

Class Method Summary collapse

Class Method Details

.generate_gcc_define_flag(name, domain, groups = []) ⇒ Object

Generates a define flag. Example: -DDEBUG=3

Parameters:

  • name (String)

    The name of the flag.

  • domain (:boolean, :boolean_no, Array<String>, Range)

    The domain of the flag. For a further explaintion how this is used, see the documentation of the Flag class.

  • groups (Array<String>) (defaults to: [])

    Array of Strings that denote the groups, that this flag is a member in. For more information on this concept see the documentation of the Flag class


41
42
43
# File 'lib/flag_factory.rb', line 41

def FlagFactory.generate_gcc_define_flag(name, domain, groups=[])
  generate_gcc_flag(name, domain, "-D", groups)
end

.generate_gcc_flag(name, domain, prefix = "-f", delimiter = "=", groups = []) ⇒ Object

Generates a normal GCC flag. Examples: -fomit-frame-pointer/-fno-omit-frame-pointer, -ffp-contract=fast

Parameters:

  • name (String)

    The name of the flag.

  • domain (:boolean, :boolean_no, Array<String>, Range)

    The domain of the flag. For a further explaintion how this is used, see the documentation of the Flag class.

  • prefix (String) (defaults to: "-f")

    The prefix of the flag. For instance the prefix for machine dependent options is “-m”. This defaults to “-f”.

  • delimiter (String) (defaults to: "=")

    If the domain is non-boolean this delimiter is used by the string representation function to delimit flag name and flag value.

  • groups (Array<String>) (defaults to: [])

    Array of Strings that denote the groups, that this flag is a member in. For more information on this concept see the documentation of the Flag class


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flag_factory.rb', line 14

def FlagFactory.generate_gcc_flag(name, domain, prefix="-f", delimiter="=",
                                  groups=[])
  case domain
  when Range, Array
    # -mmemcpy-strategy=loop
    representation = lambda do |value|
      "%s%s%s%s" % [prefix, name, delimiter, value]
    end
  when :boolean
    # -fomit-framepointer
    representation = lambda do |value|
      value ? "%s%s" % [prefix, name] : nil
    end
  when :boolean_no
    # -mno-mmx
    representation = lambda do |value|
      prefix + (value ? "" : "no-") + name
    end
  end
  flag = Flag.new(name, domain, representation, groups)
end

.generate_gcc_machine_flag(name, domain, groups = []) ⇒ Object

Generates a define flag. Example: -march=native

Parameters:

  • name (String)

    The name of the flag.

  • domain (:boolean, :boolean_no, Array<String>, Range)

    The domain of the flag. For a further explaintion how this is used, see the documentation of the Flag class.

  • groups (Array<String>) (defaults to: [])

    Array of Strings that denote the groups, that this flag is a member in. For more information on this concept see the documentation of the Flag class


50
51
52
# File 'lib/flag_factory.rb', line 50

def FlagFactory.generate_gcc_machine_flag(name, domain, groups=[])
  generate_gcc_flag(name, domain, "-m", groups)
end

.generate_gcc_param_flag(name, domain, groups = []) ⇒ Object

Generates a define flag. Example: –param predictable-branch-outcome=10

Parameters:

  • name (String)

    The name of the flag.

  • domain (:boolean, :boolean_no, Array<String>, Range)

    The domain of the flag. For a further explaintion how this is used, see the documentation of the Flag class.

  • groups (Array<String>) (defaults to: [])

    Array of Strings that denote the groups, that this flag is a member in. For more information on this concept see the documentation of the Flag class

Raises:

  • (ArgumentError)

59
60
61
62
63
64
65
66
# File 'lib/flag_factory.rb', line 59

def FlagFactory.generate_gcc_param_flag(name, domain, groups=[])
  raise ArgumentError,
    "--param arguments can only have ranges" unless domain.is_a Range
  Flag.new(name, domain,
           lambda do |value|
             "--param %s=%s" % [name, value]
           end, groups)
end