kompiler 0.1.2 → 0.2.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kompiler/architectures/armv8a/instructions.rb +47 -56
- data/lib/kompiler/mc_builder.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36f0387094d41fc93e8f85e56446392a1941cbcd115bf94c3ffd799c3d85cc78
|
4
|
+
data.tar.gz: 63a7973c95797b77119b47f24b8aa5bda591d7d2a4e5cbd5e34485fb11aea9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761aed3357cef9084d7dc0e7d8f9a73bb6dc883c7b1fc2cb5b0ee8b6499aa3f1f972bcc48d8d8adb2a3bd7f793738b28c1a37a21c17152d958cb79e39c7f8dab
|
7
|
+
data.tar.gz: dae7000f44475fdcb2c6c8e78c82f638ca09790c4442706ddeb57b5f76a41f30786bec6fd6e1620c5eba95999c283c5ed8083161d258562ba4672651a2caab54
|
@@ -275,33 +275,28 @@ end
|
|
275
275
|
],
|
276
276
|
bitsize: 32
|
277
277
|
},
|
278
|
+
|
278
279
|
{
|
279
280
|
keyword: "ldr",
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
284
|
-
["get_bits", 0, 0, 12], # Immediate offset zero
|
285
|
-
["bits", 1,0, 1,0, 0, 1,1,1, 1,1],
|
286
|
-
],
|
287
|
-
bitsize: 32
|
288
|
-
},
|
289
|
-
{
|
290
|
-
keyword: "ldr",
|
291
|
-
operands: [{type: "register", restrictions: {reg_size: 32}}, {type: "register", restrictions: {reg_size: 64}}],
|
281
|
+
name: "Load Register",
|
282
|
+
description: "Loads 4 or 8 bytes from memory at the address in the second register, and writes it to the destination register",
|
283
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Destination"}, {type: "register", restrictions: {reg_type: "gpr", reg_size: 64}, name: "Source address"}],
|
292
284
|
mc_constructor: [
|
293
285
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
294
286
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
295
287
|
["get_bits", 0, 0, 12], # Immediate offset zero
|
296
|
-
["bits", 1,0, 1,0, 0, 1,1,1
|
288
|
+
["bits", 1,0, 1,0, 0, 1,1,1],
|
289
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []],
|
290
|
+
["bits", 1],
|
297
291
|
],
|
298
292
|
bitsize: 32
|
299
293
|
},
|
294
|
+
|
300
295
|
{
|
301
296
|
keyword: "ldrb",
|
302
297
|
name: "Load Register Byte",
|
303
298
|
description: "Loads a byte from memory and writes the result to the destination register.",
|
304
|
-
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Destination"}, {type: "register", restrictions: {reg_size: 64, reg_type: "gpr"}, name: "Source address"}],
|
299
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr", reg_size: 32}, name: "Destination"}, {type: "register", restrictions: {reg_size: 64, reg_type: "gpr"}, name: "Source address"}],
|
305
300
|
mc_constructor: [
|
306
301
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
307
302
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
@@ -321,41 +316,19 @@ end
|
|
321
316
|
],
|
322
317
|
bitsize: 32
|
323
318
|
},
|
324
|
-
{
|
325
|
-
keyword: "str",
|
326
|
-
description: "Stores the contents of a 32 bit register at the address specified by the second register",
|
327
|
-
operands: [{type: "register", restrictions: {reg_size: 32}, name: "Content"}, {type: "register", restrictions: {reg_size: 64}, name: "Address"}],
|
328
|
-
mc_constructor: [
|
329
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
330
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
331
|
-
["get_bits", 0, 0, 12], # Immediate offset zero
|
332
|
-
["bits", 0,0, 1,0, 0, 1,1,1, 0,1],
|
333
|
-
],
|
334
|
-
bitsize: 32
|
335
|
-
},
|
336
|
-
{
|
337
|
-
keyword: "str",
|
338
|
-
description: "Stores the contents of a 64 bit register at the address specified by the second register",
|
339
|
-
operands: [{type: "register", restrictions: {reg_size: 64}, name: "Content"}, {type: "register", restrictions: {reg_size: 64}, name: "Address"}],
|
340
|
-
mc_constructor: [
|
341
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
342
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
343
|
-
["get_bits", 0, 0, 12], # Immediate offset zero
|
344
|
-
["bits", 0,0, 1,0, 0, 1,1,1, 1,1],
|
345
|
-
],
|
346
|
-
bitsize: 32
|
347
|
-
},
|
348
319
|
|
349
320
|
{
|
350
|
-
keyword: "
|
351
|
-
name: "
|
352
|
-
description: "Stores the contents of a
|
353
|
-
operands: [{type: "register", restrictions: {
|
321
|
+
keyword: "str",
|
322
|
+
name: "Store",
|
323
|
+
description: "Stores the contents of a 64 bit register at the address specified by the second register.",
|
324
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Content"}, {type: "register", restrictions: {reg_type: "gpr", reg_size: 64}, name: "Address"}],
|
354
325
|
mc_constructor: [
|
355
326
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
356
327
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
357
|
-
["get_bits",
|
358
|
-
["bits", 0,0, 1,0, 0, 1,1,1
|
328
|
+
["get_bits", 0, 0, 12],
|
329
|
+
["bits", 0,0, 1,0, 0, 1,1,1],
|
330
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []],
|
331
|
+
["bits", 1] # size second bit always 1
|
359
332
|
],
|
360
333
|
bitsize: 32
|
361
334
|
},
|
@@ -364,42 +337,60 @@ end
|
|
364
337
|
keyword: "str_unsigned",
|
365
338
|
name: "STR (immediate), unsigned offset",
|
366
339
|
description: "Stores the contents of a 64 bit register at the address specified by the second register with an unsigned immediate offset.",
|
367
|
-
operands: [{type: "register", restrictions: {
|
340
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Content"}, {type: "register", restrictions: {reg_type: "gpr", reg_size: 64}, name: "Address"}, {type: "immediate", name: "Address Offset"}],
|
368
341
|
mc_constructor: [
|
342
|
+
["case", ["get_key", ["get_operand", 0], :reg_size],
|
343
|
+
64, ["if_eq_else", ["modulo", ["get_operand", 2], 8], 0, [], ["raise_error", "str_unsigned Error: Unsigned offset must be divisible by 8 for 64-bit registers."]],
|
344
|
+
32, ["if_eq_else", ["modulo", ["get_operand", 2], 4], 0, [], ["raise_error", "str_unsigned Error: Unsigned offset must be divisible by 4 for 32-bit registers."]],
|
345
|
+
[]
|
346
|
+
],
|
369
347
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
370
348
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
371
|
-
["get_bits",
|
372
|
-
|
349
|
+
["get_bits",
|
350
|
+
["case", ["get_key", ["get_operand", 0], :reg_size],
|
351
|
+
64, ["divide", ["get_operand", 2], 8],
|
352
|
+
32, ["divide", ["get_operand", 2], 4],
|
353
|
+
["get_operand", 2]
|
354
|
+
],
|
355
|
+
0, 12],
|
356
|
+
["bits", 0,0, 1,0, 0, 1,1,1],
|
357
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []],
|
358
|
+
["bits", 1] # size second bit always 1
|
373
359
|
],
|
374
360
|
bitsize: 32
|
375
361
|
},
|
376
362
|
|
363
|
+
|
377
364
|
{
|
378
365
|
keyword: "str_pre_index",
|
379
366
|
name: "STR (immediate), signed offset, pre-index",
|
380
|
-
description: "Stores the contents of a
|
381
|
-
operands: [{type: "register", restrictions: {
|
367
|
+
description: "Stores the contents of a general purpose register at the address specified by the second register with an immediate offset added before writing.",
|
368
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Content"}, {type: "register", restrictions: {reg_type: "gpr", reg_size: 64}, name: "Address"}, {type: "immediate", name: "Address Offset"}],
|
382
369
|
mc_constructor: [
|
383
370
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
384
371
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
385
372
|
["bits", 1, 1],
|
386
373
|
["get_bits", ["get_operand", 2], 0, 9],
|
387
|
-
["bits", 0, 0,0, 0,0, 0, 1,1,1
|
374
|
+
["bits", 0, 0,0, 0,0, 0, 1,1,1],
|
375
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []],
|
376
|
+
["bits", 1] # size second bit always 1
|
388
377
|
],
|
389
378
|
bitsize: 32
|
390
379
|
},
|
391
380
|
|
392
381
|
{
|
393
|
-
keyword: "
|
394
|
-
name: "STR (immediate), signed offset,
|
395
|
-
description: "Stores the contents of a
|
396
|
-
operands: [{type: "register", restrictions: {
|
382
|
+
keyword: "str_post_index",
|
383
|
+
name: "STR (immediate), signed offset, post-index",
|
384
|
+
description: "Stores the contents of a general purpose register at the address specified by the second register, with an immediate offset added after writing.",
|
385
|
+
operands: [{type: "register", restrictions: {reg_type: "gpr"}, name: "Content"}, {type: "register", restrictions: {reg_type: "gpr", reg_size: 64}, name: "Address"}, {type: "immediate", name: "Address Offset"}],
|
397
386
|
mc_constructor: [
|
398
387
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
399
388
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
400
|
-
["bits", 1,
|
389
|
+
["bits", 1, 0],
|
401
390
|
["get_bits", ["get_operand", 2], 0, 9],
|
402
|
-
["bits", 0, 0,0, 0,0, 0, 1,1,1
|
391
|
+
["bits", 0, 0,0, 0,0, 0, 1,1,1],
|
392
|
+
["case", ["get_key", ["get_operand", 0], :reg_size], 64, ["bits", 1], 32, ["bits", 0], []],
|
393
|
+
["bits", 1] # size second bit always 1
|
403
394
|
],
|
404
395
|
bitsize: 32
|
405
396
|
},
|
data/lib/kompiler/mc_builder.rb
CHANGED
@@ -28,6 +28,16 @@ MC_AST_NODES = [
|
|
28
28
|
{name: "get_label_address", n_args: 1, func: lambda {|args, state| state[:labels].include?(args[0]) ? state[:labels][args[0]] : raise("Label \"#{args[0]}\" not found: Program build not possible") } },
|
29
29
|
{name: "bits", n_args: "any", func: lambda {|args, state| args } },
|
30
30
|
{name: "if_eq_else", n_args: 4, eval_args: false, func: lambda {|args, state| (eval_mc_node_arg(args[0], state) == eval_mc_node_arg(args[1], state)) ? eval_mc_node_arg(args[2], state) : eval_mc_node_arg(args[3], state) }},
|
31
|
+
{name: "case", n_args: "any", eval_args: false, func: lambda do |args, state|
|
32
|
+
value = eval_mc_node_arg(args[0], state)
|
33
|
+
raise "Incorrect use of the \"case\" MC Constructor: incorrect number of arguments. This is likely a problem with the architecture, not the program being compiled." if (args.size - 2) % 2 != 0
|
34
|
+
args[1...-1].each_slice(2) do |check_value, block|
|
35
|
+
if value == check_value
|
36
|
+
return eval_mc_node_arg(block, state)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
eval_mc_node_arg(args.last, state)
|
40
|
+
end},
|
31
41
|
{name: "raise_error", n_args: 1, func: lambda {|args, state| raise args[0] } },
|
32
42
|
{name: "get_key", n_args: 2, func: lambda {|args, state| args[0][args[1]] }},
|
33
43
|
]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kompiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyryl Shyshko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Kompiler is a low-level, modular and extendable compiler for any architecture.
|
14
14
|
By default Kompiler supports ARMv8-a, but other architecture extensions can be downloaded
|