diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a5addf --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +out.s +out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3623322 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -Wall -g +SRCS = $(wildcard *.c */*.c */*/*.c) +OBJS = $(SRCS:.c=.o) +MAIN = cinc +.PHONY: clean +all: $(MAIN) +$(MAIN): $(OBJS) + $(CC) $(CFLAGS) -o $(MAIN) $(OBJS) +run: $(MAIN) + ./$(MAIN) +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ +clean: + $(RM) *.o *~ $(MAIN) out out.s diff --git a/cinc/ast.c b/ast.c similarity index 100% rename from cinc/ast.c rename to ast.c diff --git a/cinc/ast.h b/ast.h similarity index 100% rename from cinc/ast.h rename to ast.h diff --git a/cinc.xcodeproj/project.pbxproj b/cinc.xcodeproj/project.pbxproj deleted file mode 100644 index ed49c86..0000000 --- a/cinc.xcodeproj/project.pbxproj +++ /dev/null @@ -1,323 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 50; - objects = { - -/* Begin PBXBuildFile section */ - F61910612142A876003B8798 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = F61910602142A876003B8798 /* main.c */; }; - F61910692142A8C5003B8798 /* tokenize.c in Sources */ = {isa = PBXBuildFile; fileRef = F61910682142A8C5003B8798 /* tokenize.c */; }; - F62F6C0D214B1BFC00EDE8D2 /* func.c in Sources */ = {isa = PBXBuildFile; fileRef = F62F6C0C214B1BFC00EDE8D2 /* func.c */; }; - F6544B112147F086002C78F7 /* env.c in Sources */ = {isa = PBXBuildFile; fileRef = F6544B102147F086002C78F7 /* env.c */; }; - F65A954E21454B31005FCAF5 /* token.c in Sources */ = {isa = PBXBuildFile; fileRef = F65A954D21454B31005FCAF5 /* token.c */; }; - F661C333214590930021FCCE /* parser.c in Sources */ = {isa = PBXBuildFile; fileRef = F661C332214590930021FCCE /* parser.c */; }; - F661C3362145CE760021FCCE /* ast.c in Sources */ = {isa = PBXBuildFile; fileRef = F661C3352145CE760021FCCE /* ast.c */; }; - F661C3392145D9C40021FCCE /* generate.c in Sources */ = {isa = PBXBuildFile; fileRef = F661C3382145D9C40021FCCE /* generate.c */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - F619105B2142A876003B8798 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - F619105D2142A876003B8798 /* cinc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cinc; sourceTree = BUILT_PRODUCTS_DIR; }; - F61910602142A876003B8798 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; - F61910672142A8C5003B8798 /* tokenize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tokenize.h; sourceTree = ""; }; - F61910682142A8C5003B8798 /* tokenize.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tokenize.c; sourceTree = ""; }; - F62F6C0B214B1BFC00EDE8D2 /* func.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = func.h; sourceTree = ""; }; - F62F6C0C214B1BFC00EDE8D2 /* func.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = func.c; sourceTree = ""; }; - F6544B0F2147F086002C78F7 /* env.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = env.h; sourceTree = ""; }; - F6544B102147F086002C78F7 /* env.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = env.c; sourceTree = ""; }; - F65A954D21454B31005FCAF5 /* token.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = token.c; sourceTree = ""; }; - F661C331214590930021FCCE /* parser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = parser.h; sourceTree = ""; }; - F661C332214590930021FCCE /* parser.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = parser.c; sourceTree = ""; }; - F661C3342145CE760021FCCE /* ast.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ast.h; sourceTree = ""; }; - F661C3352145CE760021FCCE /* ast.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ast.c; sourceTree = ""; }; - F661C3372145D9C40021FCCE /* generate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = generate.h; sourceTree = ""; }; - F661C3382145D9C40021FCCE /* generate.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = generate.c; sourceTree = ""; }; - F661C33A2145DE300021FCCE /* token.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = token.h; sourceTree = ""; }; - F6B6C137214712F3008F5230 /* oplist.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = oplist.txt; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - F619105A2142A876003B8798 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - F61910542142A876003B8798 = { - isa = PBXGroup; - children = ( - F619105F2142A876003B8798 /* cinc */, - F619105E2142A876003B8798 /* Products */, - ); - sourceTree = ""; - }; - F619105E2142A876003B8798 /* Products */ = { - isa = PBXGroup; - children = ( - F619105D2142A876003B8798 /* cinc */, - ); - name = Products; - sourceTree = ""; - }; - F619105F2142A876003B8798 /* cinc */ = { - isa = PBXGroup; - children = ( - F61910602142A876003B8798 /* main.c */, - F61910672142A8C5003B8798 /* tokenize.h */, - F61910682142A8C5003B8798 /* tokenize.c */, - F65A954D21454B31005FCAF5 /* token.c */, - F661C33A2145DE300021FCCE /* token.h */, - F661C331214590930021FCCE /* parser.h */, - F661C332214590930021FCCE /* parser.c */, - F661C3342145CE760021FCCE /* ast.h */, - F661C3352145CE760021FCCE /* ast.c */, - F661C3372145D9C40021FCCE /* generate.h */, - F661C3382145D9C40021FCCE /* generate.c */, - F62F6C0B214B1BFC00EDE8D2 /* func.h */, - F62F6C0C214B1BFC00EDE8D2 /* func.c */, - F6B6C137214712F3008F5230 /* oplist.txt */, - F6544B0F2147F086002C78F7 /* env.h */, - F6544B102147F086002C78F7 /* env.c */, - ); - path = cinc; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - F619105C2142A876003B8798 /* cinc */ = { - isa = PBXNativeTarget; - buildConfigurationList = F61910642142A876003B8798 /* Build configuration list for PBXNativeTarget "cinc" */; - buildPhases = ( - F61910592142A876003B8798 /* Sources */, - F619105A2142A876003B8798 /* Frameworks */, - F619105B2142A876003B8798 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = cinc; - productName = cinc; - productReference = F619105D2142A876003B8798 /* cinc */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - F61910552142A876003B8798 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0940; - ORGANIZATIONNAME = "Peter Terpstra"; - TargetAttributes = { - F619105C2142A876003B8798 = { - CreatedOnToolsVersion = 9.4.1; - }; - }; - }; - buildConfigurationList = F61910582142A876003B8798 /* Build configuration list for PBXProject "cinc" */; - compatibilityVersion = "Xcode 9.3"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = F61910542142A876003B8798; - productRefGroup = F619105E2142A876003B8798 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - F619105C2142A876003B8798 /* cinc */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - F61910592142A876003B8798 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F65A954E21454B31005FCAF5 /* token.c in Sources */, - F6544B112147F086002C78F7 /* env.c in Sources */, - F661C3362145CE760021FCCE /* ast.c in Sources */, - F62F6C0D214B1BFC00EDE8D2 /* func.c in Sources */, - F61910692142A8C5003B8798 /* tokenize.c in Sources */, - F661C333214590930021FCCE /* parser.c in Sources */, - F661C3392145D9C40021FCCE /* generate.c in Sources */, - F61910612142A876003B8798 /* main.c in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - F61910622142A876003B8798 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - F61910632142A876003B8798 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - }; - name = Release; - }; - F61910652142A876003B8798 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - "EXCLUDED_SOURCE_FILE_NAMES[arch=*]" = out.s; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - F61910662142A876003B8798 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - "EXCLUDED_SOURCE_FILE_NAMES[arch=*]" = out.s; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - F61910582142A876003B8798 /* Build configuration list for PBXProject "cinc" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F61910622142A876003B8798 /* Debug */, - F61910632142A876003B8798 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - F61910642142A876003B8798 /* Build configuration list for PBXNativeTarget "cinc" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F61910652142A876003B8798 /* Debug */, - F61910662142A876003B8798 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = F61910552142A876003B8798 /* Project object */; -} diff --git a/cinc.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/cinc.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 8a4b50a..0000000 --- a/cinc.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/cinc.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/cinc.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/cinc.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index fe2b454..0000000 --- a/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcschemes/xcschememanagement.plist b/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index e10c83c..0000000 --- a/cinc.xcodeproj/xcuserdata/peterterpstra.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - SchemeUserState - - cinc.xcscheme - - orderHint - 0 - - - - diff --git a/cinc/out.s b/cinc/out.s deleted file mode 100644 index 3e34a97..0000000 --- a/cinc/out.s +++ /dev/null @@ -1,41 +0,0 @@ -.globl _main -_main: -push rbp -mov rbp,rsp -mov rax,0 -push rax -mov rax,0 -push rax -l0: -mov rax,[rbp-16] -push rax -mov rax,7 -pop rcx -cmp rcx,rax -mov rax,0 -setl al -je l1 -mov rax,[rbp-8] -push rax -mov rax,2 -pop rcx -add rax,rcx -mov [rbp-8],rax -add rsp,0 -l2: -mov rax,[rbp-16] -inc rax -mov [rbp-16],rax -dec rax -jmp l0 -l1: -add rsp,8 -mov rax,[rbp-8] -mov rsp,rbp -pop rbp -ret -add rsp,8 -mov rax,0 -mov rsp,rbp -pop rbp -ret diff --git a/cinc/env.c b/env.c similarity index 100% rename from cinc/env.c rename to env.c diff --git a/cinc/env.h b/env.h similarity index 100% rename from cinc/env.h rename to env.h diff --git a/cinc/func.c b/func.c similarity index 100% rename from cinc/func.c rename to func.c diff --git a/cinc/func.h b/func.h similarity index 100% rename from cinc/func.h rename to func.h diff --git a/cinc/generate.c b/generate.c similarity index 100% rename from cinc/generate.c rename to generate.c diff --git a/cinc/generate.h b/generate.h similarity index 100% rename from cinc/generate.h rename to generate.h diff --git a/cinc/main.c b/main.c similarity index 84% rename from cinc/main.c rename to main.c index 5b651cf..d0e7493 100644 --- a/cinc/main.c +++ b/main.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "tokenize.h" #include "ast.h" #include "parser.h" @@ -42,10 +43,11 @@ int main(int argc, const char * argv[]) { printf("%s",prg); #endif FILE* outfile=fopen("/Users/peterterpstra/Desktop/projects/xcode/cinc/cinc/out.s","w"); - //compile with gcc -masm=intel out.s -o out fputs(prg, outfile); fclose(outfile); free(prg); free_tree(ast); free_toklist(tokens); + execlp("gcc","gcc","-masm=intel","-o","/Users/peterterpstra/Desktop/projects/xcode/cinc/cinc/out","/Users/peterterpstra/Desktop/projects/xcode/cinc/cinc/out.s",(char*)NULL); + perror("cinc"); } diff --git a/cinc/oplist.txt b/oplist.txt similarity index 100% rename from cinc/oplist.txt rename to oplist.txt diff --git a/cinc/parser.c b/parser.c similarity index 100% rename from cinc/parser.c rename to parser.c diff --git a/cinc/parser.h b/parser.h similarity index 100% rename from cinc/parser.h rename to parser.h diff --git a/cinc/token.c b/token.c similarity index 100% rename from cinc/token.c rename to token.c diff --git a/cinc/token.h b/token.h similarity index 100% rename from cinc/token.h rename to token.h diff --git a/cinc/tokenize.c b/tokenize.c similarity index 100% rename from cinc/tokenize.c rename to tokenize.c diff --git a/cinc/tokenize.h b/tokenize.h similarity index 100% rename from cinc/tokenize.h rename to tokenize.h