ruby-yasm 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yasm/program.rb CHANGED
@@ -1,52 +1,47 @@
1
- require 'yasm/task'
2
-
3
- require 'rprogram'
4
- require 'tempfile'
1
+ require 'yasm/command'
5
2
 
6
3
  module YASM
7
- class Program < RProgram::Program
8
-
9
- name_program 'yasm'
4
+ #
5
+ # @deprecated Please use {Command} instead.
6
+ #
7
+ class Program < Command
10
8
 
11
9
  #
12
- # Finds the +yasm+ program and assembles a file.
10
+ # Finds the `yasm` program and assembles a file.
13
11
  #
14
12
  # @param [Hash{Symbol => Object}] options
15
13
  # Additional options for yasm.
16
14
  #
17
- # @yield [task]
18
- # If a block is given, it will be passed a task object used to
15
+ # @yield [program]
16
+ # If a block is given, it will be passed a program object used to
19
17
  # specify options for yasm.
20
18
  #
21
- # @yieldparam [Task] task
22
- # The yasm task object.
19
+ # @yieldparam [Program] program
20
+ # The yasm program object.
23
21
  #
24
22
  # @return [Boolean]
25
23
  # Specifies whether the command exited normally.
26
24
  #
27
- def self.assmeble(options={},&block)
28
- self.find().assemble(options,&block)
29
- end
30
-
25
+ # @example
26
+ # Program.assemble(
27
+ # :parser => :gas,
28
+ # :output => 'code.o',
29
+ # :file => 'code.S'
30
+ # )
31
31
  #
32
- # Finds the +yasm+ program, then assembles an assembly file and writes
33
- # the output to a temporary file.
32
+ # @example
33
+ # Program.assemble do |yasm|
34
+ # yasm.target! :x86
34
35
  #
35
- # @param [Hash{Symbol => Object}] options
36
- # Additional options for yasm.
36
+ # yasm.syntax = :gas
37
+ # yasm.file = 'code.S'
38
+ # yasm.output = 'code.o'
39
+ # end
37
40
  #
38
- # @yield [task]
39
- # If a block is given, it will be passed a task object used to
40
- # specify options for yasm.
41
- #
42
- # @yieldparam [Task] task
43
- # The yasm task object.
44
- #
45
- # @return [TempFile]
46
- # The temporary file containing the assembled object code.
41
+ # @see #assemble
47
42
  #
48
- def self.assemble_temp(options={},&block)
49
- self.find().assemble(options,&block)
43
+ def self.assemble(options={},&block)
44
+ new(options,&block).assemble()
50
45
  end
51
46
 
52
47
  #
@@ -55,43 +50,48 @@ module YASM
55
50
  # @param [Hash{Symbol => Object}] options
56
51
  # Additional options for yasm.
57
52
  #
58
- # @yield [task]
59
- # If a block is given, it will be passed a task object used to
53
+ # @yield [program]
54
+ # If a block is given, it will be passed a program object used to
60
55
  # specify options for yasm.
61
56
  #
62
- # @yieldparam [Task] task
63
- # The yasm task object.
57
+ # @yieldparam [Program] program
58
+ # The yasm program object.
64
59
  #
65
60
  # @return [Boolean]
66
61
  # Specifies whether the command exited normally.
67
62
  #
68
- def assemble(options={},&block)
69
- run_task(Task.new(options,&block))
63
+ # @example
64
+ # Program.assemble(
65
+ # :parser => :gas,
66
+ # :output => 'code.o',
67
+ # :file => 'code.S'
68
+ # )
69
+ #
70
+ # @example
71
+ # Program.assemble do |yasm|
72
+ # yasm.target! :x86
73
+ #
74
+ # yasm.syntax = :gas
75
+ # yasm.file = 'code.S'
76
+ # yasm.output = 'code.o'
77
+ # end
78
+ #
79
+ def assemble(options={})
80
+ options.each do |name,value|
81
+ self[name] = value
82
+ end
83
+
84
+ yield self if block_given?
85
+
86
+ run_command()
70
87
  end
71
88
 
72
89
  #
73
- # Assembles an assembly file and writes the output to a temporary file.
74
- #
75
- # @param [Hash{Symbol => Object}] options
76
- # Additional options for yasm.
77
- #
78
- # @yield [task]
79
- # If a block is given, it will be passed a task object used to
80
- # specify options for yasm.
81
- #
82
- # @yieldparam [Task] task
83
- # The yasm task object.
84
- #
85
- # @return [TempFile]
86
- # The temporary file containing the assembled object code.
90
+ # @deprecated Please use {#target=} instead.
87
91
  #
88
- def assemble_temp(options={},&block)
89
- task = Task.new(options,&block)
90
- task.output = Tempfile.new('yasm').path
91
-
92
- if run_task(task)
93
- return task.output
94
- end
92
+ def target!(name)
93
+ self.target = name
94
+ return true
95
95
  end
96
96
 
97
97
  end
data/lib/yasm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module YASM
2
2
  # ruby-yasm VERSION
3
- VERSION = '0.1.0'
3
+ VERSION = '0.3.0'
4
4
  end
data/lib/yasm.rb CHANGED
@@ -1,2 +1,3 @@
1
+ require 'yasm/command'
1
2
  require 'yasm/program'
2
3
  require 'yasm/version'
data/ruby-yasm.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gemspec = YAML.load_file('gemspec.yml')
5
+
6
+ gem.name = gemspec.fetch('name')
7
+ gem.version = gemspec.fetch('version') do
8
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
9
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
10
+
11
+ require 'yasm/version'
12
+ YASM::VERSION
13
+ end
14
+
15
+ gem.summary = gemspec['summary']
16
+ gem.description = gemspec['description']
17
+ gem.licenses = Array(gemspec['license'])
18
+ gem.authors = Array(gemspec['authors'])
19
+ gem.email = gemspec['email']
20
+ gem.homepage = gemspec['homepage']
21
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
22
+
23
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
24
+
25
+ gem.files = if gemspec['files'] then glob[gemspec['files']]
26
+ else `git ls-files`.split($/)
27
+ end
28
+
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
31
+ end
32
+
33
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
34
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
35
+
36
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
37
+ %w[ext lib].select { |dir| File.directory?(dir) }
38
+ })
39
+
40
+ gem.requirements = gemspec['requirements']
41
+ gem.required_ruby_version = gemspec['required_ruby_version']
42
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
43
+ gem.post_install_message = gemspec['post_install_message']
44
+
45
+ split = lambda { |string| string.split(/,\s*/) }
46
+
47
+ if gemspec['dependencies']
48
+ gemspec['dependencies'].each do |name,versions|
49
+ gem.add_dependency(name,split[versions])
50
+ end
51
+ end
52
+
53
+ if gemspec['development_dependencies']
54
+ gemspec['development_dependencies'].each do |name,versions|
55
+ gem.add_development_dependency(name,split[versions])
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'helpers/files'
3
+
4
+ require 'yasm/command'
5
+ require 'tempfile'
6
+
7
+ describe YASM::Command do
8
+ include Helpers::Files
9
+
10
+ describe ".run" do
11
+ subject { described_class }
12
+
13
+ it "should be able to assemble a file" do
14
+ file = Tempfile.new('yasm').path
15
+
16
+ subject.run do |yasm|
17
+ yasm.target = :x86
18
+ yasm.syntax = :gas
19
+ yasm.file = assembly_file('gas')
20
+ yasm.output = file
21
+ end
22
+
23
+ expect(File.size(file)).to be > 0
24
+ end
25
+ end
26
+
27
+ describe "#target" do
28
+ context "when no target has been set" do
29
+ it "must return nil" do
30
+ expect(subject.target).to be(nil)
31
+ end
32
+ end
33
+
34
+ context "when the target has been set to :x86" do
35
+ before { subject.target = :x86 }
36
+
37
+ it "must return :x86" do
38
+ expect(subject.target).to eq(:x86)
39
+ end
40
+ end
41
+
42
+ context "when #arch is :x86 and #machine is :x86" do
43
+ before do
44
+ subject.arch = :x86
45
+ subject.machine = :x86
46
+ end
47
+
48
+ it "must return :x86" do
49
+ expect(subject.target).to eq(:x86)
50
+ end
51
+ end
52
+
53
+ context "when the target has been set to :amd64" do
54
+ before { subject.target = :amd64}
55
+
56
+ it "must return :amd64" do
57
+ expect(subject.target).to eq(:amd64)
58
+ end
59
+ end
60
+
61
+ context "when #arch is :x86 and #machine is :amd64" do
62
+ before do
63
+ subject.arch = :x86
64
+ subject.machine = :amd64
65
+ end
66
+
67
+ it "must return :amd64" do
68
+ expect(subject.target).to eq(:amd64)
69
+ end
70
+ end
71
+
72
+ context "when the target has been set to :lc3b" do
73
+ before { subject.target = :lc3b}
74
+
75
+ it "must return :lc3b" do
76
+ expect(subject.target).to eq(:lc3b)
77
+ end
78
+ end
79
+
80
+ context "when #arch is :lc3b and #machine is :lc3b" do
81
+ before do
82
+ subject.arch = :lc3b
83
+ subject.machine = :lc3b
84
+ end
85
+
86
+ it "must return :lc3b" do
87
+ expect(subject.target).to eq(:lc3b)
88
+ end
89
+ end
90
+ end
91
+ end
data/spec/program_spec.rb CHANGED
@@ -1,38 +1,104 @@
1
- require 'yasm/program'
2
-
3
1
  require 'spec_helper'
4
2
  require 'helpers/files'
5
3
 
6
- describe Program do
4
+ require 'yasm/program'
5
+ require 'tempfile'
6
+
7
+ describe YASM::Program do
7
8
  include Helpers::Files
8
9
 
9
- before(:all) do
10
- @yasm = Program.find
10
+ describe ".assemble" do
11
+ subject { described_class }
12
+
13
+ it "should be able to assemble a file" do
14
+ file = Tempfile.new('yasm').path
15
+
16
+ subject.assemble do |yasm|
17
+ yasm.target! :x86
18
+
19
+ yasm.syntax = :gas
20
+ yasm.file = assembly_file('gas')
21
+ yasm.output = file
22
+ end
23
+
24
+ expect(File.size(file)).to be > 0
25
+ end
11
26
  end
12
27
 
13
- it "should be able to assemble a file" do
14
- file = Tempfile.new('yasm').path
28
+ describe "#assemble" do
29
+ it "should be able to assemble a file" do
30
+ file = Tempfile.new('yasm').path
31
+
32
+ subject.assemble do |yasm|
33
+ yasm.target! :x86
15
34
 
16
- @yasm.assemble do |yasm|
17
- yasm.target! :x86
35
+ yasm.syntax = :gas
36
+ yasm.file = assembly_file('gas')
37
+ yasm.output = file
38
+ end
18
39
 
19
- yasm.syntax = :gas
20
- yasm.file = assembly_file('gas')
21
- yasm.output = file
40
+ expect(File.size(file)).to be > 0
22
41
  end
42
+ end
43
+
44
+ describe "#initialize" do
45
+ subject { described_class.new(target: :amd64) }
23
46
 
24
- File.size(file).should > 0
47
+ it "should support a :target option" do
48
+ expect(subject.arch).to eq(:x86)
49
+ expect(subject.machine).to eq(:amd64)
50
+ end
25
51
  end
26
52
 
27
- it "should assemble a file, and write the output to a temporary file" do
28
- file = @yasm.assemble_temp do |yasm|
29
- yasm.target! :x86
53
+ describe "#target!" do
54
+ it "should return true for valid targets" do
55
+ expect(subject.target!(:amd64)).to be(true)
56
+ end
57
+
58
+ context "when given an unknown target name" do
59
+ let(:name) { :lol }
30
60
 
31
- yasm.syntax = :gas
32
- yasm.file = assembly_file('gas')
61
+ it "should raise ArgumentError when passed unknown targets" do
62
+ expect {
63
+ subject.target!(name)
64
+ }.to raise_error(ArgumentError,"unknown YASM target: #{name.inspect}")
65
+ end
33
66
  end
34
67
 
35
- file.should_not be_nil
36
- File.size(file).should > 0
68
+ context "when given :x86" do
69
+ before { subject.target!(:x86) }
70
+
71
+ it "should set the #arch value" do
72
+ expect(subject.arch).to eq(:x86)
73
+ end
74
+
75
+ it "should set the #machine value" do
76
+ expect(subject.machine).to eq(:x86)
77
+ end
78
+ end
79
+
80
+ context "when given :amd64" do
81
+ before { subject.target!(:amd64) }
82
+
83
+ it "should set the #arch value" do
84
+ expect(subject.arch).to eq(:x86)
85
+ end
86
+
87
+ it "should set the #machine value" do
88
+ expect(subject.machine).to eq(:amd64)
89
+ end
90
+ end
91
+
92
+ context "when given :lc3b" do
93
+ before { subject.target!(:lc3b) }
94
+
95
+ it "should set the #arch value" do
96
+ expect(subject.arch).to eq(:lc3b)
97
+ end
98
+
99
+ it "should set the #machine value" do
100
+ expect(subject.machine).to eq(:lc3b)
101
+ end
102
+ end
37
103
  end
38
104
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'rubygems'
2
- gem 'rspec', '>=1.2.9'
3
- require 'spec'
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ SimpleCov.start
4
4
 
5
5
  require 'yasm/version'
6
-
7
6
  include YASM
data/spec/yasm_spec.rb CHANGED
@@ -4,6 +4,6 @@ require 'spec_helper'
4
4
 
5
5
  describe YASM do
6
6
  it "should have a VERSION constant" do
7
- YASM.const_defined?('VERSION').should == true
7
+ expect(subject.const_defined?('VERSION')).to eq(true)
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,140 +1,98 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-yasm
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Postmodern
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
14
- bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
- ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
16
- BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
- CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
- 1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
19
- mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
20
- W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
21
- 7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
22
- +Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
23
- T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
- sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
25
- ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
26
- xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
27
- cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
28
- GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
29
- /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
30
- pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
- -----END CERTIFICATE-----
32
-
33
- date: 2009-12-27 00:00:00 -08:00
34
- default_executable:
35
- dependencies:
36
- - !ruby/object:Gem::Dependency
37
- name: rprogram
10
+ cert_chain: []
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: command_mapper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
38
20
  type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: 0.1.8
45
- version:
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
48
34
  type: :development
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.2.9
55
- version:
56
- - !ruby/object:Gem::Dependency
57
- name: yard
58
- type: :development
59
- version_requirement:
60
- version_requirements: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 0.5.2
65
- version:
66
- - !ruby/object:Gem::Dependency
67
- name: hoe
68
- type: :development
69
- version_requirement:
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 2.4.0
75
- version:
76
- description: |-
77
- A Ruby interface to YASM.
78
-
79
- YASM is a complete rewrite of the NASM assembler, YASM currently supports
80
- the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes,
81
- outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32,
82
- and Win64 object formats, and generates source debugging information in
83
- STABS, DWARF 2, and CodeView 8 formats.
84
- email:
85
- - postmodern.mod3@gmail.com
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: ruby-yasm provides a Ruby interface to YASM assembler.
42
+ email: postmodern.mod3@gmail.com
86
43
  executables: []
87
-
88
44
  extensions: []
89
-
90
- extra_rdoc_files:
91
- - Manifest.txt
92
- files:
93
- - History.rdoc
94
- - Manifest.txt
95
- - README.rdoc
45
+ extra_rdoc_files:
46
+ - ChangeLog.md
47
+ - LICENSE.txt
48
+ - README.md
49
+ files:
50
+ - ".document"
51
+ - ".gemtest"
52
+ - ".github/workflows/ruby.yml"
53
+ - ".gitignore"
54
+ - ".rspec"
55
+ - ".specopts"
56
+ - ".yardopts"
57
+ - ChangeLog.md
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
96
61
  - Rakefile
62
+ - gemspec.yml
97
63
  - lib/yasm.rb
98
- - lib/yasm/task.rb
64
+ - lib/yasm/command.rb
99
65
  - lib/yasm/program.rb
100
- - lib/yasm/yasm.rb
101
66
  - lib/yasm/version.rb
102
- - tasks/spec.rb
103
- - tasks/yard.rb
104
- - spec/spec_helper.rb
67
+ - ruby-yasm.gemspec
68
+ - spec/command_spec.rb
105
69
  - spec/helpers/files.rb
106
70
  - spec/helpers/files/gas.S
107
- - spec/task_spec.rb
108
71
  - spec/program_spec.rb
72
+ - spec/spec_helper.rb
109
73
  - spec/yasm_spec.rb
110
- has_rdoc: yard
111
- homepage: http://www.tortall.net/projects/yasm/
112
- licenses: []
113
-
114
- post_install_message:
115
- rdoc_options:
116
- - --main
117
- - README.rdoc
118
- require_paths:
74
+ homepage: https://github.com/postmodern/ruby-yasm#readme
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
119
81
  - lib
120
- required_ruby_version: !ruby/object:Gem::Requirement
121
- requirements:
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
122
84
  - - ">="
123
- - !ruby/object:Gem::Version
124
- version: "0"
125
- version:
126
- required_rubygems_version: !ruby/object:Gem::Requirement
127
- requirements:
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
128
89
  - - ">="
129
- - !ruby/object:Gem::Version
130
- version: "0"
131
- version:
132
- requirements: []
133
-
134
- rubyforge_project: ruby-yasm
135
- rubygems_version: 1.3.5
136
- signing_key:
137
- specification_version: 3
138
- summary: A Ruby interface to YASM
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements:
93
+ - yasm >= 0.6.0
94
+ rubygems_version: 3.2.22
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A Ruby interface to YASM.
139
98
  test_files: []
140
-
data/History.rdoc DELETED
@@ -1,4 +0,0 @@
1
- === 0.1.0 / 2009-12-24
2
-
3
- * Initial release.
4
-