diff --git a/cinc.xcodeproj/project.pbxproj b/cinc.xcodeproj/project.pbxproj index 4809f4b..ffca562 100644 --- a/cinc.xcodeproj/project.pbxproj +++ b/cinc.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 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 */; }; - F661C33C2145DF370021FCCE /* out.s in Sources */ = {isa = PBXBuildFile; fileRef = F661C33B2145DF370021FCCE /* out.s */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -29,6 +28,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + F606D3182145FAB300E817B6 /* out.mys */ = {isa = PBXFileReference; lastKnownFileType = text; path = out.mys; sourceTree = ""; }; 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 = ""; }; @@ -41,7 +41,6 @@ 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 = ""; }; - F661C33B2145DF370021FCCE /* out.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = out.s; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -85,7 +84,7 @@ F661C3352145CE760021FCCE /* ast.c */, F661C3372145D9C40021FCCE /* generate.h */, F661C3382145D9C40021FCCE /* generate.c */, - F661C33B2145DF370021FCCE /* out.s */, + F606D3182145FAB300E817B6 /* out.mys */, ); path = cinc; sourceTree = ""; @@ -147,7 +146,6 @@ buildActionMask = 2147483647; files = ( F65A954E21454B31005FCAF5 /* token.c in Sources */, - F661C33C2145DF370021FCCE /* out.s in Sources */, F661C3362145CE760021FCCE /* ast.c in Sources */, F61910692142A8C5003B8798 /* tokenize.c in Sources */, F661C333214590930021FCCE /* parser.c in Sources */, diff --git a/cinc/main.c b/cinc/main.c index 77a17b9..c6bb859 100644 --- a/cinc/main.c +++ b/cinc/main.c @@ -14,14 +14,36 @@ #include "parser.h" #include "generate.h" +#define PARSER_DEBUG 0 + int main(int argc, const char * argv[]) { - char* prgstr="int main() {\nreturn 0;\n}"; + char* prgstr="int main() {\n return 173;\n}\n"; + if (PARSER_DEBUG) { + printf("Program:\n"); + printf("%s",prgstr); + } Token* tokens=tokenize(prgstr); + if (PARSER_DEBUG) { + printf("Tokens:\n"); + Token* tok=tokens; + while (tok) { + print_tok(tok); + tok=tok->next; + } + } AstNode* ast=parse(tokens); free_toklist(tokens); + if (PARSER_DEBUG) { + printf("AST:\n"); + print_tree(ast, 0); + } char* prg=generate_prg(ast); free_tree(ast); - FILE* outfile=fopen("/Users/peterterpstra/Desktop/projects/xcode/cinc/cinc/out.s","w"); + if (PARSER_DEBUG) { + printf("Output assembly:\n"); + printf("%s",prg); + } + FILE* outfile=fopen("/Users/peterterpstra/Desktop/projects/xcode/cinc/cinc/out.mys","w"); fputs(prg, outfile); fclose(outfile); free(prg); diff --git a/cinc/out.s b/cinc/out.mys similarity index 66% rename from cinc/out.s rename to cinc/out.mys index f64fe9f..3a33c22 100644 --- a/cinc/out.s +++ b/cinc/out.mys @@ -1,4 +1,4 @@ .globl _main _main: -mov rax,0 +mov rax,173 ret