From cc530e3446624a1b2c11178711ba23404bd5cedf Mon Sep 17 00:00:00 2001 From: xushiwei Date: Mon, 24 Jun 2024 22:37:53 +0800 Subject: [PATCH] c/raylib demo --- c/raylib/_demo/raylibdemo/raydemo.go | 18 ++++++++ c/raylib/llgo_autogen.lla | Bin 0 -> 404 bytes c/raylib/raylib.go | 43 ++++++++++++++++-- chore/_xtool/astdump/astdump.cpp | 63 +++++++++++++++++++++++++++ chore/_xtool/astdump/build.sh | 2 + 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 c/raylib/_demo/raylibdemo/raydemo.go create mode 100644 c/raylib/llgo_autogen.lla create mode 100644 chore/_xtool/astdump/astdump.cpp create mode 100755 chore/_xtool/astdump/build.sh diff --git a/c/raylib/_demo/raylibdemo/raydemo.go b/c/raylib/_demo/raylibdemo/raydemo.go new file mode 100644 index 00000000..62baabc1 --- /dev/null +++ b/c/raylib/_demo/raylibdemo/raydemo.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/goplus/llgo/c" + "github.com/goplus/llgo/c/raylib" +) + +func main() { + const screenWidth = 800 + const screenHeight = 450 + raylib.InitWindow(screenWidth, screenHeight, c.Str("Raylib DEMO")) + for !raylib.WindowShouldClose() { + raylib.BeginDrawing() + raylib.ClearBackground(raylib.RAYWHITE) + raylib.DrawRectangle(screenWidth/2-50, screenHeight/2-50, 100, 100, raylib.BLUE) + raylib.EndDrawing() + } +} diff --git a/c/raylib/llgo_autogen.lla b/c/raylib/llgo_autogen.lla new file mode 100644 index 0000000000000000000000000000000000000000..634259475150bb26ff019bd0e4c328871129a294 GIT binary patch literal 404 zcmWIWW@Zs#U|`^25ZZhr;`_S;%nyLP3?>E!eg+waoSgLh_{7qZ{Pfg3y_}rT5Kac> z#f_C|OMtkvf}4SnpMAIP8S#E{sa&?hFqq?G&Fizb_{{8PsO;4dblrxBUVpum7H4IOX4$8r-;4$?d1;=D*?T z?|*JO{Aly>7oP2Jtb%9BNG$qnlIk}9McvQ+*X~cdU9I!ktNv$I*Y*8E>4l5|-i%Cg s%(#L|0vKov48X8pSkee$VFVm2B;e2jEx? +#include +#include + +CXChildVisitResult visit(CXCursor c, CXCursor parent, CXClientData client_data); + +void printAST(CXCursor cursor, unsigned int depth = 0) { + CXString cursorKind = clang_getCursorKindSpelling(clang_getCursorKind(cursor)); + CXString cursorSpelling = clang_getCursorSpelling(cursor); + + for (unsigned int i = 0; i < depth; ++i) { + std::cout << " "; + } + + std::cout << clang_getCString(cursorKind) << ": " + << clang_getCString(cursorSpelling) << std::endl; + + clang_disposeString(cursorKind); + clang_disposeString(cursorSpelling); + + CXCursor child; + clang_visitChildren( + cursor, + visit, + &depth + ); +} + +CXChildVisitResult visit(CXCursor c, CXCursor parent, CXClientData client_data) { + unsigned int* depth = (unsigned int*)client_data; + printAST(c, *depth + 1); + return CXChildVisit_Continue; +} + +int main(int argc, char* argv[]) { + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; + } + + CXIndex index = clang_createIndex(0, 0); + CXTranslationUnit unit = clang_parseTranslationUnit( + index, + argv[1], + nullptr, 0, + nullptr, 0, + CXTranslationUnit_None + ); + + if (unit == nullptr) { + std::cerr << "Unable to parse translation unit. Quitting." << std::endl; + return 1; + } + + CXCursor cursor = clang_getTranslationUnitCursor(unit); + std::cout << "AST for " << argv[1] << ":" << std::endl; + printAST(cursor); + + clang_disposeTranslationUnit(unit); + clang_disposeIndex(index); + + return 0; +} \ No newline at end of file diff --git a/chore/_xtool/astdump/build.sh b/chore/_xtool/astdump/build.sh new file mode 100755 index 00000000..d255f327 --- /dev/null +++ b/chore/_xtool/astdump/build.sh @@ -0,0 +1,2 @@ +export LLVM_DIR=/opt/homebrew/Cellar/llvm@17/17.0.6 +clang -L$LLVM_DIR/lib -lclang -lc++ -I$LLVM_DIR/include astdump.cpp