Add IR quadruple definitions

This commit is contained in:
Eugen Wissner 2024-08-12 21:00:52 +02:00
parent 38a8d6811c
commit f78592378a
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 47 additions and 2 deletions

View File

@ -31,6 +31,7 @@ library elna-internal
import: warnings import: warnings
exposed-modules: exposed-modules:
Language.Elna.AST Language.Elna.AST
Language.Elna.Intermediate
Language.Elna.Location Language.Elna.Location
Language.Elna.NameAnalysis Language.Elna.NameAnalysis
Language.Elna.Parser Language.Elna.Parser

View File

@ -0,0 +1,44 @@
module Language.Elna.Intermediate
( Label(..)
, Operand(..)
, Quadruple(..)
, Variable(..)
) where
import Data.Int (Int32)
import Data.Word (Word32)
import Data.Text (Text)
data Operand
= VariableOperand Text
| IntOperand Int32
deriving (Eq, Show)
newtype Label = Label Text
deriving (Eq, Show)
newtype Variable = Variable Text
deriving (Eq, Show)
data Quadruple
= StartQuadruple
| GoToQuadruple Label
| AssignQuadruple Operand Variable
| ArrayQuadruple Variable Word32 Variable
| ArrayAssignQuadruple Operand Word32 Variable
| AddQuadruple Operand Operand Variable
| SubtractionQuadruple Operand Operand Variable
| ProductQuadruple Operand Operand Variable
| DivisionQuadruple Operand Operand Variable
| NegationQuadruple Operand Variable
| EqualQuadruple Operand Operand Label
| NonEqualQuadruple Operand Operand Label
| LessQuadruple Operand Operand Label
| GreaterQuadruple Operand Operand Label
| LessOrEqualQuadruple Operand Operand Label
| GreaterOrEqualQuadruple Operand Operand Label
| LabelQuadruple Label
| ParameterQuadruple Operand
| CallQuadruple Variable Word32
| StopQuadruple
deriving (Eq, Show)

View File

@ -57,7 +57,7 @@ spec = describe "nameAnalysis" $ do
it "puts parameters into the local symbol table" $ do it "puts parameters into the local symbol table" $ do
let given = "proc main(ref param: int) {}" let given = "proc main(ref param: int) {}"
expected = SymbolTable.enter "param" (VariableInfo intType True) SymbolTable.empty expected = SymbolTable.enter "param" (VariableInfo True intType) SymbolTable.empty
actual <- nameAnalysisOnText given actual <- nameAnalysisOnText given
case SymbolTable.lookup "main" <$> actual of case SymbolTable.lookup "main" <$> actual of
@ -68,7 +68,7 @@ spec = describe "nameAnalysis" $ do
it "puts variables into the local symbol table" $ do it "puts variables into the local symbol table" $ do
let given = "proc main() { var var1: int; }" let given = "proc main() { var var1: int; }"
expected = SymbolTable.enter "var1" (VariableInfo intType False) SymbolTable.empty expected = SymbolTable.enter "var1" (VariableInfo False intType) SymbolTable.empty
actual <- nameAnalysisOnText given actual <- nameAnalysisOnText given
case SymbolTable.lookup "main" <$> actual of case SymbolTable.lookup "main" <$> actual of