Small fixes to assembly output

This commit is contained in:
Curle 2022-03-06 02:28:42 +00:00
parent 734bc049e7
commit 39756f4e89
3 changed files with 50 additions and 6 deletions

View File

@ -226,16 +226,28 @@ int AssembleTree(struct ASTNode* Node, int Register, int LoopBeginLabel, int Loo
return AsShiftRight(LeftVal, RightVal);
case OP_POSTINC:
return AsLdGlobalVar(Node->Symbol, Node->Operation);
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
return AsLdLocalVar(Node->Symbol, Node->Operation);
else
return AsLdGlobalVar(Node->Symbol, Node->Operation);
case OP_POSTDEC:
return AsLdGlobalVar(Node->Symbol, Node->Operation);
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
return AsLdLocalVar(Node->Symbol, Node->Operation);
else
return AsLdGlobalVar(Node->Symbol, Node->Operation);
case OP_PREINC:
return AsLdGlobalVar(Node->Symbol, Node->Operation);
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
return AsLdLocalVar(Node->Symbol, Node->Operation);
else
return AsLdGlobalVar(Node->Symbol, Node->Operation);
case OP_PREDEC:
return AsLdGlobalVar(Node->Symbol, Node->Operation);
if (Node->Symbol->Storage == SC_LOCAL || Node->Symbol->Storage == SC_PARAM)
return AsLdLocalVar(Node->Symbol, Node->Operation);
else
return AsLdGlobalVar(Node->Symbol, Node->Operation);
case OP_BOOLNOT:
return AsBooleanNOT(LeftVal);
@ -562,7 +574,7 @@ int AsShl(int Register, int Val) {
*/
int AsLdGlobalVar(struct SymbolTableEntry* Entry, int Operation) {
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]);
int TypeSize = PrimitiveSize(Entry->Type);

View File

@ -178,7 +178,7 @@ struct ASTNode* AccessArray() {
LeftNode = ConstructASTNode(OP_ADD, Entry->Type, LeftNode, NULL, RightNode, NULL, 0);
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");
return LeftNode;
}

32
tests/sieve.er Normal file
View 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);
}