rename "parsec" to "translate-c"

master
Andrew Kelley 2017-11-24 14:56:05 -05:00
parent afbbdb2c67
commit 5a25505668
13 changed files with 47 additions and 47 deletions

View File

@ -339,7 +339,7 @@ set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/target.cpp"
"${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"
"${CMAKE_SOURCE_DIR}/src/util.cpp"
"${CMAKE_SOURCE_DIR}/src/parsec.cpp"
"${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
)

View File

@ -58,5 +58,5 @@ pub fn build(b: &Builder) {
test_step.dependOn(tests.addCompileErrorTests(b, test_filter));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter));
test_step.dependOn(tests.addDebugSafetyTests(b, test_filter));
test_step.dependOn(tests.addParseCTests(b, test_filter));
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
}

View File

@ -22,4 +22,4 @@ make install
./zig build --build-file ../build.zig test-compile-errors --verbose
./zig build --build-file ../build.zig test-asm-link --verbose
./zig build --build-file ../build.zig test-debug-safety --verbose
./zig build --build-file ../build.zig test-parsec --verbose
./zig build --build-file ../build.zig test-translate-c --verbose

View File

@ -208,7 +208,7 @@ fn printUsage(outstream: &io.OutStream) -> %void {
\\ build-exe [source] create executable from source or object files
\\ build-lib [source] create library from source or object files
\\ build-obj [source] create object from source or assembly
\\ parsec [source] convert c code to zig code
\\ translate-c [source] convert c code to zig code
\\ targets list available compilation targets
\\ test [source] create and run a test build
\\ version print version number and exit

View File

@ -28,7 +28,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
if (node->owner->c_import_node != nullptr) {
// if this happens, then parsec generated code that
// if this happens, then translate_c generated code that
// failed semantic analysis, which isn't supposed to happen
ErrorMsg *err = add_node_error(g, node->owner->c_import_node,
buf_sprintf("compiler bug: @cImport generated invalid zig code"));
@ -48,7 +48,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg) {
if (node->owner->c_import_node != nullptr) {
// if this happens, then parsec generated code that
// if this happens, then translate_c generated code that
// failed semantic analysis, which isn't supposed to happen
Buf *note_path = buf_create_from_str("?.c");

View File

@ -15,7 +15,7 @@
#include "ir.hpp"
#include "link.hpp"
#include "os.hpp"
#include "parsec.hpp"
#include "translate_c.hpp"
#include "target.hpp"
#include "zig_llvm.hpp"
@ -5353,7 +5353,7 @@ static void init(CodeGen *g) {
define_builtin_compile_vars(g);
}
void codegen_parsec(CodeGen *g, Buf *full_path) {
void codegen_translate_c(CodeGen *g, Buf *full_path) {
find_libc_include_path(g);
Buf *src_basename = buf_alloc();

View File

@ -56,7 +56,7 @@ PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir,
void codegen_add_assembly(CodeGen *g, Buf *path);
void codegen_add_object(CodeGen *g, Buf *object_path);
void codegen_parsec(CodeGen *g, Buf *path);
void codegen_translate_c(CodeGen *g, Buf *path);
#endif

View File

@ -11,7 +11,7 @@
#include "ir.hpp"
#include "ir_print.hpp"
#include "os.hpp"
#include "parsec.hpp"
#include "translate_c.hpp"
#include "range_set.hpp"
#include "softfloat.hpp"

View File

@ -23,7 +23,7 @@ static int usage(const char *arg0) {
" build-exe [source] create executable from source or object files\n"
" build-lib [source] create library from source or object files\n"
" build-obj [source] create object from source or assembly\n"
" parsec [source] convert c code to zig code\n"
" translate-c [source] convert c code to zig code\n"
" targets list available compilation targets\n"
" test [source] create and run a test build\n"
" version print version number and exit\n"
@ -229,7 +229,7 @@ enum Cmd {
CmdTest,
CmdVersion,
CmdZen,
CmdParseC,
CmdTranslateC,
CmdTargets,
};
@ -632,8 +632,8 @@ int main(int argc, char **argv) {
cmd = CmdVersion;
} else if (strcmp(arg, "zen") == 0) {
cmd = CmdZen;
} else if (strcmp(arg, "parsec") == 0) {
cmd = CmdParseC;
} else if (strcmp(arg, "translate-c") == 0) {
cmd = CmdTranslateC;
} else if (strcmp(arg, "test") == 0) {
cmd = CmdTest;
out_type = OutTypeExe;
@ -646,7 +646,7 @@ int main(int argc, char **argv) {
} else {
switch (cmd) {
case CmdBuild:
case CmdParseC:
case CmdTranslateC:
case CmdTest:
if (!in_file) {
in_file = arg;
@ -703,13 +703,13 @@ int main(int argc, char **argv) {
switch (cmd) {
case CmdBuild:
case CmdParseC:
case CmdTranslateC:
case CmdTest:
{
if (cmd == CmdBuild && !in_file && objects.length == 0 && asm_files.length == 0) {
fprintf(stderr, "Expected source file argument or at least one --object or --assembly argument.\n");
return usage(arg0);
} else if ((cmd == CmdParseC || cmd == CmdTest) && !in_file) {
} else if ((cmd == CmdTranslateC || cmd == CmdTest) && !in_file) {
fprintf(stderr, "Expected source file argument.\n");
return usage(arg0);
} else if (cmd == CmdBuild && out_type == OutTypeObj && objects.length != 0) {
@ -719,7 +719,7 @@ int main(int argc, char **argv) {
assert(cmd != CmdBuild || out_type != OutTypeUnknown);
bool need_name = (cmd == CmdBuild || cmd == CmdParseC);
bool need_name = (cmd == CmdBuild || cmd == CmdTranslateC);
Buf *in_file_buf = nullptr;
@ -742,7 +742,7 @@ int main(int argc, char **argv) {
return usage(arg0);
}
Buf *zig_root_source_file = (cmd == CmdParseC) ? nullptr : in_file_buf;
Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;
Buf *full_cache_dir = buf_alloc();
os_path_resolve(buf_create_from_str("."),
@ -841,8 +841,8 @@ int main(int argc, char **argv) {
if (timing_info)
codegen_print_timing_report(g, stdout);
return EXIT_SUCCESS;
} else if (cmd == CmdParseC) {
codegen_parsec(g, in_file_buf);
} else if (cmd == CmdTranslateC) {
codegen_translate_c(g, in_file_buf);
ast_render(g, stdout, g->root_import->root, 4);
if (timing_info)
codegen_print_timing_report(g, stdout);

View File

@ -11,7 +11,7 @@
#include "error.hpp"
#include "ir.hpp"
#include "os.hpp"
#include "parsec.hpp"
#include "translate_c.hpp"
#include "parser.hpp"

View File

@ -18,7 +18,7 @@ const build_examples = @import("build_examples.zig");
const compile_errors = @import("compile_errors.zig");
const assemble_and_link = @import("assemble_and_link.zig");
const debug_safety = @import("debug_safety.zig");
const parsec = @import("parsec.zig");
const translate_c = @import("translate_c.zig");
const TestTarget = struct {
os: builtin.Os,
@ -123,16 +123,16 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
return cases.step;
}
pub fn addParseCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
const cases = %%b.allocator.create(ParseCContext);
*cases = ParseCContext {
pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
const cases = %%b.allocator.create(TranslateCContext);
*cases = TranslateCContext {
.b = b,
.step = b.step("test-parsec", "Run the C header file parsing tests"),
.step = b.step("test-translate-c", "Run the C header file parsing tests"),
.test_index = 0,
.test_filter = test_filter,
};
parsec.addCases(cases);
translate_c.addCases(cases);
return cases.step;
}
@ -770,7 +770,7 @@ pub const BuildExamplesContext = struct {
}
};
pub const ParseCContext = struct {
pub const TranslateCContext = struct {
b: &build.Builder,
step: &build.Step,
test_index: usize,
@ -799,17 +799,17 @@ pub const ParseCContext = struct {
}
};
const ParseCCmpOutputStep = struct {
const TranslateCCmpOutputStep = struct {
step: build.Step,
context: &ParseCContext,
context: &TranslateCContext,
name: []const u8,
test_index: usize,
case: &const TestCase,
pub fn create(context: &ParseCContext, name: []const u8, case: &const TestCase) -> &ParseCCmpOutputStep {
pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {
const allocator = context.b.allocator;
const ptr = %%allocator.create(ParseCCmpOutputStep);
*ptr = ParseCCmpOutputStep {
const ptr = %%allocator.create(TranslateCCmpOutputStep);
*ptr = TranslateCCmpOutputStep {
.step = build.Step.init("ParseCCmpOutput", allocator, make),
.context = context,
.name = name,
@ -821,7 +821,7 @@ pub const ParseCContext = struct {
}
fn make(step: &build.Step) -> %void {
const self = @fieldParentPtr(ParseCCmpOutputStep, "step", step);
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
const b = self.context.b;
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
@ -829,7 +829,7 @@ pub const ParseCContext = struct {
var zig_args = ArrayList([]const u8).init(b.allocator);
%%zig_args.append(b.zig_exe);
%%zig_args.append("parsec");
%%zig_args.append("translate-c");
%%zig_args.append(b.pathFromRoot(root_src));
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
@ -882,7 +882,7 @@ pub const ParseCContext = struct {
if (stderr.len != 0 and !self.case.allow_warnings) {
warn(
\\====== parsec emitted warnings: ============
\\====== translate-c emitted warnings: =======
\\{}
\\============================================
\\
@ -914,7 +914,7 @@ pub const ParseCContext = struct {
warn("\n");
}
pub fn create(self: &ParseCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
source: []const u8, expected_lines: ...) -> &TestCase
{
const tc = %%self.b.allocator.create(TestCase);
@ -932,37 +932,37 @@ pub const ParseCContext = struct {
return tc;
}
pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
pub fn add(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
const tc = self.create(false, "source.h", name, source, expected_lines);
self.addCase(tc);
}
pub fn addC(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
pub fn addC(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
const tc = self.create(false, "source.c", name, source, expected_lines);
self.addCase(tc);
}
pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
pub fn addAllowWarnings(self: &TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) {
const tc = self.create(true, "source.h", name, source, expected_lines);
self.addCase(tc);
}
pub fn addCase(self: &ParseCContext, case: &const TestCase) {
pub fn addCase(self: &TranslateCContext, case: &const TestCase) {
const b = self.b;
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parsec {}", case.name);
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "translate-c {}", case.name);
if (self.test_filter) |filter| {
if (mem.indexOf(u8, annotated_case_name, filter) == null)
return;
}
const parsec_and_cmp = ParseCCmpOutputStep.create(self, annotated_case_name, case);
self.step.dependOn(&parsec_and_cmp.step);
const translate_c_and_cmp = TranslateCCmpOutputStep.create(self, annotated_case_name, case);
self.step.dependOn(&translate_c_and_cmp.step);
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
parsec_and_cmp.step.dependOn(&write_src.step);
translate_c_and_cmp.step.dependOn(&write_src.step);
}
}
};

View File

@ -1,6 +1,6 @@
const tests = @import("tests.zig");
pub fn addCases(cases: &tests.ParseCContext) {
pub fn addCases(cases: &tests.TranslateCContext) {
cases.addAllowWarnings("simple data types",
\\#include <stdint.h>
\\int foo(char a, unsigned char b, signed char c);