commit 55efae7c59cfe64fdc46ed5c28bb72a304108256 Author: feng-arch Date: Wed Oct 30 11:29:20 2024 +0800 initial this repos, add template frome students diff --git a/asm_parser.c b/asm_parser.c new file mode 100644 index 0000000..8c7d174 --- /dev/null +++ b/asm_parser.c @@ -0,0 +1,17 @@ +/*************************************************************************** + * file name : asm_parser.c * + * author : * + * description : the functions are declared in asm_parser.h * + * The intention of this library is to parse a .ASM file * + * * + * * + *************************************************************************** + * + */ + +#include +#include +#include +#include "asm_parser.h" + +/* to do - implement all the functions in asm_parser.h */ \ No newline at end of file diff --git a/asm_parser.h b/asm_parser.h new file mode 100644 index 0000000..e1eba35 --- /dev/null +++ b/asm_parser.h @@ -0,0 +1,22 @@ +/*************************************************************************** + * file name : asm_parser.h * + * author : * + * description : this header file declares the functions for those * + * in the "asm_parser.c" library * + * standard "string.h" C-library. * + * * + *************************************************************************** + * + */ + +#define ROWS 100 +#define COLS 255 + +int read_asm_file (char* filename, char program [ROWS][COLS] ) ; +int parse_instruction (char* instr, char* instr_bin_str) ; +int parse_reg (char reg_num, char* instr_bin_str) ; +int parse_add (char* instr, char* instr_bin_str ) ; +int parse_mul (char* instr, char* instr_bin_str ) ; +/* add additional helper functions to support other instructions */ +unsigned short int str_to_bin (char* instr_bin_str) ; +int write_obj_file (char* filename, unsigned short int program_bin[ROWS] ) ; diff --git a/assembler.c b/assembler.c new file mode 100644 index 0000000..849f75c --- /dev/null +++ b/assembler.c @@ -0,0 +1,25 @@ +/*************************************************************************** + * file name : assembler.c * + * author : * + * description : This program will assemble a .ASM file into a .OBJ file * + * This program will use the "asm_parser" library to achieve * + * its functionality. * + * * + *************************************************************************** + * + */ + +#include +#include +#include +#include "asm_parser.h" + +int main(int argc, char** argv) { + + char* filename = NULL ; // name of ASM file + char program [ROWS][COLS] ; // ASM file line-by-line + char program_bin_str [ROWS][17] ; // instructions converted to a binary string + unsigned short int program_bin [ROWS] ; // instructions in binary (HEX) + + +} diff --git a/cpp b/cpp new file mode 100644 index 0000000..c0ac89e Binary files /dev/null and b/cpp differ diff --git a/lcc b/lcc new file mode 100644 index 0000000..2f9dc42 Binary files /dev/null and b/lcc differ diff --git a/libs/.gitkeep b/libs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rcc b/rcc new file mode 100644 index 0000000..b3b0fed Binary files /dev/null and b/rcc differ diff --git a/test1.asm b/test1.asm new file mode 100644 index 0000000..ae0fc24 --- /dev/null +++ b/test1.asm @@ -0,0 +1,7 @@ +ADD R1, R0, R1 +MUL R2, R1, R1 +SUB R3, R2, R1 +DIV R1, R3, R2 +AND R1, R2, R3 +OR R1, R3, R2 +XOR R1, R3, R2 diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/files-validation.cfg b/tests/files-validation.cfg new file mode 100644 index 0000000..989dd12 --- /dev/null +++ b/tests/files-validation.cfg @@ -0,0 +1,5 @@ +# This validation config is autogenerated by buildconfigs.sh script +# Here you can specify files that user has to enter relative to workplace directory. + +# Allowed file types, default "", but can be name of file like: "submit/my_string.c" and similar +ALLOWED_FILE_TYPES="submit/asm_parser.c, submit/assembler.c" diff --git a/tests/runtests.sh b/tests/runtests.sh new file mode 100644 index 0000000..81a7b4f --- /dev/null +++ b/tests/runtests.sh @@ -0,0 +1,36 @@ +#!/bin/bash +cd /home/codio/workspace/tests + +# make sure source code exists +. ./files-validation.cfg +FILES_ALLOWED=$(echo "${ALLOWED_FILE_TYPES}" | tr -d '[:space:]') +VALIDATION_SUCCESSFULL="0" +for file_allowed in $(echo "${FILES_ALLOWED}" | sed -n 1'p' | tr ',' '\n'); do + if [ ! -f "../${file_allowed}" ]; then + echo "Could not find ${file_allowed}, please check if you have uploaded your files" + VALIDATION_SUCCESSFULL="1" + fi +done +if [ "${VALIDATION_SUCCESSFULL}" -eq "1" ]; then + echo "You have missing files, please check if you have uploaded everything that was required" + exit 1 +fi + +echo "No files are missing." +echo "______________________" +echo + +# test compile all .c files +cd /home/codio/workspace +for file_allowed in $(echo "${FILES_ALLOWED}" | sed -n 1'p' | tr ',' '\n'); do + if [[ $file_allowed == *.c ]]; then + file_name="$(cut -d'/' -f2 <<<$file_allowed)" + if clang -c $file_allowed; then + echo "$file_name - Compile successful." + rm "$(cut -d'.' -f1 <<<$file_name)"".o" + else + echo "$file_name - Failed to compile!" + fi + fi +done +echo \ No newline at end of file diff --git a/tests/weights.cfg b/tests/weights.cfg new file mode 100644 index 0000000..3072b5e --- /dev/null +++ b/tests/weights.cfg @@ -0,0 +1,5 @@ +# Score weights for all test classes +# This file has been generated by buildweightsconfig.sh script +# The score weights will work only if you include the weight key as first word of failure message +# The score weight can be set between 0 and infinity points :) +