Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shen, Siran
wacc
Commits
9b834d88
Commit
9b834d88
authored
Mar 18, 2021
by
徐世桐
Browse files
sx119: passed function simple, scope and function nested to be debugged
parent
c8d7da4b
Changes
6
Hide whitespace changes
Inline
Side-by-side
scripts/constantPropagationTest.sh
View file @
9b834d88
...
...
@@ -25,11 +25,9 @@ for folder in ${VALID_EXAMPLES[@]}; do
echo
$file
./compile
-t
-o1
$file
>
"
${
EXECUTABLE_FILE_NAME
}
.log.txt"
mv
"
${
EXECUTABLE_FILE_NAME
}
.log.txt"
"
${
VALID_EXAMPLES_SRC_DIR
}${
folder
}
/
${
FILE_NAME
}
.log"
# if diff "${EXECUTABLE_FILE_NAME}.log.txt" "${VALID_EXAMPLES_SRC_DIR}${folder}/${FILE_NAME}.log" -I scope; then
# (( COUNTER += 1 ))
# fi
if
diff
"
${
EXECUTABLE_FILE_NAME
}
.log.txt"
"
${
VALID_EXAMPLES_SRC_DIR
}${
folder
}
/
${
FILE_NAME
}
.log"
-I
scope
;
then
((
COUNTER +
=
1
))
fi
echo
"
$COUNTER
/
$((
$TOTAL_COUNT
))
files have been executed"
...
...
src/backend/intel/IntelInstructionGenerator.java
View file @
9b834d88
...
...
@@ -74,20 +74,9 @@ import static backend.arm.instructions.STR.StrMode.STRB;
import
static
backend
.
arm
.
instructions
.
addressing
.
AddressingMode2
.
AddrMode2
.
OFFSET
;
import
static
backend
.
arm
.
instructions
.
addressing
.
AddressingMode2
.
AddrMode2
.
PREINDEX
;
import
static
backend
.
arm
.
instructions
.
arithmeticLogic
.
ARMArithmeticLogic
.
armUnopAsm
;
import
static
utils
.
Utils
.
ARM_POINTER_SIZE
;
import
static
utils
.
Utils
.
BOOL_BASIC_TYPE
;
import
static
utils
.
Utils
.
CHAR_ARRAY_TYPE
;
import
static
utils
.
Utils
.
CHAR_BASIC_TYPE
;
import
static
utils
.
Utils
.
FALSE
;
import
static
utils
.
Utils
.
FUNC_HEADER
;
import
static
utils
.
Utils
.
INTEL_POINTER_SIZE
;
import
static
utils
.
Utils
.
INT_BASIC_TYPE
;
import
static
utils
.
Utils
.*;
import
static
utils
.
Utils
.
RoutineInstruction
.
CHECK_NULL_POINTER
;
import
static
utils
.
Utils
.
STRING_BASIC_TYPE
;
import
static
utils
.
Utils
.
SystemCallInstruction
.
MALLOC
;
import
static
utils
.
Utils
.
TRUE
;
import
static
utils
.
Utils
.
WORD_SIZE
;
import
static
utils
.
Utils
.
intToIntelSize
;
import
static
utils
.
backend
.
Cond
.
E
;
import
static
utils
.
backend
.
Cond
.
EQ
;
import
static
utils
.
backend
.
Cond
.
NE
;
...
...
@@ -112,6 +101,10 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
private
int
currParamListSize
;
/* stack size of current scope, not including parameter and for-init statement stack size
* at entry of visitScope, it is stack size of parent scopeNode, if no parent, equal to 0 */
private
int
currentScopeStackSize
;
public
IntelInstructionGenerator
()
{
branchLabelGenerator
=
new
LabelGenerator
<>(
".L"
,
Label
.
class
);
dataLabelGenerator
=
new
LabelGenerator
<>(
".LC"
,
Label
.
class
);
...
...
@@ -119,6 +112,7 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
dataSection
=
new
LinkedHashMap
<>();
biDataSection
=
new
LinkedHashMap
<>();
currParamListSize
=
0
;
currentScopeStackSize
=
0
;
}
@Override
...
...
@@ -270,13 +264,14 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
// todo: 1 mov should be consistent with moved in parameter size,
// 2 should move to stack below rsp, prevent overwrite variable in using by main body
System
.
out
.
println
(
"in function call"
);
for
(
int
i
=
paramNum
-
1
;
i
>=
0
;
i
--)
{
ExprNode
expr
=
params
.
get
(
i
);
visit
(
expr
);
IntelConcreteRegister
reg
=
intelRegAllocator
.
curr
();
int
size
=
expr
.
getType
().
getSize
();
instructions
.
add
(
new
Sub
(
size
,
IntelInstructionSize
.
Q
,
r
b
p
));
instructions
.
add
(
new
Mov
(
reg
.
withSize
(
intToIntelSize
.
get
(
size
)),
new
IntelAddress
(
r
b
p
)));
instructions
.
add
(
new
Sub
(
size
,
IntelInstructionSize
.
Q
,
r
s
p
));
instructions
.
add
(
new
Mov
(
reg
.
withSize
(
intToIntelSize
.
get
(
size
)),
new
IntelAddress
(
r
s
p
)));
intelRegAllocator
.
free
();
...
...
@@ -290,7 +285,7 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
/* 3 add back stack pointer */
if
(
paramSize
>
0
)
{
instructions
.
add
(
new
Add
(
paramSize
,
IntelInstructionSize
.
Q
,
r
b
p
));
instructions
.
add
(
new
Add
(
paramSize
,
IntelInstructionSize
.
Q
,
r
s
p
));
}
/* 4 get result, put in a general register */
...
...
@@ -307,6 +302,10 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
System
.
out
.
println
(
"offset "
+
currSymbolTable
.
getStackOffset
(
node
.
getName
(),
node
.
getSymbol
()));
System
.
out
.
println
(
"paramList size "
+
currParamListSize
);
System
.
out
.
println
(
"stack offset"
+
stackOffset
);
System
.
out
.
println
(
"ident size "
+
identTypeSize
);
System
.
out
.
print
(
"ident type "
);
node
.
getType
().
showType
();
System
.
out
.
println
();
System
.
out
.
println
();
int
offset
=
currSymbolTable
.
getStackOffset
(
node
.
getName
(),
node
.
getSymbol
())
-
currParamListSize
+
stackOffset
;
...
...
@@ -467,7 +466,7 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
/* TODO: add intel move type here */
int
offset
=
node
.
getScope
().
lookup
(
node
.
getIdentifier
()).
getStackOffset
();
int
offset
=
node
.
getScope
().
lookup
(
node
.
getIdentifier
()).
getStackOffset
()
-
currParamListSize
;
instructions
.
add
(
new
Mov
(
intelRegAllocator
.
curr
().
withSize
(
intToIntelSize
.
get
(
identTypeSize
)),
new
IntelAddress
(
rbp
,
-
offset
)));
intelRegAllocator
.
free
();
...
...
@@ -555,7 +554,7 @@ public class IntelInstructionGenerator extends InstructionGenerator<IntelInstruc
private
final
Map
<
Type
,
String
>
printTypeStringMap
=
Map
.
of
(
INT_BASIC_TYPE
,
"%d"
,
CHAR_BASIC_TYPE
,
"%c"
,
STRING_BASIC_TYPE
,
"%s"
,
STRING_BASIC_TYPE
_INTEL
,
"%s"
,
CHAR_ARRAY_TYPE
,
"%s"
);
...
...
src/frontend/SemanticChecker.java
View file @
9b834d88
...
...
@@ -361,8 +361,8 @@ public class SemanticChecker extends WACCParserBaseVisitor<Node> {
/* ARM: initialise as -4 byte in order to leave space for PUSH {lr},
which takes up 4 bute on stack
intel:
rbp is assigned after push, so all
*/
int
tempStackAddr
=
this
.
arch
.
equals
(
AssemblyArchitecture
.
ARMv6
)
?
-
WORD_SIZE
:
-
QUAD_SIZE
;
intel:
one QUAD size is for PC, one QUAD size is for rbp pushed
*/
int
tempStackAddr
=
this
.
arch
.
equals
(
AssemblyArchitecture
.
ARMv6
)
?
-
WORD_SIZE
:
-
2
*
QUAD_SIZE
;
List
<
IdentNode
>
params
=
funcNode
.
getParamList
();
int
paramNum
=
params
.
size
();
...
...
@@ -1258,6 +1258,9 @@ public class SemanticChecker extends WACCParserBaseVisitor<Node> {
@Override
public
Node
visitStringType
(
StringTypeContext
ctx
)
{
if
(
arch
.
equals
(
AssemblyArchitecture
.
Intelx86
))
{
return
new
TypeDeclareNode
(
STRING_BASIC_TYPE_INTEL
);
}
return
new
TypeDeclareNode
(
STRING_BASIC_TYPE
);
}
...
...
src/frontend/node/stat/ScopeNode.java
View file @
9b834d88
...
...
@@ -76,6 +76,10 @@ public class ScopeNode extends StatNode {
isForStat
=
true
;
}
public
boolean
isAvoidSubStack
()
{
return
avoidSubStack
;
}
public
int
getStackSize
()
{
if
(
avoidSubStack
)
{
return
0
;
...
...
src/frontend/type/BasicType.java
View file @
9b834d88
...
...
@@ -49,6 +49,8 @@ public class BasicType implements Type {
case
INT:
return
WORD_SIZE
;
case
STRING:
System
.
out
.
println
(
"using intel string = "
+
INTEL_POINTER_SIZE
);
System
.
out
.
println
(
"arch is "
+
arch
.
name
());
return
arch
.
equals
(
AssemblyArchitecture
.
ARMv6
)
?
Utils
.
ARM_POINTER_SIZE
:
Utils
.
INTEL_POINTER_SIZE
;
default
:
throw
new
IllegalArgumentException
(
"unsupported base type enum: "
+
basicTypeEnum
);
...
...
src/utils/Utils.java
View file @
9b834d88
...
...
@@ -37,6 +37,7 @@ public class Utils {
public
static
final
Type
BOOL_BASIC_TYPE
=
new
BasicType
(
BasicTypeEnum
.
BOOL
,
AssemblyArchitecture
.
ARMv6
);
public
static
final
Type
CHAR_BASIC_TYPE
=
new
BasicType
(
BasicTypeEnum
.
CHAR
,
AssemblyArchitecture
.
ARMv6
);
public
static
final
Type
STRING_BASIC_TYPE
=
new
BasicType
(
BasicTypeEnum
.
STRING
,
AssemblyArchitecture
.
ARMv6
);
public
static
final
Type
STRING_BASIC_TYPE_INTEL
=
new
BasicType
(
BasicTypeEnum
.
STRING
,
AssemblyArchitecture
.
Intelx86
);
public
static
final
Type
ARRAY_TYPE
=
new
ArrayType
(
AssemblyArchitecture
.
ARMv6
);
public
static
final
Type
PAIR_TYPE
=
new
PairType
(
AssemblyArchitecture
.
ARMv6
);
public
static
final
Type
STRUCT_TYPE
=
new
StructType
(
""
,
AssemblyArchitecture
.
ARMv6
);
...
...
@@ -46,11 +47,11 @@ public class Utils {
/* a list of allowed types in read, free, cmp statement */
public
static
final
Set
<
Type
>
readStatAllowedTypes
=
new
HashSet
<>(
Arrays
.
asList
(
STRING_BASIC_TYPE
,
INT_BASIC_TYPE
,
CHAR_BASIC_TYPE
));
Arrays
.
asList
(
STRING_BASIC_TYPE
,
INT_BASIC_TYPE
,
CHAR_BASIC_TYPE
,
STRING_BASIC_TYPE_INTEL
));
public
static
final
Set
<
Type
>
freeStatAllowedTypes
=
new
HashSet
<>(
Arrays
.
asList
(
ARRAY_TYPE
,
PAIR_TYPE
,
STRUCT_TYPE
));
public
static
final
Set
<
Type
>
cmpStatAllowedTypes
=
new
HashSet
<>(
Arrays
.
asList
(
STRING_BASIC_TYPE
,
INT_BASIC_TYPE
,
CHAR_BASIC_TYPE
));
Arrays
.
asList
(
STRING_BASIC_TYPE
,
INT_BASIC_TYPE
,
CHAR_BASIC_TYPE
,
STRING_BASIC_TYPE_INTEL
));
/* mapping from string literals to internal representations of UnopEnum and Type */
public
static
final
Map
<
String
,
Unop
>
unopEnumMapping
=
Map
.
of
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment