Skip to content

Commit

Permalink
Merge pull request #357 from andrey-terekhov/e-flag
Browse files Browse the repository at this point in the history
Flag -E & Actions update
  • Loading branch information
Victor-Y-Fadeev authored Feb 11, 2023
2 parents 3c7d91f + 1aa60ff commit 9da460d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 163 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ jobs:
runs-on: windows-latest
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Build Win32 release
run: |
mkdir build32 && cd build32 && cmake .. -A Win32 && cd ..
Expand Down Expand Up @@ -52,9 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Build release
run: |
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && cd ..
Expand All @@ -76,9 +72,7 @@ jobs:
runs-on: macos-latest
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Build release
run: |
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && cd ..
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ on:

jobs:
sync:
if: github.repository_owner == 'andrey-terekhov'
runs-on: ubuntu-latest
name: Git Repo Sync
env:
target_url: ${{ secrets.TARGET_URL }}
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
if: ${{ env.target_url != '' }}
with:
fetch-depth: 0
- name: Synchronization with GitLab
uses: wangchucheng/[email protected]
if: ${{ env.target_url != '' }}
with:
# Such as https://github.com/wangchucheng/git-repo-sync.git
target-url: ${{ secrets.TARGET_URL }}
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ jobs:
runs-on: windows-2022
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Run script
shell: bash
run: |
Expand All @@ -24,9 +22,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Run script
run: |
patch ./scripts/test.sh < ./scripts/llvm.patch
Expand All @@ -37,9 +33,7 @@ jobs:
runs-on: macos-11
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Set up environment
run: brew install coreutils
- name: Run script
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/virtual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ jobs:
runs-on: windows-2022
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Run script
shell: bash
run: ./scripts/test.sh
Expand All @@ -22,9 +20,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Run script
run: ./scripts/test.sh

Expand All @@ -33,9 +29,7 @@ jobs:
runs-on: macos-11
steps:
- name: GitHub repository checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
uses: actions/checkout@v3
- name: Set up environment
run: brew install coreutils
- name: Run script
Expand Down
35 changes: 0 additions & 35 deletions RuC.sublime-project

This file was deleted.

44 changes: 11 additions & 33 deletions libs/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,6 @@ static inline void make_executable(const char *const path)
#endif
}

/** Skip linker stage */
static inline bool skip_linker(const workspace *const ws)
{
for (size_t i = 0; ; i++)
{
const char *flag = ws_get_flag(ws, i);
if (flag == NULL)
{
return false;
}
else if (strcmp(flag, "-c") == 0)
{
return true;
}
}
}


static status_t compile_from_io(const workspace *const ws, universal_io *const io, const encoder enc)
{
Expand All @@ -90,7 +73,7 @@ static status_t compile_from_io(const workspace *const ws, universal_io *const i
int ret = parse(&sx);
status_t sts = sts_parse_error;

if (!ret && !skip_linker(ws))
if (!ret && !ws_has_flag(ws, "-c")) // Skip linker stage
{
ret = !sx_is_correct(&sx);
sts = sts_link_error;
Expand Down Expand Up @@ -157,22 +140,17 @@ static status_t compile_from_ws(workspace *const ws, const encoder enc)

status_t compile(workspace *const ws)
{
for (size_t i = 0; ; i++)
if (ws_has_flag(ws, "-LLVM"))
{
return compile_to_llvm(ws);
}
else if (ws_has_flag(ws, "-MIPS"))
{
return compile_to_mips(ws);
}
else // if (ws_has_flag(ws, "-VM"))
{
const char *flag = ws_get_flag(ws, i);

if (flag == NULL || strcmp(flag, "-VM") == 0)
{
return compile_to_vm(ws);
}
else if (strcmp(flag, "-LLVM") == 0)
{
return compile_to_llvm(ws);
}
else if (strcmp(flag, "-MIPS") == 0)
{
return compile_to_mips(ws);
}
return compile_to_vm(ws);
}
}

Expand Down
23 changes: 8 additions & 15 deletions libs/compiler/llvmgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3046,22 +3046,15 @@ static int emit_translation_unit(information *const info, const node *const nd)

static void architecture(const workspace *const ws, syntax *const sx)
{
for (size_t i = 0; ; i++)
if (ws_has_flag(ws, "--mipsel"))
{
const char *flag = ws_get_flag(ws, i);

if (flag == NULL || strcmp(flag, "--x86_64") == 0)
{
uni_printf(sx->io, "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n");
uni_printf(sx->io, "target triple = \"x86_64-pc-linux-gnu\"\n\n");
return;
}
else if (strcmp(flag, "--mipsel") == 0)
{
uni_printf(sx->io, "target datalayout = \"e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64\"\n");
uni_printf(sx->io, "target triple = \"mipsel\"\n\n");
return;
}
uni_printf(sx->io, "target datalayout = \"e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64\"\n");
uni_printf(sx->io, "target triple = \"mipsel\"\n\n");
}
else // if (ws_has_flag(ws, "--x86_64"))
{
uni_printf(sx->io, "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n");
uni_printf(sx->io, "target triple = \"x86_64-pc-linux-gnu\"\n\n");
}
}

Expand Down
35 changes: 1 addition & 34 deletions libs/compiler/reporter.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,10 @@
#include <string.h>


/**
* Check if error recovery disabled
*
* @param ws Compiler workspace
*
* @return Recovery status
*/
static inline bool recovery_status(const workspace *const ws)
{
for (size_t i = 0; ; i++)
{
const char *flag = ws_get_flag(ws, i);
if (flag == NULL)
{
return false;
}
else if (strcmp(flag, "-Wno") == 0)
{
return true;
}
}
}


/*
* __ __ __ ______ ______ ______ ______ ______ ______ ______
* /\ \ /\ "-.\ \ /\__ _\ /\ ___\ /\ == \ /\ ___\ /\ __ \ /\ ___\ /\ ___\
* \ \ \ \ \ \-. \ \/_/\ \/ \ \ __\ \ \ __< \ \ __\ \ \ __ \ \ \ \____ \ \ __\
* \ \_\ \ \_\\"\_\ \ \_\ \ \_____\ \ \_\ \_\ \ \_\ \ \_\ \_\ \ \_____\ \ \_____\
* \/_/ \/_/ \/_/ \/_/ \/_____/ \/_/ /_/ \/_/ \/_/\/_/ \/_____/ \/_____/
*/


reporter reporter_create(const workspace *const ws)
{
reporter rprt;
rprt.is_recovery_disabled = recovery_status(ws);
rprt.is_recovery_disabled = ws_has_flag(ws, "-Wno");
rprt.errors = 0;
rprt.warnings = 0;

Expand Down
18 changes: 1 addition & 17 deletions libs/preprocessor/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@
#define MAX_CMT_SIZE MAX_ARG_SIZE + 32


static inline int is_recovery_disabled(const workspace *const ws)
{
for (size_t i = 0; ; i++)
{
const char *flag = ws_get_flag(ws, i);
if (flag == NULL)
{
return 0;
}
else if (strcmp(flag, "-Wno") == 0)
{
return 1;
}
}
}

void env_init(environment *const env, linker *const lk, universal_io *const output)
{
env->output = output;
Expand Down Expand Up @@ -70,7 +54,7 @@ void env_init(environment *const env, linker *const lk, universal_io *const outp
env->error_string[0] = '\0';

env->was_error = 0;
env->disable_recovery = is_recovery_disabled(lk->ws);
env->disable_recovery = ws_has_flag(lk->ws, "-Wno");

for (size_t i = 0; i < HASH; i++)
{
Expand Down
21 changes: 21 additions & 0 deletions libs/utils/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,27 @@ bool ws_is_correct(const workspace *const ws)
return ws != NULL && !ws->was_error;
}

bool ws_has_flag(const workspace *const ws, const char *const flag)
{
if (!ws_is_correct(ws) || flag == NULL)
{
return false;
}

for (size_t i = 0; ; i++)
{
const char *temp = strings_get(&ws->flags, i);
if (temp == NULL)
{
return false;
}
else if (strcmp(temp, flag) == 0)
{
return true;
}
}
}


const char *ws_get_file(const workspace *const ws, const size_t index)
{
Expand Down
10 changes: 10 additions & 0 deletions libs/utils/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ EXPORTED int ws_set_output(workspace *const ws, const char *const path);
*/
EXPORTED bool ws_is_correct(const workspace *const ws);

/**
* Check that workspace contains flag
*
* @param ws Workspace structure
* @param flag Flag to check
*
* @return @c 1 on true, @c 0 on false
*/
EXPORTED bool ws_has_flag(const workspace *const ws, const char *const flag);


/**
* Get file by index from workspase
Expand Down

0 comments on commit 9da460d

Please sign in to comment.