improve cross plateform binary portability
This commit is contained in:
45
.github/workflows/release.yml
vendored
Normal file
45
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Build and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*' # Trigger on any tag push
|
||||
|
||||
jobs:
|
||||
build_and_release:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Python (needed for Conan)
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install Conan
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install conan
|
||||
|
||||
- name: Configure Conan
|
||||
run: |
|
||||
conan profile new default --detect --force
|
||||
conan profile update settings.compiler.libcxx=libstdc++11 default
|
||||
|
||||
- name: Install dependencies and build with Conan
|
||||
run: |
|
||||
conan install . --build=missing
|
||||
conan build .
|
||||
|
||||
- name: Create GitHub Release
|
||||
id: create_release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
tag: ${{ github.ref_name }}
|
||||
name: Release ${{ github.ref_name }}
|
||||
body: |
|
||||
Automated release based on tag ${{ github.ref_name }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -60,4 +60,4 @@ build
|
||||
*.yy.c
|
||||
*.yy.h
|
||||
|
||||
out.car
|
||||
out.arbin
|
||||
@@ -42,7 +42,6 @@ set_target_properties(argon PROPERTIES
|
||||
|
||||
# Step 6: Conan libraries
|
||||
find_package(BDWgc REQUIRED)
|
||||
find_package(cJSON REQUIRED)
|
||||
find_package(gmp REQUIRED)
|
||||
|
||||
target_compile_options(argon PRIVATE -O3 -Wall -Wextra -Wno-unused-function -s)
|
||||
@@ -50,7 +49,6 @@ target_link_options(argon PRIVATE -static)
|
||||
|
||||
target_link_libraries(argon PRIVATE
|
||||
BDWgc::BDWgc
|
||||
cjson::cjson
|
||||
gmp::gmp
|
||||
m
|
||||
)
|
||||
|
||||
4
Makefile
4
Makefile
@@ -3,7 +3,7 @@ LEXER_C = src/lexer/lex.yy.c
|
||||
LEXER_H = src/lexer/lex.yy.h
|
||||
|
||||
CFILES = $(shell find src -name '*.c')
|
||||
CFLAGS = -lm -lcjson -lgc -lgmp -Wall -Wextra -Wno-unused-function
|
||||
CFLAGS = $(ARCHFLAGS) -lm -lgc -lgmp -Wall -Wextra -Wno-unused-function
|
||||
BINARY = bin/argon
|
||||
|
||||
all: $(BINARY)
|
||||
@@ -13,7 +13,7 @@ $(LEXER_C) $(LEXER_H): $(LEXER_SRC)
|
||||
|
||||
$(BINARY): $(CFILES) $(LEXER_C) $(LEXER_H)
|
||||
mkdir -p bin
|
||||
gcc -static -O3 -o $(BINARY) $(CFILES) $(CFLAGS) -s
|
||||
gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) -s
|
||||
|
||||
debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
||||
mkdir -p bin
|
||||
|
||||
@@ -11,13 +11,11 @@ class ArgonConan(ConanFile):
|
||||
# Remove tool_requires, no flex from Conan
|
||||
requires = [
|
||||
"gmp/6.3.0",
|
||||
"cjson/1.7.16",
|
||||
"bdwgc/8.2.8"
|
||||
]
|
||||
|
||||
default_options = {
|
||||
"gmp/*:shared": False,
|
||||
"cjson/*:shared": False,
|
||||
"bdwgc/*:shared": False
|
||||
}
|
||||
|
||||
|
||||
18
src/main.c
18
src/main.c
@@ -5,9 +5,11 @@
|
||||
#include "parser/parser.h"
|
||||
#include "translator/translator.h"
|
||||
|
||||
#include <endian.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -44,11 +46,19 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
darray_free(&ast, free_parsed);
|
||||
|
||||
file = fopen("out.car", "wb");
|
||||
file = fopen("out.arbin", "wb");
|
||||
|
||||
fwrite(&translated.registerCount, sizeof(size_t), 1, file);
|
||||
fwrite(&translated.constants.size, sizeof(size_t), 1, file);
|
||||
fwrite(&translated.bytecode.size, sizeof(size_t), 1, file);
|
||||
uint64_t regCount = (uint64_t)translated.registerCount;
|
||||
uint64_t constantsSize = (uint64_t)translated.constants.size;
|
||||
uint64_t bytecodeSize = (uint64_t)translated.bytecode.size;
|
||||
|
||||
regCount = htole64(regCount);
|
||||
constantsSize = htole64(constantsSize);
|
||||
bytecodeSize = htole64(bytecodeSize);
|
||||
|
||||
fwrite(®Count, sizeof(uint64_t), 1, file);
|
||||
fwrite(&constantsSize, sizeof(uint64_t), 1, file);
|
||||
fwrite(&bytecodeSize, sizeof(uint64_t), 1, file);
|
||||
fwrite(translated.constants.data, 1, translated.constants.size, file);
|
||||
fwrite(translated.bytecode.data, translated.bytecode.element_size,
|
||||
translated.bytecode.size, file);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "../../lexer/token.h"
|
||||
|
||||
#include "../../memory.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -46,12 +46,13 @@ size_t arena_push(ConstantArena *arena, const void *data, size_t length) {
|
||||
Translated init_translator() {
|
||||
Translated translated;
|
||||
translated.registerCount = 0;
|
||||
darray_init(&translated.bytecode, sizeof(size_t));
|
||||
darray_init(&translated.bytecode, sizeof(uint64_t));
|
||||
arena_init(&translated.constants);
|
||||
return translated;
|
||||
}
|
||||
|
||||
size_t push_instruction_code(Translated * translator, size_t code) {
|
||||
size_t push_instruction_code(Translated * translator, uint64_t code) {
|
||||
code = htole64(code);
|
||||
size_t offset = translator->bytecode.size;
|
||||
darray_push(&translator->bytecode, &code);
|
||||
return offset;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../dynamic_array/darray.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "../dynamic_array/darray.h"
|
||||
#include "../parser/parser.h"
|
||||
#include "../memory.h"
|
||||
@@ -26,7 +27,7 @@ void * arena_get(ConstantArena *arena, size_t offset);
|
||||
|
||||
size_t arena_push(ConstantArena *arena, const void *data, size_t length);
|
||||
|
||||
size_t push_instruction_code(Translated * translator, size_t code);
|
||||
size_t push_instruction_code(Translated * translator, uint64_t code);
|
||||
|
||||
void set_registers(Translated * translator, size_t count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user