mirror of
https://github.com/Colton1skees/Dna
synced 2026-06-21 13:42:09 +00:00
Implement missing atomic intrinsics; Implement missing nodes in ast conversion code
This commit is contained in:
@@ -61,9 +61,12 @@ namespace Dna.BinaryTranslator.Unsafe
|
||||
{
|
||||
var writePrefix = "__remill_write_memory_";
|
||||
var readPrefix = "__remill_read_memory";
|
||||
var atomicBeginPrefix = "__remill_atomic_begin";
|
||||
var atomicEndPrefix = "__remill_atomic_end";
|
||||
var atomicBarrierPrefix = "__remill_barrier_store_load";
|
||||
|
||||
var memFunctions = module.GetFunctions()
|
||||
.Where(x => x.Name.Contains(writePrefix) || x.Name.Contains(readPrefix))
|
||||
.Where(x => x.Name.Contains(writePrefix) || x.Name.Contains(readPrefix) || x.Name.Contains(atomicBeginPrefix) || x.Name.Contains(atomicEndPrefix) || x.Name.Contains(atomicBarrierPrefix))
|
||||
.ToList();
|
||||
|
||||
foreach (var function in memFunctions)
|
||||
@@ -85,7 +88,7 @@ namespace Dna.BinaryTranslator.Unsafe
|
||||
else if (function.Name.Contains(readPrefix))
|
||||
ImplementMemRead(function, localMemPtr);
|
||||
else
|
||||
throw new InvalidOperationException($"Cannot implement memory intrinsic: {function}");
|
||||
ImplementAtomic(function);
|
||||
|
||||
// Mark the function for inlining.
|
||||
LLVMCloning.InlineFunction(function);
|
||||
@@ -130,5 +133,10 @@ namespace Dna.BinaryTranslator.Unsafe
|
||||
var loadValue = builder.BuildLoad2(valueType, loadPointer);
|
||||
builder.BuildRet(loadValue);
|
||||
}
|
||||
|
||||
private void ImplementAtomic(LLVMValueRef function)
|
||||
{
|
||||
builder.BuildRet(function.GetParam(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace Dna.LLVMInterop.API.LLVMBindings.Analysis
|
||||
|
||||
public unsafe static implicit operator LLVMOpaqueMemoryAccess*(MemoryAccess memAccess)
|
||||
{
|
||||
if (memAccess == null)
|
||||
return null;
|
||||
return (LLVMOpaqueMemoryAccess*)memAccess.Handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Dna.Passes
|
||||
CondType.Uge => astCtx.bvuge(op1(), op2()),
|
||||
CondType.Ugt => astCtx.bvugt(op1(), op2()),
|
||||
CondType.Ule => astCtx.bvule(op1(), op2()),
|
||||
//CondType.Ult => astCtx.bvult(op1(), op2()),
|
||||
CondType.Ult => astCtx.bvnot(astCtx.bvuge(op1(), op2())),
|
||||
_ => throw new InvalidOperationException(string.Format("CondType {0} is not valid.", predicate))
|
||||
};
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace Dna.Passes
|
||||
case LLVMOpcode.LLVMZExt:
|
||||
var zxTy = inst.TypeOf;
|
||||
var srcZxTy = inst.GetOperand(0).TypeOf;
|
||||
emit(astCtx.zx(astCtx.bv(zxTy.IntWidth - srcZxTy.IntWidth, zxTy.IntWidth), op1()));
|
||||
emit(astCtx.zx(astCtx.bv(zxTy.IntWidth - srcZxTy.IntWidth, srcZxTy.IntWidth), op1()));
|
||||
break;
|
||||
// If the value is a load inst, create a substitution variable to represent it.
|
||||
// Do the same thing with phi nodes and function calls.
|
||||
|
||||
@@ -57,7 +57,6 @@ namespace Dna.Passes
|
||||
var ast = llvmToTriton.GetAst(inst);
|
||||
|
||||
// TODO: Re-enable size check when the ast size change is pushed up to master
|
||||
Debugger.Break();
|
||||
/*
|
||||
if (ast.astSize > 2000)
|
||||
continue;
|
||||
@@ -170,6 +169,8 @@ namespace Dna.Passes
|
||||
BvultNode ultNode => builder.BuildICmp(LLVMIntPredicate.LLVMIntULT, op1(), op2()),
|
||||
BvsltNode sltNode => builder.BuildICmp(LLVMIntPredicate.LLVMIntSLT, op1(), op2()),
|
||||
BvugtNode bvugtNode => builder.BuildICmp(LLVMIntPredicate.LLVMIntUGT, op1(), op2()),
|
||||
BvuleNode uleNode => builder.BuildICmp(LLVMIntPredicate.LLVMIntULE, op1(), op2()),
|
||||
BvugeNode ugeNode => builder.BuildICmp(LLVMIntPredicate.LLVMIntUGE, op1(), op2()),
|
||||
ExtractNode extractNode => LowerExtract(cache, substitutionMapping, builder, extractNode),
|
||||
BvuremNode uremNode => builder.BuildURem(op1(), op2()),
|
||||
BvudivNode uremNode => builder.BuildUDiv(op1(), op2()),
|
||||
|
||||
+1
-1
Submodule LLVMSharp updated: 3406af09e3...25d21d32da
+1
-1
Submodule TritonTranslator updated: e2b1ad9efc...c86dc54399
Reference in New Issue
Block a user