Class: YASM::Command

Inherits:
CommandMapper::Command
  • Object
show all
Defined in:
lib/yasm/command.rb

Overview

Provides an interface for invoking the yasm utility.

Examples

Assemble a binary file:

YASM::Command.run(syntax: :gas, file: 'hello_world.S', output: 'hello_world.o')

Assemble amd64 assembly, in GAS syntax, into an ELF64 file with debugging information:

YASM::Command.run do |yasm|
  yasm.target = :amd64

  yasm.syntax = :gas
  yasm.file   = 'hello_world.S'

  yasm.output        = 'hello_world.o'
  yasm.output_format = :elf64
  yasm.debug_format  = :stabs
end

yasm options:

  • --version - yasm.version
  • --license - yasm.license
  • --help - yasm.help
  • --arch - yasm.arch
    • x86 - x86 (IA-32 and derivatives), AMD64
    • lc3b - LC-3b
  • --parser - yasm.parser
    • gas - GNU AS (GAS)-compatible parser
    • gnu - GNU AS (GAS)-compatible parser
    • nasm - NASM-compatible parser
    • tasm - TASM-compatible parser
  • --preproc - yasm.preprocessor
    • nasm - Real NASM Preprocessor
    • tasm - Real TASM Preprocessor
    • raw - Disable preprocessing
    • cpp - Run input through external C preprocessor
    • gas - GNU AS (GAS)-compatible preprocessor
  • --oformat - yasm.output_format
    • dbg - Trace of all info passed to object format module
    • bin - Flat format binary
    • dosexe - DOS .EXE format binary
    • elf - ELF
    • elf32 - ELF (32-bit)
    • elf64 - ELF (64-bit)
    • elfx32 - ELF (x32)
    • coff - COFF (DJGPP)
    • macho - Mac OS X ABI Mach-O File Format
    • macho32 - Mac OS X ABI Mach-O File Format (32-bit)
    • macho64 - Mac OS X ABI Mach-O File Format (64-bit)
    • rdf - Relocatable Dynamic Object File Format (RDOFF) v2.0
    • win32 - Win32
    • win64 - Win64
    • x64 - Win64
    • xdf - Extended Dynamic Object
  • --dformat - yasm.debug_format
    • cv8 - CodeView debugging format for VC8
    • dwarf2 - DWARF2 debugging format
    • null - No debugging info
    • stabs - Stabs debugging format
  • --lformat - yasm.list_format
    • nasm -NASM-style list format
  • --list - yasm.list_file
  • --objfile - yasm.output
  • --mapfile - yasm.map_file
  • --machine - yasm.machine
    • x86 - IA-32 and derivatives
    • amd64 - AMD64
    • x32 - X32
  • --force-strict - yasm.force_strict
  • -w - yasm.inhibit_warnings
  • -W - yasm.toggle_warnings
  • -M - yasm.gen_makefile_deps
  • -E - yasm.redirect_errors_to
  • -e - yasm.redirect_errors
  • --preproc-only - yasm.preprocessor_only
  • -I - yasm.include
  • -P - yasm.pre_include
  • -D - yasm.define
  • -U - yasm.undefine
  • -X - yasm.message_style
    • gnu
    • vc
  • --prefix - yasm.prefix
  • --suffix - yasm.suffix
  • file - yasm.file

Since:

  • 0.3.0

Direct Known Subclasses

Program

Constant Summary collapse

TARGETS =

The known YASM targets

Since:

  • 0.3.0

{
  x86:   {arch: :x86,  machine: :x86},
  amd64: {arch: :x86,  machine: :amd64},
  lc3b:  {arch: :lc3b, machine: :lc3b}
}

Instance Method Summary collapse

Instance Method Details

#target:x86, ...

Determines which target was set.

Returns:

  • (:x86, :amd64, :lc3b, nil)

    The target name or nil if no target has been set.

Since:

  • 0.3.0



242
243
244
245
246
# File 'lib/yasm/command.rb', line 242

def target
  if arch && machine
    TARGETS.key(arch: arch.to_sym, machine: machine.to_sym)
  end
end

#target=(name) ⇒ Symbol

Sets that target.

Parameters:

  • name (:x86, :amd64, :lc3b)

    The target name.

Returns:

  • (Symbol)

    The set target.

Raises:

  • (ArgumentError)

    An unknown target name was given.

Since:

  • 0.3.0



260
261
262
263
264
265
266
267
268
# File 'lib/yasm/command.rb', line 260

def target=(name)
  target = TARGETS.fetch(name.to_sym) do
    raise(ArgumentError,"unknown YASM target: #{name.inspect}")
  end

  self.arch    = target[:arch]
  self.machine = target[:machine]
  return name
end