Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Closed

Ir #44

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
e031566
feat: started working on actual IR
Zffu Dec 25, 2024
32f1dd0
feat: added block struct
Zffu Dec 25, 2024
e8c280f
feat: removed old IR
Zffu Dec 25, 2024
e57648a
feat: moved structures into struct header
Zffu Dec 25, 2024
331e604
feat: added IR functions
Zffu Dec 25, 2024
fa95e02
feat: added appendInstruction in header
Zffu Dec 25, 2024
1c2b8e5
feat: added BLOCK_SWAP ir instruction
Zffu Dec 25, 2024
6d27731
feat: added COND_BLOCK_SWAP ir instruction
Zffu Dec 25, 2024
4a31525
feat: added LOGICAL_BLOCK_SWAP ir instruction
Zffu Dec 25, 2024
8f71b1c
feat: added S_ALLOC ir instruction
Zffu Dec 25, 2024
d6e348d
feat: added PTR_SET ir instruction
Zffu Dec 25, 2024
3c874a7
feat: added PTR_LOAD ir instruction
Zffu Dec 25, 2024
445a6c0
feat: added IADD ir instruction
Zffu Dec 25, 2024
6606e88
feat: added ISUB ir instruction
Zffu Dec 25, 2024
639185b
feat: added IMUL ir instruction
Zffu Dec 25, 2024
d4e574d
feat: added IDIV ir instruction
Zffu Dec 25, 2024
42cf342
feat: added ICMP
Zffu Dec 25, 2024
657cd90
feat: added ICMP_H
Zffu Dec 25, 2024
b9a4da6
feat: added ICMP_L
Zffu Dec 25, 2024
1f4a323
feat: added PRM_PUSH
Zffu Dec 25, 2024
ad1f511
feat: added CALL
Zffu Dec 25, 2024
717d721
feat: added RET
Zffu Dec 25, 2024
9c6f855
feat: added docs for block swapping instructions
Zffu Dec 25, 2024
2f4fb53
feat: added docs for memory instructions
Zffu Dec 25, 2024
3f5d8c1
feat: added docs for artimethrics
Zffu Dec 25, 2024
552e3bf
feat: added docs for comparing instructions
Zffu Dec 25, 2024
639af9a
feat: finished adding docs to instructions
Zffu Dec 25, 2024
cfabebd
feat: added RET_PUSH and removed argument of RET
Zffu Dec 25, 2024
2968c71
feat: added enum in appendInstruction
Zffu Dec 25, 2024
5af741c
feat: added parseFunction in header
Zffu Dec 25, 2024
c3b912c
feat: added implementation of appendInstruction
Zffu Dec 25, 2024
6340c63
fix: missing include
Zffu Dec 25, 2024
01b46b9
feat: added basic AST -> IR function (variable dec)
Zffu Dec 26, 2024
c42919b
feat: ast sucks so we remaking it
Zffu Dec 26, 2024
8a9b1d9
feat: added parser header and AST_ROOT_TREE struct
Zffu Dec 26, 2024
4e06b34
feat: added function dec struct
Zffu Dec 26, 2024
80c2014
feat: added AST_TREE_BRANCH struct
Zffu Dec 26, 2024
f72ffff
feat: corrected structs to align with AST_TREE_BRANCh
Zffu Dec 26, 2024
e83bd16
feat: added AST_ASM_FUNCTION_DEC
Zffu Dec 26, 2024
739c961
feat: added AST_PARAMETER struct
Zffu Dec 26, 2024
787a8b1
feat: added AST_FUNCTION_INVOKE struct
Zffu Dec 26, 2024
868cfbb
feat: added AST_VARIABLE_DEC struct
Zffu Dec 26, 2024
fd3a82b
feat: added parseRoot in header
Zffu Dec 26, 2024
9257bf5
feat: added parseVariableDeclaration in header
Zffu Dec 26, 2024
3b91f18
feat: added AST_VARIABLE_MOD struct
Zffu Dec 26, 2024
8759b26
feat: added parseVariableModification in header
Zffu Dec 26, 2024
0cebed9
feat: added TYPE_INT32 token
Zffu Dec 26, 2024
f0a4046
feat: added variable declaration parsing
Zffu Dec 26, 2024
065091e
feat: added AST_VALUE struct
Zffu Dec 26, 2024
875e051
feat: added parseValue in header
Zffu Dec 26, 2024
bc7681a
feat: added parseValue
Zffu Dec 26, 2024
cc41fa2
feat: added parseValueGroup
Zffu Dec 26, 2024
06925b0
feat: added value parsing in variable dec
Zffu Dec 26, 2024
2e11704
feat: added parseVariableModification
Zffu Dec 26, 2024
cb3f081
feat: added base of parseRoot
Zffu Dec 26, 2024
0f7e8ca
feat: added endingIndex in ASt_TREE_BRANCH
Zffu Dec 26, 2024
abccb1b
feat: added endingIndexes on target structures
Zffu Dec 26, 2024
e607477
feat: made structures a bit cleaner
Zffu Dec 26, 2024
0d11dc6
feat: added handling for brackets close when type == AST_FUNC_ROOT
Zffu Dec 26, 2024
5868c73
feat: added parseFunctionDeclaration in header
Zffu Dec 26, 2024
f0f4799
feat: added basic parseFunctionDeclaration
Zffu Dec 26, 2024
57e38fd
feat: added missing ending indexes
Zffu Dec 26, 2024
ddb61df
feat: added argument parsing
Zffu Dec 26, 2024
7e7a27c
feat: made the two function declaration structs castable
Zffu Dec 26, 2024
b049088
feat: added parseParameters in header
Zffu Dec 26, 2024
8b91178
feat: added parseFunctionParameters'
Zffu Dec 26, 2024
9b2ecf5
feat: made parseFunctionParameters to reduce overhead
Zffu Dec 26, 2024
508c18c
feat: made parseFunctionDeclaration use parseFunctionParameters
Zffu Dec 26, 2024
48ee076
feat: added parseASMFunctionDeclaration in header
Zffu Dec 26, 2024
68ac28d
feat: added parseASMFunctionDeclaration
Zffu Dec 26, 2024
45415f2
feat: added function body parsing
Zffu Dec 28, 2024
3f857bb
feat: updated ir function parsing
Zffu Dec 28, 2024
8893f0c
feat: added S_ALLOC ir instruction for variable dec in function IR
Zffu Dec 28, 2024
3cee574
feat: added variable value in IR
Zffu Dec 28, 2024
aabc442
feat: added parseVariableDeclaration in header
Zffu Dec 29, 2024
a4137f4
feat: started moving the ir parsing into thier respective categories
Zffu Dec 29, 2024
7e4bda0
Merge pull request #43 from Quickfall/master
Zffu Dec 29, 2024
b6895cd
feat: added parseValue in header
Zffu Dec 30, 2024
47fd8f5
Merge branch 'ir' of https://github.com/Quickfall/quickfall into ir
Zffu Dec 30, 2024
d470b5a
feat: added parseValue impl
Zffu Dec 30, 2024
1a19162
feat: made parseValue return end index
Zffu Dec 30, 2024
dc220e5
feat: implemented parseVariableDeclaration in new irs file
Zffu Dec 30, 2024
c61f206
feat: added getValueSize header
Zffu Dec 30, 2024
d2ba9e0
feat: added getValueSize
Zffu Dec 30, 2024
cfaced2
feat: added value handling in parseVariableDeclaration
Zffu Dec 30, 2024
2645263
fix: remove broken includes for now
Zffu Dec 30, 2024
2d75804
fix: compiling fixes
Zffu Dec 30, 2024
bd95525
feat: finished moving parseVariableDeclaration
Zffu Dec 30, 2024
b785c4f
feat: moved variable parsing of parseFunction to parseVariableDeclara…
Zffu Jan 1, 2025
afb44cf
feat: removal of invalid and unused stdl for now
Zffu Jan 1, 2025
776de97
chore: made IR_INSTRUCTION_CODE enum typedef cleaner
Zffu Jan 1, 2025
3eb98d2
chore: made IR structures typedef cleaner
Zffu Jan 1, 2025
6b4b87c
feat: added QASM parser header
Zffu Jan 1, 2025
8efe889
feat: started working on QASM parsing
Zffu Jan 1, 2025
9663cc8
feat: parseInstruction in header
Zffu Jan 1, 2025
86c9331
feat: added pushInstruction
Zffu Jan 1, 2025
8f58c84
feat: added space seperator QASM parsing
Zffu Jan 1, 2025
dc7a289
feat: added instruction hash -> code type
Zffu Jan 1, 2025
ff13555
feat: moved qasm parser into parser dir
Zffu Jan 2, 2025
1537c15
feat: added parseInt32
Zffu Jan 2, 2025
521b367
feat: added parseInt32 impl
Zffu Jan 2, 2025
566f9f5
feat: parseVariableName
Zffu Jan 2, 2025
195a6d1
feat: added param parsing for BLOCK_SWAP and COND_BLOCK_SWAP
Zffu Jan 2, 2025
eff013a
feat: added param parsing for LOGICAL_BLOCK_SWAP
Zffu Jan 2, 2025
ad1f1c1
feat: changed param order
Zffu Jan 2, 2025
4c90852
feat: added param parsing for S_ALLOC
Zffu Jan 2, 2025
a3b84cd
feat: added PTR_SET param parsing
Zffu Jan 2, 2025
95ed677
feat: added parsing for the rest of instructions
Zffu Jan 3, 2025
1917679
fix: fixed qasm related issues
Zffu Jan 4, 2025
8b0e3e9
feat: moved parseFunction into the individual ir file
Zffu Jan 4, 2025
67a001e
fix: added missing imports
Zffu Jan 4, 2025
78b7613
feat: added parseASMFunction in header
Zffu Jan 4, 2025
ba2127f
feat: added parseASMFunction impl
Zffu Jan 4, 2025
0773a99
feat: changed IR_FUNCTION -> IR_FUNCTION* ptr
Zffu Jan 4, 2025
eb11966
feat: added parameters in IR_FUNCTION struct
Zffu Jan 4, 2025
0161ce0
feat: changed qasm blocks to be global rather than function definitive
Zffu Jan 5, 2025
dc3abb0
feat: added parseIR in header
Zffu Jan 5, 2025
3ba7951
feat: added parseIR impl
Zffu Jan 8, 2025
9b4ddc8
fix: added forgotten return statement
Zffu Jan 8, 2025
3a9e827
feat: initialized out
Zffu Jan 8, 2025
80419b0
fix: removed unused return statement
Zffu Jan 8, 2025
21b9c17
feat: freed some char buffers
Zffu Jan 8, 2025
8be6ef1
feat: removed debugger call
Zffu Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions lib/winx86-64/lowlevel.qfall

This file was deleted.

19 changes: 5 additions & 14 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include "../compiler/compiler.h"
#include "../compiler/pe/pe.h"
#include "../compiler/ir.h"

#include "../ir/ir.h"

#include "../utils/logging.c"

Expand All @@ -40,8 +41,8 @@ void showCommandEntry(char* commandName, char* description, int argumentCount, c
void showHelpMessage() {
printf("\n%sQuickfall%s - The programming language.\n\nCommands:\n", TEXT_CYAN, RESET);

char** arguments = malloc(5 * 24);
char** argumentDescriptions = malloc(5 * 256);
char** arguments = malloc(4);
char** argumentDescriptions = malloc(125);

arguments[0] = "-p";
argumentDescriptions[0] = "Determines the targeted platform. Defaults to the current platform.";
Expand Down Expand Up @@ -114,17 +115,7 @@ int main(int argc, char* argv[]) {
fclose(fptr);

LEXER_RESULT result = runLexer(buff, size);
AST_NODE* root = parseNodes(result, 0, AST_ROOT);

IR_CTX* ctx = makeContext(root);

if(ctx == NULL) {
printf("Error: the IR context is null! Something went wrong during compiling! Please check any logs for errors\n");
return -1;
}

fptr = fopen(outputFile, "w");
compile(ctx, fptr);
void* root = parseRoot(result, 0, AST_TYPE_ROOT);

break;
case 'v':
Expand Down
171 changes: 1 addition & 170 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,182 +7,13 @@
#include <stdlib.h>

#include "./compiler.h"
#include "./ir.h"

#include "../parser/ast.h"

#include "../utils/hash.h"
#include "../utils/hashmap.h"

#include "./pe/pe.h"

/**
* Parses the AST tree into a context.
* @param tree the AST tree.
*/
IR_CTX* makeContext(AST_NODE* tree) {
IR_CTX* ctx = malloc(sizeof(IR_CTX));

int buffSize = 32;
ctx->nodes = malloc(sizeof(IR_NODE) * 32);

ctx->nodeIndex = 0;
ctx->nodeMap = createHashmap(512,200);

while(tree != NULL) {
switch(tree->type) {
case AST_VARIABLE_DECLARATION:

int hash = hashstr(tree->left->value);

if(hashGet(ctx->nodeMap, hash) != NULL) {
printf("Variable %s is already declared!\n", tree->left->value);
return NULL;
}

IR_NODE* node = createIRNode(IR_VARIABLE, tree->left->value);

node->type = tree->value;

if(tree->right != NULL && tree->right->value) node->value = tree->right->value;

ctx->nodes[ctx->nodeIndex] = node;
ctx->nodeIndex++;

hashPut(ctx->nodeMap, hash, node);

if(ctx->nodeIndex > buffSize) {
buffSize = buffSize * 1.5;
ctx->nodes = realloc(ctx->nodes, buffSize);
}

break;

case AST_FUNCTION_DECLARATION:

hash = hashstr(tree->left->right->value);

if(hashGet(ctx->nodeMap, hash) != NULL) {
printf("Function %s was already declared!\n", tree->left->right->value);
return NULL;
}

node = createIRNode(IR_FUNCTION, tree->left->right->value);

node->type = tree->left->value;

while(tree->left->left->next != NULL) {

IR_NODE* var = createIRNode(IR_FUNCTION_ARGUMENT, tree->right->value);

node->variables[node->variableIndex] = var;
node->variableIndex++;

hashPut(node->variableMap, hashstr(tree->left->left->right->value), var);

tree->left->left = tree->left->left->next;
}

node->tree = tree->right;

ctx->nodes[ctx->nodeIndex] = node;
ctx->nodeIndex++;

hashPut(ctx->nodeMap, hash, node);
break;

case AST_ASM_FUNCTION_DECLARATION:
hash = hashstr(tree->left->right->value);

if(hashGet(ctx->nodeMap, hash) != NULL) {
printf("Assembly function %s is already defined!\n");
return NULL;
}

node = createIRNode(IR_ASM_FUNCTION, tree->left->right->value);

node->value = tree->value;
node->valueSize = tree->valueSize;

while(tree->left->left->next != NULL) {

IR_NODE* var = createIRNode(IR_FUNCTION_ARGUMENT, tree->left->left->right->value);

node->variables[node->variableIndex] = var;
node->variableIndex++;

hashPut(node->variableMap, hashstr(tree->left->left->right->value), var);


tree->left->left = tree->left->left->next;
}

ctx->nodes[ctx->nodeIndex] = node;
ctx->nodeIndex++;

hashPut(ctx->nodeMap, hash, node);

break;

}

tree = tree->next;
}

return ctx;
}

/**
* Compiles the Context tree to an executable named the provided file name.
* @param ctx the IR context.
* @param out the output file.
*/
void compile(IR_CTX* ctx, FILE* out) {

uint8_t* buff = malloc(sizeof(uint8_t) * 512);
int i = 0;

int h = hashstr("main");

if(hashGet(ctx->nodeMap, h) == NULL) {
printf("Error: the main function wasn't defined!\n");
return;
}

IR_NODE* node = hashGet(ctx->nodeMap, h);

if(node->nodeType != IR_FUNCTION) {
printf("Error: main must be a function!\n");
return;
}

while(node->tree != NULL) {

if(node->tree->type == AST_FUNCTION_INVOKE) {

int hash = hashstr(node->tree->value);

IR_NODE* wa = hashGet(ctx->nodeMap, hash);

if(wa == NULL) {
printf("Error: The %s function doesn't exist!\n", node->tree->value);
return;
}

if(wa->nodeType == IR_ASM_FUNCTION) {
unsigned char b;
unsigned char* ptr = (unsigned char*) wa->value;

for(int ii = 0; ii < wa->valueSize; ++ii) {
buff[i] = ptr[ii];
++i;
}
}
}

node->tree = node->tree->next;
}

//todo: change format based on user
compilePE(out, buff, i);
void compile(FILE* out) {
}
13 changes: 1 addition & 12 deletions src/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
#ifndef COMPILER_H
#define COMPILER_H

#include "../utils/hashmap.h"
#include "../parser/ast.h"

#include "./ir.h"

/**
* Parses the AST tree into a context.
* @param tree the AST tree.
*/
IR_CTX* makeContext(AST_NODE* tree);

/**
* Compiles the Context tree to an executable named the provided name.
* @param ctx the IR context.
* @param char the output file.
*/
void compile(IR_CTX* ctx, FILE* outputFileName);
void compile(FILE* outputFileName);

#endif
29 changes: 0 additions & 29 deletions src/compiler/ir.c

This file was deleted.

67 changes: 0 additions & 67 deletions src/compiler/ir.h

This file was deleted.

Loading
Loading