commit 4908c1830ec5c5de990102e1482b4730e1817d0f Author: bʰedoh₂ swé Date: Sat Feb 22 17:40:06 2025 +0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..457218d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +tmp/ +result.rom +result.rom.sym diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d505b73 --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +Copyright (C) 2025 by bedohswe bedohswe@firemail.cc + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..badf440 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +.SUFFIXES: .cc .bc + +CLANG ?= clang +LLVM_CBE ?= llvm-cbe +LLVM ?= llvm +UXNASM ?= uxnasm +SED ?= sed +OPT ?= opt + +CHIBICC_UXN ?= uxn-chibicc + +SRCS = src/main.cc + +.cc.bc: + $(CLANG) -Os $< -o $*.bc -emit-llvm -c --target=avr -Wno-avr-rtlib-linking-quirks -std=c++20 + +result.rom: $(SRCS:.cc=.bc) symbols.bc + mkdir -p tmp/ + $(LLVM)-link $(SRCS:.cc=.bc) -o tmp/unopt.bc + $(OPT) -Os tmp/unopt.bc -o tmp/unclean.bc + $(LLVM)-link --only-needed symbols.bc tmp/unclean.bc -o tmp/linked.bc + $(LLVM_CBE) -O2 tmp/linked.bc -o tmp/linked.cbe.c + $(CLANG) -x c -P -E -include ./on_link.h tmp/linked.cbe.c -o tmp/linked.i + $(CHIBICC_UXN) -O tmp/linked.i > tmp/linked.tal + $(SED) -e 's/;_/;U_/g' -e 's/@_/@U_/g' -e 's/ _/ U_/g' -e '/\( bss \)/,/\( data \)/d' tmp/linked.tal > tmp/result.tal + $(UXNASM) tmp/result.tal result.rom + +all: result.rom + +clean: + rm -rf src/main.bc $(SRCS:.cc=.bc) tmp/ result.rom result.rom.sym diff --git a/README.md b/README.md new file mode 100644 index 0000000..29291a3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +C++ hello for Uxn. +Requires [LLVM CBE](https://github.com/JuliaHubOSS/llvm-cbe/), [chibicc for Uxn](https://github.com/lynn/chibicc), clang. diff --git a/on_link.h b/on_link.h new file mode 100644 index 0000000..8a28440 --- /dev/null +++ b/on_link.h @@ -0,0 +1,7 @@ +#undef __GNUC__ +#define long short +#define __forceinline +#define _MSC_VER +#define const +#define __declspec(a) +#define __assume(a) diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..5343f69 --- /dev/null +++ b/src/main.cc @@ -0,0 +1,9 @@ +#include "uxn.hh" +void print(char *c) { + for (char* i = c; *i != '\0'; i++) + deo2(*i, 0x18); +} + +int main(void) { + print((char*)"Hello, World!\n"); +} diff --git a/src/types.hh b/src/types.hh new file mode 100644 index 0000000..96fcb3d --- /dev/null +++ b/src/types.hh @@ -0,0 +1,4 @@ +#ifndef TYPES_HH +#define TYPES_HH +typedef decltype(sizeof(0)) size_t; +#endif diff --git a/src/uxn.hh b/src/uxn.hh new file mode 100644 index 0000000..2affd0c --- /dev/null +++ b/src/uxn.hh @@ -0,0 +1,9 @@ +#ifndef UXN_HH +#define UXN_HH +extern "C" { + void deo(char data, char device); + void deo2(int data, char device); + char dei(char device); + int dei2(char device); +} +#endif diff --git a/symbols.bc b/symbols.bc new file mode 100644 index 0000000..478b99b Binary files /dev/null and b/symbols.bc differ diff --git a/symbols.cc b/symbols.cc new file mode 100644 index 0000000..234ceb6 --- /dev/null +++ b/symbols.cc @@ -0,0 +1,5 @@ +int main(void); + +extern "C" void* someUselessFunction(void) { + return (void*)main; +}