@@ -424,6 +424,7 @@ module LLVM-REGISTERS is
424
424
<k> Assign(X:Id, V:KResult) => . ...</k>
425
425
<registers> M:Map => M[V / X] </registers>
426
426
427
+ // TODO using constructors in the AST instead of matching on a string
427
428
rule [lookup-register]:
428
429
<k> X => V ...</k>
429
430
<registers>... X |-> V:KResult ...</registers>
@@ -458,6 +459,8 @@ module LLVM-BRANCHING is
458
459
</k>
459
460
when unsigned(i(1), I) ==Int 0
460
461
462
+ // TODO put static switch information into a map like with phi nodes
463
+ // TODO semantic design pattern: list traversal -> statically storing info and using simple rules later
461
464
rule [switch-default]:
462
465
<k> Switch(_, I:Int, Label:K, listK(.List{K}))
463
466
=> Unconditional(Label:K)
@@ -581,10 +584,13 @@ end module
581
584
module LLVM-DECLARATIONS is
582
585
including LLVM-INCLUDE
583
586
587
+ // TODO: semantic design pattern: assignment rule
584
588
rule
585
589
<k> Alias(Name:Id, K:K) => . ...</k>
586
590
<globalRegisters> Map:Map => Map[K/Name] </globalRegisters>
587
591
592
+ // TODO list{K}ToK module sections
593
+ // TODO: semantic design pattern: multi-arity (want multiple pieces of data at the same time like key/value pairs) vs. variadic (when you don't need to do things at the same time)
588
594
rule
589
595
<k> Module(Name:Id, TargetLayout:K, TargetTriple:K, Typedefs:K, GlobalVars:K, Aliases:K, Functions:K)
590
596
=> Typedefs
@@ -645,6 +651,7 @@ module LLVM-DECLARATIONS is
645
651
)
646
652
where FUNCTION = FunctionDecl(RetType:KResult, Name:Id, Arguments:K)
647
653
654
+ // TODO add redundant context for readability (maps)
648
655
rule
649
656
<k> Body((BasicBlock(Name:Id, K:K),, L:List{K}))
650
657
=> BasicBlock(Name:Id, K:K)
@@ -692,6 +699,8 @@ module LLVM-CALL-RET is
692
699
// TODO ... on RHS to reset cell
693
700
// TODO assuming single module
694
701
702
+ // TODO perhaps another semantic design pattern: idea of context switching: pushing on a stack, doing something, and then popping from the stack
703
+
695
704
rule
696
705
<k> Call(_, Callee(funptr(FunName:Id), listK(Args:List{K}))) ~> Tail:K
697
706
=> contextSwitch(FunName, Tail)
@@ -720,6 +729,7 @@ module LLVM-CALL-RET is
720
729
<callStack> . => frame(Tail, C) ...</callStack>
721
730
722
731
732
+ // TODO perhaps a pattern: turning a list of pairs into a map
723
733
724
734
// might need a way to convert nonmatching types here? depends on semantics
725
735
rule
@@ -876,6 +886,9 @@ module LLVM-FLOATING-POINT-ARITHMETIC is
876
886
=> F1 *Float F2
877
887
...</k>
878
888
889
+ // TODO incorrect since NaN * 0 = NaN
890
+ rule FMul(_, F:#Float, PositiveZero) => 0.0
891
+
879
892
end module
880
893
881
894
module LLVM-GEP is
@@ -1023,6 +1036,7 @@ module LLVM-HELPERS-SPLIT-BYTES is
1023
1036
=> listK(L)
1024
1037
...</k>
1025
1038
1039
+ // TODO perhaps a pattern: even more localized rewriting: rewriting inside a constructor rather than rewriting the whole thing
1026
1040
rule
1027
1041
<k> splitFloatBytes(
1028
1042
V:KResult,
@@ -1348,6 +1362,9 @@ module LLVM-CONVERSIONS is
1348
1362
rule
1349
1363
<k> BitCast(_, Loc:Loc) => Loc:Loc ...</k>
1350
1364
1365
+ //rule
1366
+ //<k> BitCast(IntegerType(_), F:#Float) => Float2Int(F) ...</k>
1367
+
1351
1368
// TODO need to normalize here
1352
1369
rule
1353
1370
<k> IntToPtr(Type:KResult, K:K) => intToPtr(Type, K:K) ...</k>
@@ -1611,6 +1628,18 @@ module LLVM-INTERNAL-TESTING-FUNCTIONS is
1611
1628
andBool (I >=Int 0 orBool I <=Int 0) // real integer
1612
1629
end module
1613
1630
1631
+ module LLVM-EXCEPTIONS is
1632
+ including LLVM-INCLUDE
1633
+
1634
+
1635
+ /*
1636
+ rule
1637
+ <k> Call(_, Callee(funptr(Name("@__cxa")), listK(V1:KResult,, V2:KResult)))
1638
+ => @__cxa_allocate_exception
1639
+ ...</k>
1640
+ */
1641
+ end module
1642
+
1614
1643
module LLVM-SEMANTICS is
1615
1644
including LLVM-INCLUDE
1616
1645
@@ -1638,6 +1667,7 @@ module LLVM-SEMANTICS is
1638
1667
including LLVM-STANDARD-LIBRARY
1639
1668
including LLVM-SYSCALLS-PREPROCESS
1640
1669
including LLVM-SYSCALLS
1670
+ including LLVM-EXCEPTIONS
1641
1671
1642
1672
including LLVM-INTERNAL-TESTING-FUNCTIONS
1643
1673
end module
0 commit comments