| author | |
| committer | |
| log | 1d554f3161e7bcf76a180c9280a53cd0f5927591 |
| tree | f89aa7adadee316aab00a2018040cee3dc1c418b |
| parent | 50f0ed918c4f5c70685752188b6a3853fc7205b9 |
5 files changed, 58 insertions(+), 2 deletions(-)
CMakeLists.txt+6-1| ... | @@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING | ... | @@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING |
| 6 | project(zig C) | 6 | project(zig C) |
| 7 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) | 7 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 8 | 8 | ||
| 9 | set(ZIG_VERSION_MAJOR 1) | 9 | set(ZIG_VERSION_MAJOR 0) |
| 10 | set(ZIG_VERSION_MINOR 0) | 10 | set(ZIG_VERSION_MINOR 0) |
| 11 | set(ZIG_VERSION_PATCH 0) | 11 | set(ZIG_VERSION_PATCH 0) |
| 12 | set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}") | 12 | set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}") |
| ... | @@ -15,6 +15,11 @@ message("Configuring zig version ${ZIG_VERSION}") | ... | @@ -15,6 +15,11 @@ message("Configuring zig version ${ZIG_VERSION}") |
| 15 | find_package(llvm) | 15 | find_package(llvm) |
| 16 | include_directories(${LLVM_INCLUDE_DIR}) | 16 | include_directories(${LLVM_INCLUDE_DIR}) |
| 17 | 17 | ||
| 18 | include_directories( | ||
| 19 | ${CMAKE_SOURCE_DIR} | ||
| 20 | ${CMAKE_BINARY_DIR} | ||
| 21 | ) | ||
| 22 | |||
| 18 | set(ZIG_SOURCES | 23 | set(ZIG_SOURCES |
| 19 | "${CMAKE_SOURCE_DIR}/src/main.c" | 24 | "${CMAKE_SOURCE_DIR}/src/main.c" |
| 20 | ) | 25 | ) |
src/main.c+42-1| ... | @@ -1,5 +1,46 @@ | ... | @@ -1,5 +1,46 @@ |
| 1 | #include "config.h" | ||
| 1 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <string.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | |||
| 6 | static int usage(char *arg0) { | ||
| 7 | fprintf(stderr, "Usage: %s --output outfile code.zig\n" | ||
| 8 | "Other options:\n" | ||
| 9 | "--version print version number and exit\n" | ||
| 10 | , arg0); | ||
| 11 | return EXIT_FAILURE; | ||
| 12 | } | ||
| 2 | 13 | ||
| 3 | int main(int argc, char **argv) { | 14 | int main(int argc, char **argv) { |
| 4 | return 0; | 15 | char *arg0 = argv[0]; |
| 16 | char *in_file = NULL; | ||
| 17 | char *out_file = NULL; | ||
| 18 | for (int i = 1; i < argc; i += 1) { | ||
| 19 | char *arg = argv[i]; | ||
| 20 | if (arg[0] == '-' && arg[1] == '-') { | ||
| 21 | if (strcmp(arg, "--version") == 0) { | ||
| 22 | printf("%s\n", ZIG_VERSION_STRING); | ||
| 23 | return EXIT_SUCCESS; | ||
| 24 | } else if (i + 1 >= argc) { | ||
| 25 | return usage(arg0); | ||
| 26 | } else { | ||
| 27 | i += 1; | ||
| 28 | if (strcmp(arg, "--output") == 0) { | ||
| 29 | out_file = argv[i]; | ||
| 30 | } else { | ||
| 31 | return usage(arg0); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } else if (!in_file) { | ||
| 35 | in_file = arg; | ||
| 36 | } else { | ||
| 37 | return usage(arg0); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | if (!in_file || !out_file) | ||
| 42 | return usage(arg0); | ||
| 43 | |||
| 44 | fprintf(stderr, "in: %s out: %s\n", in_file, out_file); | ||
| 45 | return EXIT_SUCCESS; | ||
| 5 | } | 46 | } |
test/add.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | int add(int a, int b); | ||
test/add.zig created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | int add(int a, int b) { | ||
| 2 | return a + b; | ||
| 3 | } | ||
test/hello.zig created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "add.h" | ||
| 3 | |||
| 4 | int main(int argc, char **argv) { | ||
| 5 | fprintf(stderr, "hello: %d", add(1, 2)); | ||
| 6 | } | ||