Skip to content

Commit

Permalink
Merge pull request #282 from andrey-terekhov/llvm
Browse files Browse the repository at this point in the history
LLVM
  • Loading branch information
Victor-Y-Fadeev authored Mar 9, 2022
2 parents 3b4f323 + 1968d97 commit dbc0bd3
Show file tree
Hide file tree
Showing 93 changed files with 3,336 additions and 19 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test on LLVM

on:
- push
- pull_request

jobs:
windows:
name: Windows Server 2019
runs-on: windows-2019
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run script
shell: bash
run: |
patch ./scripts/test.sh < ./scripts/llvm.patch
./scripts/test.sh
ubuntu:
name: Ubuntu 20.04
runs-on: ubuntu-20.04
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run script
run: |
patch ./scripts/test.sh < ./scripts/llvm.patch
./scripts/test.sh
macos:
name: macOS Big Sur 11
runs-on: macos-11
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up environment
run: brew install coreutils
- name: Run script
run: |
patch ./scripts/test.sh < ./scripts/llvm.patch
./scripts/test.sh
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ variables:

stages:
- virtual
- llvm

virtual:
stage: virtual
Expand All @@ -13,3 +14,31 @@ virtual:
- apt-get install -y build-essential cmake git
script:
- ./scripts/test.sh

llvm-intel:
stage: llvm
before_script:
- apt-get update
- apt-get install -y build-essential cmake clang-11 gcc-mipsel-linux-gnu
script:
- patch ./scripts/test.sh < ./scripts/llvm.patch
- ./scripts/test.sh

llvm-baikal:
stage: llvm
before_script:
- apt-get update
- apt-get install -y build-essential cmake clang-11 gcc-mipsel-linux-gnu sshpass
script:
- patch ./scripts/test.sh < ./scripts/llvm-baikal.patch
- ./scripts/test.sh -d

llvm-uemu:
stage: llvm
before_script:
- apt-get update
- apt-get install -y build-essential cmake clang-11 gcc-mipsel-linux-gnu git
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.softcom.su/ruc/uemu ../uemu
script:
- patch ./scripts/test.sh < ./scripts/llvm-uemu.patch
- ./scripts/test.sh -d
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Virtual](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml/badge.svg)](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml)
[![Virtual](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml/badge.svg)](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml) [![LLVM](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml/badge.svg)](https://github.com/andrey-terekhov/RuC/actions/workflows/virtual.yml)
# ![Logo](https://raw.githubusercontent.com/Victor-Y-Fadeev/RuC-WPF/master/RuC.WPF/Images/Repository.png) Russian C

Этот репозиторий содержит компилятор языка RuC.
Expand Down
39 changes: 39 additions & 0 deletions libs/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string.h>
#include "codegen.h"
#include "errors.h"
#include "llvmgen.h"
#include "parser.h"
#include "preprocessor.h"
#include "syntax.h"
Expand Down Expand Up @@ -160,6 +161,10 @@ int compile(workspace *const ws)
{
return compile_to_vm(ws);
}
else if (strcmp(flag, "-LLVM") == 0)
{
return compile_to_llvm(ws);
}
}
}

Expand All @@ -179,6 +184,17 @@ int compile_to_vm(workspace *const ws)
return ret;
}

int compile_to_llvm(workspace *const ws)
{
if (ws_get_output(ws) == NULL)
{
ws_set_output(ws, DEFAULT_LLVM);
}

return compile_from_ws(ws, &encode_to_llvm);
}



int auto_compile(const int argc, const char *const *const argv)
{
Expand All @@ -196,6 +212,14 @@ int auto_compile_to_vm(const int argc, const char *const *const argv)
return ret;
}

int auto_compile_to_llvm(const int argc, const char *const *const argv)
{
workspace ws = ws_parse_args(argc, argv);
const int ret = compile_to_llvm(&ws);
ws_clear(&ws);
return ret;
}


int no_macro_compile_to_vm(const char *const path)
{
Expand All @@ -216,3 +240,18 @@ int no_macro_compile_to_vm(const char *const path)
ws_clear(&ws);
return ret;
}

int no_macro_compile_to_llvm(const char *const path)
{
universal_io io = io_create();
in_set_file(&io, path);

workspace ws = ws_create();
ws_add_file(&ws, path);
ws_set_output(&ws, DEFAULT_LLVM);
out_set_file(&io, ws_get_output(&ws));

const int ret = compile_from_io(&ws, &io, &encode_to_llvm);
ws_clear(&ws);
return ret;
}
28 changes: 28 additions & 0 deletions libs/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ EXPORTED int compile(workspace *const ws);
*/
EXPORTED int compile_to_vm(workspace *const ws);

/**
* Compile LLVM code from workspace
*
* @param ws Compiler workspace
*
* @return Status code
*/
EXPORTED int compile_to_llvm(workspace *const ws);


/**
* Compile code from terminal arguments
Expand All @@ -66,6 +75,16 @@ EXPORTED int auto_compile(const int argc, const char *const *const argv);
*/
EXPORTED int auto_compile_to_vm(const int argc, const char *const *const argv);

/**
* Compile LLVM code from terminal arguments
*
* @param argc Number of command line arguments
* @param argv Command line arguments
*
* @return Status code
*/
EXPORTED int auto_compile_to_llvm(const int argc, const char *const *const argv);


/**
* Compile RuC virtual machine code with no macro
Expand All @@ -76,6 +95,15 @@ EXPORTED int auto_compile_to_vm(const int argc, const char *const *const argv);
*/
EXPORTED int no_macro_compile_to_vm(const char *const path);

/**
* Compile LLVM code with no macro
*
* @param path File path
*
* @return Status code
*/
EXPORTED int no_macro_compile_to_llvm(const char *const path);

#ifdef __cplusplus
} /* extern "C" */
#endif
9 changes: 9 additions & 0 deletions libs/compiler/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,17 @@ static void get_error(const err_t num, char *const msg, va_list args)
case tables_cannot_be_compressed:
sprintf(msg, "невозможно сжать таблицы до заданного размера");
break;

case wrong_init_in_actparam:
sprintf(msg, "в инициализаторе-фактическом параметре функции могут быть только константы");
case array_borders_cannot_be_static_dynamic:
sprintf(msg, "массив не может иметь статические и динамические границы");
break;
case such_array_is_not_supported:
sprintf(msg, "такие массивы пока не поддерживаются в кодогенераторе");
break;
case too_many_arguments:
sprintf(msg, "слишком много аргументов у функции, допустимое количество до 128");
break;

default:
Expand Down
3 changes: 3 additions & 0 deletions libs/compiler/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ typedef enum ERROR
// Codegen errors
tables_cannot_be_compressed,
wrong_init_in_actparam,
array_borders_cannot_be_static_dynamic,
such_array_is_not_supported,
too_many_arguments
} err_t;

/** Warnings codes */
Expand Down
Loading

0 comments on commit dbc0bd3

Please sign in to comment.