From 24397e5682514f2988072d7039ed39c08e3ba7ef Mon Sep 17 00:00:00 2001 From: Shagun Agrawal Date: Sun, 8 Dec 2024 21:57:39 +0530 Subject: Add tacky phase for long type generation Tacky phase generation for for long types Refactor expression handling for Tacky phase by using postwalk function Refactor symbol namespaces --- src/cljcc/schema.clj | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'src/cljcc/schema.clj') diff --git a/src/cljcc/schema.clj b/src/cljcc/schema.clj index 9084435..5f86dd8 100644 --- a/src/cljcc/schema.clj +++ b/src/cljcc/schema.clj @@ -52,7 +52,9 @@ [:type [:= :exp]] [:exp-type [:= :cast-exp]] [:target-type #'Type] + [:typed-inner [:ref #'Exp]] [:value [:ref #'Exp]] + [:children [:= [:value]]] [:value-type {:optional true} #'Type]]) (def UnaryExp @@ -61,6 +63,7 @@ [:exp-type [:= :unary-exp]] [:unary-operator `[:enum ~@t/unary-ops]] [:value [:ref #'Exp]] + [:children [:= [:value]]] [:value-type {:optional true} #'Type]]) (def BinaryExp @@ -70,6 +73,7 @@ [:binary-operator `[:enum ~@(set (keys t/bin-ops))]] [:left [:ref #'Exp]] [:right [:ref #'Exp]] + [:children [:= [:left :right]]] [:value-type {:optional true} #'Type]]) (def AssignmentExp @@ -77,6 +81,7 @@ [:type [:= :exp]] [:exp-type [:= :assignment-exp]] [:assignment-operator `[:enum ~@t/assignment-ops]] + [:children [:= [:left :right]]] [:left [:ref #'Exp]] [:right [:ref #'Exp]] [:value-type {:optional true} #'Type]]) @@ -85,6 +90,7 @@ [:map [:type [:= :exp]] [:exp-type [:= :conditional-exp]] + [:children [:= [:left :right :middle]]] [:left [:ref #'Exp]] [:middle [:ref #'Exp]] [:right [:ref #'Exp]] @@ -96,6 +102,7 @@ [:exp-type [:= :function-call-exp]] [:identifier string?] [:arguments [:vector [:ref #'Exp]]] + [:children [:= [:arguments]]] [:value-type {:optional true} #'Type]]) (def Exp @@ -316,3 +323,127 @@ [:map [:ident->symbol #'SymbolMap] [:program #'Program]]) + +(def TackyVar + [:map + [:type [:= :variable]] + [:value string?]]) + +(def TackyConstant + [:map + [:type [:= :constant]] + [:value #'Const]]) + +(def TackyVal + [:schema {:registry {::mtacky-var #'TackyVar + ::mtacky-constant #'TackyConstant}} + [:multi {:dispatch :type} + [:variable #'TackyVar] + [:constant #'TackyConstant]]]) + +(def TackyReturn + [:map + [:type [:= :return]] + [:val #'TackyVal]]) + +(def TackySignExtend + [:map + [:type [:= :sign-extend]] + [:src #'TackyVal] + [:dst #'TackyVal]]) + +(def TackyTruncate + [:map + [:type [:= :truncate]] + [:src #'TackyVal] + [:dst #'TackyVal]]) + +(def TackyUnary + [:map + [:type [:= :unary]] + [:unary-operator `[:enum ~@t/tacky-unary-ops]] + [:src #'TackyVal] + [:dst #'TackyVal]]) + +(def TackyBinary + [:map + [:type [:= :binary]] + [:binary-operator `[:enum ~@t/tacky-binary-ops]] + [:src1 #'TackyVal] + [:src2 #'TackyVal] + [:dst #'TackyVal]]) + +(def TackyCopy + [:map + [:type [:= :copy]] + [:src #'TackyVal] + [:dst #'TackyVal]]) + +(def TackyJump + [:map + [:type [:= :jump]] + [:identifier string?]]) + +(def TackyJumpIfZero + [:map + [:type [:= :jump-if-zero]] + [:val #'TackyVal] + [:identifier string?]]) + +(def TackyJumpIfNotZero + [:map + [:type [:= :jump-if-not-zero]] + [:val #'TackyVal] + [:identifier string?]]) + +(def TackyLabel + [:map + [:type [:= :label]] + [:identifier string?]]) + +(def TackyFunCall + [:map + [:type [:= :fun-call]] + [:identifier string?] + [:arguments [:vector #'TackyVal]] + [:dst #'TackyVal]]) + +(def TackyInstruction + [:multi {:dispatch :type} + [:return #'TackyReturn] + [:sign-extend #'TackySignExtend] + [:truncate #'TackyTruncate] + [:unary #'TackyUnary] + [:binary #'TackyBinary] + [:copy #'TackyCopy] + [:jump #'TackyJump] + [:jump-if-zero #'TackyJumpIfZero] + [:jump-if-not-zero #'TackyJumpIfNotZero] + [:label #'TackyLabel] + [:fun-call #'TackyFunCall]]) + +(def TackyFunction + [:map + [:identifier string?] + [:global? boolean?] + [:type [:= :declaration]] + [:declaration-type [:= :function]] + [:parameters [:vector string?]] + [:instructions [:vector #'TackyInstruction]]]) + +(def TackyStaticVariable + [:map + [:identifier string?] + [:global? boolean?] + [:variable-type #'Type] + [:initial #'Initial] + [:declaration-type [:= :static-variable]] + [:type [:= :declaration]]]) + +(def TackyTopLevel + [:multi {:dispatch :declaration-type} + [:static-variable #'TackyStaticVariable] + [:function #'TackyFunction]]) + +(def TackyProgram + [:vector #'TackyTopLevel]) -- cgit v1.2.3