Small fixes to assembly output
This commit is contained in:
parent
734bc049e7
commit
39756f4e89
|
@ -226,15 +226,27 @@ int AssembleTree(struct ASTNode* Node, int Register, int LoopBeginLabel, int Loo
|
||||||
return AsShiftRight(LeftVal, RightVal);
|
return AsShiftRight(LeftVal, RightVal);
|
||||||
|
|
||||||
case OP_POSTINC:
|
case OP_POSTINC:
|
||||||
|
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
|
||||||
|
return AsLdLocalVar(Node->Symbol, Node->Operation);
|
||||||
|
else
|
||||||
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
||||||
|
|
||||||
case OP_POSTDEC:
|
case OP_POSTDEC:
|
||||||
|
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
|
||||||
|
return AsLdLocalVar(Node->Symbol, Node->Operation);
|
||||||
|
else
|
||||||
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
||||||
|
|
||||||
case OP_PREINC:
|
case OP_PREINC:
|
||||||
|
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
|
||||||
|
return AsLdLocalVar(Node->Symbol, Node->Operation);
|
||||||
|
else
|
||||||
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
||||||
|
|
||||||
case OP_PREDEC:
|
case OP_PREDEC:
|
||||||
|
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
|
||||||
|
return AsLdLocalVar(Node->Symbol, Node->Operation);
|
||||||
|
else
|
||||||
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
return AsLdGlobalVar(Node->Symbol, Node->Operation);
|
||||||
|
|
||||||
case OP_BOOLNOT:
|
case OP_BOOLNOT:
|
||||||
|
@ -562,7 +574,7 @@ int AsShl(int Register, int Val) {
|
||||||
*/
|
*/
|
||||||
int AsLdGlobalVar(struct SymbolTableEntry* Entry, int Operation) {
|
int AsLdGlobalVar(struct SymbolTableEntry* Entry, int Operation) {
|
||||||
int Reg = RetrieveRegister();
|
int Reg = RetrieveRegister();
|
||||||
|
printf("\tGlobally storing a %s\n", ScopeNames[Entry->Storage]);
|
||||||
printf("\tStoring %s's contents into %s, globally\n", Entry->Name, Registers[Reg]);
|
printf("\tStoring %s's contents into %s, globally\n", Entry->Name, Registers[Reg]);
|
||||||
|
|
||||||
int TypeSize = PrimitiveSize(Entry->Type);
|
int TypeSize = PrimitiveSize(Entry->Type);
|
||||||
|
|
|
@ -178,7 +178,7 @@ struct ASTNode* AccessArray() {
|
||||||
|
|
||||||
LeftNode = ConstructASTNode(OP_ADD, Entry->Type, LeftNode, NULL, RightNode, NULL, 0);
|
LeftNode = ConstructASTNode(OP_ADD, Entry->Type, LeftNode, NULL, RightNode, NULL, 0);
|
||||||
printf("\tAccessArray: Preparing LeftNode for dereference.\r\n");
|
printf("\tAccessArray: Preparing LeftNode for dereference.\r\n");
|
||||||
LeftNode = ConstructASTBranch(OP_DEREF, ValueAt(LeftNode->ExprType), LeftNode, NULL, 0);
|
LeftNode = ConstructASTBranch(OP_DEREF, ValueAt(LeftNode->ExprType), LeftNode, Entry, 0);
|
||||||
printf("\tArray Access constructed\r\n");
|
printf("\tArray Access constructed\r\n");
|
||||||
return LeftNode;
|
return LeftNode;
|
||||||
}
|
}
|
||||||
|
|
32
tests/sieve.er
Normal file
32
tests/sieve.er
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import "tests/import/defs.eh"
|
||||||
|
|
||||||
|
long num[100];
|
||||||
|
int :: main() {
|
||||||
|
long i;
|
||||||
|
i = 0;
|
||||||
|
long j;
|
||||||
|
j = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 100; i++) {
|
||||||
|
num[i] = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; (num[i] * num[i]) <= 100; i++) {
|
||||||
|
if (num[i] != 0) {
|
||||||
|
for (j = num[i] * num[i]; j <= 100; j = num[i] + j) {
|
||||||
|
num[j - 1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Finding primes 2..%d\n\n",100);
|
||||||
|
|
||||||
|
for (i = 1; i < 100; i++) {
|
||||||
|
if (num[i] != 0) {
|
||||||
|
printf("%d\t", num[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user