kompiler 0.2.0.pre.1 → 0.2.0.pre.2
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/lib/kompiler/architectures/armv8a/instructions.rb +48 -30
- data/lib/kompiler/parsers.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69b1e8272e45a6c9ce0b8bb60dbfb89b0d65d0f8f615cbd744726857ecf1d94f
|
4
|
+
data.tar.gz: eba0c518a787b345d191a2cf41e76ecb52ca25dac10f14f17b72d5cbbcb2f201
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a325a47eff59b3766cead44c9e81063773af594e224d96aa667b7015a7a469d10be65e0ecdb68b36db88645472ae320309e92872ba568c3ed32f8da4525b113e
|
7
|
+
data.tar.gz: 31881ac3bba3ac3e3afa0a1c87366ea1680c32189d07cbdcd62e7eee33b19712fb85c0198b91b2315377e1f16ad0a973c95083810ef0a125c4a385ea84774101
|
@@ -398,69 +398,64 @@ end
|
|
398
398
|
|
399
399
|
{
|
400
400
|
keyword: "cmp",
|
401
|
-
|
401
|
+
name: "Compare (immediate)",
|
402
|
+
description: "Subtracts an immediate value from a register value, and updates the condition flags based on the result.",
|
403
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}}, {type: "immediate"}],
|
402
404
|
mc_constructor: [
|
403
405
|
["bits", 1,1,1,1,1],
|
404
406
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
405
|
-
["get_bits", ["get_operand", 1], 0, 12], # Immediate
|
406
|
-
["bits", 0, 0,1,0,0,0,1, 1, 1
|
407
|
+
["get_bits", ["get_operand", 1], 0, 12], # Immediate value
|
408
|
+
["bits", 0, 0,1,0,0,0,1, 1, 1],
|
409
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []], # sf
|
407
410
|
],
|
408
411
|
bitsize: 32
|
409
412
|
},
|
410
413
|
|
411
414
|
{
|
412
415
|
keyword: "cmp",
|
413
|
-
name: "
|
414
|
-
description: "
|
415
|
-
operands: [{type: "register", restrictions: {
|
416
|
+
name: "Compare (registers)",
|
417
|
+
description: "Subtracts the second register value from the first register value, and updates the condition flags based on the result.",
|
418
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Register 1"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 2"}],
|
416
419
|
mc_constructor: [
|
420
|
+
["if_eq_else", ["get_key", ["get_operand", 0], :reg_size], ["get_key", ["get_operand", 1], :reg_size], [], ["raise_error", "cmp Error: Register sizes are not the same"]],
|
417
421
|
["bits", 1,1,1,1,1], # Rd
|
418
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
422
|
+
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5], # Rn
|
419
423
|
["get_bits", 0, 0, 6], # Immediate offset zero (shift amount)
|
420
424
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5], # Rm
|
421
425
|
["bits", 0],
|
422
426
|
["bits", 0, 0], # Shift type
|
423
|
-
["bits", 1,1,0,1,0,1,1
|
424
|
-
|
425
|
-
bitsize: 32
|
426
|
-
},
|
427
|
-
|
428
|
-
{
|
429
|
-
keyword: "cmp",
|
430
|
-
name: "CMP (two registers)",
|
431
|
-
description: "Compares two 32-bit registers and updates condition flags based on the result.",
|
432
|
-
operands: [{type: "register", restrictions: {reg_size: 32}, name: "Register 1"}, {type: "register", restrictions: {reg_size: 32}, name: "Register 2"}],
|
433
|
-
mc_constructor: [
|
434
|
-
["bits", 1,1,1,1,1], # Rd
|
435
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
436
|
-
["get_bits", 0, 0, 6], # Immediate offset zero (shift amount)
|
437
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5], # Rm
|
438
|
-
["bits", 0],
|
439
|
-
["bits", 0, 0], # Shift type
|
440
|
-
["bits", 1,1,0,1,0,1,1,0],
|
427
|
+
["bits", 1,1,0,1,0,1,1],
|
428
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []], # sf
|
441
429
|
],
|
442
430
|
bitsize: 32
|
443
431
|
},
|
432
|
+
|
444
433
|
|
445
434
|
{
|
446
435
|
keyword: "sub",
|
447
|
-
|
436
|
+
name: "Subtract (immediate)",
|
437
|
+
description: "Subtract an immediate value from a register value, and store the result in the destination register",
|
438
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Destination"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Source"}, {type: "immediate", name: "Immediate"}],
|
448
439
|
mc_constructor: [
|
440
|
+
["if_eq_else", ["get_key", ["get_operand", 0], :reg_size], ["get_key", ["get_operand", 1], :reg_size], [], ["raise_error", "sub Error: Register sizes are not the same"]],
|
449
441
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
450
442
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
451
443
|
["get_bits", ["get_operand", 2], 0, 12], # Immediate offset zero
|
452
444
|
["bits", 0], # Shift
|
453
|
-
["bits", 0,1,0,0,0,1,0,1
|
445
|
+
["bits", 0,1,0,0,0,1,0,1],
|
446
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []], # sf
|
454
447
|
],
|
455
448
|
bitsize: 32
|
456
449
|
},
|
457
450
|
|
458
451
|
{
|
459
452
|
keyword: "mul",
|
460
|
-
name: "
|
461
|
-
description: "Multiply the contents of two registers and store the output in the destination register.",
|
462
|
-
operands: [{type: "register", restrictions: {reg_type: "gpr"}}, {type: "register", restrictions: {reg_type: "gpr"}}, {type: "register", restrictions: {reg_type: "gpr"}}],
|
453
|
+
name: "Multiply",
|
454
|
+
description: "Multiply the contents of two registers, and store the output in the destination register.",
|
455
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Destination"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 1"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 2"}],
|
463
456
|
mc_constructor: [
|
457
|
+
["if_eq_else", ["get_key", ["get_operand", 0], :reg_size], ["get_key", ["get_operand", 1], :reg_size], [], ["raise_error", "mul Error: Register sizes are not the same"]],
|
458
|
+
["if_eq_else", ["get_key", ["get_operand", 1], :reg_size], ["get_key", ["get_operand", 2], :reg_size], [], ["raise_error", "mul Error: Register sizes are not the same"]],
|
464
459
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5], # Rd
|
465
460
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5], # Rn
|
466
461
|
["bits", 1,1,1,1,1, 0], # Ra o0
|
@@ -473,6 +468,29 @@ end
|
|
473
468
|
},
|
474
469
|
|
475
470
|
|
471
|
+
{
|
472
|
+
keyword: "madd",
|
473
|
+
name: "Multiply-Add",
|
474
|
+
description: "Multiplies two register values, adds a third register value, and writes the result to the destination register.",
|
475
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Destination"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 1 (to multiply)"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 2 (to multiply)"}, {type: "register", restrictions: {reg_type: "gpr"}, name: "Register 3 (to add)"}],
|
476
|
+
mc_constructor: [
|
477
|
+
# Checks for register sizes being the same
|
478
|
+
["if_eq_else", ["get_key", ["get_operand", 0], :reg_size], ["get_key", ["get_operand", 1], :reg_size], [], ["raise_error", "madd Error: Register sizes are not the same"]],
|
479
|
+
["if_eq_else", ["get_key", ["get_operand", 1], :reg_size], ["get_key", ["get_operand", 2], :reg_size], [], ["raise_error", "madd Error: Register sizes are not the same"]],
|
480
|
+
["if_eq_else", ["get_key", ["get_operand", 2], :reg_size], ["get_key", ["get_operand", 3], :reg_size], [], ["raise_error", "madd Error: Register sizes are not the same"]],
|
481
|
+
|
482
|
+
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5], # Rd
|
483
|
+
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5], # Rn
|
484
|
+
["get_bits", ["encode_gp_register", ["get_operand", 3]], 0, 5], #Ra
|
485
|
+
["bits", 0], # o0
|
486
|
+
["get_bits", ["encode_gp_register", ["get_operand", 2]], 0, 5], # Rm
|
487
|
+
["bits", 0,0,0, 1,1,0,1,1, 0,0],
|
488
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []], # sf
|
489
|
+
],
|
490
|
+
bitsize: 32,
|
491
|
+
},
|
492
|
+
|
493
|
+
|
476
494
|
#
|
477
495
|
# B.cond instructions
|
478
496
|
#
|
data/lib/kompiler/parsers.rb
CHANGED
@@ -22,6 +22,8 @@ def self.parse_str(code)
|
|
22
22
|
str_content << "\r"
|
23
23
|
elsif code[i] == "\\"
|
24
24
|
str_content << "\\"
|
25
|
+
elsif code[i] == "0"
|
26
|
+
str_content << "\0"
|
25
27
|
else
|
26
28
|
str_content << "\\"
|
27
29
|
str_content << code[i]
|
@@ -145,6 +147,29 @@ def self.check_decimal_operand(str)
|
|
145
147
|
end
|
146
148
|
|
147
149
|
|
150
|
+
def self.check_char_operand(str)
|
151
|
+
|
152
|
+
# If doesn't start with ' or doesn't end with ', return false
|
153
|
+
if (str[0] != "'") || (str[-1] != "'")
|
154
|
+
return [false, nil]
|
155
|
+
end
|
156
|
+
|
157
|
+
# Use existing logic to parse the contents
|
158
|
+
to_parse = str.dup
|
159
|
+
to_parse[0] = '"'
|
160
|
+
to_parse[-1] = '"'
|
161
|
+
content, parse_i = parse_str(to_parse)
|
162
|
+
|
163
|
+
# If more than one character, return false
|
164
|
+
if content.size != 1
|
165
|
+
return [false, nil]
|
166
|
+
end
|
167
|
+
|
168
|
+
return [true, content.encode("ascii").bytes[0]]
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
148
173
|
def self.check_immediate_operand(operand_str)
|
149
174
|
|
150
175
|
is_bin, bin_value = check_binary_operand(operand_str)
|
@@ -156,6 +181,9 @@ def self.check_immediate_operand(operand_str)
|
|
156
181
|
is_hex, hex_value = check_hex_operand(operand_str)
|
157
182
|
return [true, {type: "immediate", value: hex_value, def_type: "hex"}] if is_hex
|
158
183
|
|
184
|
+
is_char, char_value = check_char_operand(operand_str)
|
185
|
+
return [true, {type: "immediate", value: char_value, def_type: "char"}] if is_char
|
186
|
+
|
159
187
|
return [false, nil]
|
160
188
|
end
|
161
189
|
|