Пример #1
0
   def __init__(self):
      self.ImmediateCode          = [] # unoptimized immediate code
      self.ImmediateCodeOptimized = [] # optimized immediate code
      self.Variables              = []

      self.ArchOutput = Architecture()

      # type:

      # while       begin of a while loop
      #             statement    statement of the header
      #             body         the body of the while loop (is a list)

      # number      (statement) only a number
      #             value        the value of the number

      # TODO< remove this >
      # assigment   asign a new value to a number
      #             variable     the name of the target variable
      #             statement    a statement for the assigment of a new value

      # assigment2       assign the right side to the left
      #                  left          leftside
      #                  right         rightside

      # minusAssigment   -=
      #                  left          leftside
      #                  right         rightside

      # variable         access a variable
      #                  name          the name of the variable

      # mul              multiplication
      #                  left          leftside
      #                  right         rightside

      # div              division
      #                  left          leftside
      #                  right         rightside

      # add              addition
      #                  left          leftside
      #                  right         rightside

      # sub              subtraction
      #                  left          leftside
      #                  right         rightside

      # if               if thing
      #                  statement     the statement
      #                  block         the contained block
      #                  else          None or another block with the else part

      # true             (statement)

      # false            (statement)

      # greaterEqual     (statement)
      #                  left          leftside
      #                  right         rightside

      # TODO< smallerEqual, Equal, Unequal, Smaller, Greater >

      # break            break expression

      # postinc          (statement)
      #                  statement

      # preinc           (statement)
      #                  statement

      # postdec          (statement)
      #                  statement

      # preinc           (statement)
      #                  statement

      # return           (statement)
      #                  expression       is the expression that have to be avaluated, can also be not set (None)
      #                  expressionSet    was the Expression set (True or False)

      # newConstArray    creates a new constant unchangable array
      #                  name             is the name of the array
      #                  info             Typeinformation, is a 'Datatype' Object

      # newVar2          allocates space for a new (scoped) variable
      #                  name             is the Variablename
      #                  info             Typeinformation, is a 'Datatype' Object
      
      # constantFloat    is a contant float
      #                  value            is the floatingpoint value

      """
      self.Root = [
         {"type":"newVar", "name":"Counter", "dataType":0,"bits":32},
         {"type":"assigment2", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":20}},
         {"type":"newVar", "name":"Xn", "dataType":0, "bits":32},
         {"type":"assigment2", "left":{"type":"variable", "name":"Xn"}, "right":{"type":"number", "value":5}},
         {"type":"newVar", "name":"Number", "dataType":0, "bits":32},
         {"type":"assigment2", "left":{"type":"variable", "name":"Number"}, "right":{"type":"number", "value":500}},

         {"type":"while", "statement":{"type":"number", "value":1}, "body":[
            {"type":"minusAssignment", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":1}},
            {"type":"assigment2", "left":{"type":"variable", "name":"Xn"}, "right":{
               "type":"div", "left":{"type":"add", "left":{"type":"variable", "name":"Xn"}, "right":{"type":"div", "left":{"type":"variable", "name":"Number"}, "right":{"type":"variable", "name":"Xn"}}}, "right":{"type":"number", "value":2}
            }}
         ]}
      ]"""

      # algorithm for calculating of the sqrt

      # (examples/calc my sqrt)
      # (is a serial code)
      # works

      """

      Type1 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type1.Bits = 32

      Type2 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type2.Bits = 32

      Type3 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type3.Bits = 32

      self.Root = [
         {"type":"newVar2", "name":"Input", "info":Type1},
         {"type":"assigment2", "left":{"type":"variable", "name":"Input"}, "right":{"type":"number", "value":29}},
         {"type":"newVar2", "name":"Counter", "info":Type2},
         {"type":"assigment2", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":0}},
         {"type":"newVar2", "name":"Old", "info":Type3},
         {"type":"assigment2", "left":{"type":"variable", "name":"Old"}, "right":{"type":"number", "value":0}},
         
         {"type":"while", "statement":{"type":"true"}, "body":[
            {"type":"assigment2", "left":{"type":"variable", "name":"Old"}, "right":{
               "type":"add", "left":{"type":"variable", "name":"Old"}, "right":{
                  "type":"add", "left":{"type":"mul", "left":{"type":"number", "value":2}, "right":{"type":"variable", "name":"Counter"}}, "right":{"type":"number", "value":1}
               }
            }},

            {
               "type":"if",
               "statement":{"type":"greaterEqual", "left":{"type":"variable", "name":"Old"}, "right":{"type":"variable", "name":"Input"}},
               "block":[
                  {"type":"break"}
               ]
            },

            {
               "type":"postinc",
               "statement":{"type":"variable", "name":"Counter"}
            }
         ]}
      ]

      """

      # cordic algorithm

      """
      const fixed6p12 ATanTable[1] = [0.7853981633974483 , 0.4636476090008061,
                                0.24497866312686414, 0.12435499454676144,
                                0.06241880999595735, 0.031239833430268277,
                                0.015623728620476831];
      """

      """
      Type1 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype
      Type1.PrePointBits = 6
      Type1.PostPointBits = 12
      Type1.IsArray = True
      Type1.IsConst = True
      Type1.ArrayValues = [0.7853981633974483 , 0.4636476090008061, 0.24497866312686414, 0.12435499454676144, 0.06241880999595735, 0.031239833430268277, 0.015623728620476831]

      Type2 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype
      Type2.PrePointBits = 6
      Type2.PostPointBits = 12

      Type3 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype
      Type3.PrePointBits = 6
      Type3.PostPointBits = 12

      Type4 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype
      Type4.PrePointBits = 6
      Type4.PostPointBits = 12

      self.Root = [
         {"type":"newConstArray", "name":"ATanTable", "info":Type1},
         {"type":"newVar2", "name":"X", "info":Type2},
         {"type":"assigment2", "left":{"type":"variable", "name":"X"}, "right":{"type":"constantFloat", "value":4.0}},
         {"type":"newVar2", "name":"Y", "info":Type3},
         {"type":"assigment2", "left":{"type":"variable", "name":"Y"}, "right":{"type":"constantFloat", "value":1.0}},
         
         {"type":"newVar2", "name":"Phi", "info":Type4},
         {"type":"assigment2", "left":{"type":"variable", "name":"Phi"}, "right":{"type":"constantFloat", "value":0.907571}}
         
         
      ]
      """

      # Testcode for the parallelistation code

      Type1 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type1.Bits = 32

      Type2 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type2.Bits = 32

      Type3 = Datatype(Datatype.EnumBasetype.UNSIGNED)
      Type3.Bits = 32

      self.Root = [
         {"type":"newVar2", "name":"A", "info":Type1},
         {"type":"newVar2", "name":"B", "info":Type2},
         {"type":"newVar2", "name":"C", "info":Type3},
         
         {"type":"assigment2", "left":{"type":"variable", "name":"A"}, "right":{
            "type":"add", "left":{"type":"variable", "name":"A"}, "right":{"type":"add", "left":{"type":"variable", "name":"B"}, "right":{"type":"variable", "name":"C"}}
         #}}
         }}
      ]


      self.ImmediateCodeObj = ImmediateCode()