llvm-native-core 0.1.11

LLVM-native core semantic engine — IR, CodeGen, X86 MC, Clang frontend pipeline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
//! Clang Frontend — C/C++ compiler frontend for LLVM-native.
//! Clean-room behavioral reconstruction from the C11/C17 and C++17
//! standards (ISO/IEC 9899:2011/2018, ISO/IEC 14882:2017) and
//! published Clang documentation.
//!
//! Components:
//! - Lexer: tokenizes C source into tokens
//! - Preprocessor: handles #include, #define, #ifdef, macros
//! - Parser: recursive-descent C parser producing AST
//! - AST: complete C abstract syntax tree types
//! - Sema: semantic analysis, type checking, scope management
//! - CodeGen: AST → LLVM IR lowering
//! - Driver: compiler driver (cc1-like)
//!
//! C++ extensions:
//! - cpp_ast: C++ AST types (classes, templates, operators, etc.)
//! - cpp_parser: C++ recursive-descent parser
//! - cpp_sema: C++ semantic analysis (access, templates, overloading)
//! - cpp_codegen: C++ IR lowering (vtables, RTTI, EH, new/delete)
//! - cpp_token: C++ token types (keywords, operators, alternative tokens)
//! - cpp_lexer: C++ lexer extensions (raw strings, UDLs, digraphs)
//! - cpp_driver: C++ compiler driver (clang++-style interface)
//! - name_mangling: Itanium C++ ABI name mangling
//! - vtable: Vtable layout and emission
//! - rtti: Run-Time Type Information
//! - exception: C++ exception handling (try/catch/throw lowering)
//! - template: Template instantiation engine
//! - overload: Overload resolution
//! - coroutines_cpp: C++20 coroutine lowering
//! - cpp_modules: C++20 modules support
//!
//! Note: All modules previously disabled have been replaced with full
//! `_x86` or `_deep` implementations.

// ── C Frontend Core ───────────────────────────────────────────────────────
pub mod ast;
pub mod clang_abi_bridge;
pub mod clang_ast_import;
pub mod clang_libc;
pub mod clang_main;
pub mod clang_module_loader;
pub mod clang_pipeline;
pub mod clang_sema_checks;
pub mod clang_sysroot;
pub mod clang_target;
pub mod codegen;
pub mod diagnostics;
pub mod driver;
pub mod lexer;
pub mod libclang;
pub mod parser;
pub mod preprocessor;
pub mod sema;
pub mod token;

// ── Re-exports ───────────────────────────────────────────────────────────

pub use diagnostics::DiagnosticEngine as Diagnostics;
pub use driver::{ClangDriver, CompileCommand};
pub use lexer::{SourceLocation, SourceManager};
pub use preprocessor::{MacroDefinition, PreprocessorState};

// Re-export from extended x86 pipeline modules
pub use clang_compiler_service_x86::CompilationDatabase;

// ── C Frontend Deep/Extended ──────────────────────────────────────────────
pub mod clang_builtin_headers_x86;
pub mod clang_codecomplete_deep;
pub mod clang_codecomplete_x86;
pub mod clang_compile_bench;
pub mod clang_deep_cxx;
pub mod clang_deep_lexer;
pub mod clang_deep_sema_final;
pub mod clang_deep_sema_fix_x86;
pub mod clang_deep_sema_x86;
pub mod clang_diagnostics_x86;
pub mod clang_driver_jobs_x86;
pub mod clang_embedded_x86;
pub mod clang_header_search_x86;
pub mod clang_libcxx_full_x86;
pub mod clang_modules_full_x86;
pub mod clang_parse_ast_test_x86;
pub mod clang_parser_deep;
pub mod clang_pch_modules_x86;
pub mod clang_pipeline_x86;
pub mod clang_preprocessor_deep;
pub mod clang_preprocessor_x86;
pub mod clang_projects_combined_x86;
pub mod clang_refactor_x86;
pub mod clang_serialization_x86;
pub mod clang_stl_full_x86;
pub mod clang_sysroot_x86;
pub mod clang_test_harness_x86;
pub mod clang_toolchain_x86;
pub mod clang_tooling_full_x86;
pub mod clang_tools_full_x86;

// ── C++ Frontend Core ─────────────────────────────────────────────────────
pub mod constexpr;
pub mod coroutines_cpp;
pub mod cpp_ast;
pub mod cpp_codegen;
pub mod cpp_driver;
pub mod cpp_lexer;
pub mod cpp_modules;
pub mod cpp_parser;
pub mod cpp_token;
pub mod exception;
pub mod name_mangling;
pub mod overload;
pub mod rtti;
pub mod template;
pub mod vtable;

// ── C++ Frontend Deep/Extended ────────────────────────────────────────────
pub mod clang_cxx23_26_x86;

// ── X86 Golden Path Integration ───────────────────────────────────────────
pub mod clang_e2e_pipeline;
pub mod clang_static_analyzer_x86;
pub mod clang_x86_codegen_full;
pub mod clang_x86_driver_full;
pub mod clang_x86_pipeline;
pub mod static_analyzer_x86;

// ── Clang Tools & Services ────────────────────────────────────────────────
pub mod clang_analysis_deep;
pub mod clang_analyzer_checkers_deep;
pub mod clang_build_systems_x86;
pub mod clang_compiler_service_x86;
pub mod clang_diag_renderer_x86;
pub mod clang_doc_x86;
pub mod clang_fixit_engine_x86;
pub mod clang_package_managers_x86;

// ── Cross-Domain Support ──────────────────────────────────────────────────
pub mod clang_cloud_x86;
pub mod clang_concurrency_x86;
pub mod clang_database_x86;
pub mod clang_games_x86;
pub mod clang_golden_bridge;
pub mod clang_golden_path_tests;
pub mod clang_gui_x86;
pub mod clang_interop_x86;
pub mod clang_multimedia_x86;
pub mod clang_networking_x86;
pub mod clang_self_host_validation;
pub mod clang_selfhost;
pub mod clang_selfhost2;
pub mod clang_selfhost_x86;
pub mod clang_wasm_types;
pub mod clang_webassembly_x86;
pub mod clang_x86_e2e_pipeline_full;
pub mod clang_x86_e2e_tests;

// ── X86 Analysis Deep Re-exports ────────────────────────────────────────
pub use clang_analysis_deep::{
    make_test_cfg,
    make_x86_analysis_deep,
    run_x86_analysis_deep,
    run_x86_analysis_deep_plist,
    run_x86_analysis_deep_sarif,
    x86_analysis_checker_names,
    AddrSinkAnalysis,
    AlphaCPlusPlusDeleteChecker,
    AlphaCPlusPlusEnumCastChecker,
    AlphaCPlusPlusIteratorChecker,
    AlphaCPlusPlusMoveChecker,
    AlphaCPlusPlusSmartPtrChecker,
    AlphaSecurityArrayBoundChecker,
    AlphaSecurityMallocChecker,
    AlphaSecurityRetValChecker,
    AlphaSecurityTaintChecker,
    AlphaUnixChrootChecker,
    AlphaUnixCstringChecker,
    AlphaUnixPthreadChecker,
    AlphaUnixSimpleStreamChecker,
    AlphaUnixStreamChecker,
    AnalysisBlock,
    AnalysisCFG,
    AnalysisConfig,
    AnalysisConsumer,
    AnalysisOutputFormat,
    AnalysisStmt,
    // All 38 alpha/optin checkers
    BoolAssignmentChecker,
    BugCategory,
    BugOnConstraint,
    BugReport,
    BugSeverity,
    CallAndMessageChecker,
    CallSite,
    Checker,
    ConjuredKind,
    Constraint,
    ConstraintSolver,
    DivZeroChecker,
    DynamicTypeChecker,
    ExplodedGraph,
    ExplodedNode,
    GraphStats,
    IdenticalExprChecker,
    InlineConfig,
    NullDereferenceChecker,
    NullabilityConstraint,
    OptinAndroidChecker,
    OptinFuchsiaChecker,
    OptinMPIChecker,
    OptinOSXAPI,
    OptinOSXCocoa,
    OptinOpenMPChecker,
    OptinPerformanceFasterStringFind,
    OptinPerformancePaddingChecker,
    OptinPortabilityEndianChecker,
    OptinWebKitChecker,
    PlistConfig,
    ProgramPoint,
    ProgramPointKind,
    ProgramState,
    RangeConstraint,
    ReturnPointerRangeChecker,
    ReturnStackAddressChecker,
    SarifConfig,
    SizeofPointerChecker,
    // SourceLocation already re-exported from lexer
    StackAddrLeakChecker,
    SymConjured,
    SymExpr,
    SymRegion,
    SymbolicExecutionEngine,
    TaintConstraint,
    TaintPropagation,
    TaintSource,
    UndefResultChecker,
    UninitializedObjectChecker,
    UnsafeBufferUsageChecker,
    VLASizeChecker,
    WorklistStrategy,
    X86AnalysisDeep,
};

// ── C Frontend Re-exports ───────────────────────────────────────────────
pub use ast::*;
pub use codegen::{compile_c, ClangCodeGen};
pub use diagnostics::{
    ClangSourceLocation, DiagID, DiagMapping, DiagSeverity, DiagState, DiagnosticBuilder,
    DiagnosticConsumer, DiagnosticEngine, DiagnosticNote, DiagnosticOptions,
    DiagnosticOutputFormat, DiagnosticRenderer, ErrorMessageCatalog, FixItHint, SourceRange,
    StructuredDiagnostic, TextDiagnosticPrinter, WarningGroupRegistry,
};
use driver::{compile_c_file, compile_c_string, compile_c_to_assembly};
pub use lexer::Lexer;
pub use libclang::*;
pub use parser::Parser;
pub use preprocessor::Preprocessor;
pub use sema::Sema;
pub use token::{Token, TokenKind};

// ── Type aliases for commonly-used names ──────────────────────────────────
// (these are already re-exported above)
pub use diagnostics::{ClangSourceFile, ClangSourceManager};
pub use lexer::SourceLocation as LexerSourceLocation;
pub use preprocessor::MacroDef;

// ── Pipeline re-exports ───────────────────────────────────────────────────
pub use clang_pipeline::{CodeModel, PipelineResult, RelocModel};

// ── C++ Frontend Re-exports ─────────────────────────────────────────────
pub use constexpr::{ConstEvalError, ConstExprEvaluator, ConstValue};
pub use coroutines_cpp::{CoroutineFrame, CoroutineLowering, CoroutineState, PromiseTypeDesc};
pub use cpp_ast::{
    BaseSpecifier, CXXCompoundStmt, CXXDecl, CXXExpr, CXXMemberDecl, CXXName, CXXOperator,
    CXXParamDecl, CXXRecordKind, CXXStmt, CXXTranslationUnit, CtorInit, EnumConstant,
    LambdaCapture, NestedNameSpecifier, TemplateParamDecl,
};
pub use cpp_codegen::CXXCodeGen;
pub use cpp_driver::{compile_cpp_source, compile_cpp_with_options, CXXDriver, CXXStdLib};
pub use cpp_lexer::CppLexer;
pub use cpp_modules::{ModuleDecl as CppModuleDecl, ModuleImport, ModuleMap, ModuleName};
pub use cpp_parser::{parse_cpp, CppParser};
pub use cpp_token::{
    cpp_keyword_lookup, AccessSpecifier as CppAccessSpecifier, CppStandard, CppTokenKind,
};
pub use exception::{EHCodeGen, PersonalityKind, ITANIUM_PERSONALITY_FN, LSDA};
pub use name_mangling::{demangle, mangle_simple_function, MangledName, Mangler};
pub use overload::{CandidateRank, CandidateViability, OverloadCandidate, OverloadResolver};
pub use rtti::{RttiBuilder, RttiDescriptor, RttiKind};
pub use template::{DeductionResult, TemplateDeductor, TemplateInstantiator};
pub use vtable::{ThunkGenerator, VtableBuilder, VtableEntry, VtableLayout};

// ── X86 Deep Sema Re-exports ────────────────────────────────────────────
pub use clang_deep_sema_x86::{
    analyze_x86_function, analyze_x86_tu, contains_x86_message, make_x86_32_deep_sema,
    make_x86_64_deep_sema, x86_assign, x86_binary, x86_call, x86_compound, x86_ident, x86_int_lit,
    x86_make_function, x86_make_tu, x86_make_variable, x86_return, X86ConstExprError,
    X86ConstValue, X86ConstexprEval, X86ConvKind, X86ConversionRank, X86ConversionResult,
    X86DeclValidator, X86DeepSema, X86DiagCategory, X86DiagNote, X86DiagSeverity, X86Diagnostic,
    X86DiagnosticEmitter, X86ExprValidator, X86FixIt, X86ImplicitConversion, X86InstantiationDepth,
    X86LookupPhase, X86NameDependence, X86OverloadCandidate, X86OverloadResolution, X86ScopeEntry,
    X86ScopeKind, X86ScopeManager, X86TemplateParam, X86TemplateSema, X86TypePromotion,
    X86ValueCategory, X86_LP64_INT_SIZE, X86_LP64_LONG_SIZE, X86_LP64_POINTER_SIZE,
};

// ── X86 Deep Sema Final Re-exports ─────────────────────────────────────
pub use clang_deep_sema_final::{
    analyze_x86_tu_final, make_x86_32_deep_sema_final, make_x86_64_cxx17_deep_sema_final,
    make_x86_64_deep_sema_final, x86_depth_stats, x86_eval_constexpr_final, X86ConceptChecker,
    X86ConceptDef, X86ConceptResult, X86ConstexprStats, X86DeepSemaFinal, X86DeferredName,
    X86DeferredNameKind, X86DependentNameResolver, X86DepthStats, X86DepthTracker,
    X86EnhancedScope, X86EnhancedScopeEntry, X86EnhancedScopeKind, X86EnhancedScopeManager,
    X86FinalConstExprError, X86FinalConstValue, X86FinalConstexprEval, X86FinalDependence,
    X86InstantiationFrame, X86InstantiationKind, X86SfinaeContext, X86SfinaeError,
    X86SfinaeHandler, X86SfinaeSeverity, X86TwoPhaseLookup, X86TwoPhaseResult,
    X86_MAX_CONSTEXPR_DEPTH, X86_MAX_CONSTEXPR_STEPS, X86_MAX_SFINAE_CONTEXTS,
    X86_MAX_TEMPLATE_DEPTH,
};

// ── X86 Parse/AST Test Re-exports ───────────────────────────────────────
pub use clang_parse_ast_test_x86::{
    compare_x86_ast, pretty_print_x86_ast, run_x86_parse_ast_tests, test_x86_ast_roundtrip,
    X86AstComparator, X86AstNodeKind, X86AstPrettyPrinter, X86AstSerializer,
    X86AstVerificationResult, X86CSnippets, X86CppSnippets, X86ExpectedAstNode, X86ParseASTTest,
};

// ── X86 Clang Pipeline Re-exports ───────────────────────────────────────
pub use clang_pipeline_x86::{
    make_x86_32_pipeline, make_x86_release_pipeline, x86_clang_compile,
    x86_clang_compile_stop_after, x86_clang_compile_with_opts, X86ClangCompileOptions,
    X86ClangDiagLevel, X86ClangDiagnostic, X86ClangDiagnosticEngine, X86ClangPipeline,
    X86ClangResult, X86ClangStage, X86ClangStageResult, X86ClangStats, X86IncrementalTracker,
};

// ── X86 Deep Checkers Re-exports ────────────────────────────────────────
pub use clang_analyzer_checkers_deep::{
    make_x86_deep_checkers, run_x86_checker, run_x86_deep_checkers, x86_checker_names,
    X86AutosarChecker, X86BugproneChecker, X86CertCChecker, X86CertCppChecker, X86CheckerCategory,
    X86CheckerConfig, X86CheckerDependency, X86CheckerDependencyManager, X86CheckerFinding,
    X86CheckerResult, X86CheckerSeverity, X86CheckerSuppression, X86CheckerToggle,
    X86ConcurrencyChecker, X86CoreGuidelinesChecker, X86DeepCheckers, X86DocumentationChecker,
    X86MisraCChecker, X86ModernizeChecker, X86PerformanceChecker, X86PortabilityChecker,
    X86ReadabilityChecker, X86SecurityChecker,
};

// Target-specific re-exports
pub use clang_target::{
    create_aarch64_machine, create_arm_machine, create_riscv32_machine, create_riscv64_machine,
    create_target_machine, create_x86_64_machine, data_layout_for_triple, ClangABI, ClangOptLevel,
    ClangTargetInfo, CpuFeatureDatabase, DebugInfoKind, FunctionAttrMapper, HostCpuDetector,
    StackProtectorLevel, TargetCodeGenInfo, TargetFlags,
};

/// C language standard versions.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CLangStandard {
    C89,
    C99,
    C11,
    C17,
    C23,
    Gnu89,
    Gnu99,
    Gnu11,
    Gnu17,
}

impl Default for CLangStandard {
    fn default() -> Self {
        CLangStandard::C17
    }
}

impl CLangStandard {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::C89 => "c89",
            Self::C99 => "c99",
            Self::C11 => "c11",
            Self::C17 => "c17",
            Self::C23 => "c23",
            Self::Gnu89 => "gnu89",
            Self::Gnu99 => "gnu99",
            Self::Gnu11 => "gnu11",
            Self::Gnu17 => "gnu17",
        }
    }

    pub fn from_str(s: &str) -> Option<Self> {
        match s {
            "c89" | "c90" => Some(Self::C89),
            "c99" => Some(Self::C99),
            "c11" => Some(Self::C11),
            "c17" | "c18" => Some(Self::C17),
            "c23" | "c2x" => Some(Self::C23),
            "gnu89" => Some(Self::Gnu89),
            "gnu99" => Some(Self::Gnu99),
            "gnu11" => Some(Self::Gnu11),
            "gnu17" => Some(Self::Gnu17),
            _ => None,
        }
    }

    pub fn is_gnu(&self) -> bool {
        matches!(self, Self::Gnu89 | Self::Gnu99 | Self::Gnu11 | Self::Gnu17)
    }

    pub fn has_bool(&self) -> bool {
        matches!(
            self,
            Self::C99 | Self::C11 | Self::C17 | Self::C23 | Self::Gnu99 | Self::Gnu11 | Self::Gnu17
        )
    }

    pub fn has_long_long(&self) -> bool {
        matches!(
            self,
            Self::C99 | Self::C11 | Self::C17 | Self::C23 | Self::Gnu99 | Self::Gnu11 | Self::Gnu17
        )
    }
}

/// Compiler warnings and flags.
#[derive(Debug, Clone)]
pub struct ClangOptions {
    pub standard: CLangStandard,
    pub optimize: bool,
    pub debug_info: bool,
    pub warnings: bool,
    pub pedantic: bool,
    pub wall: bool,
    pub werror: bool,
    pub verbose: bool,
    pub includes: Vec<String>,
    pub defines: Vec<(String, Option<String>)>,
    pub output_file: Option<String>,
    pub target_triple: String,
}

impl Default for ClangOptions {
    fn default() -> Self {
        Self {
            standard: CLangStandard::C17,
            optimize: true,
            debug_info: false,
            warnings: true,
            pedantic: false,
            wall: false,
            werror: false,
            verbose: false,
            includes: Vec::new(),
            defines: Vec::new(),
            output_file: None,
            target_triple: "x86_64-unknown-linux-gnu".into(),
        }
    }
}