Skip to content

Commit

Permalink
feature: mir string & array work now
Browse files Browse the repository at this point in the history
  • Loading branch information
park671 committed Nov 5, 2024
1 parent 7f1046b commit c86e81a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions compiler/mir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ static const char *convertArithmeticOpString(MirOperator mirOperator) {
return "/";
case OP_MOD:
return "%";
case OP_ADR:
return "[adr]";
case OP_DREF:
return "[deref]";
case OP_ASSIGNMENT:
return "=";
case OP_UNKNOWN:
Expand Down Expand Up @@ -289,7 +293,7 @@ void printMirCode(MirCode *mirCode) {
switch (mirCode->mirType) {
case MIR_2: {
if (mirCode->mir2->distType.primitiveType < 3) {
loge(MIR_TAG, "error!");
loge(MIR_TAG, "mir2 error!");
}
logd(MIR_TAG, "type %d: %s %s %s",
mirCode->mir2->distType,
Expand All @@ -301,7 +305,7 @@ void printMirCode(MirCode *mirCode) {
}
case MIR_3: {
if (mirCode->mir2->distType.primitiveType < 3) {
loge(MIR_TAG, "error!");
loge(MIR_TAG, "mir3 error!");
}
logd(MIR_TAG, "type %d: %s = %s %s %s",
mirCode->mir3->distType,
Expand Down Expand Up @@ -1397,5 +1401,7 @@ Mir *generateMir(AstProgram *program) {
}
mir->mirMethod = firstMirMethod;
mir->methodSize = methodSize;
mir->mirData = firstMirData;
mir->dataSize = mirDataLine;
return mir;
}
3 changes: 2 additions & 1 deletion compiler/syntaxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ Token *travelAst(Token *token, void *currentNode, AstNodeType nodeType) {
array->next = nullptr;
} else {
array->next = (AstArrayData*)pccMalloc(SYNTAX_TAG, sizeof(AstArrayData));
array = array->next;
}
}
//consume this string
Expand Down Expand Up @@ -685,7 +686,7 @@ Token *travelAst(Token *token, void *currentNode, AstNodeType nodeType) {
case NODE_ARRAY_DATA: {
AstArrayData* astArrayData = (AstArrayData*) currentNode;
token = travelAst(token, &astArrayData->data, NODE_PRIMITIVE_DATA);
if (strcmp(token->content, ",") != 0) {
if (strcmp(token->content, ",") == 0) {
//consume ,
token = token->next;
astArrayData->next = (AstArrayData*) pccMalloc(SYNTAX_TAG, sizeof(AstArrayData));
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ int main(int argc, char **argv) {
Mir *mir = generateMir(program);
releaseAstMemory();
mir = optimize(mir, optimizationLevel);
printMir(mir);
generateTargetFile(mir,
targetArch,
targetPlatform,
Expand Down

0 comments on commit c86e81a

Please sign in to comment.