rips 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/example.rips +22 -4
- data/lib/rips/assembler.rb +67 -3
- data/lib/rips/error.rb +3 -1
- data/lib/rips/variables/address.rb +7 -11
- data/lib/rips/variables/inmediate.rb +5 -9
- data/lib/rips/variables/port.rb +5 -9
- data/lib/rips/variables/register.rb +5 -9
- data/lib/rips/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba8ac0a5eaa357455a6e03c2a68780872c13e52
|
4
|
+
data.tar.gz: dadbb4848036104eccb883594f6ebc55242e2f8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea3e6aa10a9688867818db06eb00cd1ea57259c1346fe3784ebcf1f7c3eb639db7b8e14556b8ee0cf3c05574aab69187fd9a8fb7d1e08c7825c6c3b4f991dbb
|
7
|
+
data.tar.gz: 4df51297c08a6e4460327b78aeab6856e619a0f773baf6e5b7e8ad95d1b9d716bcd167fb5389fbab79995fefc16300d54cc4e73e2111ffe9ee330ea6398638ae
|
data/example.rips
CHANGED
@@ -2,9 +2,27 @@
|
|
2
2
|
# Example #
|
3
3
|
#***************#
|
4
4
|
|
5
|
-
# Output in
|
5
|
+
# Output in progfile.dat
|
6
6
|
|
7
|
-
|
8
|
-
li $2, -5 # Load -5 in Register 2
|
7
|
+
main:
|
9
8
|
|
10
|
-
|
9
|
+
li $14, 2
|
10
|
+
li $15, 1
|
11
|
+
li $1, 0
|
12
|
+
li $2, 0
|
13
|
+
|
14
|
+
ajal:
|
15
|
+
|
16
|
+
jal adder
|
17
|
+
j increment
|
18
|
+
|
19
|
+
adder:
|
20
|
+
|
21
|
+
add $3, $1, $2 # Reg3 = Reg1 + Reg2
|
22
|
+
jr
|
23
|
+
|
24
|
+
increment:
|
25
|
+
|
26
|
+
add $1, $1, $14
|
27
|
+
sub $2, $2, $15
|
28
|
+
j ajal # Repeat process
|
data/lib/rips/assembler.rb
CHANGED
@@ -8,6 +8,8 @@ module Rips
|
|
8
8
|
# @output: array with coded instructions
|
9
9
|
# @cmd: line split on tokens (name + arguments)
|
10
10
|
# @instruction: instruction instance
|
11
|
+
# @instructions: array with line for each instruction
|
12
|
+
# @labels: name and number line of label
|
11
13
|
# @line: number of file's line
|
12
14
|
def initialize (debug)
|
13
15
|
@debug = debug
|
@@ -15,7 +17,37 @@ module Rips
|
|
15
17
|
@output = []
|
16
18
|
@cmd = {}
|
17
19
|
@instruction
|
18
|
-
@
|
20
|
+
@instructions = []
|
21
|
+
@labels = {}
|
22
|
+
@line = 1
|
23
|
+
end
|
24
|
+
|
25
|
+
# Store labels and number line
|
26
|
+
def find_labels
|
27
|
+
|
28
|
+
@input.each_with_index do |line, i|
|
29
|
+
if !line.empty?
|
30
|
+
label = line.scan(/\w+:/)
|
31
|
+
if (label.size == 1)
|
32
|
+
|
33
|
+
if !@labels.include?(label[0].to_s.split(":").first)
|
34
|
+
@labels[label[0].to_s.split(":").first] = [*@instructions.each_with_index].bsearch{|x, _| x >= i}.last
|
35
|
+
else
|
36
|
+
Error::message(7, i+1, label[0].to_s.split(":").first)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Store number line for each instruction
|
44
|
+
def find_instructions
|
45
|
+
|
46
|
+
@input.each_with_index do |line,i|
|
47
|
+
if (!line.empty?) && (line.scan(/\w+:/).empty?) && (line[0] != "#")
|
48
|
+
@instructions << i+1
|
49
|
+
end
|
50
|
+
end
|
19
51
|
end
|
20
52
|
|
21
53
|
# Stores each new line of file
|
@@ -26,10 +58,24 @@ module Rips
|
|
26
58
|
# Analyze and translate each instruction
|
27
59
|
def run
|
28
60
|
|
61
|
+
find_instructions
|
62
|
+
find_labels
|
63
|
+
|
64
|
+
puts "instructions...."
|
65
|
+
@instructions.each do |k|
|
66
|
+
puts "#{k}"
|
67
|
+
end
|
68
|
+
|
69
|
+
puts "labels...."
|
70
|
+
@labels.each do |k,v|
|
71
|
+
puts "#{k}:#{v}"
|
72
|
+
end
|
73
|
+
|
29
74
|
@input.each do |line|
|
30
75
|
|
31
76
|
# If line is empty -> next line
|
32
|
-
if
|
77
|
+
# Or if not is a label
|
78
|
+
if (!line.empty?) && (line.scan(/\w+:/).empty?)
|
33
79
|
|
34
80
|
parse_input(line)
|
35
81
|
@instruction = nil
|
@@ -39,6 +85,8 @@ module Rips
|
|
39
85
|
|
40
86
|
exists_instruction
|
41
87
|
@instruction = get_instruction
|
88
|
+
|
89
|
+
parse_label
|
42
90
|
|
43
91
|
argument_size
|
44
92
|
argument_syntax
|
@@ -85,14 +133,30 @@ module Rips
|
|
85
133
|
@cmd[:comments] = line
|
86
134
|
else
|
87
135
|
@cmd[:name] = line.split("#").first.split(" ").first.downcase
|
88
|
-
@cmd[:arguments] = line.split("#").first.split(@cmd[:name])
|
136
|
+
@cmd[:arguments] = line.split("#").first.split("#{@cmd[:name]} ")
|
89
137
|
if !@cmd[:arguments].empty?
|
90
138
|
@cmd[:arguments] = @cmd[:arguments].pop.split("#").first.delete(" ").split(",")
|
91
139
|
end
|
140
|
+
if @cmd[:arguments].first == "jr" ||
|
141
|
+
@cmd[:arguments].first == "nop"
|
142
|
+
@cmd[:arguments] = []
|
143
|
+
end
|
92
144
|
@cmd[:comments] = line.split("#").slice(1..-1).join
|
93
145
|
@cmd[:comments].insert(0,"#") if !@cmd[:comments].empty?
|
94
146
|
end
|
147
|
+
end
|
95
148
|
|
149
|
+
# Translate label's name to instruction's number
|
150
|
+
def parse_label
|
151
|
+
if (@instruction.is_a? Rips::Instructions::Bez) ||
|
152
|
+
(@instruction.is_a? Rips::Instructions::Bnez) ||
|
153
|
+
(@instruction.is_a? Rips::Instructions::J) ||
|
154
|
+
(@instruction.is_a? Rips::Instructions::Jal)
|
155
|
+
|
156
|
+
puts @cmd[:arguments]
|
157
|
+
@cmd[:arguments] = [@labels[@cmd[:arguments].first].to_s]
|
158
|
+
puts "Salto a: #{@cmd[:arguments]}"
|
159
|
+
end
|
96
160
|
end
|
97
161
|
|
98
162
|
# Obtain instruction's instance object
|
data/lib/rips/error.rb
CHANGED
@@ -8,7 +8,9 @@ module Rips
|
|
8
8
|
"RIPS ERROR (3). Permission denied to read file.",
|
9
9
|
"RIPS ERROR (4). In line %d: doesn't exist `%s` instruction in Instruction Set.",
|
10
10
|
"RIPS ERROR (5). In line %d: for `%s` instruction wrong number of arguments (%d for %d).",
|
11
|
-
"RIPS ERROR (6). In line %d: syntax error, %s."
|
11
|
+
"RIPS ERROR (6). In line %d: syntax error, %s.",
|
12
|
+
"RIPS ERROR (7). In line %d: There is already a label called `%s`.",
|
13
|
+
"RIPS ERROR (8). In line %d: Unknown syntax for label `%s` (try `labelname:`)." ]
|
12
14
|
|
13
15
|
def self.message (num, *args)
|
14
16
|
puts MESSAGES[num] % args
|
@@ -12,24 +12,20 @@ module Rips
|
|
12
12
|
def initialize(size = 10)
|
13
13
|
super(size)
|
14
14
|
@range = [0, 2**@length-1]
|
15
|
-
@syntax = "#{@range[0]}
|
15
|
+
@syntax = "#{@range[0]}..#{@range[1]} | label"
|
16
16
|
end
|
17
17
|
|
18
18
|
# Check input variable syntax
|
19
19
|
def syntax? (value)
|
20
20
|
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# It should be between syntax range
|
26
|
-
if !between?(value, @range)
|
27
|
-
return false
|
21
|
+
if (number?(value)) && (between?(value, @range))
|
22
|
+
true
|
23
|
+
elsif value.is_a?(String)
|
24
|
+
true
|
28
25
|
else
|
29
|
-
|
30
|
-
end
|
26
|
+
false
|
27
|
+
end
|
31
28
|
end
|
32
|
-
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -12,22 +12,18 @@ module Rips
|
|
12
12
|
def initialize(size = 8)
|
13
13
|
super(size)
|
14
14
|
@range = [-2**(@length-1), 2**(@length-1)-1]
|
15
|
-
@syntax = "#{@range[0]}
|
15
|
+
@syntax = "#{@range[0]}..#{@range[1]}"
|
16
16
|
end
|
17
17
|
|
18
18
|
# Check input variable syntax
|
19
19
|
def syntax? (value)
|
20
20
|
|
21
|
-
if !number?(value)
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
|
25
21
|
# It should be between syntax range
|
26
|
-
if
|
27
|
-
|
22
|
+
if number?(value) && between?(value, @range)
|
23
|
+
true
|
28
24
|
else
|
29
|
-
|
30
|
-
end
|
25
|
+
false
|
26
|
+
end
|
31
27
|
end
|
32
28
|
|
33
29
|
end
|
data/lib/rips/variables/port.rb
CHANGED
@@ -13,22 +13,18 @@ module Rips
|
|
13
13
|
super(size)
|
14
14
|
@syntax = "@0-3"
|
15
15
|
@range = [0, 2**@length-1]
|
16
|
-
@syntax = "@#{@range[0]}
|
16
|
+
@syntax = "@#{@range[0]}-#{@range[1]}"
|
17
17
|
end
|
18
18
|
|
19
19
|
# Check input variable syntax
|
20
20
|
def syntax? (value)
|
21
21
|
|
22
|
-
if !port?(value)
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
|
26
22
|
# It should be between syntax range
|
27
|
-
if
|
28
|
-
|
23
|
+
if port?(value) && between?(value, @range)
|
24
|
+
true
|
29
25
|
else
|
30
|
-
|
31
|
-
end
|
26
|
+
false
|
27
|
+
end
|
32
28
|
end
|
33
29
|
|
34
30
|
end
|
@@ -12,22 +12,18 @@ module Rips
|
|
12
12
|
def initialize(size = 4)
|
13
13
|
super(size)
|
14
14
|
@range = [0, 2**@length-1]
|
15
|
-
@syntax = "$#{@range[0]}
|
15
|
+
@syntax = "$#{@range[0]}-#{@range[1]}"
|
16
16
|
end
|
17
17
|
|
18
18
|
# Check input variable syntax
|
19
19
|
def syntax? (value)
|
20
20
|
|
21
|
-
if !register?(value)
|
22
|
-
return false
|
23
|
-
end
|
24
|
-
|
25
21
|
# It should be between syntax range
|
26
|
-
if
|
27
|
-
|
22
|
+
if register?(value) && between?(value, @range)
|
23
|
+
true
|
28
24
|
else
|
29
|
-
|
30
|
-
end
|
25
|
+
false
|
26
|
+
end
|
31
27
|
end
|
32
28
|
|
33
29
|
end
|
data/lib/rips/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rips
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Madh93
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|