Skip to content

Commit f8f49e6

Browse files
committed
Add TODOs and ideas from last time.
1 parent ed40260 commit f8f49e6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

semantics/llvm-semantics.k

+30
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ module LLVM-REGISTERS is
424424
<k> Assign(X:Id, V:KResult) => . ...</k>
425425
<registers> M:Map => M[V / X] </registers>
426426

427+
// TODO using constructors in the AST instead of matching on a string
427428
rule [lookup-register]:
428429
<k> X => V ...</k>
429430
<registers>... X |-> V:KResult ...</registers>
@@ -458,6 +459,8 @@ module LLVM-BRANCHING is
458459
</k>
459460
when unsigned(i(1), I) ==Int 0
460461

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
461464
rule [switch-default]:
462465
<k> Switch(_, I:Int, Label:K, listK(.List{K}))
463466
=> Unconditional(Label:K)
@@ -581,10 +584,13 @@ end module
581584
module LLVM-DECLARATIONS is
582585
including LLVM-INCLUDE
583586

587+
// TODO: semantic design pattern: assignment rule
584588
rule
585589
<k> Alias(Name:Id, K:K) => . ...</k>
586590
<globalRegisters> Map:Map => Map[K/Name] </globalRegisters>
587591

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)
588594
rule
589595
<k> Module(Name:Id, TargetLayout:K, TargetTriple:K, Typedefs:K, GlobalVars:K, Aliases:K, Functions:K)
590596
=> Typedefs
@@ -645,6 +651,7 @@ module LLVM-DECLARATIONS is
645651
)
646652
where FUNCTION = FunctionDecl(RetType:KResult, Name:Id, Arguments:K)
647653

654+
// TODO add redundant context for readability (maps)
648655
rule
649656
<k> Body((BasicBlock(Name:Id, K:K),, L:List{K}))
650657
=> BasicBlock(Name:Id, K:K)
@@ -692,6 +699,8 @@ module LLVM-CALL-RET is
692699
// TODO ... on RHS to reset cell
693700
// TODO assuming single module
694701

702+
// TODO perhaps another semantic design pattern: idea of context switching: pushing on a stack, doing something, and then popping from the stack
703+
695704
rule
696705
<k> Call(_, Callee(funptr(FunName:Id), listK(Args:List{K}))) ~> Tail:K
697706
=> contextSwitch(FunName, Tail)
@@ -720,6 +729,7 @@ module LLVM-CALL-RET is
720729
<callStack> . => frame(Tail, C) ...</callStack>
721730

722731

732+
// TODO perhaps a pattern: turning a list of pairs into a map
723733

724734
// might need a way to convert nonmatching types here? depends on semantics
725735
rule
@@ -876,6 +886,9 @@ module LLVM-FLOATING-POINT-ARITHMETIC is
876886
=> F1 *Float F2
877887
...</k>
878888

889+
// TODO incorrect since NaN * 0 = NaN
890+
rule FMul(_, F:#Float, PositiveZero) => 0.0
891+
879892
end module
880893

881894
module LLVM-GEP is
@@ -1023,6 +1036,7 @@ module LLVM-HELPERS-SPLIT-BYTES is
10231036
=> listK(L)
10241037
...</k>
10251038

1039+
// TODO perhaps a pattern: even more localized rewriting: rewriting inside a constructor rather than rewriting the whole thing
10261040
rule
10271041
<k> splitFloatBytes(
10281042
V:KResult,
@@ -1348,6 +1362,9 @@ module LLVM-CONVERSIONS is
13481362
rule
13491363
<k> BitCast(_, Loc:Loc) => Loc:Loc ...</k>
13501364

1365+
//rule
1366+
//<k> BitCast(IntegerType(_), F:#Float) => Float2Int(F) ...</k>
1367+
13511368
// TODO need to normalize here
13521369
rule
13531370
<k> IntToPtr(Type:KResult, K:K) => intToPtr(Type, K:K) ...</k>
@@ -1611,6 +1628,18 @@ module LLVM-INTERNAL-TESTING-FUNCTIONS is
16111628
andBool (I >=Int 0 orBool I <=Int 0) // real integer
16121629
end module
16131630

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+
16141643
module LLVM-SEMANTICS is
16151644
including LLVM-INCLUDE
16161645

@@ -1638,6 +1667,7 @@ module LLVM-SEMANTICS is
16381667
including LLVM-STANDARD-LIBRARY
16391668
including LLVM-SYSCALLS-PREPROCESS
16401669
including LLVM-SYSCALLS
1670+
including LLVM-EXCEPTIONS
16411671

16421672
including LLVM-INTERNAL-TESTING-FUNCTIONS
16431673
end module

0 commit comments

Comments
 (0)