Commit 1d554f3161
Changed files (5)
src/main.c
@@ -1,5 +1,46 @@
+#include "config.h"
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static int usage(char *arg0) {
+ fprintf(stderr, "Usage: %s --output outfile code.zig\n"
+ "Other options:\n"
+ "--version print version number and exit\n"
+ , arg0);
+ return EXIT_FAILURE;
+}
int main(int argc, char **argv) {
- return 0;
+ char *arg0 = argv[0];
+ char *in_file = NULL;
+ char *out_file = NULL;
+ for (int i = 1; i < argc; i += 1) {
+ char *arg = argv[i];
+ if (arg[0] == '-' && arg[1] == '-') {
+ if (strcmp(arg, "--version") == 0) {
+ printf("%s\n", ZIG_VERSION_STRING);
+ return EXIT_SUCCESS;
+ } else if (i + 1 >= argc) {
+ return usage(arg0);
+ } else {
+ i += 1;
+ if (strcmp(arg, "--output") == 0) {
+ out_file = argv[i];
+ } else {
+ return usage(arg0);
+ }
+ }
+ } else if (!in_file) {
+ in_file = arg;
+ } else {
+ return usage(arg0);
+ }
+ }
+
+ if (!in_file || !out_file)
+ return usage(arg0);
+
+ fprintf(stderr, "in: %s out: %s\n", in_file, out_file);
+ return EXIT_SUCCESS;
}
test/add.h
@@ -0,0 +1,1 @@
+int add(int a, int b);
test/add.zig
@@ -0,0 +1,3 @@
+int add(int a, int b) {
+ return a + b;
+}
test/hello.zig
@@ -0,0 +1,6 @@
+#include <stdio.h>
+#include "add.h"
+
+int main(int argc, char **argv) {
+ fprintf(stderr, "hello: %d", add(1, 2));
+}
CMakeLists.txt
@@ -6,7 +6,7 @@ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
project(zig C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
-set(ZIG_VERSION_MAJOR 1)
+set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 0)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
@@ -15,6 +15,11 @@ message("Configuring zig version ${ZIG_VERSION}")
find_package(llvm)
include_directories(${LLVM_INCLUDE_DIR})
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_BINARY_DIR}
+)
+
set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/main.c"
)