kompiler 0.1.1 → 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 +51 -47
- 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,25 +275,33 @@ end
|
|
275
275
|
],
|
276
276
|
bitsize: 32
|
277
277
|
},
|
278
|
+
|
278
279
|
{
|
279
280
|
keyword: "ldr",
|
280
|
-
|
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"}],
|
281
284
|
mc_constructor: [
|
282
285
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
283
286
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
284
287
|
["get_bits", 0, 0, 12], # Immediate offset zero
|
285
|
-
["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],
|
286
291
|
],
|
287
292
|
bitsize: 32
|
288
293
|
},
|
294
|
+
|
289
295
|
{
|
290
|
-
keyword: "
|
291
|
-
|
296
|
+
keyword: "ldrb",
|
297
|
+
name: "Load Register Byte",
|
298
|
+
description: "Loads a byte from memory and writes the result to the destination register.",
|
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"}],
|
292
300
|
mc_constructor: [
|
293
301
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
294
302
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
295
303
|
["get_bits", 0, 0, 12], # Immediate offset zero
|
296
|
-
["bits", 1,0, 1,0, 0, 1,1,1, 0,
|
304
|
+
["bits", 1,0, 1,0, 0, 1,1,1, 0,0],
|
297
305
|
],
|
298
306
|
bitsize: 32
|
299
307
|
},
|
@@ -308,41 +316,19 @@ end
|
|
308
316
|
],
|
309
317
|
bitsize: 32
|
310
318
|
},
|
311
|
-
{
|
312
|
-
keyword: "str",
|
313
|
-
description: "Stores the contents of a 32 bit register at the address specified by the second register",
|
314
|
-
operands: [{type: "register", restrictions: {reg_size: 32}, name: "Content"}, {type: "register", restrictions: {reg_size: 64}, name: "Address"}],
|
315
|
-
mc_constructor: [
|
316
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
317
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
318
|
-
["get_bits", 0, 0, 12], # Immediate offset zero
|
319
|
-
["bits", 0,0, 1,0, 0, 1,1,1, 0,1],
|
320
|
-
],
|
321
|
-
bitsize: 32
|
322
|
-
},
|
323
|
-
{
|
324
|
-
keyword: "str",
|
325
|
-
description: "Stores the contents of a 64 bit register at the address specified by the second register",
|
326
|
-
operands: [{type: "register", restrictions: {reg_size: 64}, name: "Content"}, {type: "register", restrictions: {reg_size: 64}, name: "Address"}],
|
327
|
-
mc_constructor: [
|
328
|
-
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
329
|
-
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
330
|
-
["get_bits", 0, 0, 12], # Immediate offset zero
|
331
|
-
["bits", 0,0, 1,0, 0, 1,1,1, 1,1],
|
332
|
-
],
|
333
|
-
bitsize: 32
|
334
|
-
},
|
335
319
|
|
336
320
|
{
|
337
|
-
keyword: "
|
338
|
-
name: "
|
339
|
-
description: "Stores the contents of a
|
340
|
-
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"}],
|
341
325
|
mc_constructor: [
|
342
326
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
343
327
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
344
|
-
["get_bits",
|
345
|
-
["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
|
346
332
|
],
|
347
333
|
bitsize: 32
|
348
334
|
},
|
@@ -351,42 +337,60 @@ end
|
|
351
337
|
keyword: "str_unsigned",
|
352
338
|
name: "STR (immediate), unsigned offset",
|
353
339
|
description: "Stores the contents of a 64 bit register at the address specified by the second register with an unsigned immediate offset.",
|
354
|
-
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"}],
|
355
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
|
+
],
|
356
347
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
357
348
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
358
|
-
["get_bits",
|
359
|
-
|
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
|
360
359
|
],
|
361
360
|
bitsize: 32
|
362
361
|
},
|
363
362
|
|
363
|
+
|
364
364
|
{
|
365
365
|
keyword: "str_pre_index",
|
366
366
|
name: "STR (immediate), signed offset, pre-index",
|
367
|
-
description: "Stores the contents of a
|
368
|
-
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"}],
|
369
369
|
mc_constructor: [
|
370
370
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
371
371
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
372
372
|
["bits", 1, 1],
|
373
373
|
["get_bits", ["get_operand", 2], 0, 9],
|
374
|
-
["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
|
375
377
|
],
|
376
378
|
bitsize: 32
|
377
379
|
},
|
378
380
|
|
379
381
|
{
|
380
|
-
keyword: "
|
381
|
-
name: "STR (immediate), signed offset,
|
382
|
-
description: "Stores the contents of a
|
383
|
-
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"}],
|
384
386
|
mc_constructor: [
|
385
387
|
["get_bits", ["encode_gp_register", ["get_operand", 0]], 0, 5],
|
386
388
|
["get_bits", ["encode_gp_register", ["get_operand", 1]], 0, 5],
|
387
|
-
["bits", 1,
|
389
|
+
["bits", 1, 0],
|
388
390
|
["get_bits", ["get_operand", 2], 0, 9],
|
389
|
-
["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
|
390
394
|
],
|
391
395
|
bitsize: 32
|
392
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.
|
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
|