rename parseh to parsec
parent
48c44615a4
commit
2c9bdad346
|
@ -193,7 +193,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/parseh.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/parsec.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
|
||||
)
|
||||
|
||||
|
|
|
@ -19,5 +19,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.addParseHTests(b, test_filter));
|
||||
test_step.dependOn(tests.addParseCTests(b, test_filter));
|
||||
}
|
||||
|
|
|
@ -15,4 +15,4 @@ make install
|
|||
# we have to skip cross compiling OSX tests because apt.llvm.org has an old version
|
||||
# of llvm for the version of ubuntu that travis is running on.
|
||||
./zig build --build-file ../build.zig test-behavior test-std test-compiler-rt -Dtest-filter=linux
|
||||
./zig build --build-file ../build.zig test-compare-output test-build-examples test-compile-errors test-asm-link test-debug-safety test-parseh
|
||||
./zig build --build-file ../build.zig test-compare-output test-build-examples test-compile-errors test-asm-link test-debug-safety test-parsec
|
||||
|
|
|
@ -26,7 +26,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
|
|||
static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
|
||||
|
||||
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
|
||||
// if this assert fails, then parseh generated code that
|
||||
// if this assert fails, then parsec generated code that
|
||||
// failed semantic analysis, which isn't supposed to happen
|
||||
assert(!node->owner->c_import_node);
|
||||
|
||||
|
@ -38,7 +38,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 this assert fails, then parseh generated code that
|
||||
// if this assert fails, then parsec generated code that
|
||||
// failed semantic analysis, which isn't supposed to happen
|
||||
assert(!node->owner->c_import_node);
|
||||
|
||||
|
@ -1265,7 +1265,6 @@ TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, Type
|
|||
}
|
||||
|
||||
static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
|
||||
// if you change this logic you likely must also change similar logic in parseh.cpp
|
||||
assert(enum_type->id == TypeTableEntryIdEnum);
|
||||
|
||||
if (enum_type->data.enumeration.complete)
|
||||
|
@ -1578,8 +1577,6 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
|
|||
}
|
||||
|
||||
static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
|
||||
// if you change the logic of this function likely you must make a similar change in
|
||||
// parseh.cpp
|
||||
assert(struct_type->id == TypeTableEntryIdStruct);
|
||||
|
||||
if (struct_type->data.structure.complete)
|
||||
|
@ -3079,8 +3076,6 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
|
|||
continue;
|
||||
}
|
||||
|
||||
// Note: target_tld->name is not necessarily equal to entry->key because
|
||||
// of aliases that parseh uses.
|
||||
Buf *target_tld_name = entry->key;
|
||||
|
||||
auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "ir.hpp"
|
||||
#include "link.hpp"
|
||||
#include "os.hpp"
|
||||
#include "parseh.hpp"
|
||||
#include "parsec.hpp"
|
||||
#include "target.hpp"
|
||||
#include "zig_llvm.hpp"
|
||||
|
||||
|
@ -5001,7 +5001,7 @@ static void init(CodeGen *g) {
|
|||
define_builtin_compile_vars(g);
|
||||
}
|
||||
|
||||
void codegen_parseh(CodeGen *g, Buf *full_path) {
|
||||
void codegen_parsec(CodeGen *g, Buf *full_path) {
|
||||
find_libc_include_path(g);
|
||||
|
||||
Buf *src_basename = buf_alloc();
|
||||
|
|
|
@ -54,7 +54,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_parseh(CodeGen *g, Buf *path);
|
||||
void codegen_parsec(CodeGen *g, Buf *path);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "ir.hpp"
|
||||
#include "ir_print.hpp"
|
||||
#include "os.hpp"
|
||||
#include "parseh.hpp"
|
||||
#include "parsec.hpp"
|
||||
#include "quadmath.hpp"
|
||||
#include "range_set.hpp"
|
||||
|
||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -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"
|
||||
" parseh [source] convert a c header file to zig extern declarations\n"
|
||||
" parsec [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"
|
||||
|
@ -132,7 +132,7 @@ enum Cmd {
|
|||
CmdTest,
|
||||
CmdVersion,
|
||||
CmdZen,
|
||||
CmdParseH,
|
||||
CmdParseC,
|
||||
CmdTargets,
|
||||
};
|
||||
|
||||
|
@ -470,8 +470,8 @@ int main(int argc, char **argv) {
|
|||
cmd = CmdVersion;
|
||||
} else if (strcmp(arg, "zen") == 0) {
|
||||
cmd = CmdZen;
|
||||
} else if (strcmp(arg, "parseh") == 0) {
|
||||
cmd = CmdParseH;
|
||||
} else if (strcmp(arg, "parsec") == 0) {
|
||||
cmd = CmdParseC;
|
||||
} else if (strcmp(arg, "test") == 0) {
|
||||
cmd = CmdTest;
|
||||
out_type = OutTypeExe;
|
||||
|
@ -484,7 +484,7 @@ int main(int argc, char **argv) {
|
|||
} else {
|
||||
switch (cmd) {
|
||||
case CmdBuild:
|
||||
case CmdParseH:
|
||||
case CmdParseC:
|
||||
case CmdTest:
|
||||
if (!in_file) {
|
||||
in_file = arg;
|
||||
|
@ -541,13 +541,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
switch (cmd) {
|
||||
case CmdBuild:
|
||||
case CmdParseH:
|
||||
case CmdParseC:
|
||||
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 == CmdParseH || cmd == CmdTest) && !in_file) {
|
||||
} else if ((cmd == CmdParseC || cmd == CmdTest) && !in_file) {
|
||||
fprintf(stderr, "Expected source file argument.\n");
|
||||
return usage(arg0);
|
||||
} else if (cmd == CmdBuild && out_type == OutTypeObj && objects.length != 0) {
|
||||
|
@ -557,7 +557,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
assert(cmd != CmdBuild || out_type != OutTypeUnknown);
|
||||
|
||||
bool need_name = (cmd == CmdBuild || cmd == CmdParseH);
|
||||
bool need_name = (cmd == CmdBuild || cmd == CmdParseC);
|
||||
|
||||
Buf *in_file_buf = nullptr;
|
||||
|
||||
|
@ -580,7 +580,7 @@ int main(int argc, char **argv) {
|
|||
return usage(arg0);
|
||||
}
|
||||
|
||||
Buf *zig_root_source_file = (cmd == CmdParseH) ? nullptr : in_file_buf;
|
||||
Buf *zig_root_source_file = (cmd == CmdParseC) ? nullptr : in_file_buf;
|
||||
|
||||
Buf *full_cache_dir = buf_alloc();
|
||||
os_path_resolve(buf_create_from_str("."),
|
||||
|
@ -668,8 +668,8 @@ int main(int argc, char **argv) {
|
|||
if (timing_info)
|
||||
codegen_print_timing_report(g, stdout);
|
||||
return EXIT_SUCCESS;
|
||||
} else if (cmd == CmdParseH) {
|
||||
codegen_parseh(g, in_file_buf);
|
||||
} else if (cmd == CmdParseC) {
|
||||
codegen_parsec(g, in_file_buf);
|
||||
ast_render(g, stdout, g->root_import->root, 4);
|
||||
if (timing_info)
|
||||
codegen_print_timing_report(g, stdout);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "error.hpp"
|
||||
#include "ir.hpp"
|
||||
#include "os.hpp"
|
||||
#include "parseh.hpp"
|
||||
#include "parsec.hpp"
|
||||
#include "parser.hpp"
|
||||
|
||||
|
||||
|
@ -2250,10 +2250,10 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
|
|||
clang_argv.append("c");
|
||||
|
||||
if (c->codegen->is_native_target) {
|
||||
char *ZIG_PARSEH_CFLAGS = getenv("ZIG_NATIVE_PARSEH_CFLAGS");
|
||||
if (ZIG_PARSEH_CFLAGS) {
|
||||
char *ZIG_PARSEC_CFLAGS = getenv("ZIG_NATIVE_PARSEC_CFLAGS");
|
||||
if (ZIG_PARSEC_CFLAGS) {
|
||||
Buf tmp_buf = BUF_INIT;
|
||||
char *start = ZIG_PARSEH_CFLAGS;
|
||||
char *start = ZIG_PARSEC_CFLAGS;
|
||||
char *space = strstr(start, " ");
|
||||
while (space) {
|
||||
if (space - start > 0) {
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef ZIG_PARSEH_HPP
|
||||
#define ZIG_PARSEH_HPP
|
||||
#ifndef ZIG_PARSEC_HPP
|
||||
#define ZIG_PARSEC_HPP
|
||||
|
||||
#include "all_types.hpp"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: &tests.ParseHContext) {
|
||||
pub fn addCases(cases: &tests.ParseCContext) {
|
||||
cases.addAllowWarnings("simple data types",
|
||||
\\#include <stdint.h>
|
||||
\\int foo(char a, unsigned char b, signed char c);
|
|
@ -17,7 +17,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 parseh = @import("parseh.zig");
|
||||
const parsec = @import("parsec.zig");
|
||||
|
||||
const TestTarget = struct {
|
||||
os: builtin.Os,
|
||||
|
@ -115,16 +115,16 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
|
|||
return cases.step;
|
||||
}
|
||||
|
||||
pub fn addParseHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(ParseHContext);
|
||||
*cases = ParseHContext {
|
||||
pub fn addParseCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(ParseCContext);
|
||||
*cases = ParseCContext {
|
||||
.b = b,
|
||||
.step = b.step("test-parseh", "Run the C header file parsing tests"),
|
||||
.step = b.step("test-parsec", "Run the C header file parsing tests"),
|
||||
.test_index = 0,
|
||||
.test_filter = test_filter,
|
||||
};
|
||||
|
||||
parseh.addCases(cases);
|
||||
parsec.addCases(cases);
|
||||
|
||||
return cases.step;
|
||||
}
|
||||
|
@ -752,7 +752,7 @@ pub const BuildExamplesContext = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub const ParseHContext = struct {
|
||||
pub const ParseCContext = struct {
|
||||
b: &build.Builder,
|
||||
step: &build.Step,
|
||||
test_index: usize,
|
||||
|
@ -781,18 +781,18 @@ pub const ParseHContext = struct {
|
|||
}
|
||||
};
|
||||
|
||||
const ParseHCmpOutputStep = struct {
|
||||
const ParseCCmpOutputStep = struct {
|
||||
step: build.Step,
|
||||
context: &ParseHContext,
|
||||
context: &ParseCContext,
|
||||
name: []const u8,
|
||||
test_index: usize,
|
||||
case: &const TestCase,
|
||||
|
||||
pub fn create(context: &ParseHContext, name: []const u8, case: &const TestCase) -> &ParseHCmpOutputStep {
|
||||
pub fn create(context: &ParseCContext, name: []const u8, case: &const TestCase) -> &ParseCCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(ParseHCmpOutputStep);
|
||||
*ptr = ParseHCmpOutputStep {
|
||||
.step = build.Step.init("ParseHCmpOutput", allocator, make),
|
||||
const ptr = %%allocator.create(ParseCCmpOutputStep);
|
||||
*ptr = ParseCCmpOutputStep {
|
||||
.step = build.Step.init("ParseCCmpOutput", allocator, make),
|
||||
.context = context,
|
||||
.name = name,
|
||||
.test_index = context.test_index,
|
||||
|
@ -803,13 +803,13 @@ pub const ParseHContext = struct {
|
|||
}
|
||||
|
||||
fn make(step: &build.Step) -> %void {
|
||||
const self = @fieldParentPtr(ParseHCmpOutputStep, "step", step);
|
||||
const self = @fieldParentPtr(ParseCCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
%%zig_args.append("parseh");
|
||||
%%zig_args.append("parsec");
|
||||
%%zig_args.append(b.pathFromRoot(root_src));
|
||||
|
||||
%%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
@ -855,7 +855,7 @@ pub const ParseHContext = struct {
|
|||
|
||||
if (stderr.len != 0 and !self.case.allow_warnings) {
|
||||
%%io.stderr.printf(
|
||||
\\====== parseh emitted warnings: ============
|
||||
\\====== parsec emitted warnings: ============
|
||||
\\{}
|
||||
\\============================================
|
||||
\\
|
||||
|
@ -888,7 +888,7 @@ pub const ParseHContext = struct {
|
|||
%%io.stderr.printf("\n");
|
||||
}
|
||||
|
||||
pub fn create(self: &ParseHContext, allow_warnings: bool, name: []const u8,
|
||||
pub fn create(self: &ParseCContext, allow_warnings: bool, name: []const u8,
|
||||
source: []const u8, expected_lines: ...) -> &TestCase
|
||||
{
|
||||
const tc = %%self.b.allocator.create(TestCase);
|
||||
|
@ -906,32 +906,32 @@ pub const ParseHContext = struct {
|
|||
return tc;
|
||||
}
|
||||
|
||||
pub fn add(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
||||
pub fn add(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
||||
const tc = self.create(false, name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addAllowWarnings(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
||||
pub fn addAllowWarnings(self: &ParseCContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
||||
const tc = self.create(true, name, source, expected_lines);
|
||||
self.addCase(tc);
|
||||
}
|
||||
|
||||
pub fn addCase(self: &ParseHContext, case: &const TestCase) {
|
||||
pub fn addCase(self: &ParseCContext, case: &const TestCase) {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parseh {}", case.name);
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parsec {}", case.name);
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
}
|
||||
|
||||
const parseh_and_cmp = ParseHCmpOutputStep.create(self, annotated_case_name, case);
|
||||
self.step.dependOn(&parseh_and_cmp.step);
|
||||
const parsec_and_cmp = ParseCCmpOutputStep.create(self, annotated_case_name, case);
|
||||
self.step.dependOn(&parsec_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);
|
||||
parseh_and_cmp.step.dependOn(&write_src.step);
|
||||
parsec_and_cmp.step.dependOn(&write_src.step);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue