Stopped using indirect pointer and refactored to temporals
This commit is contained in:
parent
1234b8ddcd
commit
34d4697aa9
3 changed files with 74 additions and 83 deletions
|
|
@ -46,7 +46,7 @@ globalIndex2 = 0
|
||||||
# Adds a symbol to the symbols table.
|
# Adds a symbol to the symbols table.
|
||||||
|
|
||||||
|
|
||||||
def addSymbol(name, symbolType, value = 0):
|
def addSymbol(name, symbolType, value=0):
|
||||||
global currentIndex
|
global currentIndex
|
||||||
symbols[name] = {
|
symbols[name] = {
|
||||||
'type': symbolType,
|
'type': symbolType,
|
||||||
|
|
@ -55,9 +55,7 @@ def addSymbol(name, symbolType, value = 0):
|
||||||
'dimension1': globalDimension1,
|
'dimension1': globalDimension1,
|
||||||
'dimension2': globalDimension2,
|
'dimension2': globalDimension2,
|
||||||
}
|
}
|
||||||
if globalDimensionalSize != 1:
|
currentIndex += globalDimensionalSize
|
||||||
symbols[name]['indirectPointer'] = f'${currentIndex + globalDimensionalSize}'
|
|
||||||
currentIndex += 1 if globalDimensionalSize == 1 else globalDimensionalSize + 1
|
|
||||||
|
|
||||||
# Returns the last item of a list without deleting it.
|
# Returns the last item of a list without deleting it.
|
||||||
|
|
||||||
|
|
@ -460,7 +458,7 @@ def p_action_1(p):
|
||||||
dimension1 = symbols[p[-2]]['dimension1']
|
dimension1 = symbols[p[-2]]['dimension1']
|
||||||
dimension2 = symbols[p[-2]]['dimension2']
|
dimension2 = symbols[p[-2]]['dimension2']
|
||||||
if dimension2 is not 0:
|
if dimension2 is not 0:
|
||||||
indirectPointer = symbols[p[-2]]['indirectPointer']
|
indirectPointer = avail.pop(0)
|
||||||
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
if isDirection(globalIndex1) or isDirection(globalIndex2):
|
||||||
resultQuadruplets.append(
|
resultQuadruplets.append(
|
||||||
f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
f'* {globalIndex1} {dimension1} {indirectPointer}\n')
|
||||||
|
|
@ -478,7 +476,7 @@ def p_action_1(p):
|
||||||
globalIndex1 = 0
|
globalIndex1 = 0
|
||||||
globalIndex2 = 0
|
globalIndex2 = 0
|
||||||
elif dimension1 is not 0:
|
elif dimension1 is not 0:
|
||||||
indirectPointer = symbols[p[-2]]['indirectPointer']
|
indirectPointer = avail.pop(0)
|
||||||
if isDirection(globalIndex1):
|
if isDirection(globalIndex1):
|
||||||
resultQuadruplets.append(
|
resultQuadruplets.append(
|
||||||
f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
f'+ {direction} {globalIndex1} {indirectPointer}\n')
|
||||||
|
|
@ -530,9 +528,9 @@ def p_action_4(p):
|
||||||
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_5(p):
|
def p_action_5(p):
|
||||||
|
|
@ -558,9 +556,9 @@ def p_action_6(p):
|
||||||
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_8(p):
|
def p_action_8(p):
|
||||||
|
|
@ -578,7 +576,9 @@ def p_action_8(p):
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
# Return the operand to the availbale if it is a temporal.
|
# Return the operand to the availbale if it is a temporal.
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
|
if (isTemp(operand1)):
|
||||||
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_9(p):
|
def p_action_9(p):
|
||||||
|
|
@ -599,9 +599,9 @@ def p_action_9(p):
|
||||||
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_10(p):
|
def p_action_10(p):
|
||||||
|
|
@ -627,9 +627,9 @@ def p_action_11(p):
|
||||||
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_12(p):
|
def p_action_12(p):
|
||||||
|
|
@ -660,9 +660,9 @@ def p_action_14(p):
|
||||||
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
operator) + ' ' + str(operand1) + ' ' + str(operand2) + ' ' + str(temp) + '\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_15(p):
|
def p_action_15(p):
|
||||||
|
|
@ -698,7 +698,7 @@ def p_action_17(p):
|
||||||
resultQuadruplets.append('gotoF ' + str(operand1) + ' _\n')
|
resultQuadruplets.append('gotoF ' + str(operand1) + ' _\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_18(p):
|
def p_action_18(p):
|
||||||
|
|
@ -786,7 +786,7 @@ def p_action_25(p):
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
# Return the operand to the availbale if it is a temporal.
|
# Return the operand to the availbale if it is a temporal.
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_26(p):
|
def p_action_26(p):
|
||||||
|
|
@ -810,9 +810,9 @@ def p_action_26(p):
|
||||||
resultQuadruplets.append(f'gotoF {str(temp)} _\n')
|
resultQuadruplets.append(f'gotoF {str(temp)} _\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
if (isTemp(operand2)):
|
if (isTemp(operand2)):
|
||||||
avail = [operand2] + avail
|
avail = [operand2.replace('*', '$')] + avail
|
||||||
if (isTemp(operand1)):
|
if (isTemp(operand1)):
|
||||||
avail = [operand1] + avail
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_27(p):
|
def p_action_27(p):
|
||||||
|
|
@ -880,10 +880,13 @@ def p_action_32(p):
|
||||||
def p_action_33(p):
|
def p_action_33(p):
|
||||||
"action_33 :"
|
"action_33 :"
|
||||||
global quadrupletIndex
|
global quadrupletIndex
|
||||||
|
global avail
|
||||||
operand1 = operandsStack.pop()
|
operand1 = operandsStack.pop()
|
||||||
typesStack.pop()
|
typesStack.pop()
|
||||||
resultQuadruplets.append(f'print {operand1}\n')
|
resultQuadruplets.append(f'print {operand1}\n')
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
if (isTemp(operand1)):
|
||||||
|
avail = [operand1.replace('*', '$')] + avail
|
||||||
|
|
||||||
|
|
||||||
def p_action_34(p):
|
def p_action_34(p):
|
||||||
|
|
@ -941,8 +944,6 @@ def p_action_41(p):
|
||||||
quadrupletIndex += 1
|
quadrupletIndex += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def p_action_setDim1(p):
|
def p_action_setDim1(p):
|
||||||
"action_setDim1 :"
|
"action_setDim1 :"
|
||||||
global globalIndex1
|
global globalIndex1
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,13 @@
|
||||||
program test
|
program test
|
||||||
integer [10][10] :: a
|
integer [10][10] :: a
|
||||||
integer :: i, j, counter
|
integer :: i, j, counter
|
||||||
subroutine fillMatrix
|
i = 1
|
||||||
counter = 1
|
j = 2
|
||||||
do i = 0, 9 then
|
a(i) = 1
|
||||||
do j = 0, 9 then
|
a(j) = 2
|
||||||
a(i,j) = counter
|
print 'a(i) = ', a(i), endline
|
||||||
counter = counter + 1
|
print 'a(j) = ', a(j), endline
|
||||||
end do
|
a(i) = a(j) + a(i)
|
||||||
end do
|
print 'a(i) = ', a(i), endline
|
||||||
end subroutine
|
i = j + 2
|
||||||
subroutine printMatrix
|
|
||||||
do i = 0, 9 then
|
|
||||||
do j = 0, 9 then
|
|
||||||
print a(i,j), ' '
|
|
||||||
end do
|
|
||||||
print endline
|
|
||||||
end do
|
|
||||||
end subroutine
|
|
||||||
fillMatrix()
|
|
||||||
printMatrix()
|
|
||||||
end program
|
end program
|
||||||
|
|
@ -1,42 +1,42 @@
|
||||||
goto 41
|
goto 2
|
||||||
= 1 $153
|
= 1 $150
|
||||||
= 0 $151
|
= 2 $151
|
||||||
<= $151 9 $0
|
* $150 10 $0
|
||||||
gotoF $0 21
|
+ 0 $0 $0
|
||||||
= 0 $152
|
+ 50 $0 $0
|
||||||
<= $152 9 $1
|
= 1 *0
|
||||||
gotoF $1 18
|
* $151 10 $0
|
||||||
* $151 10 $150
|
+ 0 $0 $0
|
||||||
+ $152 $150 $150
|
+ 50 $0 $0
|
||||||
+ 50 $150 $150
|
= 2 *0
|
||||||
= $153 *150
|
print 'a(i) = '
|
||||||
+ $153 1 $2
|
* $150 10 $0
|
||||||
= $2 $153
|
+ 0 $0 $0
|
||||||
+ $152 1 $2
|
+ 50 $0 $0
|
||||||
= $2 $152
|
print *0
|
||||||
goto 7
|
|
||||||
+ $151 1 $2
|
|
||||||
= $2 $151
|
|
||||||
goto 4
|
|
||||||
goback
|
|
||||||
= 0 $151
|
|
||||||
<= $151 9 $2
|
|
||||||
gotoF $2 40
|
|
||||||
= 0 $152
|
|
||||||
<= $152 9 $3
|
|
||||||
gotoF $3 36
|
|
||||||
* $151 10 $150
|
|
||||||
+ $152 $150 $150
|
|
||||||
+ 50 $150 $150
|
|
||||||
print *150
|
|
||||||
print ' '
|
|
||||||
+ $152 1 $4
|
|
||||||
= $4 $152
|
|
||||||
goto 26
|
|
||||||
print endline
|
print endline
|
||||||
+ $151 1 $4
|
print 'a(j) = '
|
||||||
= $4 $151
|
* $151 10 $0
|
||||||
goto 23
|
+ 0 $0 $0
|
||||||
goback
|
+ 50 $0 $0
|
||||||
call 2
|
print *0
|
||||||
call 22
|
print endline
|
||||||
|
* $150 10 $0
|
||||||
|
+ 0 $0 $0
|
||||||
|
+ 50 $0 $0
|
||||||
|
* $151 10 $1
|
||||||
|
+ 0 $1 $1
|
||||||
|
+ 50 $1 $1
|
||||||
|
* $150 10 $2
|
||||||
|
+ 0 $2 $2
|
||||||
|
+ 50 $2 $2
|
||||||
|
+ *1 *2 $3
|
||||||
|
= $3 *0
|
||||||
|
print 'a(i) = '
|
||||||
|
* $150 10 $0
|
||||||
|
+ 0 $0 $0
|
||||||
|
+ 50 $0 $0
|
||||||
|
print *0
|
||||||
|
print endline
|
||||||
|
+ $151 2 $0
|
||||||
|
= $0 $150
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue